mirror of
https://github.com/rust-lang/cargo.git
synced 2025-10-01 11:30:39 +00:00
auto merge of #558 : alexcrichton/cargo/issue-553, r=brson
This commit is contained in:
commit
31c4baf8ab
@ -66,6 +66,9 @@ define CARGO_TARGET
|
||||
cargo-$(1): $$(CARGO)
|
||||
"$$(CFG_RUSTC)" -v
|
||||
$$(CARGO) build --target $(1) $$(OPT_FLAG) $$(ARGS)
|
||||
|
||||
test-unit-$(1): $$(CARGO)
|
||||
$$(CARGO) test --target $(1) $$(only)
|
||||
endef
|
||||
$(foreach target,$(CFG_TARGET),$(eval $(call CARGO_TARGET,$(target))))
|
||||
|
||||
@ -76,10 +79,7 @@ $(CARGO): src/snapshots.txt
|
||||
|
||||
# === Tests
|
||||
|
||||
test: test-unit style no-exes
|
||||
|
||||
test-unit: $(CARGO)
|
||||
$(CARGO) test $(only)
|
||||
test: test-unit style no-exes $(foreach target,$(CFG_TARGET),test-unit-$(target))
|
||||
|
||||
style:
|
||||
sh tests/check-style.sh
|
||||
|
@ -22,8 +22,8 @@ pub struct Context<'a, 'b> {
|
||||
pub resolve: &'a Resolve,
|
||||
pub sources: &'a SourceMap<'b>,
|
||||
pub compilation: Compilation,
|
||||
pub env: &'a str,
|
||||
|
||||
env: &'a str,
|
||||
host: Layout,
|
||||
target: Option<Layout>,
|
||||
target_triple: String,
|
||||
|
@ -170,6 +170,15 @@ fn compile<'a, 'b>(targets: &[&'a Target], pkg: &'a Package,
|
||||
|
||||
fn compile_custom(pkg: &Package, cmd: &str,
|
||||
cx: &Context, first: bool) -> CargoResult<Work> {
|
||||
let root = cx.get_package(cx.resolve.root());
|
||||
let profile = root.get_manifest().get_targets().iter()
|
||||
.find(|target| target.get_profile().get_env() == cx.env)
|
||||
.map(|target| target.get_profile());
|
||||
let profile = match profile {
|
||||
Some(profile) => profile,
|
||||
None => return Err(internal(format!("no profile for {}", cx.env)))
|
||||
};
|
||||
|
||||
// TODO: this needs to be smarter about splitting
|
||||
let mut cmd = cmd.split(' ');
|
||||
// TODO: this shouldn't explicitly pass `KindTarget` for dest/deps_dir, we
|
||||
@ -180,7 +189,10 @@ fn compile_custom(pkg: &Package, cmd: &str,
|
||||
let mut p = process(cmd.next().unwrap(), pkg, cx)
|
||||
.env("OUT_DIR", Some(&output))
|
||||
.env("DEPS_DIR", Some(&output))
|
||||
.env("TARGET", Some(cx.target_triple()));
|
||||
.env("TARGET", Some(cx.target_triple()))
|
||||
.env("DEBUG", Some(profile.get_debug().to_string()))
|
||||
.env("OPT_LEVEL", Some(profile.get_opt_level().to_string()))
|
||||
.env("PROFILE", Some(profile.get_env()));
|
||||
for arg in cmd {
|
||||
p = p.arg(arg);
|
||||
}
|
||||
|
@ -78,6 +78,14 @@ commands.
|
||||
directory in which all the output of the dependency's
|
||||
build command was placed. This is useful for picking up
|
||||
things like header files and such from other packages.
|
||||
* `CARGO_MANIFEST_DIR` - The directory containing the manifest for the package
|
||||
being built.
|
||||
* `OPT_LEVEL`, `DEBUG` - values of the corresponding variables for the
|
||||
profile currently being built.
|
||||
* `PROFILE` - name of the profile currently being built (see
|
||||
[profiles][profile]).
|
||||
|
||||
[profile]: manifest.html#the-[profile.*]-sections
|
||||
|
||||
# A complete example
|
||||
|
||||
|
@ -793,6 +793,15 @@ test!(custom_build_env_vars {
|
||||
use std::io::fs::PathExtensions;
|
||||
fn main() {{
|
||||
let _ncpus = os::getenv("NUM_JOBS").unwrap();
|
||||
let debug = os::getenv("DEBUG").unwrap();
|
||||
assert_eq!(debug.as_slice(), "true");
|
||||
|
||||
let opt = os::getenv("OPT_LEVEL").unwrap();
|
||||
assert_eq!(opt.as_slice(), "0");
|
||||
|
||||
let opt = os::getenv("PROFILE").unwrap();
|
||||
assert_eq!(opt.as_slice(), "compile");
|
||||
|
||||
let out = os::getenv("OUT_DIR").unwrap();
|
||||
assert!(out.as_slice().starts_with(r"{0}"));
|
||||
assert!(Path::new(out).is_dir());
|
||||
@ -800,6 +809,11 @@ test!(custom_build_env_vars {
|
||||
let out = os::getenv("DEP_BAR_BAR_OUT_DIR").unwrap();
|
||||
assert!(out.as_slice().starts_with(r"{0}"));
|
||||
assert!(Path::new(out).is_dir());
|
||||
|
||||
let out = os::getenv("CARGO_MANIFEST_DIR").unwrap();
|
||||
let p1 = Path::new(out);
|
||||
let p2 = os::make_absolute(&Path::new(file!()).dir_path().dir_path());
|
||||
assert!(p1 == p2, "{{}} != {{}}", p1.display(), p2.display());
|
||||
}}
|
||||
"#,
|
||||
p.root().join("target").join("native").display()));
|
||||
|
Loading…
x
Reference in New Issue
Block a user