2019-11-25 02:42:45 +00:00
|
|
|
//! Tests for --out-dir flag.
|
|
|
|
|
2018-04-03 13:06:56 +00:00
|
|
|
use std::env;
|
2018-08-28 09:20:03 +00:00
|
|
|
use std::fs::{self, File};
|
|
|
|
use std::path::Path;
|
2018-04-03 13:06:56 +00:00
|
|
|
|
2019-09-12 17:14:29 +00:00
|
|
|
use cargo_test_support::sleep_ms;
|
|
|
|
use cargo_test_support::{basic_manifest, project};
|
2018-04-03 06:51:52 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-04-03 06:51:52 +00:00
|
|
|
fn binary_with_debug() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-04-03 06:51:52 +00:00
|
|
|
.file("src/main.rs", r#"fn main() { println!("Hello, World!") }"#)
|
|
|
|
.build();
|
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("build -Z unstable-options --out-dir out")
|
|
|
|
.masquerade_as_nightly_cargo()
|
|
|
|
.run();
|
2018-04-03 06:51:52 +00:00
|
|
|
check_dir_contents(
|
|
|
|
&p.root().join("out"),
|
|
|
|
&["foo"],
|
2018-04-03 15:23:02 +00:00
|
|
|
&["foo", "foo.dSYM"],
|
2018-04-03 06:51:52 +00:00
|
|
|
&["foo.exe", "foo.pdb"],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-04-03 06:51:52 +00:00
|
|
|
fn static_library_with_debug() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-04-03 06:51:52 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[lib]
|
|
|
|
crate-type = ["staticlib"]
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-04-03 06:51:52 +00:00
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
|
|
|
#[no_mangle]
|
|
|
|
pub extern "C" fn foo() { println!("Hello, World!") }
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2018-04-03 06:51:52 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("build -Z unstable-options --out-dir out")
|
|
|
|
.masquerade_as_nightly_cargo()
|
|
|
|
.run();
|
2018-04-03 06:51:52 +00:00
|
|
|
check_dir_contents(
|
|
|
|
&p.root().join("out"),
|
|
|
|
&["libfoo.a"],
|
|
|
|
&["libfoo.a"],
|
|
|
|
&["foo.lib"],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-04-03 06:51:52 +00:00
|
|
|
fn dynamic_library_with_debug() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-04-03 06:51:52 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[lib]
|
|
|
|
crate-type = ["cdylib"]
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-04-03 06:51:52 +00:00
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
|
|
|
#[no_mangle]
|
|
|
|
pub extern "C" fn foo() { println!("Hello, World!") }
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2018-04-03 06:51:52 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("build -Z unstable-options --out-dir out")
|
|
|
|
.masquerade_as_nightly_cargo()
|
|
|
|
.run();
|
2018-04-03 06:51:52 +00:00
|
|
|
check_dir_contents(
|
|
|
|
&p.root().join("out"),
|
|
|
|
&["libfoo.so"],
|
2018-04-03 15:23:02 +00:00
|
|
|
&["libfoo.dylib"],
|
2018-04-03 06:51:52 +00:00
|
|
|
&["foo.dll", "foo.dll.lib"],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-04-03 06:51:52 +00:00
|
|
|
fn rlib_with_debug() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-04-03 06:51:52 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[lib]
|
|
|
|
crate-type = ["rlib"]
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-04-03 06:51:52 +00:00
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
|
|
|
pub fn foo() { println!("Hello, World!") }
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2018-04-03 06:51:52 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("build -Z unstable-options --out-dir out")
|
|
|
|
.masquerade_as_nightly_cargo()
|
|
|
|
.run();
|
2018-04-03 06:51:52 +00:00
|
|
|
check_dir_contents(
|
|
|
|
&p.root().join("out"),
|
|
|
|
&["libfoo.rlib"],
|
|
|
|
&["libfoo.rlib"],
|
|
|
|
&["libfoo.rlib"],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-04-03 06:51:52 +00:00
|
|
|
fn include_only_the_binary_from_the_current_package() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-04-03 06:51:52 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[workspace]
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
utils = { path = "./utils" }
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/lib.rs", "extern crate utils;")
|
2018-04-03 06:51:52 +00:00
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
|
|
|
extern crate foo;
|
|
|
|
extern crate utils;
|
|
|
|
fn main() {
|
|
|
|
println!("Hello, World!")
|
|
|
|
}
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("utils/Cargo.toml", &basic_manifest("utils", "0.0.1"))
|
2018-04-03 06:51:52 +00:00
|
|
|
.file("utils/src/lib.rs", "")
|
|
|
|
.build();
|
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("build -Z unstable-options --bin foo --out-dir out")
|
|
|
|
.masquerade_as_nightly_cargo()
|
|
|
|
.run();
|
2018-04-03 06:51:52 +00:00
|
|
|
check_dir_contents(
|
|
|
|
&p.root().join("out"),
|
|
|
|
&["foo"],
|
2018-04-03 15:23:02 +00:00
|
|
|
&["foo", "foo.dSYM"],
|
2018-04-03 06:51:52 +00:00
|
|
|
&["foo.exe", "foo.pdb"],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-04-03 13:06:56 +00:00
|
|
|
fn out_dir_is_a_file() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-04-03 13:06:56 +00:00
|
|
|
.file("src/main.rs", r#"fn main() { println!("Hello, World!") }"#)
|
|
|
|
.build();
|
|
|
|
File::create(p.root().join("out")).unwrap();
|
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("build -Z unstable-options --out-dir out")
|
|
|
|
.masquerade_as_nightly_cargo()
|
|
|
|
.with_status(101)
|
2019-08-27 19:52:49 +00:00
|
|
|
.with_stderr_contains("[ERROR] failed to create directory [..]")
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2018-04-03 13:06:56 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-04-03 13:06:56 +00:00
|
|
|
fn replaces_artifacts() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-04-03 13:06:56 +00:00
|
|
|
.file("src/main.rs", r#"fn main() { println!("foo") }"#)
|
|
|
|
.build();
|
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("build -Z unstable-options --out-dir out")
|
|
|
|
.masquerade_as_nightly_cargo()
|
|
|
|
.run();
|
2018-08-28 21:05:39 +00:00
|
|
|
p.process(
|
|
|
|
&p.root()
|
|
|
|
.join(&format!("out/foo{}", env::consts::EXE_SUFFIX)),
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.with_stdout("foo")
|
2018-08-28 21:05:39 +00:00
|
|
|
.run();
|
2018-04-03 13:06:56 +00:00
|
|
|
|
2018-04-03 15:23:02 +00:00
|
|
|
sleep_ms(1000);
|
|
|
|
p.change_file("src/main.rs", r#"fn main() { println!("bar") }"#);
|
2018-04-03 13:06:56 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("build -Z unstable-options --out-dir out")
|
|
|
|
.masquerade_as_nightly_cargo()
|
|
|
|
.run();
|
2018-08-28 21:05:39 +00:00
|
|
|
p.process(
|
|
|
|
&p.root()
|
|
|
|
.join(&format!("out/foo{}", env::consts::EXE_SUFFIX)),
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.with_stdout("bar")
|
2018-08-28 21:05:39 +00:00
|
|
|
.run();
|
2018-04-03 13:06:56 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-11-10 17:48:07 +00:00
|
|
|
fn avoid_build_scripts() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[workspace]
|
|
|
|
members = ["a", "b"]
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("a/Cargo.toml", &basic_manifest("a", "0.0.1"))
|
|
|
|
.file("a/src/main.rs", "fn main() {}")
|
|
|
|
.file("a/build.rs", r#"fn main() { println!("hello-build-a"); }"#)
|
|
|
|
.file("b/Cargo.toml", &basic_manifest("b", "0.0.1"))
|
|
|
|
.file("b/src/main.rs", "fn main() {}")
|
|
|
|
.file("b/build.rs", r#"fn main() { println!("hello-build-b"); }"#)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("build -Z unstable-options --out-dir out -vv")
|
|
|
|
.masquerade_as_nightly_cargo()
|
|
|
|
.with_stdout_contains("[a 0.0.1] hello-build-a")
|
|
|
|
.with_stdout_contains("[b 0.0.1] hello-build-b")
|
|
|
|
.run();
|
|
|
|
check_dir_contents(
|
|
|
|
&p.root().join("out"),
|
|
|
|
&["a", "b"],
|
|
|
|
&["a", "a.dSYM", "b", "b.dSYM"],
|
|
|
|
&["a.exe", "a.pdb", "b.exe", "b.pdb"],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-01-17 13:26:58 +00:00
|
|
|
#[cargo_test]
|
|
|
|
fn cargo_build_out_dir() {
|
|
|
|
let p = project()
|
|
|
|
.file("src/main.rs", r#"fn main() { println!("Hello, World!") }"#)
|
|
|
|
.file(
|
|
|
|
".cargo/config",
|
|
|
|
r#"
|
|
|
|
[build]
|
|
|
|
out-dir = "out"
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("build -Z unstable-options")
|
|
|
|
.masquerade_as_nightly_cargo()
|
|
|
|
.run();
|
|
|
|
check_dir_contents(
|
|
|
|
&p.root().join("out"),
|
|
|
|
&["foo"],
|
|
|
|
&["foo", "foo.dSYM"],
|
|
|
|
&["foo.exe", "foo.pdb"],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-04-03 06:51:52 +00:00
|
|
|
fn check_dir_contents(
|
|
|
|
out_dir: &Path,
|
|
|
|
expected_linux: &[&str],
|
|
|
|
expected_mac: &[&str],
|
|
|
|
expected_win: &[&str],
|
|
|
|
) {
|
|
|
|
let expected = if cfg!(target_os = "windows") {
|
|
|
|
expected_win
|
|
|
|
} else if cfg!(target_os = "macos") {
|
|
|
|
expected_mac
|
|
|
|
} else {
|
|
|
|
expected_linux
|
|
|
|
};
|
|
|
|
|
|
|
|
let actual = list_dir(out_dir);
|
|
|
|
let mut expected = expected.iter().map(|s| s.to_string()).collect::<Vec<_>>();
|
2018-07-16 20:23:48 +00:00
|
|
|
expected.sort_unstable();
|
2018-04-03 06:51:52 +00:00
|
|
|
assert_eq!(actual, expected);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn list_dir(dir: &Path) -> Vec<String> {
|
|
|
|
let mut res = Vec::new();
|
|
|
|
for entry in fs::read_dir(dir).unwrap() {
|
|
|
|
let entry = entry.unwrap();
|
|
|
|
res.push(entry.file_name().into_string().unwrap());
|
|
|
|
}
|
2018-07-16 20:23:48 +00:00
|
|
|
res.sort_unstable();
|
2018-04-03 06:51:52 +00:00
|
|
|
res
|
|
|
|
}
|