use util::{internal, ChainError, Require};
use super::job::Work;
-use super::{fingerprint, process, KindHost, Context};
+use super::{fingerprint, process, KindTarget, KindHost, Context};
use util::Freshness;
/// Contains the parsed output of a custom build script.
/// Prepares a `Work` that executes the target as a custom build script.
pub fn prepare(pkg: &Package, target: &Target, cx: &mut Context)
-> CargoResult<(Work, Work, Freshness)> {
+ // TODO: this shouldn't explicitly pass `KindTarget` for the layout, we
+ // may be running a build script for a plugin dependency.
let (script_output, old_script_output, build_output, old_build_output) = {
- let layout = cx.layout(pkg, KindHost);
- (layout.build(pkg),
- layout.proxy().old_build(pkg),
- layout.build_out(pkg),
- layout.proxy().old_build(pkg).join("out"))
+ let target = cx.layout(pkg, KindTarget);
+ let host = cx.layout(pkg, KindHost);
+ (host.build(pkg),
+ host.proxy().old_build(pkg),
+ target.build_out(pkg),
+ target.proxy().old_build(pkg).join("out"))
};
// Building the command to execute
script_output.clone(), old_build_output.clone(),
build_output.clone());
- try!(fs::mkdir(&script_output, USER_RWX));
+ try!(fs::mkdir_recursive(&cx.layout(pkg, KindTarget).build(pkg), USER_RWX));
+ try!(fs::mkdir_recursive(&cx.layout(pkg, KindHost).build(pkg), USER_RWX));
// Prepare the unit of "dirty work" which will actually run the custom build
// command.
.with_stderr("dylib outputs are not supported for \
arm-apple-ios"));
})
+
+test!(cross_with_a_build_script {
+ if disabled() { return }
+
+ let target = alternate();
+ let p = project("foo")
+ .file("Cargo.toml", r#"
+ [package]
+ name = "foo"
+ version = "0.0.0"
+ authors = []
+ build = 'build.rs'
+ "#)
+ .file("build.rs", format!(r#"
+ use std::os;
+ fn main() {{
+ assert_eq!(os::getenv("TARGET").unwrap().as_slice(), "{0}");
+ let mut path = Path::new(os::getenv("OUT_DIR").unwrap());
+ assert_eq!(path.filename().unwrap(), b"out");
+ path.pop();
+ assert!(path.filename().unwrap().starts_with(b"foo-"));
+ path.pop();
+ assert_eq!(path.filename().unwrap(), b"build");
+ path.pop();
+ assert_eq!(path.filename().unwrap(), b"{0}");
+ path.pop();
+ assert_eq!(path.filename().unwrap(), b"target");
+ }}
+ "#, target).as_slice())
+ .file("src/main.rs", "fn main() {}");
+
+ assert_that(p.cargo_process("build").arg("--target").arg(&target).arg("-v"),
+ execs().with_status(0)
+ .with_stdout(format!("\
+{compiling} foo v0.0.0 (file://[..])
+{running} `rustc build.rs [..] --out-dir {dir}{sep}target{sep}build{sep}foo-[..]`
+{running} `{dir}{sep}target{sep}build{sep}foo-[..]build-script-build`
+{running} `rustc {dir}{sep}src{sep}main.rs [..] --target {target} [..]`
+", compiling = COMPILING, running = RUNNING, target = target,
+ dir = p.root().display(), sep = path::SEP).as_slice()));
+})
+