Skip to content

Commit 31c4baf

Browse files
committed
auto merge of #558 : alexcrichton/cargo/issue-553, r=brson
2 parents 0aa3daf + 48399a1 commit 31c4baf

File tree

5 files changed

+40
-6
lines changed

5 files changed

+40
-6
lines changed

Makefile.in

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ define CARGO_TARGET
6666
cargo-$(1): $$(CARGO)
6767
"$$(CFG_RUSTC)" -v
6868
$$(CARGO) build --target $(1) $$(OPT_FLAG) $$(ARGS)
69+
70+
test-unit-$(1): $$(CARGO)
71+
$$(CARGO) test --target $(1) $$(only)
6972
endef
7073
$(foreach target,$(CFG_TARGET),$(eval $(call CARGO_TARGET,$(target))))
7174

@@ -76,10 +79,7 @@ $(CARGO): src/snapshots.txt
7679

7780
# === Tests
7881

79-
test: test-unit style no-exes
80-
81-
test-unit: $(CARGO)
82-
$(CARGO) test $(only)
82+
test: test-unit style no-exes $(foreach target,$(CFG_TARGET),test-unit-$(target))
8383

8484
style:
8585
sh tests/check-style.sh

src/cargo/ops/cargo_rustc/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ pub struct Context<'a, 'b> {
2222
pub resolve: &'a Resolve,
2323
pub sources: &'a SourceMap<'b>,
2424
pub compilation: Compilation,
25+
pub env: &'a str,
2526

26-
env: &'a str,
2727
host: Layout,
2828
target: Option<Layout>,
2929
target_triple: String,

src/cargo/ops/cargo_rustc/mod.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,15 @@ fn compile<'a, 'b>(targets: &[&'a Target], pkg: &'a Package,
170170

171171
fn compile_custom(pkg: &Package, cmd: &str,
172172
cx: &Context, first: bool) -> CargoResult<Work> {
173+
let root = cx.get_package(cx.resolve.root());
174+
let profile = root.get_manifest().get_targets().iter()
175+
.find(|target| target.get_profile().get_env() == cx.env)
176+
.map(|target| target.get_profile());
177+
let profile = match profile {
178+
Some(profile) => profile,
179+
None => return Err(internal(format!("no profile for {}", cx.env)))
180+
};
181+
173182
// TODO: this needs to be smarter about splitting
174183
let mut cmd = cmd.split(' ');
175184
// TODO: this shouldn't explicitly pass `KindTarget` for dest/deps_dir, we
@@ -180,7 +189,10 @@ fn compile_custom(pkg: &Package, cmd: &str,
180189
let mut p = process(cmd.next().unwrap(), pkg, cx)
181190
.env("OUT_DIR", Some(&output))
182191
.env("DEPS_DIR", Some(&output))
183-
.env("TARGET", Some(cx.target_triple()));
192+
.env("TARGET", Some(cx.target_triple()))
193+
.env("DEBUG", Some(profile.get_debug().to_string()))
194+
.env("OPT_LEVEL", Some(profile.get_opt_level().to_string()))
195+
.env("PROFILE", Some(profile.get_env()));
184196
for arg in cmd {
185197
p = p.arg(arg);
186198
}

src/doc/native-build.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ commands.
7878
directory in which all the output of the dependency's
7979
build command was placed. This is useful for picking up
8080
things like header files and such from other packages.
81+
* `CARGO_MANIFEST_DIR` - The directory containing the manifest for the package
82+
being built.
83+
* `OPT_LEVEL`, `DEBUG` - values of the corresponding variables for the
84+
profile currently being built.
85+
* `PROFILE` - name of the profile currently being built (see
86+
[profiles][profile]).
87+
88+
[profile]: manifest.html#the-[profile.*]-sections
8189

8290
# A complete example
8391

tests/test_cargo_compile.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,13 +793,27 @@ test!(custom_build_env_vars {
793793
use std::io::fs::PathExtensions;
794794
fn main() {{
795795
let _ncpus = os::getenv("NUM_JOBS").unwrap();
796+
let debug = os::getenv("DEBUG").unwrap();
797+
assert_eq!(debug.as_slice(), "true");
798+
799+
let opt = os::getenv("OPT_LEVEL").unwrap();
800+
assert_eq!(opt.as_slice(), "0");
801+
802+
let opt = os::getenv("PROFILE").unwrap();
803+
assert_eq!(opt.as_slice(), "compile");
804+
796805
let out = os::getenv("OUT_DIR").unwrap();
797806
assert!(out.as_slice().starts_with(r"{0}"));
798807
assert!(Path::new(out).is_dir());
799808
800809
let out = os::getenv("DEP_BAR_BAR_OUT_DIR").unwrap();
801810
assert!(out.as_slice().starts_with(r"{0}"));
802811
assert!(Path::new(out).is_dir());
812+
813+
let out = os::getenv("CARGO_MANIFEST_DIR").unwrap();
814+
let p1 = Path::new(out);
815+
let p2 = os::make_absolute(&Path::new(file!()).dir_path().dir_path());
816+
assert!(p1 == p2, "{{}} != {{}}", p1.display(), p2.display());
803817
}}
804818
"#,
805819
p.root().join("target").join("native").display()));

0 commit comments

Comments
 (0)