2015-02-06 07:27:53 +00:00
|
|
|
use std::env;
|
2015-03-09 19:07:35 +00:00
|
|
|
use std::fs::{self, File};
|
2015-02-27 01:04:25 +00:00
|
|
|
use std::io::prelude::*;
|
2014-06-19 22:21:00 +00:00
|
|
|
|
2017-07-13 03:28:39 +00:00
|
|
|
use cargo::util::paths::dylib_path_envvar;
|
2017-07-19 13:59:50 +00:00
|
|
|
use cargo::util::{process, ProcessBuilder};
|
2016-05-26 00:06:25 +00:00
|
|
|
use cargotest::{is_nightly, rustc_host, sleep_ms};
|
2018-03-14 15:17:44 +00:00
|
|
|
use cargotest::support::paths::{root, CargoPathExt};
|
|
|
|
use cargotest::support::ProjectBuilder;
|
|
|
|
use cargotest::support::{basic_bin_manifest, execs, main_file, project};
|
2017-01-07 11:01:39 +00:00
|
|
|
use cargotest::support::registry::Package;
|
2017-12-24 23:32:29 +00:00
|
|
|
use cargotest::ChannelChanger;
|
2018-03-14 15:17:44 +00:00
|
|
|
use hamcrest::{assert_that, existing_dir, existing_file, is_not};
|
2018-03-26 10:42:30 +00:00
|
|
|
use tempfile;
|
2014-03-19 01:10:48 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn cargo_compile_simple() {
|
2014-05-13 00:33:13 +00:00
|
|
|
let p = project("foo")
|
2015-03-26 18:17:44 +00:00
|
|
|
.file("Cargo.toml", &basic_bin_manifest("foo"))
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]))
|
|
|
|
.build();
|
2014-03-19 01:10:48 +00:00
|
|
|
|
2017-07-22 03:12:21 +00:00
|
|
|
assert_that(p.cargo("build"), execs().with_status(0));
|
2014-06-25 05:06:11 +00:00
|
|
|
assert_that(&p.bin("foo"), existing_file());
|
2014-05-09 00:50:28 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
process(&p.bin("foo")),
|
|
|
|
execs().with_status(0).with_stdout("i am foo\n"),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-03-19 01:10:48 +00:00
|
|
|
|
2017-06-26 23:07:36 +00:00
|
|
|
#[test]
|
|
|
|
fn cargo_fail_with_no_stderr() {
|
|
|
|
let p = project("foo")
|
|
|
|
.file("Cargo.toml", &basic_bin_manifest("foo"))
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/foo.rs", &String::from("refusal"))
|
|
|
|
.build();
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build").arg("--message-format=json"),
|
|
|
|
execs()
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr_does_not_contain("--- stderr"),
|
|
|
|
);
|
2017-06-26 23:07:36 +00:00
|
|
|
}
|
|
|
|
|
2017-01-11 16:20:36 +00:00
|
|
|
/// Check that the `CARGO_INCREMENTAL` environment variable results in
|
|
|
|
/// `rustc` getting `-Zincremental` passed to it.
|
|
|
|
#[test]
|
|
|
|
fn cargo_compile_incremental() {
|
|
|
|
let p = project("foo")
|
|
|
|
.file("Cargo.toml", &basic_bin_manifest("foo"))
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]))
|
|
|
|
.build();
|
2017-01-11 16:20:36 +00:00
|
|
|
|
|
|
|
assert_that(
|
2017-02-15 14:16:41 +00:00
|
|
|
p.cargo("build").arg("-v").env("CARGO_INCREMENTAL", "1"),
|
2018-03-14 15:17:44 +00:00
|
|
|
execs()
|
|
|
|
.with_stderr_contains(
|
|
|
|
"[RUNNING] `rustc [..] -C incremental=[..][/]target[/]debug[/]incremental[..]`\n",
|
|
|
|
)
|
|
|
|
.with_status(0),
|
|
|
|
);
|
2017-01-11 16:30:12 +00:00
|
|
|
|
|
|
|
assert_that(
|
2017-02-15 14:16:41 +00:00
|
|
|
p.cargo("test").arg("-v").env("CARGO_INCREMENTAL", "1"),
|
2018-03-14 15:17:44 +00:00
|
|
|
execs()
|
|
|
|
.with_stderr_contains(
|
|
|
|
"[RUNNING] `rustc [..] -C incremental=[..][/]target[/]debug[/]incremental[..]`\n",
|
|
|
|
)
|
|
|
|
.with_status(0),
|
|
|
|
);
|
2017-01-11 16:20:36 +00:00
|
|
|
}
|
|
|
|
|
2017-12-13 22:08:16 +00:00
|
|
|
#[test]
|
|
|
|
fn incremental_profile() {
|
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-12-13 22:08:16 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[profile.dev]
|
|
|
|
incremental = false
|
|
|
|
|
|
|
|
[profile.release]
|
|
|
|
incremental = true
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-12-13 22:08:16 +00:00
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
assert_that(
|
|
|
|
p.cargo("build").arg("-v").env_remove("CARGO_INCREMENTAL"),
|
2018-03-14 15:17:44 +00:00
|
|
|
execs()
|
|
|
|
.with_stderr_does_not_contain("[..]C incremental=[..]")
|
|
|
|
.with_status(0),
|
|
|
|
);
|
2017-12-13 22:08:16 +00:00
|
|
|
|
|
|
|
assert_that(
|
|
|
|
p.cargo("build").arg("-v").env("CARGO_INCREMENTAL", "1"),
|
2018-03-14 15:17:44 +00:00
|
|
|
execs()
|
|
|
|
.with_stderr_contains("[..]C incremental=[..]")
|
|
|
|
.with_status(0),
|
|
|
|
);
|
2017-12-13 22:08:16 +00:00
|
|
|
|
|
|
|
assert_that(
|
2018-03-14 15:17:44 +00:00
|
|
|
p.cargo("build")
|
|
|
|
.arg("--release")
|
|
|
|
.arg("-v")
|
|
|
|
.env_remove("CARGO_INCREMENTAL"),
|
|
|
|
execs()
|
|
|
|
.with_stderr_contains("[..]C incremental=[..]")
|
|
|
|
.with_status(0),
|
|
|
|
);
|
2017-12-13 22:08:16 +00:00
|
|
|
|
|
|
|
assert_that(
|
2018-03-14 15:17:44 +00:00
|
|
|
p.cargo("build")
|
|
|
|
.arg("--release")
|
|
|
|
.arg("-v")
|
|
|
|
.env("CARGO_INCREMENTAL", "0"),
|
|
|
|
execs()
|
|
|
|
.with_stderr_does_not_contain("[..]C incremental=[..]")
|
|
|
|
.with_status(0),
|
|
|
|
);
|
2017-12-13 22:08:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn incremental_config() {
|
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-12-13 22:08:16 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-12-13 22:08:16 +00:00
|
|
|
.file("src/main.rs", "fn main() {}")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
".cargo/config",
|
|
|
|
r#"
|
2017-12-13 22:08:16 +00:00
|
|
|
[build]
|
|
|
|
incremental = false
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-12-13 22:08:16 +00:00
|
|
|
.build();
|
|
|
|
|
|
|
|
assert_that(
|
|
|
|
p.cargo("build").arg("-v").env_remove("CARGO_INCREMENTAL"),
|
2018-03-14 15:17:44 +00:00
|
|
|
execs()
|
|
|
|
.with_stderr_does_not_contain("[..]C incremental=[..]")
|
|
|
|
.with_status(0),
|
|
|
|
);
|
2017-12-13 22:08:16 +00:00
|
|
|
|
|
|
|
assert_that(
|
|
|
|
p.cargo("build").arg("-v").env("CARGO_INCREMENTAL", "1"),
|
2018-03-14 15:17:44 +00:00
|
|
|
execs()
|
|
|
|
.with_stderr_contains("[..]C incremental=[..]")
|
|
|
|
.with_status(0),
|
|
|
|
);
|
2017-12-13 22:08:16 +00:00
|
|
|
}
|
|
|
|
|
2018-02-28 02:34:04 +00:00
|
|
|
#[test]
|
|
|
|
fn cargo_compile_with_workspace_excluded() {
|
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2018-02-28 02:34:04 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2018-02-28 02:34:04 +00:00
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
assert_that(
|
|
|
|
p.cargo("build").arg("--all").arg("--exclude").arg("foo"),
|
2018-03-14 15:17:44 +00:00
|
|
|
execs()
|
|
|
|
.with_stderr_does_not_contain("[..]virtual[..]")
|
2018-02-28 21:43:08 +00:00
|
|
|
.with_stderr_contains("[..]no packages to compile")
|
2018-03-14 15:17:44 +00:00
|
|
|
.with_status(101),
|
|
|
|
);
|
2018-02-28 02:34:04 +00:00
|
|
|
}
|
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn cargo_compile_manifest_path() {
|
2014-08-01 15:52:51 +00:00
|
|
|
let p = project("foo")
|
2015-03-26 18:17:44 +00:00
|
|
|
.file("Cargo.toml", &basic_bin_manifest("foo"))
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]))
|
|
|
|
.build();
|
2014-08-01 15:52:51 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build")
|
|
|
|
.arg("--manifest-path")
|
|
|
|
.arg("foo/Cargo.toml")
|
|
|
|
.cwd(p.root().parent().unwrap()),
|
|
|
|
execs().with_status(0),
|
|
|
|
);
|
2014-08-01 15:52:51 +00:00
|
|
|
assert_that(&p.bin("foo"), existing_file());
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-08-01 15:52:51 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn cargo_compile_with_invalid_manifest() {
|
2018-03-14 15:17:44 +00:00
|
|
|
let p = project("foo").file("Cargo.toml", "").build();
|
2014-05-09 00:50:28 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build"),
|
|
|
|
execs().with_status(101).with_stderr(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[ERROR] failed to parse manifest at `[..]`
|
2015-01-14 02:43:33 +00:00
|
|
|
|
2015-01-16 17:43:28 +00:00
|
|
|
Caused by:
|
2017-12-17 21:58:51 +00:00
|
|
|
virtual manifests must be configured with [workspace]
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
),
|
|
|
|
)
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-06-23 15:39:50 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn cargo_compile_with_invalid_manifest2() {
|
2014-06-23 15:39:50 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r"
|
2014-06-23 15:39:50 +00:00
|
|
|
[project]
|
|
|
|
foo = bar
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2014-06-23 15:39:50 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build"),
|
|
|
|
execs().with_status(101).with_stderr(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[ERROR] failed to parse manifest at `[..]`
|
2015-01-16 17:43:28 +00:00
|
|
|
|
|
|
|
Caused by:
|
|
|
|
could not parse input as TOML
|
2015-01-14 02:43:33 +00:00
|
|
|
|
2017-02-10 20:01:52 +00:00
|
|
|
Caused by:
|
|
|
|
invalid number at line 3
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
),
|
|
|
|
)
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-05-09 00:50:28 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn cargo_compile_with_invalid_manifest3() {
|
2014-08-28 19:28:23 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-08-28 19:28:23 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/Cargo.toml", "a = bar")
|
|
|
|
.build();
|
2014-08-28 19:28:23 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build")
|
|
|
|
.arg("--manifest-path")
|
|
|
|
.arg("src/Cargo.toml"),
|
|
|
|
execs().with_status(101).with_stderr(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[ERROR] failed to parse manifest at `[..]`
|
2015-01-16 17:43:28 +00:00
|
|
|
|
|
|
|
Caused by:
|
2017-02-10 20:01:52 +00:00
|
|
|
could not parse input as TOML
|
|
|
|
|
|
|
|
Caused by:
|
|
|
|
invalid number at line 1
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
),
|
|
|
|
)
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-08-28 19:28:23 +00:00
|
|
|
|
2016-07-10 17:29:31 +00:00
|
|
|
#[test]
|
|
|
|
fn cargo_compile_duplicate_build_targets() {
|
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2016-07-10 17:29:31 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[lib]
|
|
|
|
name = "main"
|
2017-07-09 10:03:22 +00:00
|
|
|
path = "src/main.rs"
|
2016-07-10 17:29:31 +00:00
|
|
|
crate-type = ["dylib"]
|
|
|
|
|
|
|
|
[dependencies]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
2016-08-05 16:07:18 +00:00
|
|
|
#![allow(warnings)]
|
2016-07-10 17:29:31 +00:00
|
|
|
fn main() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2016-07-10 17:29:31 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build"),
|
|
|
|
execs().with_status(0).with_stderr(
|
|
|
|
"\
|
2016-08-05 16:07:18 +00:00
|
|
|
warning: file found to be present in multiple build targets: [..]main.rs
|
|
|
|
[COMPILING] foo v0.0.1 ([..])
|
|
|
|
[FINISHED] [..]
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
),
|
|
|
|
);
|
2016-07-10 17:29:31 +00:00
|
|
|
}
|
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn cargo_compile_with_invalid_version() {
|
2014-06-25 01:48:38 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-06-25 01:48:38 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
authors = []
|
|
|
|
version = "1.0"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2014-06-25 01:48:38 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build"),
|
|
|
|
execs().with_status(101).with_stderr(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[ERROR] failed to parse manifest at `[..]`
|
2015-01-14 02:43:33 +00:00
|
|
|
|
2015-01-16 17:43:28 +00:00
|
|
|
Caused by:
|
2017-05-27 23:42:10 +00:00
|
|
|
Expected dot for key `project.version`
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
),
|
|
|
|
)
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-06-25 01:48:38 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn cargo_compile_with_invalid_package_name() {
|
2015-05-17 12:03:23 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2015-05-17 12:03:23 +00:00
|
|
|
[package]
|
|
|
|
name = ""
|
|
|
|
authors = []
|
|
|
|
version = "0.0.0"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2015-05-17 12:03:23 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build"),
|
|
|
|
execs().with_status(101).with_stderr(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[ERROR] failed to parse manifest at `[..]`
|
2015-05-17 12:03:23 +00:00
|
|
|
|
|
|
|
Caused by:
|
2017-12-08 19:31:17 +00:00
|
|
|
package name cannot be an empty string
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
),
|
|
|
|
)
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-05-17 12:03:23 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn cargo_compile_with_invalid_bin_target_name() {
|
2015-05-17 12:03:23 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2015-05-17 12:03:23 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
authors = []
|
|
|
|
version = "0.0.0"
|
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
name = ""
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2015-05-17 12:03:23 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build"),
|
|
|
|
execs().with_status(101).with_stderr(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[ERROR] failed to parse manifest at `[..]`
|
2015-05-17 12:03:23 +00:00
|
|
|
|
|
|
|
Caused by:
|
2017-07-08 21:59:31 +00:00
|
|
|
binary target names cannot be empty
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
),
|
|
|
|
)
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-05-17 12:03:23 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn cargo_compile_with_forbidden_bin_target_name() {
|
2015-06-03 13:35:44 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2015-06-03 13:35:44 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
authors = []
|
|
|
|
version = "0.0.0"
|
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
name = "build"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2015-06-03 13:35:44 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build"),
|
|
|
|
execs().with_status(101).with_stderr(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[ERROR] failed to parse manifest at `[..]`
|
2015-06-03 13:35:44 +00:00
|
|
|
|
|
|
|
Caused by:
|
|
|
|
the binary target name `build` is forbidden
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
),
|
|
|
|
)
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-06-03 13:35:44 +00:00
|
|
|
|
2018-03-19 17:23:40 +00:00
|
|
|
#[test]
|
|
|
|
fn cargo_compile_with_bin_and_crate_type() {
|
|
|
|
let p = project("foo")
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
authors = []
|
|
|
|
version = "0.0.0"
|
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
name = "the_foo_bin"
|
|
|
|
path = "src/foo.rs"
|
|
|
|
crate-type = ["cdylib", "rlib"]
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/foo.rs", "fn main() {}")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
assert_that(
|
|
|
|
p.cargo("build"),
|
|
|
|
execs().with_status(101).with_stderr(
|
|
|
|
"\
|
|
|
|
[ERROR] failed to parse manifest at `[..]`
|
|
|
|
|
|
|
|
Caused by:
|
|
|
|
the target `the_foo_bin` is a binary and can't have any crate-types set \
|
|
|
|
(currently \"cdylib, rlib\")",
|
|
|
|
),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn cargo_compile_with_bin_and_proc() {
|
|
|
|
let p = project("foo")
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
authors = []
|
|
|
|
version = "0.0.0"
|
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
name = "the_foo_bin"
|
|
|
|
path = "src/foo.rs"
|
|
|
|
proc-macro = true
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/foo.rs", "fn main() {}")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
assert_that(
|
|
|
|
p.cargo("build"),
|
|
|
|
execs().with_status(101).with_stderr(
|
|
|
|
"\
|
|
|
|
[ERROR] failed to parse manifest at `[..]`
|
|
|
|
|
|
|
|
Caused by:
|
|
|
|
the target `the_foo_bin` is a binary and can't have `proc-macro` set `true`",
|
|
|
|
),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn cargo_compile_with_invalid_lib_target_name() {
|
2015-05-17 12:03:23 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2015-05-17 12:03:23 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
authors = []
|
|
|
|
version = "0.0.0"
|
|
|
|
|
|
|
|
[lib]
|
|
|
|
name = ""
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2015-05-17 12:03:23 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build"),
|
|
|
|
execs().with_status(101).with_stderr(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[ERROR] failed to parse manifest at `[..]`
|
2015-05-17 12:03:23 +00:00
|
|
|
|
|
|
|
Caused by:
|
2017-07-08 21:59:31 +00:00
|
|
|
library target names cannot be empty
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
),
|
|
|
|
)
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-05-17 12:03:23 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn cargo_compile_without_manifest() {
|
2018-03-26 10:42:30 +00:00
|
|
|
let tmpdir = tempfile::Builder::new().prefix("cargo").tempdir().unwrap();
|
2017-07-22 03:12:21 +00:00
|
|
|
let p = ProjectBuilder::new("foo", tmpdir.path().to_path_buf()).build();
|
2014-05-09 00:50:28 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build"),
|
2018-03-14 15:43:41 +00:00
|
|
|
execs()
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr("[ERROR] could not find `Cargo.toml` in `[..]` or any parent directory"),
|
2018-03-14 15:17:44 +00:00
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-05-13 00:33:13 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn cargo_compile_with_invalid_code() {
|
2014-05-13 00:33:13 +00:00
|
|
|
let p = project("foo")
|
2015-03-26 18:17:44 +00:00
|
|
|
.file("Cargo.toml", &basic_bin_manifest("foo"))
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/foo.rs", "invalid rust code!")
|
|
|
|
.build();
|
2014-05-13 00:33:13 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build"),
|
|
|
|
execs().with_status(101).with_stderr_contains(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[ERROR] Could not compile `foo`.
|
2014-07-18 11:49:34 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
To learn more, run the command again with --verbose.\n",
|
|
|
|
),
|
|
|
|
);
|
2014-09-03 15:23:59 +00:00
|
|
|
assert_that(&p.root().join("Cargo.lock"), existing_file());
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-05-13 00:33:13 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn cargo_compile_with_invalid_code_in_deps() {
|
2014-07-11 20:32:27 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-07-11 20:32:27 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies.bar]
|
|
|
|
path = "../bar"
|
|
|
|
[dependencies.baz]
|
|
|
|
path = "../baz"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/main.rs", "invalid rust code!")
|
|
|
|
.build();
|
|
|
|
let _bar = project("bar")
|
2015-03-26 18:17:44 +00:00
|
|
|
.file("Cargo.toml", &basic_bin_manifest("bar"))
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/lib.rs", "invalid rust code!")
|
|
|
|
.build();
|
|
|
|
let _baz = project("baz")
|
2015-03-26 18:17:44 +00:00
|
|
|
.file("Cargo.toml", &basic_bin_manifest("baz"))
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/lib.rs", "invalid rust code!")
|
|
|
|
.build();
|
|
|
|
assert_that(p.cargo("build"), execs().with_status(101));
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-07-11 20:32:27 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn cargo_compile_with_warnings_in_the_root_package() {
|
2014-05-13 00:33:13 +00:00
|
|
|
let p = project("foo")
|
2015-03-26 18:17:44 +00:00
|
|
|
.file("Cargo.toml", &basic_bin_manifest("foo"))
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/foo.rs", "fn main() {} fn dead() {}")
|
|
|
|
.build();
|
2014-05-13 00:33:13 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build"),
|
2018-03-14 15:43:41 +00:00
|
|
|
execs()
|
|
|
|
.with_status(0)
|
|
|
|
.with_stderr_contains("[..]function is never used: `dead`[..]"),
|
2018-03-14 15:17:44 +00:00
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-05-13 00:33:13 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn cargo_compile_with_warnings_in_a_dep_package() {
|
2017-07-22 03:12:21 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-05-13 00:33:13 +00:00
|
|
|
[project]
|
|
|
|
|
|
|
|
name = "foo"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["wycats@example.com"]
|
|
|
|
|
Implement a registry source
# cargo upload
The cargo-upload command will take the local package and upload it to the
specified registry. The local package is uploaded as a tarball compressed with
gzip under maximum compression. Most of this is done by just delegating to
`cargo package` The host to upload to is specified, in order of priority, by a
command line `--host` flag, the `registry.host` config key, and then the default
registry. The default registry is still `example.com`
The registry itself is still a work in progress, but the general plumbing for a
command such as this would look like:
1. Ensure the local package has been compressed into an archive.
2. Fetch the relevant registry and login token from config files.
3. Ensure all dependencies for a package are listed as coming from the same
registry.
4. Upload the archive to the registry with the login token.
5. The registry will verify the package is under 2MB (configurable).
6. The registry will upload the archive to S3, calculating a checksum in the
process.
7. The registry will add an entry to the registry's index (a git repository).
The entry will include the name of the package, the version uploaded, the
checksum of the upload, and then the list of dependencies (name/version req)
8. The local `cargo upload` command will succeed.
# cargo login
Uploading requires a token from the api server, and this token follows the same
config chain for the host except that there is no fallback. To implement login,
the `cargo login` command is used. With 0 arguments, the command will request
that a site be visited for a login token, and with an argument it will set the
argument as the new login token.
The `util::config` module was modified to allow writing configuration as well as
reading it. The support is a little lacking in that comments are blown away, but
the support is there at least.
# RegistrySource
An implementation of `RegistrySource` has been created (deleting the old
`DummyRegistrySource`). This implementation only needs a URL to be constructed,
and it is assumed that the URL is running an instance of the cargo registry.
## RegistrySource::update
Currently this will unconditionally update the registry's index (a git
repository). Tuning is necessary to prevent updating the index each time (more
coming soon).
## RegistrySource::query
This is called in the resolve phase of cargo. This function is given a
dependency to query for, and the source will simply look into the index to see
if any package with the name is present. If found, the package's index file will
be loaded and parsed into a list of summaries.
The main optimization of this function is to not require the entire registry to
ever be resident in memory. Instead, only necessary packages are loaded into
memory and parsed.
## RegistrySource::download
This is also called during the resolve phase of cargo, but only when a package
has been selected to be built (actually resolved). This phase of the source will
actually download and unpack the tarball for the package.
Currently a configuration file is located in the root of a registry's index
describing the root url to download packages from.
This function is optimized for two different metrics:
1. If a tarball is downloaded, it is not downloaded again. It is assumed that
once a tarball is successfully downloaded it will never change.
2. If the unpacking destination has a `.cargo-ok` file, it is assumed that the
unpacking has already occurred and does not need to happen again.
With these in place, a rebuild should take almost no time at all.
## RegistrySource::get
This function is simply implemented in terms of a PathSource's `get` function by
creating a `PathSource` for all unpacked tarballs as part of the `download`
stage.
## Filesystem layout
There are a few new directories as part of the `.cargo` home folder:
* `.cargo/registry/index/$hostname-$hash` - This is the directory containing the
actual index of the registry. `$hostname` comes from its url, and `$hash` is
the hash of the entire url.
* `.cargo/registry/cache/$hostname-$hash/$pkg-$vers.tar.gz` - This is a
directory used to cache the downloads of packages from the registry.
* `.cargo/registry/src/$hostname-$hash/$pkg-$vers` - This is the location of the
unpacked packages. They will be compiled from this location.
# New Dependencies
Cargo has picked up a new dependency on the `curl-rust` package in order to send
HTTP requests to the registry as well as send HTTP requests to download
tarballs.
2014-07-18 15:40:45 +00:00
|
|
|
[dependencies.bar]
|
|
|
|
path = "bar"
|
2014-05-13 00:33:13 +00:00
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
|
|
|
|
name = "foo"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/foo.rs", &main_file(r#""{}", bar::gimme()"#, &["bar"]))
|
|
|
|
.file(
|
|
|
|
"bar/Cargo.toml",
|
|
|
|
r#"
|
2014-05-13 00:33:13 +00:00
|
|
|
[project]
|
|
|
|
|
|
|
|
name = "bar"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["wycats@example.com"]
|
|
|
|
|
2014-08-14 06:08:02 +00:00
|
|
|
[lib]
|
2014-05-13 00:33:13 +00:00
|
|
|
|
|
|
|
name = "bar"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"bar/src/bar.rs",
|
|
|
|
r#"
|
2015-01-13 16:41:04 +00:00
|
|
|
pub fn gimme() -> &'static str {
|
|
|
|
"test passed"
|
2014-05-13 00:33:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn dead() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2014-05-13 00:33:13 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build"),
|
2018-03-14 15:43:41 +00:00
|
|
|
execs()
|
|
|
|
.with_status(0)
|
|
|
|
.with_stderr_contains("[..]function is never used: `dead`[..]"),
|
2018-03-14 15:17:44 +00:00
|
|
|
);
|
2014-05-13 00:33:13 +00:00
|
|
|
|
2014-06-25 05:06:11 +00:00
|
|
|
assert_that(&p.bin("foo"), existing_file());
|
2014-05-13 00:33:13 +00:00
|
|
|
|
|
|
|
assert_that(
|
2018-03-14 15:17:44 +00:00
|
|
|
process(&p.bin("foo")),
|
|
|
|
execs().with_status(0).with_stdout("test passed\n"),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-05-09 00:50:28 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn cargo_compile_with_nested_deps_inferred() {
|
Implement a registry source
# cargo upload
The cargo-upload command will take the local package and upload it to the
specified registry. The local package is uploaded as a tarball compressed with
gzip under maximum compression. Most of this is done by just delegating to
`cargo package` The host to upload to is specified, in order of priority, by a
command line `--host` flag, the `registry.host` config key, and then the default
registry. The default registry is still `example.com`
The registry itself is still a work in progress, but the general plumbing for a
command such as this would look like:
1. Ensure the local package has been compressed into an archive.
2. Fetch the relevant registry and login token from config files.
3. Ensure all dependencies for a package are listed as coming from the same
registry.
4. Upload the archive to the registry with the login token.
5. The registry will verify the package is under 2MB (configurable).
6. The registry will upload the archive to S3, calculating a checksum in the
process.
7. The registry will add an entry to the registry's index (a git repository).
The entry will include the name of the package, the version uploaded, the
checksum of the upload, and then the list of dependencies (name/version req)
8. The local `cargo upload` command will succeed.
# cargo login
Uploading requires a token from the api server, and this token follows the same
config chain for the host except that there is no fallback. To implement login,
the `cargo login` command is used. With 0 arguments, the command will request
that a site be visited for a login token, and with an argument it will set the
argument as the new login token.
The `util::config` module was modified to allow writing configuration as well as
reading it. The support is a little lacking in that comments are blown away, but
the support is there at least.
# RegistrySource
An implementation of `RegistrySource` has been created (deleting the old
`DummyRegistrySource`). This implementation only needs a URL to be constructed,
and it is assumed that the URL is running an instance of the cargo registry.
## RegistrySource::update
Currently this will unconditionally update the registry's index (a git
repository). Tuning is necessary to prevent updating the index each time (more
coming soon).
## RegistrySource::query
This is called in the resolve phase of cargo. This function is given a
dependency to query for, and the source will simply look into the index to see
if any package with the name is present. If found, the package's index file will
be loaded and parsed into a list of summaries.
The main optimization of this function is to not require the entire registry to
ever be resident in memory. Instead, only necessary packages are loaded into
memory and parsed.
## RegistrySource::download
This is also called during the resolve phase of cargo, but only when a package
has been selected to be built (actually resolved). This phase of the source will
actually download and unpack the tarball for the package.
Currently a configuration file is located in the root of a registry's index
describing the root url to download packages from.
This function is optimized for two different metrics:
1. If a tarball is downloaded, it is not downloaded again. It is assumed that
once a tarball is successfully downloaded it will never change.
2. If the unpacking destination has a `.cargo-ok` file, it is assumed that the
unpacking has already occurred and does not need to happen again.
With these in place, a rebuild should take almost no time at all.
## RegistrySource::get
This function is simply implemented in terms of a PathSource's `get` function by
creating a `PathSource` for all unpacked tarballs as part of the `download`
stage.
## Filesystem layout
There are a few new directories as part of the `.cargo` home folder:
* `.cargo/registry/index/$hostname-$hash` - This is the directory containing the
actual index of the registry. `$hostname` comes from its url, and `$hash` is
the hash of the entire url.
* `.cargo/registry/cache/$hostname-$hash/$pkg-$vers.tar.gz` - This is a
directory used to cache the downloads of packages from the registry.
* `.cargo/registry/src/$hostname-$hash/$pkg-$vers` - This is the location of the
unpacked packages. They will be compiled from this location.
# New Dependencies
Cargo has picked up a new dependency on the `curl-rust` package in order to send
HTTP requests to the registry as well as send HTTP requests to download
tarballs.
2014-07-18 15:40:45 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-07-08 00:59:18 +00:00
|
|
|
[project]
|
|
|
|
|
|
|
|
name = "foo"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["wycats@example.com"]
|
|
|
|
|
Implement a registry source
# cargo upload
The cargo-upload command will take the local package and upload it to the
specified registry. The local package is uploaded as a tarball compressed with
gzip under maximum compression. Most of this is done by just delegating to
`cargo package` The host to upload to is specified, in order of priority, by a
command line `--host` flag, the `registry.host` config key, and then the default
registry. The default registry is still `example.com`
The registry itself is still a work in progress, but the general plumbing for a
command such as this would look like:
1. Ensure the local package has been compressed into an archive.
2. Fetch the relevant registry and login token from config files.
3. Ensure all dependencies for a package are listed as coming from the same
registry.
4. Upload the archive to the registry with the login token.
5. The registry will verify the package is under 2MB (configurable).
6. The registry will upload the archive to S3, calculating a checksum in the
process.
7. The registry will add an entry to the registry's index (a git repository).
The entry will include the name of the package, the version uploaded, the
checksum of the upload, and then the list of dependencies (name/version req)
8. The local `cargo upload` command will succeed.
# cargo login
Uploading requires a token from the api server, and this token follows the same
config chain for the host except that there is no fallback. To implement login,
the `cargo login` command is used. With 0 arguments, the command will request
that a site be visited for a login token, and with an argument it will set the
argument as the new login token.
The `util::config` module was modified to allow writing configuration as well as
reading it. The support is a little lacking in that comments are blown away, but
the support is there at least.
# RegistrySource
An implementation of `RegistrySource` has been created (deleting the old
`DummyRegistrySource`). This implementation only needs a URL to be constructed,
and it is assumed that the URL is running an instance of the cargo registry.
## RegistrySource::update
Currently this will unconditionally update the registry's index (a git
repository). Tuning is necessary to prevent updating the index each time (more
coming soon).
## RegistrySource::query
This is called in the resolve phase of cargo. This function is given a
dependency to query for, and the source will simply look into the index to see
if any package with the name is present. If found, the package's index file will
be loaded and parsed into a list of summaries.
The main optimization of this function is to not require the entire registry to
ever be resident in memory. Instead, only necessary packages are loaded into
memory and parsed.
## RegistrySource::download
This is also called during the resolve phase of cargo, but only when a package
has been selected to be built (actually resolved). This phase of the source will
actually download and unpack the tarball for the package.
Currently a configuration file is located in the root of a registry's index
describing the root url to download packages from.
This function is optimized for two different metrics:
1. If a tarball is downloaded, it is not downloaded again. It is assumed that
once a tarball is successfully downloaded it will never change.
2. If the unpacking destination has a `.cargo-ok` file, it is assumed that the
unpacking has already occurred and does not need to happen again.
With these in place, a rebuild should take almost no time at all.
## RegistrySource::get
This function is simply implemented in terms of a PathSource's `get` function by
creating a `PathSource` for all unpacked tarballs as part of the `download`
stage.
## Filesystem layout
There are a few new directories as part of the `.cargo` home folder:
* `.cargo/registry/index/$hostname-$hash` - This is the directory containing the
actual index of the registry. `$hostname` comes from its url, and `$hash` is
the hash of the entire url.
* `.cargo/registry/cache/$hostname-$hash/$pkg-$vers.tar.gz` - This is a
directory used to cache the downloads of packages from the registry.
* `.cargo/registry/src/$hostname-$hash/$pkg-$vers` - This is the location of the
unpacked packages. They will be compiled from this location.
# New Dependencies
Cargo has picked up a new dependency on the `curl-rust` package in order to send
HTTP requests to the registry as well as send HTTP requests to download
tarballs.
2014-07-18 15:40:45 +00:00
|
|
|
[dependencies.bar]
|
|
|
|
path = 'bar'
|
2014-07-08 00:59:18 +00:00
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
name = "foo"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/foo.rs", &main_file(r#""{}", bar::gimme()"#, &["bar"]))
|
|
|
|
.file(
|
|
|
|
"bar/Cargo.toml",
|
|
|
|
r#"
|
2014-07-08 00:59:18 +00:00
|
|
|
[project]
|
|
|
|
|
|
|
|
name = "bar"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["wycats@example.com"]
|
|
|
|
|
Implement a registry source
# cargo upload
The cargo-upload command will take the local package and upload it to the
specified registry. The local package is uploaded as a tarball compressed with
gzip under maximum compression. Most of this is done by just delegating to
`cargo package` The host to upload to is specified, in order of priority, by a
command line `--host` flag, the `registry.host` config key, and then the default
registry. The default registry is still `example.com`
The registry itself is still a work in progress, but the general plumbing for a
command such as this would look like:
1. Ensure the local package has been compressed into an archive.
2. Fetch the relevant registry and login token from config files.
3. Ensure all dependencies for a package are listed as coming from the same
registry.
4. Upload the archive to the registry with the login token.
5. The registry will verify the package is under 2MB (configurable).
6. The registry will upload the archive to S3, calculating a checksum in the
process.
7. The registry will add an entry to the registry's index (a git repository).
The entry will include the name of the package, the version uploaded, the
checksum of the upload, and then the list of dependencies (name/version req)
8. The local `cargo upload` command will succeed.
# cargo login
Uploading requires a token from the api server, and this token follows the same
config chain for the host except that there is no fallback. To implement login,
the `cargo login` command is used. With 0 arguments, the command will request
that a site be visited for a login token, and with an argument it will set the
argument as the new login token.
The `util::config` module was modified to allow writing configuration as well as
reading it. The support is a little lacking in that comments are blown away, but
the support is there at least.
# RegistrySource
An implementation of `RegistrySource` has been created (deleting the old
`DummyRegistrySource`). This implementation only needs a URL to be constructed,
and it is assumed that the URL is running an instance of the cargo registry.
## RegistrySource::update
Currently this will unconditionally update the registry's index (a git
repository). Tuning is necessary to prevent updating the index each time (more
coming soon).
## RegistrySource::query
This is called in the resolve phase of cargo. This function is given a
dependency to query for, and the source will simply look into the index to see
if any package with the name is present. If found, the package's index file will
be loaded and parsed into a list of summaries.
The main optimization of this function is to not require the entire registry to
ever be resident in memory. Instead, only necessary packages are loaded into
memory and parsed.
## RegistrySource::download
This is also called during the resolve phase of cargo, but only when a package
has been selected to be built (actually resolved). This phase of the source will
actually download and unpack the tarball for the package.
Currently a configuration file is located in the root of a registry's index
describing the root url to download packages from.
This function is optimized for two different metrics:
1. If a tarball is downloaded, it is not downloaded again. It is assumed that
once a tarball is successfully downloaded it will never change.
2. If the unpacking destination has a `.cargo-ok` file, it is assumed that the
unpacking has already occurred and does not need to happen again.
With these in place, a rebuild should take almost no time at all.
## RegistrySource::get
This function is simply implemented in terms of a PathSource's `get` function by
creating a `PathSource` for all unpacked tarballs as part of the `download`
stage.
## Filesystem layout
There are a few new directories as part of the `.cargo` home folder:
* `.cargo/registry/index/$hostname-$hash` - This is the directory containing the
actual index of the registry. `$hostname` comes from its url, and `$hash` is
the hash of the entire url.
* `.cargo/registry/cache/$hostname-$hash/$pkg-$vers.tar.gz` - This is a
directory used to cache the downloads of packages from the registry.
* `.cargo/registry/src/$hostname-$hash/$pkg-$vers` - This is the location of the
unpacked packages. They will be compiled from this location.
# New Dependencies
Cargo has picked up a new dependency on the `curl-rust` package in order to send
HTTP requests to the registry as well as send HTTP requests to download
tarballs.
2014-07-18 15:40:45 +00:00
|
|
|
[dependencies.baz]
|
|
|
|
path = "../baz"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"bar/src/lib.rs",
|
|
|
|
r#"
|
2014-07-08 00:59:18 +00:00
|
|
|
extern crate baz;
|
|
|
|
|
|
|
|
pub fn gimme() -> String {
|
|
|
|
baz::gimme()
|
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"baz/Cargo.toml",
|
|
|
|
r#"
|
2014-07-08 00:59:18 +00:00
|
|
|
[project]
|
|
|
|
|
|
|
|
name = "baz"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["wycats@example.com"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"baz/src/lib.rs",
|
|
|
|
r#"
|
2014-07-08 00:59:18 +00:00
|
|
|
pub fn gimme() -> String {
|
2014-07-09 13:38:10 +00:00
|
|
|
"test passed".to_string()
|
2014-07-08 00:59:18 +00:00
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2014-07-08 00:59:18 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
p.cargo("build").exec_with_output().unwrap();
|
2014-07-08 00:59:18 +00:00
|
|
|
|
|
|
|
assert_that(&p.bin("foo"), existing_file());
|
2016-11-13 02:55:07 +00:00
|
|
|
assert_that(&p.bin("libbar.rlib"), is_not(existing_file()));
|
|
|
|
assert_that(&p.bin("libbaz.rlib"), is_not(existing_file()));
|
2014-07-08 00:59:18 +00:00
|
|
|
|
|
|
|
assert_that(
|
2018-03-14 15:17:44 +00:00
|
|
|
process(&p.bin("foo")),
|
|
|
|
execs().with_status(0).with_stdout("test passed\n"),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-07-08 00:59:18 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn cargo_compile_with_nested_deps_correct_bin() {
|
Implement a registry source
# cargo upload
The cargo-upload command will take the local package and upload it to the
specified registry. The local package is uploaded as a tarball compressed with
gzip under maximum compression. Most of this is done by just delegating to
`cargo package` The host to upload to is specified, in order of priority, by a
command line `--host` flag, the `registry.host` config key, and then the default
registry. The default registry is still `example.com`
The registry itself is still a work in progress, but the general plumbing for a
command such as this would look like:
1. Ensure the local package has been compressed into an archive.
2. Fetch the relevant registry and login token from config files.
3. Ensure all dependencies for a package are listed as coming from the same
registry.
4. Upload the archive to the registry with the login token.
5. The registry will verify the package is under 2MB (configurable).
6. The registry will upload the archive to S3, calculating a checksum in the
process.
7. The registry will add an entry to the registry's index (a git repository).
The entry will include the name of the package, the version uploaded, the
checksum of the upload, and then the list of dependencies (name/version req)
8. The local `cargo upload` command will succeed.
# cargo login
Uploading requires a token from the api server, and this token follows the same
config chain for the host except that there is no fallback. To implement login,
the `cargo login` command is used. With 0 arguments, the command will request
that a site be visited for a login token, and with an argument it will set the
argument as the new login token.
The `util::config` module was modified to allow writing configuration as well as
reading it. The support is a little lacking in that comments are blown away, but
the support is there at least.
# RegistrySource
An implementation of `RegistrySource` has been created (deleting the old
`DummyRegistrySource`). This implementation only needs a URL to be constructed,
and it is assumed that the URL is running an instance of the cargo registry.
## RegistrySource::update
Currently this will unconditionally update the registry's index (a git
repository). Tuning is necessary to prevent updating the index each time (more
coming soon).
## RegistrySource::query
This is called in the resolve phase of cargo. This function is given a
dependency to query for, and the source will simply look into the index to see
if any package with the name is present. If found, the package's index file will
be loaded and parsed into a list of summaries.
The main optimization of this function is to not require the entire registry to
ever be resident in memory. Instead, only necessary packages are loaded into
memory and parsed.
## RegistrySource::download
This is also called during the resolve phase of cargo, but only when a package
has been selected to be built (actually resolved). This phase of the source will
actually download and unpack the tarball for the package.
Currently a configuration file is located in the root of a registry's index
describing the root url to download packages from.
This function is optimized for two different metrics:
1. If a tarball is downloaded, it is not downloaded again. It is assumed that
once a tarball is successfully downloaded it will never change.
2. If the unpacking destination has a `.cargo-ok` file, it is assumed that the
unpacking has already occurred and does not need to happen again.
With these in place, a rebuild should take almost no time at all.
## RegistrySource::get
This function is simply implemented in terms of a PathSource's `get` function by
creating a `PathSource` for all unpacked tarballs as part of the `download`
stage.
## Filesystem layout
There are a few new directories as part of the `.cargo` home folder:
* `.cargo/registry/index/$hostname-$hash` - This is the directory containing the
actual index of the registry. `$hostname` comes from its url, and `$hash` is
the hash of the entire url.
* `.cargo/registry/cache/$hostname-$hash/$pkg-$vers.tar.gz` - This is a
directory used to cache the downloads of packages from the registry.
* `.cargo/registry/src/$hostname-$hash/$pkg-$vers` - This is the location of the
unpacked packages. They will be compiled from this location.
# New Dependencies
Cargo has picked up a new dependency on the `curl-rust` package in order to send
HTTP requests to the registry as well as send HTTP requests to download
tarballs.
2014-07-18 15:40:45 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-07-08 00:59:18 +00:00
|
|
|
[project]
|
|
|
|
|
|
|
|
name = "foo"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["wycats@example.com"]
|
|
|
|
|
Implement a registry source
# cargo upload
The cargo-upload command will take the local package and upload it to the
specified registry. The local package is uploaded as a tarball compressed with
gzip under maximum compression. Most of this is done by just delegating to
`cargo package` The host to upload to is specified, in order of priority, by a
command line `--host` flag, the `registry.host` config key, and then the default
registry. The default registry is still `example.com`
The registry itself is still a work in progress, but the general plumbing for a
command such as this would look like:
1. Ensure the local package has been compressed into an archive.
2. Fetch the relevant registry and login token from config files.
3. Ensure all dependencies for a package are listed as coming from the same
registry.
4. Upload the archive to the registry with the login token.
5. The registry will verify the package is under 2MB (configurable).
6. The registry will upload the archive to S3, calculating a checksum in the
process.
7. The registry will add an entry to the registry's index (a git repository).
The entry will include the name of the package, the version uploaded, the
checksum of the upload, and then the list of dependencies (name/version req)
8. The local `cargo upload` command will succeed.
# cargo login
Uploading requires a token from the api server, and this token follows the same
config chain for the host except that there is no fallback. To implement login,
the `cargo login` command is used. With 0 arguments, the command will request
that a site be visited for a login token, and with an argument it will set the
argument as the new login token.
The `util::config` module was modified to allow writing configuration as well as
reading it. The support is a little lacking in that comments are blown away, but
the support is there at least.
# RegistrySource
An implementation of `RegistrySource` has been created (deleting the old
`DummyRegistrySource`). This implementation only needs a URL to be constructed,
and it is assumed that the URL is running an instance of the cargo registry.
## RegistrySource::update
Currently this will unconditionally update the registry's index (a git
repository). Tuning is necessary to prevent updating the index each time (more
coming soon).
## RegistrySource::query
This is called in the resolve phase of cargo. This function is given a
dependency to query for, and the source will simply look into the index to see
if any package with the name is present. If found, the package's index file will
be loaded and parsed into a list of summaries.
The main optimization of this function is to not require the entire registry to
ever be resident in memory. Instead, only necessary packages are loaded into
memory and parsed.
## RegistrySource::download
This is also called during the resolve phase of cargo, but only when a package
has been selected to be built (actually resolved). This phase of the source will
actually download and unpack the tarball for the package.
Currently a configuration file is located in the root of a registry's index
describing the root url to download packages from.
This function is optimized for two different metrics:
1. If a tarball is downloaded, it is not downloaded again. It is assumed that
once a tarball is successfully downloaded it will never change.
2. If the unpacking destination has a `.cargo-ok` file, it is assumed that the
unpacking has already occurred and does not need to happen again.
With these in place, a rebuild should take almost no time at all.
## RegistrySource::get
This function is simply implemented in terms of a PathSource's `get` function by
creating a `PathSource` for all unpacked tarballs as part of the `download`
stage.
## Filesystem layout
There are a few new directories as part of the `.cargo` home folder:
* `.cargo/registry/index/$hostname-$hash` - This is the directory containing the
actual index of the registry. `$hostname` comes from its url, and `$hash` is
the hash of the entire url.
* `.cargo/registry/cache/$hostname-$hash/$pkg-$vers.tar.gz` - This is a
directory used to cache the downloads of packages from the registry.
* `.cargo/registry/src/$hostname-$hash/$pkg-$vers` - This is the location of the
unpacked packages. They will be compiled from this location.
# New Dependencies
Cargo has picked up a new dependency on the `curl-rust` package in order to send
HTTP requests to the registry as well as send HTTP requests to download
tarballs.
2014-07-18 15:40:45 +00:00
|
|
|
[dependencies.bar]
|
|
|
|
path = "bar"
|
2014-07-08 00:59:18 +00:00
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
name = "foo"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/main.rs", &main_file(r#""{}", bar::gimme()"#, &["bar"]))
|
|
|
|
.file(
|
|
|
|
"bar/Cargo.toml",
|
|
|
|
r#"
|
2014-07-08 00:59:18 +00:00
|
|
|
[project]
|
|
|
|
|
|
|
|
name = "bar"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["wycats@example.com"]
|
|
|
|
|
Implement a registry source
# cargo upload
The cargo-upload command will take the local package and upload it to the
specified registry. The local package is uploaded as a tarball compressed with
gzip under maximum compression. Most of this is done by just delegating to
`cargo package` The host to upload to is specified, in order of priority, by a
command line `--host` flag, the `registry.host` config key, and then the default
registry. The default registry is still `example.com`
The registry itself is still a work in progress, but the general plumbing for a
command such as this would look like:
1. Ensure the local package has been compressed into an archive.
2. Fetch the relevant registry and login token from config files.
3. Ensure all dependencies for a package are listed as coming from the same
registry.
4. Upload the archive to the registry with the login token.
5. The registry will verify the package is under 2MB (configurable).
6. The registry will upload the archive to S3, calculating a checksum in the
process.
7. The registry will add an entry to the registry's index (a git repository).
The entry will include the name of the package, the version uploaded, the
checksum of the upload, and then the list of dependencies (name/version req)
8. The local `cargo upload` command will succeed.
# cargo login
Uploading requires a token from the api server, and this token follows the same
config chain for the host except that there is no fallback. To implement login,
the `cargo login` command is used. With 0 arguments, the command will request
that a site be visited for a login token, and with an argument it will set the
argument as the new login token.
The `util::config` module was modified to allow writing configuration as well as
reading it. The support is a little lacking in that comments are blown away, but
the support is there at least.
# RegistrySource
An implementation of `RegistrySource` has been created (deleting the old
`DummyRegistrySource`). This implementation only needs a URL to be constructed,
and it is assumed that the URL is running an instance of the cargo registry.
## RegistrySource::update
Currently this will unconditionally update the registry's index (a git
repository). Tuning is necessary to prevent updating the index each time (more
coming soon).
## RegistrySource::query
This is called in the resolve phase of cargo. This function is given a
dependency to query for, and the source will simply look into the index to see
if any package with the name is present. If found, the package's index file will
be loaded and parsed into a list of summaries.
The main optimization of this function is to not require the entire registry to
ever be resident in memory. Instead, only necessary packages are loaded into
memory and parsed.
## RegistrySource::download
This is also called during the resolve phase of cargo, but only when a package
has been selected to be built (actually resolved). This phase of the source will
actually download and unpack the tarball for the package.
Currently a configuration file is located in the root of a registry's index
describing the root url to download packages from.
This function is optimized for two different metrics:
1. If a tarball is downloaded, it is not downloaded again. It is assumed that
once a tarball is successfully downloaded it will never change.
2. If the unpacking destination has a `.cargo-ok` file, it is assumed that the
unpacking has already occurred and does not need to happen again.
With these in place, a rebuild should take almost no time at all.
## RegistrySource::get
This function is simply implemented in terms of a PathSource's `get` function by
creating a `PathSource` for all unpacked tarballs as part of the `download`
stage.
## Filesystem layout
There are a few new directories as part of the `.cargo` home folder:
* `.cargo/registry/index/$hostname-$hash` - This is the directory containing the
actual index of the registry. `$hostname` comes from its url, and `$hash` is
the hash of the entire url.
* `.cargo/registry/cache/$hostname-$hash/$pkg-$vers.tar.gz` - This is a
directory used to cache the downloads of packages from the registry.
* `.cargo/registry/src/$hostname-$hash/$pkg-$vers` - This is the location of the
unpacked packages. They will be compiled from this location.
# New Dependencies
Cargo has picked up a new dependency on the `curl-rust` package in order to send
HTTP requests to the registry as well as send HTTP requests to download
tarballs.
2014-07-18 15:40:45 +00:00
|
|
|
[dependencies.baz]
|
|
|
|
path = "../baz"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"bar/src/lib.rs",
|
|
|
|
r#"
|
2014-07-08 00:59:18 +00:00
|
|
|
extern crate baz;
|
|
|
|
|
|
|
|
pub fn gimme() -> String {
|
|
|
|
baz::gimme()
|
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"baz/Cargo.toml",
|
|
|
|
r#"
|
2014-07-08 00:59:18 +00:00
|
|
|
[project]
|
|
|
|
|
|
|
|
name = "baz"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["wycats@example.com"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"baz/src/lib.rs",
|
|
|
|
r#"
|
2014-07-08 00:59:18 +00:00
|
|
|
pub fn gimme() -> String {
|
2014-07-09 13:38:10 +00:00
|
|
|
"test passed".to_string()
|
2014-07-08 00:59:18 +00:00
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2014-07-08 00:59:18 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
p.cargo("build").exec_with_output().unwrap();
|
2014-07-08 00:59:18 +00:00
|
|
|
|
|
|
|
assert_that(&p.bin("foo"), existing_file());
|
2016-11-13 02:55:07 +00:00
|
|
|
assert_that(&p.bin("libbar.rlib"), is_not(existing_file()));
|
|
|
|
assert_that(&p.bin("libbaz.rlib"), is_not(existing_file()));
|
2014-07-08 00:59:18 +00:00
|
|
|
|
|
|
|
assert_that(
|
2018-03-14 15:17:44 +00:00
|
|
|
process(&p.bin("foo")),
|
|
|
|
execs().with_status(0).with_stdout("test passed\n"),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-07-08 00:59:18 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn cargo_compile_with_nested_deps_shorthand() {
|
Implement a registry source
# cargo upload
The cargo-upload command will take the local package and upload it to the
specified registry. The local package is uploaded as a tarball compressed with
gzip under maximum compression. Most of this is done by just delegating to
`cargo package` The host to upload to is specified, in order of priority, by a
command line `--host` flag, the `registry.host` config key, and then the default
registry. The default registry is still `example.com`
The registry itself is still a work in progress, but the general plumbing for a
command such as this would look like:
1. Ensure the local package has been compressed into an archive.
2. Fetch the relevant registry and login token from config files.
3. Ensure all dependencies for a package are listed as coming from the same
registry.
4. Upload the archive to the registry with the login token.
5. The registry will verify the package is under 2MB (configurable).
6. The registry will upload the archive to S3, calculating a checksum in the
process.
7. The registry will add an entry to the registry's index (a git repository).
The entry will include the name of the package, the version uploaded, the
checksum of the upload, and then the list of dependencies (name/version req)
8. The local `cargo upload` command will succeed.
# cargo login
Uploading requires a token from the api server, and this token follows the same
config chain for the host except that there is no fallback. To implement login,
the `cargo login` command is used. With 0 arguments, the command will request
that a site be visited for a login token, and with an argument it will set the
argument as the new login token.
The `util::config` module was modified to allow writing configuration as well as
reading it. The support is a little lacking in that comments are blown away, but
the support is there at least.
# RegistrySource
An implementation of `RegistrySource` has been created (deleting the old
`DummyRegistrySource`). This implementation only needs a URL to be constructed,
and it is assumed that the URL is running an instance of the cargo registry.
## RegistrySource::update
Currently this will unconditionally update the registry's index (a git
repository). Tuning is necessary to prevent updating the index each time (more
coming soon).
## RegistrySource::query
This is called in the resolve phase of cargo. This function is given a
dependency to query for, and the source will simply look into the index to see
if any package with the name is present. If found, the package's index file will
be loaded and parsed into a list of summaries.
The main optimization of this function is to not require the entire registry to
ever be resident in memory. Instead, only necessary packages are loaded into
memory and parsed.
## RegistrySource::download
This is also called during the resolve phase of cargo, but only when a package
has been selected to be built (actually resolved). This phase of the source will
actually download and unpack the tarball for the package.
Currently a configuration file is located in the root of a registry's index
describing the root url to download packages from.
This function is optimized for two different metrics:
1. If a tarball is downloaded, it is not downloaded again. It is assumed that
once a tarball is successfully downloaded it will never change.
2. If the unpacking destination has a `.cargo-ok` file, it is assumed that the
unpacking has already occurred and does not need to happen again.
With these in place, a rebuild should take almost no time at all.
## RegistrySource::get
This function is simply implemented in terms of a PathSource's `get` function by
creating a `PathSource` for all unpacked tarballs as part of the `download`
stage.
## Filesystem layout
There are a few new directories as part of the `.cargo` home folder:
* `.cargo/registry/index/$hostname-$hash` - This is the directory containing the
actual index of the registry. `$hostname` comes from its url, and `$hash` is
the hash of the entire url.
* `.cargo/registry/cache/$hostname-$hash/$pkg-$vers.tar.gz` - This is a
directory used to cache the downloads of packages from the registry.
* `.cargo/registry/src/$hostname-$hash/$pkg-$vers` - This is the location of the
unpacked packages. They will be compiled from this location.
# New Dependencies
Cargo has picked up a new dependency on the `curl-rust` package in order to send
HTTP requests to the registry as well as send HTTP requests to download
tarballs.
2014-07-18 15:40:45 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-05-08 23:49:58 +00:00
|
|
|
[project]
|
|
|
|
|
|
|
|
name = "foo"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["wycats@example.com"]
|
|
|
|
|
Implement a registry source
# cargo upload
The cargo-upload command will take the local package and upload it to the
specified registry. The local package is uploaded as a tarball compressed with
gzip under maximum compression. Most of this is done by just delegating to
`cargo package` The host to upload to is specified, in order of priority, by a
command line `--host` flag, the `registry.host` config key, and then the default
registry. The default registry is still `example.com`
The registry itself is still a work in progress, but the general plumbing for a
command such as this would look like:
1. Ensure the local package has been compressed into an archive.
2. Fetch the relevant registry and login token from config files.
3. Ensure all dependencies for a package are listed as coming from the same
registry.
4. Upload the archive to the registry with the login token.
5. The registry will verify the package is under 2MB (configurable).
6. The registry will upload the archive to S3, calculating a checksum in the
process.
7. The registry will add an entry to the registry's index (a git repository).
The entry will include the name of the package, the version uploaded, the
checksum of the upload, and then the list of dependencies (name/version req)
8. The local `cargo upload` command will succeed.
# cargo login
Uploading requires a token from the api server, and this token follows the same
config chain for the host except that there is no fallback. To implement login,
the `cargo login` command is used. With 0 arguments, the command will request
that a site be visited for a login token, and with an argument it will set the
argument as the new login token.
The `util::config` module was modified to allow writing configuration as well as
reading it. The support is a little lacking in that comments are blown away, but
the support is there at least.
# RegistrySource
An implementation of `RegistrySource` has been created (deleting the old
`DummyRegistrySource`). This implementation only needs a URL to be constructed,
and it is assumed that the URL is running an instance of the cargo registry.
## RegistrySource::update
Currently this will unconditionally update the registry's index (a git
repository). Tuning is necessary to prevent updating the index each time (more
coming soon).
## RegistrySource::query
This is called in the resolve phase of cargo. This function is given a
dependency to query for, and the source will simply look into the index to see
if any package with the name is present. If found, the package's index file will
be loaded and parsed into a list of summaries.
The main optimization of this function is to not require the entire registry to
ever be resident in memory. Instead, only necessary packages are loaded into
memory and parsed.
## RegistrySource::download
This is also called during the resolve phase of cargo, but only when a package
has been selected to be built (actually resolved). This phase of the source will
actually download and unpack the tarball for the package.
Currently a configuration file is located in the root of a registry's index
describing the root url to download packages from.
This function is optimized for two different metrics:
1. If a tarball is downloaded, it is not downloaded again. It is assumed that
once a tarball is successfully downloaded it will never change.
2. If the unpacking destination has a `.cargo-ok` file, it is assumed that the
unpacking has already occurred and does not need to happen again.
With these in place, a rebuild should take almost no time at all.
## RegistrySource::get
This function is simply implemented in terms of a PathSource's `get` function by
creating a `PathSource` for all unpacked tarballs as part of the `download`
stage.
## Filesystem layout
There are a few new directories as part of the `.cargo` home folder:
* `.cargo/registry/index/$hostname-$hash` - This is the directory containing the
actual index of the registry. `$hostname` comes from its url, and `$hash` is
the hash of the entire url.
* `.cargo/registry/cache/$hostname-$hash/$pkg-$vers.tar.gz` - This is a
directory used to cache the downloads of packages from the registry.
* `.cargo/registry/src/$hostname-$hash/$pkg-$vers` - This is the location of the
unpacked packages. They will be compiled from this location.
# New Dependencies
Cargo has picked up a new dependency on the `curl-rust` package in order to send
HTTP requests to the registry as well as send HTTP requests to download
tarballs.
2014-07-18 15:40:45 +00:00
|
|
|
[dependencies.bar]
|
|
|
|
path = "bar"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/main.rs", &main_file(r#""{}", bar::gimme()"#, &["bar"]))
|
|
|
|
.file(
|
|
|
|
"bar/Cargo.toml",
|
|
|
|
r#"
|
2014-05-08 23:49:58 +00:00
|
|
|
[project]
|
|
|
|
|
|
|
|
name = "bar"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["wycats@example.com"]
|
|
|
|
|
Implement a registry source
# cargo upload
The cargo-upload command will take the local package and upload it to the
specified registry. The local package is uploaded as a tarball compressed with
gzip under maximum compression. Most of this is done by just delegating to
`cargo package` The host to upload to is specified, in order of priority, by a
command line `--host` flag, the `registry.host` config key, and then the default
registry. The default registry is still `example.com`
The registry itself is still a work in progress, but the general plumbing for a
command such as this would look like:
1. Ensure the local package has been compressed into an archive.
2. Fetch the relevant registry and login token from config files.
3. Ensure all dependencies for a package are listed as coming from the same
registry.
4. Upload the archive to the registry with the login token.
5. The registry will verify the package is under 2MB (configurable).
6. The registry will upload the archive to S3, calculating a checksum in the
process.
7. The registry will add an entry to the registry's index (a git repository).
The entry will include the name of the package, the version uploaded, the
checksum of the upload, and then the list of dependencies (name/version req)
8. The local `cargo upload` command will succeed.
# cargo login
Uploading requires a token from the api server, and this token follows the same
config chain for the host except that there is no fallback. To implement login,
the `cargo login` command is used. With 0 arguments, the command will request
that a site be visited for a login token, and with an argument it will set the
argument as the new login token.
The `util::config` module was modified to allow writing configuration as well as
reading it. The support is a little lacking in that comments are blown away, but
the support is there at least.
# RegistrySource
An implementation of `RegistrySource` has been created (deleting the old
`DummyRegistrySource`). This implementation only needs a URL to be constructed,
and it is assumed that the URL is running an instance of the cargo registry.
## RegistrySource::update
Currently this will unconditionally update the registry's index (a git
repository). Tuning is necessary to prevent updating the index each time (more
coming soon).
## RegistrySource::query
This is called in the resolve phase of cargo. This function is given a
dependency to query for, and the source will simply look into the index to see
if any package with the name is present. If found, the package's index file will
be loaded and parsed into a list of summaries.
The main optimization of this function is to not require the entire registry to
ever be resident in memory. Instead, only necessary packages are loaded into
memory and parsed.
## RegistrySource::download
This is also called during the resolve phase of cargo, but only when a package
has been selected to be built (actually resolved). This phase of the source will
actually download and unpack the tarball for the package.
Currently a configuration file is located in the root of a registry's index
describing the root url to download packages from.
This function is optimized for two different metrics:
1. If a tarball is downloaded, it is not downloaded again. It is assumed that
once a tarball is successfully downloaded it will never change.
2. If the unpacking destination has a `.cargo-ok` file, it is assumed that the
unpacking has already occurred and does not need to happen again.
With these in place, a rebuild should take almost no time at all.
## RegistrySource::get
This function is simply implemented in terms of a PathSource's `get` function by
creating a `PathSource` for all unpacked tarballs as part of the `download`
stage.
## Filesystem layout
There are a few new directories as part of the `.cargo` home folder:
* `.cargo/registry/index/$hostname-$hash` - This is the directory containing the
actual index of the registry. `$hostname` comes from its url, and `$hash` is
the hash of the entire url.
* `.cargo/registry/cache/$hostname-$hash/$pkg-$vers.tar.gz` - This is a
directory used to cache the downloads of packages from the registry.
* `.cargo/registry/src/$hostname-$hash/$pkg-$vers` - This is the location of the
unpacked packages. They will be compiled from this location.
# New Dependencies
Cargo has picked up a new dependency on the `curl-rust` package in order to send
HTTP requests to the registry as well as send HTTP requests to download
tarballs.
2014-07-18 15:40:45 +00:00
|
|
|
[dependencies.baz]
|
|
|
|
path = "../baz"
|
2014-05-08 23:49:58 +00:00
|
|
|
|
2014-08-14 06:08:02 +00:00
|
|
|
[lib]
|
2014-05-08 23:49:58 +00:00
|
|
|
|
|
|
|
name = "bar"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"bar/src/bar.rs",
|
|
|
|
r#"
|
2014-05-08 23:49:58 +00:00
|
|
|
extern crate baz;
|
|
|
|
|
2014-05-27 23:14:34 +00:00
|
|
|
pub fn gimme() -> String {
|
2014-05-08 23:49:58 +00:00
|
|
|
baz::gimme()
|
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"baz/Cargo.toml",
|
|
|
|
r#"
|
2014-05-08 23:49:58 +00:00
|
|
|
[project]
|
|
|
|
|
|
|
|
name = "baz"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["wycats@example.com"]
|
|
|
|
|
2014-08-14 06:08:02 +00:00
|
|
|
[lib]
|
2014-05-08 23:49:58 +00:00
|
|
|
|
|
|
|
name = "baz"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"baz/src/baz.rs",
|
|
|
|
r#"
|
2014-05-27 23:14:34 +00:00
|
|
|
pub fn gimme() -> String {
|
2014-07-09 13:38:10 +00:00
|
|
|
"test passed".to_string()
|
2014-05-08 23:49:58 +00:00
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2014-05-08 23:49:58 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
p.cargo("build").exec_with_output().unwrap();
|
2014-05-08 23:49:58 +00:00
|
|
|
|
2014-06-25 05:06:11 +00:00
|
|
|
assert_that(&p.bin("foo"), existing_file());
|
2016-11-13 02:55:07 +00:00
|
|
|
assert_that(&p.bin("libbar.rlib"), is_not(existing_file()));
|
|
|
|
assert_that(&p.bin("libbaz.rlib"), is_not(existing_file()));
|
2014-05-08 23:49:58 +00:00
|
|
|
|
|
|
|
assert_that(
|
2018-03-14 15:17:44 +00:00
|
|
|
process(&p.bin("foo")),
|
|
|
|
execs().with_status(0).with_stdout("test passed\n"),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-05-08 23:49:58 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn cargo_compile_with_nested_deps_longhand() {
|
Implement a registry source
# cargo upload
The cargo-upload command will take the local package and upload it to the
specified registry. The local package is uploaded as a tarball compressed with
gzip under maximum compression. Most of this is done by just delegating to
`cargo package` The host to upload to is specified, in order of priority, by a
command line `--host` flag, the `registry.host` config key, and then the default
registry. The default registry is still `example.com`
The registry itself is still a work in progress, but the general plumbing for a
command such as this would look like:
1. Ensure the local package has been compressed into an archive.
2. Fetch the relevant registry and login token from config files.
3. Ensure all dependencies for a package are listed as coming from the same
registry.
4. Upload the archive to the registry with the login token.
5. The registry will verify the package is under 2MB (configurable).
6. The registry will upload the archive to S3, calculating a checksum in the
process.
7. The registry will add an entry to the registry's index (a git repository).
The entry will include the name of the package, the version uploaded, the
checksum of the upload, and then the list of dependencies (name/version req)
8. The local `cargo upload` command will succeed.
# cargo login
Uploading requires a token from the api server, and this token follows the same
config chain for the host except that there is no fallback. To implement login,
the `cargo login` command is used. With 0 arguments, the command will request
that a site be visited for a login token, and with an argument it will set the
argument as the new login token.
The `util::config` module was modified to allow writing configuration as well as
reading it. The support is a little lacking in that comments are blown away, but
the support is there at least.
# RegistrySource
An implementation of `RegistrySource` has been created (deleting the old
`DummyRegistrySource`). This implementation only needs a URL to be constructed,
and it is assumed that the URL is running an instance of the cargo registry.
## RegistrySource::update
Currently this will unconditionally update the registry's index (a git
repository). Tuning is necessary to prevent updating the index each time (more
coming soon).
## RegistrySource::query
This is called in the resolve phase of cargo. This function is given a
dependency to query for, and the source will simply look into the index to see
if any package with the name is present. If found, the package's index file will
be loaded and parsed into a list of summaries.
The main optimization of this function is to not require the entire registry to
ever be resident in memory. Instead, only necessary packages are loaded into
memory and parsed.
## RegistrySource::download
This is also called during the resolve phase of cargo, but only when a package
has been selected to be built (actually resolved). This phase of the source will
actually download and unpack the tarball for the package.
Currently a configuration file is located in the root of a registry's index
describing the root url to download packages from.
This function is optimized for two different metrics:
1. If a tarball is downloaded, it is not downloaded again. It is assumed that
once a tarball is successfully downloaded it will never change.
2. If the unpacking destination has a `.cargo-ok` file, it is assumed that the
unpacking has already occurred and does not need to happen again.
With these in place, a rebuild should take almost no time at all.
## RegistrySource::get
This function is simply implemented in terms of a PathSource's `get` function by
creating a `PathSource` for all unpacked tarballs as part of the `download`
stage.
## Filesystem layout
There are a few new directories as part of the `.cargo` home folder:
* `.cargo/registry/index/$hostname-$hash` - This is the directory containing the
actual index of the registry. `$hostname` comes from its url, and `$hash` is
the hash of the entire url.
* `.cargo/registry/cache/$hostname-$hash/$pkg-$vers.tar.gz` - This is a
directory used to cache the downloads of packages from the registry.
* `.cargo/registry/src/$hostname-$hash/$pkg-$vers` - This is the location of the
unpacked packages. They will be compiled from this location.
# New Dependencies
Cargo has picked up a new dependency on the `curl-rust` package in order to send
HTTP requests to the registry as well as send HTTP requests to download
tarballs.
2014-07-18 15:40:45 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-06-10 00:51:53 +00:00
|
|
|
[project]
|
|
|
|
|
|
|
|
name = "foo"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["wycats@example.com"]
|
|
|
|
|
Implement a registry source
# cargo upload
The cargo-upload command will take the local package and upload it to the
specified registry. The local package is uploaded as a tarball compressed with
gzip under maximum compression. Most of this is done by just delegating to
`cargo package` The host to upload to is specified, in order of priority, by a
command line `--host` flag, the `registry.host` config key, and then the default
registry. The default registry is still `example.com`
The registry itself is still a work in progress, but the general plumbing for a
command such as this would look like:
1. Ensure the local package has been compressed into an archive.
2. Fetch the relevant registry and login token from config files.
3. Ensure all dependencies for a package are listed as coming from the same
registry.
4. Upload the archive to the registry with the login token.
5. The registry will verify the package is under 2MB (configurable).
6. The registry will upload the archive to S3, calculating a checksum in the
process.
7. The registry will add an entry to the registry's index (a git repository).
The entry will include the name of the package, the version uploaded, the
checksum of the upload, and then the list of dependencies (name/version req)
8. The local `cargo upload` command will succeed.
# cargo login
Uploading requires a token from the api server, and this token follows the same
config chain for the host except that there is no fallback. To implement login,
the `cargo login` command is used. With 0 arguments, the command will request
that a site be visited for a login token, and with an argument it will set the
argument as the new login token.
The `util::config` module was modified to allow writing configuration as well as
reading it. The support is a little lacking in that comments are blown away, but
the support is there at least.
# RegistrySource
An implementation of `RegistrySource` has been created (deleting the old
`DummyRegistrySource`). This implementation only needs a URL to be constructed,
and it is assumed that the URL is running an instance of the cargo registry.
## RegistrySource::update
Currently this will unconditionally update the registry's index (a git
repository). Tuning is necessary to prevent updating the index each time (more
coming soon).
## RegistrySource::query
This is called in the resolve phase of cargo. This function is given a
dependency to query for, and the source will simply look into the index to see
if any package with the name is present. If found, the package's index file will
be loaded and parsed into a list of summaries.
The main optimization of this function is to not require the entire registry to
ever be resident in memory. Instead, only necessary packages are loaded into
memory and parsed.
## RegistrySource::download
This is also called during the resolve phase of cargo, but only when a package
has been selected to be built (actually resolved). This phase of the source will
actually download and unpack the tarball for the package.
Currently a configuration file is located in the root of a registry's index
describing the root url to download packages from.
This function is optimized for two different metrics:
1. If a tarball is downloaded, it is not downloaded again. It is assumed that
once a tarball is successfully downloaded it will never change.
2. If the unpacking destination has a `.cargo-ok` file, it is assumed that the
unpacking has already occurred and does not need to happen again.
With these in place, a rebuild should take almost no time at all.
## RegistrySource::get
This function is simply implemented in terms of a PathSource's `get` function by
creating a `PathSource` for all unpacked tarballs as part of the `download`
stage.
## Filesystem layout
There are a few new directories as part of the `.cargo` home folder:
* `.cargo/registry/index/$hostname-$hash` - This is the directory containing the
actual index of the registry. `$hostname` comes from its url, and `$hash` is
the hash of the entire url.
* `.cargo/registry/cache/$hostname-$hash/$pkg-$vers.tar.gz` - This is a
directory used to cache the downloads of packages from the registry.
* `.cargo/registry/src/$hostname-$hash/$pkg-$vers` - This is the location of the
unpacked packages. They will be compiled from this location.
# New Dependencies
Cargo has picked up a new dependency on the `curl-rust` package in order to send
HTTP requests to the registry as well as send HTTP requests to download
tarballs.
2014-07-18 15:40:45 +00:00
|
|
|
[dependencies.bar]
|
|
|
|
path = "bar"
|
|
|
|
version = "0.5.0"
|
2014-06-10 00:51:53 +00:00
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
|
|
|
|
name = "foo"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/foo.rs", &main_file(r#""{}", bar::gimme()"#, &["bar"]))
|
|
|
|
.file(
|
|
|
|
"bar/Cargo.toml",
|
|
|
|
r#"
|
2014-06-10 00:51:53 +00:00
|
|
|
[project]
|
|
|
|
|
|
|
|
name = "bar"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["wycats@example.com"]
|
|
|
|
|
|
|
|
[dependencies.baz]
|
Implement a registry source
# cargo upload
The cargo-upload command will take the local package and upload it to the
specified registry. The local package is uploaded as a tarball compressed with
gzip under maximum compression. Most of this is done by just delegating to
`cargo package` The host to upload to is specified, in order of priority, by a
command line `--host` flag, the `registry.host` config key, and then the default
registry. The default registry is still `example.com`
The registry itself is still a work in progress, but the general plumbing for a
command such as this would look like:
1. Ensure the local package has been compressed into an archive.
2. Fetch the relevant registry and login token from config files.
3. Ensure all dependencies for a package are listed as coming from the same
registry.
4. Upload the archive to the registry with the login token.
5. The registry will verify the package is under 2MB (configurable).
6. The registry will upload the archive to S3, calculating a checksum in the
process.
7. The registry will add an entry to the registry's index (a git repository).
The entry will include the name of the package, the version uploaded, the
checksum of the upload, and then the list of dependencies (name/version req)
8. The local `cargo upload` command will succeed.
# cargo login
Uploading requires a token from the api server, and this token follows the same
config chain for the host except that there is no fallback. To implement login,
the `cargo login` command is used. With 0 arguments, the command will request
that a site be visited for a login token, and with an argument it will set the
argument as the new login token.
The `util::config` module was modified to allow writing configuration as well as
reading it. The support is a little lacking in that comments are blown away, but
the support is there at least.
# RegistrySource
An implementation of `RegistrySource` has been created (deleting the old
`DummyRegistrySource`). This implementation only needs a URL to be constructed,
and it is assumed that the URL is running an instance of the cargo registry.
## RegistrySource::update
Currently this will unconditionally update the registry's index (a git
repository). Tuning is necessary to prevent updating the index each time (more
coming soon).
## RegistrySource::query
This is called in the resolve phase of cargo. This function is given a
dependency to query for, and the source will simply look into the index to see
if any package with the name is present. If found, the package's index file will
be loaded and parsed into a list of summaries.
The main optimization of this function is to not require the entire registry to
ever be resident in memory. Instead, only necessary packages are loaded into
memory and parsed.
## RegistrySource::download
This is also called during the resolve phase of cargo, but only when a package
has been selected to be built (actually resolved). This phase of the source will
actually download and unpack the tarball for the package.
Currently a configuration file is located in the root of a registry's index
describing the root url to download packages from.
This function is optimized for two different metrics:
1. If a tarball is downloaded, it is not downloaded again. It is assumed that
once a tarball is successfully downloaded it will never change.
2. If the unpacking destination has a `.cargo-ok` file, it is assumed that the
unpacking has already occurred and does not need to happen again.
With these in place, a rebuild should take almost no time at all.
## RegistrySource::get
This function is simply implemented in terms of a PathSource's `get` function by
creating a `PathSource` for all unpacked tarballs as part of the `download`
stage.
## Filesystem layout
There are a few new directories as part of the `.cargo` home folder:
* `.cargo/registry/index/$hostname-$hash` - This is the directory containing the
actual index of the registry. `$hostname` comes from its url, and `$hash` is
the hash of the entire url.
* `.cargo/registry/cache/$hostname-$hash/$pkg-$vers.tar.gz` - This is a
directory used to cache the downloads of packages from the registry.
* `.cargo/registry/src/$hostname-$hash/$pkg-$vers` - This is the location of the
unpacked packages. They will be compiled from this location.
# New Dependencies
Cargo has picked up a new dependency on the `curl-rust` package in order to send
HTTP requests to the registry as well as send HTTP requests to download
tarballs.
2014-07-18 15:40:45 +00:00
|
|
|
path = "../baz"
|
2014-06-10 00:51:53 +00:00
|
|
|
version = "0.5.0"
|
|
|
|
|
2014-08-14 06:08:02 +00:00
|
|
|
[lib]
|
2014-06-10 00:51:53 +00:00
|
|
|
|
|
|
|
name = "bar"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"bar/src/bar.rs",
|
|
|
|
r#"
|
2014-06-10 00:51:53 +00:00
|
|
|
extern crate baz;
|
|
|
|
|
|
|
|
pub fn gimme() -> String {
|
|
|
|
baz::gimme()
|
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"baz/Cargo.toml",
|
|
|
|
r#"
|
2014-06-10 00:51:53 +00:00
|
|
|
[project]
|
|
|
|
|
|
|
|
name = "baz"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["wycats@example.com"]
|
|
|
|
|
2014-08-14 06:08:02 +00:00
|
|
|
[lib]
|
2014-06-10 00:51:53 +00:00
|
|
|
|
|
|
|
name = "baz"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"baz/src/baz.rs",
|
|
|
|
r#"
|
2014-06-10 00:51:53 +00:00
|
|
|
pub fn gimme() -> String {
|
2014-07-09 13:38:10 +00:00
|
|
|
"test passed".to_string()
|
2014-06-10 00:51:53 +00:00
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2014-06-10 00:51:53 +00:00
|
|
|
|
2017-07-22 03:12:21 +00:00
|
|
|
assert_that(p.cargo("build"), execs());
|
2014-06-10 00:51:53 +00:00
|
|
|
|
2014-06-25 05:06:11 +00:00
|
|
|
assert_that(&p.bin("foo"), existing_file());
|
2016-11-13 02:55:07 +00:00
|
|
|
assert_that(&p.bin("libbar.rlib"), is_not(existing_file()));
|
|
|
|
assert_that(&p.bin("libbaz.rlib"), is_not(existing_file()));
|
2014-06-10 00:51:53 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
process(&p.bin("foo")),
|
|
|
|
execs().with_status(0).with_stdout("test passed\n"),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-06-10 00:51:53 +00:00
|
|
|
|
2014-07-24 11:16:20 +00:00
|
|
|
// Check that Cargo gives a sensible error if a dependency can't be found
|
|
|
|
// because of a name mismatch.
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn cargo_compile_with_dep_name_mismatch() {
|
2014-07-24 11:16:20 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-07-24 11:16:20 +00:00
|
|
|
[package]
|
|
|
|
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = ["wycats@example.com"]
|
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
|
|
|
|
name = "foo"
|
|
|
|
|
|
|
|
[dependencies.notquitebar]
|
|
|
|
|
|
|
|
path = "bar"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-09 12:57:25 +00:00
|
|
|
.file("src/bin/foo.rs", &main_file(r#""i am foo""#, &["bar"]))
|
2015-03-26 18:17:44 +00:00
|
|
|
.file("bar/Cargo.toml", &basic_bin_manifest("bar"))
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("bar/src/bar.rs", &main_file(r#""i am bar""#, &[]))
|
|
|
|
.build();
|
2014-07-24 11:16:20 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build"),
|
|
|
|
execs().with_status(101).with_stderr(&format!(
|
|
|
|
r#"error: no matching package named `notquitebar` found
|
2016-03-01 16:24:43 +00:00
|
|
|
location searched: {proj_dir}/bar
|
2018-02-07 16:51:40 +00:00
|
|
|
required by package `foo v0.0.1 ({proj_dir})`
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
proj_dir = p.url()
|
|
|
|
)),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-07-24 11:16:20 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn cargo_compile_with_filename() {
|
2016-03-14 17:22:17 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2016-03-14 17:22:17 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2016-03-14 17:22:17 +00:00
|
|
|
.file("src/lib.rs", "")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"src/bin/a.rs",
|
|
|
|
r#"
|
2016-03-14 17:22:17 +00:00
|
|
|
extern crate foo;
|
|
|
|
fn main() { println!("hello a.rs"); }
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"examples/a.rs",
|
|
|
|
r#"
|
2016-03-14 17:22:17 +00:00
|
|
|
fn main() { println!("example"); }
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2016-03-14 17:22:17 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build").arg("--bin").arg("bin.rs"),
|
2018-03-14 15:43:41 +00:00
|
|
|
execs()
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr("[ERROR] no bin target named `bin.rs`"),
|
2018-03-14 15:17:44 +00:00
|
|
|
);
|
2016-03-14 17:22:17 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build").arg("--bin").arg("a.rs"),
|
|
|
|
execs().with_status(101).with_stderr(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[ERROR] no bin target named `a.rs`
|
2016-03-14 17:22:17 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
Did you mean `a`?",
|
|
|
|
),
|
|
|
|
);
|
2016-03-14 17:22:17 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build").arg("--example").arg("example.rs"),
|
2018-03-14 15:43:41 +00:00
|
|
|
execs()
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr("[ERROR] no example target named `example.rs`"),
|
2018-03-14 15:17:44 +00:00
|
|
|
);
|
2016-03-14 17:22:17 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build").arg("--example").arg("a.rs"),
|
|
|
|
execs().with_status(101).with_stderr(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[ERROR] no example target named `a.rs`
|
2016-03-14 17:22:17 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
Did you mean `a`?",
|
|
|
|
),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2016-03-14 17:22:17 +00:00
|
|
|
|
2017-12-24 23:32:29 +00:00
|
|
|
#[test]
|
|
|
|
fn cargo_compile_path_with_offline() {
|
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-12-24 23:32:29 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies.bar]
|
|
|
|
path = "bar"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-12-24 23:32:29 +00:00
|
|
|
.file("src/lib.rs", "")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"bar/Cargo.toml",
|
|
|
|
r#"
|
2017-12-24 23:32:29 +00:00
|
|
|
[package]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-12-24 23:32:29 +00:00
|
|
|
.file("bar/src/lib.rs", "")
|
|
|
|
.build();
|
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build")
|
|
|
|
.masquerade_as_nightly_cargo()
|
|
|
|
.arg("-Zoffline"),
|
|
|
|
execs().with_status(0),
|
|
|
|
);
|
2017-12-24 23:32:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn cargo_compile_with_downloaded_dependency_with_offline() {
|
|
|
|
Package::new("present_dep", "1.2.3")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-12-24 23:32:29 +00:00
|
|
|
[project]
|
|
|
|
name = "present_dep"
|
|
|
|
version = "1.2.3"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-12-24 23:32:29 +00:00
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.publish();
|
|
|
|
|
|
|
|
{
|
|
|
|
// make package downloaded
|
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-12-24 23:32:29 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
present_dep = "1.2.3"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-12-24 23:32:29 +00:00
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.build();
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(p.cargo("build"), execs().with_status(0));
|
2017-12-24 23:32:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let p2 = project("bar")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-12-24 23:32:29 +00:00
|
|
|
[project]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.1.0"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
present_dep = "1.2.3"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-12-24 23:32:29 +00:00
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.build();
|
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p2.cargo("build")
|
|
|
|
.masquerade_as_nightly_cargo()
|
|
|
|
.arg("-Zoffline"),
|
|
|
|
execs().with_status(0).with_stderr(format!(
|
|
|
|
"\
|
2017-12-24 23:32:29 +00:00
|
|
|
[COMPILING] present_dep v1.2.3
|
2018-01-08 18:22:12 +00:00
|
|
|
[COMPILING] bar v0.1.0 ([..])
|
2018-03-14 15:17:44 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]"
|
|
|
|
)),
|
|
|
|
);
|
2017-12-24 23:32:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn cargo_compile_offline_not_try_update() {
|
|
|
|
let p = project("bar")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-12-24 23:32:29 +00:00
|
|
|
[project]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.1.0"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
not_cached_dep = "1.2.5"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-12-24 23:32:29 +00:00
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.build();
|
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build")
|
|
|
|
.masquerade_as_nightly_cargo()
|
|
|
|
.arg("-Zoffline"),
|
|
|
|
execs().with_status(101).with_stderr(
|
|
|
|
"\
|
2018-02-07 16:51:40 +00:00
|
|
|
error: no matching package named `not_cached_dep` found
|
2017-12-24 23:32:29 +00:00
|
|
|
location searched: registry `[..]`
|
2018-02-07 16:51:40 +00:00
|
|
|
required by package `bar v0.1.0 ([..])`
|
2018-01-08 18:22:12 +00:00
|
|
|
As a reminder, you're using offline mode (-Z offline) \
|
|
|
|
which can sometimes cause surprising resolution failures, \
|
|
|
|
if this error is too confusing you may with to retry \
|
2018-03-14 15:17:44 +00:00
|
|
|
without the offline flag.",
|
|
|
|
),
|
|
|
|
);
|
2017-12-24 23:32:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2018-03-14 15:17:44 +00:00
|
|
|
fn compile_offline_without_maxvers_cached() {
|
2017-12-24 23:32:29 +00:00
|
|
|
Package::new("present_dep", "1.2.1").publish();
|
|
|
|
Package::new("present_dep", "1.2.2").publish();
|
|
|
|
|
|
|
|
Package::new("present_dep", "1.2.3")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-12-24 23:32:29 +00:00
|
|
|
[project]
|
|
|
|
name = "present_dep"
|
|
|
|
version = "1.2.3"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"pub fn get_version()->&'static str {"1.2.3"}"#,
|
|
|
|
)
|
2017-12-24 23:32:29 +00:00
|
|
|
.publish();
|
|
|
|
|
|
|
|
Package::new("present_dep", "1.2.5")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-12-24 23:32:29 +00:00
|
|
|
[project]
|
|
|
|
name = "present_dep"
|
|
|
|
version = "1.2.5"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-12-24 23:32:29 +00:00
|
|
|
.file("src/lib.rs", r#"pub fn get_version(){"1.2.5"}"#)
|
|
|
|
.publish();
|
|
|
|
|
|
|
|
{
|
|
|
|
// make package cached
|
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-12-24 23:32:29 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
present_dep = "=1.2.3"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-12-24 23:32:29 +00:00
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.build();
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(p.cargo("build"), execs().with_status(0));
|
2017-12-24 23:32:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let p2 = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-12-24 23:32:29 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
present_dep = "1.2"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
"\
|
2017-12-24 23:32:29 +00:00
|
|
|
extern crate present_dep;
|
|
|
|
fn main(){
|
|
|
|
println!(\"{}\", present_dep::get_version());
|
2018-03-14 15:17:44 +00:00
|
|
|
}",
|
|
|
|
)
|
2017-12-24 23:32:29 +00:00
|
|
|
.build();
|
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p2.cargo("run")
|
|
|
|
.masquerade_as_nightly_cargo()
|
|
|
|
.arg("-Zoffline"),
|
|
|
|
execs()
|
|
|
|
.with_status(0)
|
|
|
|
.with_stderr(format!(
|
|
|
|
"\
|
2017-12-24 23:32:29 +00:00
|
|
|
[COMPILING] present_dep v1.2.3
|
|
|
|
[COMPILING] foo v0.1.0 ({url})
|
2018-01-08 18:22:12 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2018-03-14 15:17:44 +00:00
|
|
|
Running `[..]`",
|
|
|
|
url = p2.url()
|
|
|
|
))
|
|
|
|
.with_stdout("1.2.3"),
|
2018-01-08 18:22:12 +00:00
|
|
|
);
|
2017-12-24 23:32:29 +00:00
|
|
|
}
|
|
|
|
|
2018-02-07 22:45:02 +00:00
|
|
|
#[test]
|
|
|
|
fn incompatible_dependencies() {
|
|
|
|
Package::new("bad", "0.1.0").publish();
|
|
|
|
Package::new("bad", "1.0.0").publish();
|
|
|
|
Package::new("bad", "1.0.1").publish();
|
|
|
|
Package::new("bad", "1.0.2").publish();
|
|
|
|
Package::new("foo", "0.1.0").dep("bad", "0.1.0").publish();
|
|
|
|
Package::new("bar", "0.1.1").dep("bad", "=1.0.0").publish();
|
|
|
|
Package::new("bar", "0.1.0").dep("bad", "=1.0.0").publish();
|
|
|
|
Package::new("baz", "0.1.2").dep("bad", ">=1.0.1").publish();
|
|
|
|
Package::new("baz", "0.1.1").dep("bad", ">=1.0.1").publish();
|
|
|
|
Package::new("baz", "0.1.0").dep("bad", ">=1.0.1").publish();
|
|
|
|
|
|
|
|
let p = project("transitive_load_test")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2018-02-07 22:45:02 +00:00
|
|
|
[project]
|
|
|
|
name = "incompatible_dependencies"
|
|
|
|
version = "0.0.1"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
foo = "0.1.0"
|
|
|
|
bar = "0.1.0"
|
|
|
|
baz = "0.1.0"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2018-02-07 22:45:02 +00:00
|
|
|
.file("src/main.rs", "fn main(){}")
|
|
|
|
.build();
|
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build"),
|
|
|
|
execs().with_status(101).with_stderr_contains(
|
|
|
|
"\
|
2018-02-13 01:54:52 +00:00
|
|
|
error: failed to select a version for `bad`.
|
2018-02-15 03:28:59 +00:00
|
|
|
... required by package `baz v0.1.0`
|
2018-02-07 16:51:40 +00:00
|
|
|
... which is depended on by `incompatible_dependencies v0.0.1 ([..])`
|
2018-02-15 03:28:59 +00:00
|
|
|
versions that meet the requirements `>= 1.0.1` are: 1.0.2, 1.0.1
|
|
|
|
|
|
|
|
all possible versions conflict with previously selected packages.
|
|
|
|
|
2018-02-07 16:51:40 +00:00
|
|
|
previously selected package `bad v1.0.0`
|
|
|
|
... which is depended on by `bar v0.1.0`
|
|
|
|
... which is depended on by `incompatible_dependencies v0.0.1 ([..])`
|
2018-02-15 03:28:59 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
failed to select a version for `bad` which could resolve this conflict",
|
|
|
|
),
|
|
|
|
);
|
2018-02-07 22:45:02 +00:00
|
|
|
}
|
|
|
|
|
2018-02-13 01:54:52 +00:00
|
|
|
#[test]
|
|
|
|
fn incompatible_dependencies_with_multi_semver() {
|
|
|
|
Package::new("bad", "1.0.0").publish();
|
|
|
|
Package::new("bad", "1.0.1").publish();
|
|
|
|
Package::new("bad", "2.0.0").publish();
|
|
|
|
Package::new("bad", "2.0.1").publish();
|
|
|
|
Package::new("bar", "0.1.0").dep("bad", "=1.0.0").publish();
|
|
|
|
Package::new("baz", "0.1.0").dep("bad", ">=2.0.1").publish();
|
|
|
|
|
|
|
|
let p = project("transitive_load_test")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2018-02-13 01:54:52 +00:00
|
|
|
[project]
|
|
|
|
name = "incompatible_dependencies"
|
|
|
|
version = "0.0.1"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
bar = "0.1.0"
|
|
|
|
baz = "0.1.0"
|
|
|
|
bad = ">=1.0.1, <=2.0.0"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2018-02-13 01:54:52 +00:00
|
|
|
.file("src/main.rs", "fn main(){}")
|
|
|
|
.build();
|
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build"),
|
|
|
|
execs().with_status(101).with_stderr_contains(
|
|
|
|
"\
|
2018-02-13 01:54:52 +00:00
|
|
|
error: failed to select a version for `bad`.
|
2018-02-15 03:28:59 +00:00
|
|
|
... required by package `incompatible_dependencies v0.0.1 ([..])`
|
|
|
|
versions that meet the requirements `>= 1.0.1, <= 2.0.0` are: 2.0.0, 1.0.1
|
|
|
|
|
2018-02-13 01:54:52 +00:00
|
|
|
all possible versions conflict with previously selected packages.
|
2018-02-15 03:28:59 +00:00
|
|
|
|
2018-02-13 01:54:52 +00:00
|
|
|
previously selected package `bad v2.0.1`
|
|
|
|
... which is depended on by `baz v0.1.0`
|
|
|
|
... which is depended on by `incompatible_dependencies v0.0.1 ([..])`
|
2018-02-15 03:28:59 +00:00
|
|
|
|
2018-02-13 01:54:52 +00:00
|
|
|
previously selected package `bad v1.0.0`
|
|
|
|
... which is depended on by `bar v0.1.0`
|
|
|
|
... which is depended on by `incompatible_dependencies v0.0.1 ([..])`
|
2018-02-15 03:28:59 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
failed to select a version for `bad` which could resolve this conflict",
|
|
|
|
),
|
|
|
|
);
|
2018-02-13 01:54:52 +00:00
|
|
|
}
|
|
|
|
|
2017-12-24 23:32:29 +00:00
|
|
|
#[test]
|
|
|
|
fn compile_offline_while_transitive_dep_not_cached() {
|
|
|
|
let bar = Package::new("bar", "1.0.0");
|
|
|
|
let bar_path = bar.archive_dst();
|
|
|
|
bar.publish();
|
|
|
|
|
|
|
|
let mut content = Vec::new();
|
|
|
|
|
|
|
|
let mut file = File::open(bar_path.clone()).ok().unwrap();
|
|
|
|
let _ok = file.read_to_end(&mut content).ok().unwrap();
|
|
|
|
drop(file);
|
2018-03-14 15:17:44 +00:00
|
|
|
drop(File::create(bar_path.clone()).ok().unwrap());
|
2017-12-24 23:32:29 +00:00
|
|
|
|
|
|
|
Package::new("foo", "0.1.0").dep("bar", "1.0.0").publish();
|
|
|
|
|
|
|
|
let p = project("transitive_load_test")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-12-24 23:32:29 +00:00
|
|
|
[project]
|
|
|
|
name = "transitive_load_test"
|
|
|
|
version = "0.0.1"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
foo = "0.1.0"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-12-24 23:32:29 +00:00
|
|
|
.file("src/main.rs", "fn main(){}")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
// simulate download foo, but fail to download bar
|
|
|
|
let _out = p.cargo("build").exec_with_output();
|
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
drop(File::create(bar_path).ok().unwrap().write_all(&content));
|
2017-12-24 23:32:29 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build")
|
|
|
|
.masquerade_as_nightly_cargo()
|
|
|
|
.arg("-Zoffline"),
|
|
|
|
execs().with_status(101).with_stderr(
|
|
|
|
"\
|
2018-02-07 16:51:40 +00:00
|
|
|
error: no matching package named `bar` found
|
2017-12-24 23:32:29 +00:00
|
|
|
location searched: registry `[..]`
|
2018-02-07 16:51:40 +00:00
|
|
|
required by package `foo v0.1.0`
|
|
|
|
... which is depended on by `transitive_load_test v0.0.1 ([..]/transitive_load_test)`
|
2018-01-08 18:22:12 +00:00
|
|
|
As a reminder, you're using offline mode (-Z offline) \
|
|
|
|
which can sometimes cause surprising resolution failures, \
|
|
|
|
if this error is too confusing you may with to retry \
|
2018-03-14 15:17:44 +00:00
|
|
|
without the offline flag.",
|
|
|
|
),
|
|
|
|
);
|
2017-12-24 23:32:29 +00:00
|
|
|
}
|
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn compile_path_dep_then_change_version() {
|
2015-01-11 07:03:58 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2015-01-11 07:03:58 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies.bar]
|
|
|
|
path = "bar"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2015-01-11 07:03:58 +00:00
|
|
|
.file("src/lib.rs", "")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"bar/Cargo.toml",
|
|
|
|
r#"
|
2015-01-11 07:03:58 +00:00
|
|
|
[package]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("bar/src/lib.rs", "")
|
|
|
|
.build();
|
2015-01-11 07:03:58 +00:00
|
|
|
|
2017-07-22 03:12:21 +00:00
|
|
|
assert_that(p.cargo("build"), execs().with_status(0));
|
2015-01-11 07:03:58 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
File::create(&p.root().join("bar/Cargo.toml"))
|
|
|
|
.unwrap()
|
|
|
|
.write_all(
|
|
|
|
br#"
|
2015-01-11 07:03:58 +00:00
|
|
|
[package]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.0.2"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.unwrap();
|
2015-01-11 07:03:58 +00:00
|
|
|
|
2018-03-20 18:38:25 +00:00
|
|
|
assert_that(p.cargo("build"), execs().with_status(0));
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-01-11 07:03:58 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn ignores_carriage_return_in_lockfile() {
|
2015-09-19 14:41:06 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2015-09-19 14:41:06 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
authors = []
|
|
|
|
version = "0.0.1"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
2015-09-19 14:41:06 +00:00
|
|
|
mod a; fn main() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/a.rs", "")
|
|
|
|
.build();
|
2015-09-19 14:41:06 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(p.cargo("build"), execs().with_status(0));
|
2015-09-19 14:41:06 +00:00
|
|
|
|
|
|
|
let lockfile = p.root().join("Cargo.lock");
|
|
|
|
let mut lock = String::new();
|
2018-03-14 15:17:44 +00:00
|
|
|
File::open(&lockfile)
|
|
|
|
.unwrap()
|
|
|
|
.read_to_string(&mut lock)
|
|
|
|
.unwrap();
|
2015-09-19 14:41:06 +00:00
|
|
|
let lock = lock.replace("\n", "\r\n");
|
2018-03-14 15:17:44 +00:00
|
|
|
File::create(&lockfile)
|
|
|
|
.unwrap()
|
|
|
|
.write_all(lock.as_bytes())
|
|
|
|
.unwrap();
|
|
|
|
assert_that(p.cargo("build"), execs().with_status(0));
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-09-19 14:41:06 +00:00
|
|
|
|
2016-11-13 02:55:07 +00:00
|
|
|
#[test]
|
|
|
|
fn cargo_default_env_metadata_env_var() {
|
|
|
|
// Ensure that path dep + dylib + env_var get metadata
|
|
|
|
// (even though path_dep + dylib should not)
|
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2016-11-13 02:55:07 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies.bar]
|
|
|
|
path = "bar"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2016-11-13 02:55:07 +00:00
|
|
|
.file("src/lib.rs", "// hi")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"bar/Cargo.toml",
|
|
|
|
r#"
|
2016-11-13 02:55:07 +00:00
|
|
|
[package]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[lib]
|
|
|
|
name = "bar"
|
|
|
|
crate_type = ["dylib"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("bar/src/lib.rs", "// hello")
|
|
|
|
.build();
|
2016-11-13 02:55:07 +00:00
|
|
|
|
|
|
|
// No metadata on libbar since it's a dylib path dependency
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build").arg("-v"),
|
|
|
|
execs().with_status(0).with_stderr(&format!(
|
|
|
|
"\
|
2016-11-13 03:27:09 +00:00
|
|
|
[COMPILING] bar v0.0.1 ({url}/bar)
|
2016-11-29 23:11:58 +00:00
|
|
|
[RUNNING] `rustc --crate-name bar bar[/]src[/]lib.rs --crate-type dylib \
|
2017-01-03 21:22:58 +00:00
|
|
|
--emit=dep-info,link \
|
2017-01-12 05:35:17 +00:00
|
|
|
-C prefer-dynamic -C debuginfo=2 \
|
2016-11-13 02:55:07 +00:00
|
|
|
-C metadata=[..] \
|
|
|
|
--out-dir [..] \
|
|
|
|
-L dependency={dir}[/]target[/]debug[/]deps`
|
|
|
|
[COMPILING] foo v0.0.1 ({url})
|
2017-01-03 21:22:58 +00:00
|
|
|
[RUNNING] `rustc --crate-name foo src[/]lib.rs --crate-type lib \
|
2017-01-12 05:35:17 +00:00
|
|
|
--emit=dep-info,link -C debuginfo=2 \
|
2016-11-13 02:55:07 +00:00
|
|
|
-C metadata=[..] \
|
|
|
|
-C extra-filename=[..] \
|
|
|
|
--out-dir [..] \
|
|
|
|
-L dependency={dir}[/]target[/]debug[/]deps \
|
2016-11-13 05:49:44 +00:00
|
|
|
--extern bar={dir}[/]target[/]debug[/]deps[/]{prefix}bar{suffix}`
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]",
|
2018-03-14 15:17:44 +00:00
|
|
|
dir = p.root().display(),
|
|
|
|
url = p.url(),
|
|
|
|
prefix = env::consts::DLL_PREFIX,
|
|
|
|
suffix = env::consts::DLL_SUFFIX,
|
|
|
|
)),
|
|
|
|
);
|
2016-11-13 02:55:07 +00:00
|
|
|
|
2017-02-15 14:16:41 +00:00
|
|
|
assert_that(p.cargo("clean"), execs().with_status(0));
|
2016-11-13 02:55:07 +00:00
|
|
|
|
|
|
|
// If you set the env-var, then we expect metadata on libbar
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build")
|
|
|
|
.arg("-v")
|
|
|
|
.env("__CARGO_DEFAULT_LIB_METADATA", "stable"),
|
|
|
|
execs().with_status(0).with_stderr(&format!(
|
|
|
|
"\
|
2016-11-13 06:16:56 +00:00
|
|
|
[COMPILING] bar v0.0.1 ({url}/bar)
|
2016-11-29 23:11:58 +00:00
|
|
|
[RUNNING] `rustc --crate-name bar bar[/]src[/]lib.rs --crate-type dylib \
|
2017-01-03 21:22:58 +00:00
|
|
|
--emit=dep-info,link \
|
2017-01-12 05:35:17 +00:00
|
|
|
-C prefer-dynamic -C debuginfo=2 \
|
2016-11-13 02:55:07 +00:00
|
|
|
-C metadata=[..] \
|
|
|
|
--out-dir [..] \
|
|
|
|
-L dependency={dir}[/]target[/]debug[/]deps`
|
|
|
|
[COMPILING] foo v0.0.1 ({url})
|
2017-01-03 21:22:58 +00:00
|
|
|
[RUNNING] `rustc --crate-name foo src[/]lib.rs --crate-type lib \
|
2017-01-12 05:35:17 +00:00
|
|
|
--emit=dep-info,link -C debuginfo=2 \
|
2016-11-13 02:55:07 +00:00
|
|
|
-C metadata=[..] \
|
|
|
|
-C extra-filename=[..] \
|
|
|
|
--out-dir [..] \
|
|
|
|
-L dependency={dir}[/]target[/]debug[/]deps \
|
2016-11-13 05:49:44 +00:00
|
|
|
--extern bar={dir}[/]target[/]debug[/]deps[/]{prefix}bar-[..]{suffix}`
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2016-11-13 02:55:07 +00:00
|
|
|
",
|
2018-03-14 15:17:44 +00:00
|
|
|
dir = p.root().display(),
|
|
|
|
url = p.url(),
|
|
|
|
prefix = env::consts::DLL_PREFIX,
|
|
|
|
suffix = env::consts::DLL_SUFFIX,
|
|
|
|
)),
|
|
|
|
);
|
2016-11-13 02:55:07 +00:00
|
|
|
}
|
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn crate_env_vars() {
|
2014-07-24 00:57:49 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-02-10 20:01:52 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.5.1-alpha.1"
|
|
|
|
description = "This is foo"
|
|
|
|
homepage = "http://example.com"
|
|
|
|
authors = ["wycats@example.com"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
2014-08-07 15:42:16 +00:00
|
|
|
extern crate foo;
|
2014-07-24 00:57:49 +00:00
|
|
|
|
2016-03-26 20:00:26 +00:00
|
|
|
|
2017-02-10 20:01:52 +00:00
|
|
|
static VERSION_MAJOR: &'static str = env!("CARGO_PKG_VERSION_MAJOR");
|
|
|
|
static VERSION_MINOR: &'static str = env!("CARGO_PKG_VERSION_MINOR");
|
|
|
|
static VERSION_PATCH: &'static str = env!("CARGO_PKG_VERSION_PATCH");
|
|
|
|
static VERSION_PRE: &'static str = env!("CARGO_PKG_VERSION_PRE");
|
|
|
|
static VERSION: &'static str = env!("CARGO_PKG_VERSION");
|
|
|
|
static CARGO_MANIFEST_DIR: &'static str = env!("CARGO_MANIFEST_DIR");
|
|
|
|
static PKG_NAME: &'static str = env!("CARGO_PKG_NAME");
|
|
|
|
static HOMEPAGE: &'static str = env!("CARGO_PKG_HOMEPAGE");
|
|
|
|
static DESCRIPTION: &'static str = env!("CARGO_PKG_DESCRIPTION");
|
2014-07-24 00:57:49 +00:00
|
|
|
|
|
|
|
fn main() {
|
2014-08-25 12:40:47 +00:00
|
|
|
let s = format!("{}-{}-{} @ {} in {}", VERSION_MAJOR,
|
|
|
|
VERSION_MINOR, VERSION_PATCH, VERSION_PRE,
|
|
|
|
CARGO_MANIFEST_DIR);
|
2017-02-10 20:01:52 +00:00
|
|
|
assert_eq!(s, foo::version());
|
|
|
|
println!("{}", s);
|
|
|
|
assert_eq!("foo", PKG_NAME);
|
|
|
|
assert_eq!("http://example.com", HOMEPAGE);
|
|
|
|
assert_eq!("This is foo", DESCRIPTION);
|
2017-01-10 12:02:08 +00:00
|
|
|
let s = format!("{}.{}.{}-{}", VERSION_MAJOR,
|
|
|
|
VERSION_MINOR, VERSION_PATCH, VERSION_PRE);
|
2017-02-10 20:01:52 +00:00
|
|
|
assert_eq!(s, VERSION);
|
2014-08-07 15:42:16 +00:00
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2014-08-07 15:42:16 +00:00
|
|
|
pub fn version() -> String {
|
2014-08-25 12:40:47 +00:00
|
|
|
format!("{}-{}-{} @ {} in {}",
|
2014-08-07 15:42:16 +00:00
|
|
|
env!("CARGO_PKG_VERSION_MAJOR"),
|
|
|
|
env!("CARGO_PKG_VERSION_MINOR"),
|
|
|
|
env!("CARGO_PKG_VERSION_PATCH"),
|
2014-08-25 12:40:47 +00:00
|
|
|
env!("CARGO_PKG_VERSION_PRE"),
|
|
|
|
env!("CARGO_MANIFEST_DIR"))
|
2014-07-24 00:57:49 +00:00
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2014-07-24 00:57:49 +00:00
|
|
|
|
Overhaul how cargo treats profiles
This commit is a complete overhaul of how Cargo handles compilation profiles
internally. The external interface of Cargo is not affected by this change.
Previously each Target had a Profile embedded within it. Conceptually a Target
is an entry in the manifest (a binary, benchmark, etc) and a Profile controlled
various flags (e.g. --test, -C opt-level, etc). Each Package then contained many
profiles for each possible compilation mode. For example a Package would have
one target for testing a library, benchmarking a library, documenting a library,
etc. When it came to building these targets, Cargo would filter out the targets
listed to determine what needed to be built.
This filtering was largely done based off an "environment" represented as a
string. Each mode of compilation got a separate environment string like `"test"`
or `"bench"`. Altogether, however, this approach had a number of drawbacks:
* Examples in release mode do not currently work. This is due to how examples
are classified and how release mode is handled (e.g. the "release" environment
where examples are meant to be built in the "test" environment).
* It is not trivial to implement `cargo test --release` today.
* It is not trivial to implement `cargo build --bin foo` where *only* the binary
`foo` is built. The same is true for examples.
* It is not trivial to add selective building of a number of
binaries/examples/etc.
* Filtering the list of targets to build has some pretty hokey logic that
involves pseudo-environments like "doc-all" vs "doc". This logic is duplicated
in a few places and in general is quite brittle.
* The TOML parser greatly affects compilation due to the time at which profiles
are generated, which seems somewhat backwards.
* Profiles must be overridden, but only partially, at compile time becuase only
the top-level package's profile is applied.
In general, this system just needed an overhaul. This commit made a single
change of separating `Profile` from `Target` and then basically hit `make` until
all the tests passed again. The other large architectural changes are:
* Environment strings are now entirely gone.
* Filters are implemented in a much more robust fashion.
* Release mode is now handled much more gracefully.
* The unit of compilation in the backend is no longer (package, target) but
rather (package, target, profile). This change had to be propagated many
location in the `cargo_rustc` module.
* The backend does not filter targets to build *at all*. All filtering now
happens entirely in the frontend.
I'll test issues after this change lands, but the motivation behind this is to
open the door to quickly fixing a number of outstanding issues against Cargo.
This change itself is not intended to close many bugs.
2015-02-19 19:30:35 +00:00
|
|
|
println!("build");
|
2017-07-22 03:12:21 +00:00
|
|
|
assert_that(p.cargo("build").arg("-v"), execs().with_status(0));
|
2014-07-24 00:57:49 +00:00
|
|
|
|
Overhaul how cargo treats profiles
This commit is a complete overhaul of how Cargo handles compilation profiles
internally. The external interface of Cargo is not affected by this change.
Previously each Target had a Profile embedded within it. Conceptually a Target
is an entry in the manifest (a binary, benchmark, etc) and a Profile controlled
various flags (e.g. --test, -C opt-level, etc). Each Package then contained many
profiles for each possible compilation mode. For example a Package would have
one target for testing a library, benchmarking a library, documenting a library,
etc. When it came to building these targets, Cargo would filter out the targets
listed to determine what needed to be built.
This filtering was largely done based off an "environment" represented as a
string. Each mode of compilation got a separate environment string like `"test"`
or `"bench"`. Altogether, however, this approach had a number of drawbacks:
* Examples in release mode do not currently work. This is due to how examples
are classified and how release mode is handled (e.g. the "release" environment
where examples are meant to be built in the "test" environment).
* It is not trivial to implement `cargo test --release` today.
* It is not trivial to implement `cargo build --bin foo` where *only* the binary
`foo` is built. The same is true for examples.
* It is not trivial to add selective building of a number of
binaries/examples/etc.
* Filtering the list of targets to build has some pretty hokey logic that
involves pseudo-environments like "doc-all" vs "doc". This logic is duplicated
in a few places and in general is quite brittle.
* The TOML parser greatly affects compilation due to the time at which profiles
are generated, which seems somewhat backwards.
* Profiles must be overridden, but only partially, at compile time becuase only
the top-level package's profile is applied.
In general, this system just needed an overhaul. This commit made a single
change of separating `Profile` from `Target` and then basically hit `make` until
all the tests passed again. The other large architectural changes are:
* Environment strings are now entirely gone.
* Filters are implemented in a much more robust fashion.
* Release mode is now handled much more gracefully.
* The unit of compilation in the backend is no longer (package, target) but
rather (package, target, profile). This change had to be propagated many
location in the `cargo_rustc` module.
* The backend does not filter targets to build *at all*. All filtering now
happens entirely in the frontend.
I'll test issues after this change lands, but the motivation behind this is to
open the door to quickly fixing a number of outstanding issues against Cargo.
This change itself is not intended to close many bugs.
2015-02-19 19:30:35 +00:00
|
|
|
println!("bin");
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
process(&p.bin("foo")),
|
|
|
|
execs()
|
|
|
|
.with_status(0)
|
|
|
|
.with_stdout(&format!("0-5-1 @ alpha.1 in {}\n", p.root().display())),
|
|
|
|
);
|
2014-08-07 15:42:16 +00:00
|
|
|
|
Overhaul how cargo treats profiles
This commit is a complete overhaul of how Cargo handles compilation profiles
internally. The external interface of Cargo is not affected by this change.
Previously each Target had a Profile embedded within it. Conceptually a Target
is an entry in the manifest (a binary, benchmark, etc) and a Profile controlled
various flags (e.g. --test, -C opt-level, etc). Each Package then contained many
profiles for each possible compilation mode. For example a Package would have
one target for testing a library, benchmarking a library, documenting a library,
etc. When it came to building these targets, Cargo would filter out the targets
listed to determine what needed to be built.
This filtering was largely done based off an "environment" represented as a
string. Each mode of compilation got a separate environment string like `"test"`
or `"bench"`. Altogether, however, this approach had a number of drawbacks:
* Examples in release mode do not currently work. This is due to how examples
are classified and how release mode is handled (e.g. the "release" environment
where examples are meant to be built in the "test" environment).
* It is not trivial to implement `cargo test --release` today.
* It is not trivial to implement `cargo build --bin foo` where *only* the binary
`foo` is built. The same is true for examples.
* It is not trivial to add selective building of a number of
binaries/examples/etc.
* Filtering the list of targets to build has some pretty hokey logic that
involves pseudo-environments like "doc-all" vs "doc". This logic is duplicated
in a few places and in general is quite brittle.
* The TOML parser greatly affects compilation due to the time at which profiles
are generated, which seems somewhat backwards.
* Profiles must be overridden, but only partially, at compile time becuase only
the top-level package's profile is applied.
In general, this system just needed an overhaul. This commit made a single
change of separating `Profile` from `Target` and then basically hit `make` until
all the tests passed again. The other large architectural changes are:
* Environment strings are now entirely gone.
* Filters are implemented in a much more robust fashion.
* Release mode is now handled much more gracefully.
* The unit of compilation in the backend is no longer (package, target) but
rather (package, target, profile). This change had to be propagated many
location in the `cargo_rustc` module.
* The backend does not filter targets to build *at all*. All filtering now
happens entirely in the frontend.
I'll test issues after this change lands, but the motivation behind this is to
open the door to quickly fixing a number of outstanding issues against Cargo.
This change itself is not intended to close many bugs.
2015-02-19 19:30:35 +00:00
|
|
|
println!("test");
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(p.cargo("test").arg("-v"), execs().with_status(0));
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-07-24 00:57:49 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn crate_authors_env_vars() {
|
2016-03-10 09:35:50 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2016-03-10 09:35:50 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.5.1-alpha.1"
|
|
|
|
authors = ["wycats@example.com", "neikos@example.com"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
2016-03-10 09:35:50 +00:00
|
|
|
extern crate foo;
|
|
|
|
|
|
|
|
static AUTHORS: &'static str = env!("CARGO_PKG_AUTHORS");
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let s = "wycats@example.com:neikos@example.com";
|
|
|
|
assert_eq!(AUTHORS, foo::authors());
|
|
|
|
println!("{}", AUTHORS);
|
|
|
|
assert_eq!(s, AUTHORS);
|
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2016-03-10 09:35:50 +00:00
|
|
|
pub fn authors() -> String {
|
|
|
|
format!("{}", env!("CARGO_PKG_AUTHORS"))
|
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2016-03-10 09:35:50 +00:00
|
|
|
|
|
|
|
println!("build");
|
2017-07-22 03:12:21 +00:00
|
|
|
assert_that(p.cargo("build").arg("-v"), execs().with_status(0));
|
2016-03-10 09:35:50 +00:00
|
|
|
|
|
|
|
println!("bin");
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
process(&p.bin("foo")),
|
|
|
|
execs()
|
|
|
|
.with_status(0)
|
|
|
|
.with_stdout("wycats@example.com:neikos@example.com"),
|
|
|
|
);
|
2016-03-10 09:35:50 +00:00
|
|
|
|
|
|
|
println!("test");
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(p.cargo("test").arg("-v"), execs().with_status(0));
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2016-03-10 09:35:50 +00:00
|
|
|
|
2017-07-19 13:59:50 +00:00
|
|
|
// The tester may already have LD_LIBRARY_PATH=::/foo/bar which leads to a false positive error
|
|
|
|
fn setenv_for_removing_empty_component(mut p: ProcessBuilder) -> ProcessBuilder {
|
|
|
|
let v = dylib_path_envvar();
|
|
|
|
if let Ok(search_path) = env::var(v) {
|
2018-03-14 15:17:44 +00:00
|
|
|
let new_search_path = env::join_paths(
|
|
|
|
env::split_paths(&search_path).filter(|e| !e.as_os_str().is_empty()),
|
|
|
|
).expect("join_paths");
|
2017-07-19 13:59:50 +00:00
|
|
|
p.env(v, new_search_path); // build_command() will override LD_LIBRARY_PATH accordingly
|
|
|
|
}
|
|
|
|
p
|
|
|
|
}
|
|
|
|
|
2017-07-13 03:28:39 +00:00
|
|
|
// Regression test for #4277
|
|
|
|
#[test]
|
|
|
|
fn crate_library_path_env_var() {
|
2017-07-22 03:12:21 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-07-13 03:28:39 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
&format!(
|
|
|
|
r##"
|
2017-07-13 03:28:39 +00:00
|
|
|
fn main() {{
|
|
|
|
let search_path = env!("{}");
|
|
|
|
let paths = std::env::split_paths(&search_path).collect::<Vec<_>>();
|
|
|
|
assert!(!paths.contains(&"".into()));
|
|
|
|
}}
|
2018-03-14 15:17:44 +00:00
|
|
|
"##,
|
|
|
|
dylib_path_envvar()
|
|
|
|
),
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2017-07-13 03:28:39 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
setenv_for_removing_empty_component(p.cargo("run")),
|
|
|
|
execs().with_status(0),
|
|
|
|
);
|
2017-07-13 03:28:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Regression test for #4277
|
|
|
|
#[test]
|
|
|
|
fn build_with_fake_libc_not_loading() {
|
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-07-13 03:28:39 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
2017-07-13 03:28:39 +00:00
|
|
|
fn main() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-13 03:28:39 +00:00
|
|
|
.file("src/lib.rs", r#" "#)
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("libc.so.6", r#""#)
|
|
|
|
.build();
|
2017-07-13 03:28:39 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
setenv_for_removing_empty_component(p.cargo("build")),
|
|
|
|
execs().with_status(0),
|
|
|
|
);
|
2017-07-13 03:28:39 +00:00
|
|
|
}
|
|
|
|
|
2014-07-08 00:59:18 +00:00
|
|
|
// this is testing that src/<pkg-name>.rs still works (for now)
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn many_crate_types_old_style_lib_location() {
|
2017-07-22 03:12:21 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-06-19 22:21:00 +00:00
|
|
|
[project]
|
|
|
|
|
|
|
|
name = "foo"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["wycats@example.com"]
|
|
|
|
|
2014-08-14 06:08:02 +00:00
|
|
|
[lib]
|
2014-06-19 22:21:00 +00:00
|
|
|
|
|
|
|
name = "foo"
|
|
|
|
crate_type = ["rlib", "dylib"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/foo.rs",
|
|
|
|
r#"
|
2014-06-19 22:21:00 +00:00
|
|
|
pub fn foo() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build"),
|
|
|
|
execs().with_status(0).with_stderr_contains(
|
|
|
|
"\
|
2017-07-18 13:05:35 +00:00
|
|
|
[WARNING] path `[..]src[/]foo.rs` was erroneously implicitly accepted for library `foo`,
|
2018-03-14 15:17:44 +00:00
|
|
|
please rename the file to `src/lib.rs` or set lib.path in Cargo.toml",
|
|
|
|
),
|
|
|
|
);
|
2014-06-19 22:21:00 +00:00
|
|
|
|
2015-06-26 22:51:53 +00:00
|
|
|
assert_that(&p.root().join("target/debug/libfoo.rlib"), existing_file());
|
2018-03-14 15:17:44 +00:00
|
|
|
let fname = format!("{}foo{}", env::consts::DLL_PREFIX, env::consts::DLL_SUFFIX);
|
2015-06-26 22:51:53 +00:00
|
|
|
assert_that(&p.root().join("target/debug").join(&fname), existing_file());
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-07-08 00:59:18 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn many_crate_types_correct() {
|
2017-07-22 03:12:21 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-07-08 00:59:18 +00:00
|
|
|
[project]
|
|
|
|
|
|
|
|
name = "foo"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["wycats@example.com"]
|
|
|
|
|
2014-08-14 06:08:02 +00:00
|
|
|
[lib]
|
2014-07-08 00:59:18 +00:00
|
|
|
|
|
|
|
name = "foo"
|
|
|
|
crate_type = ["rlib", "dylib"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2014-07-08 00:59:18 +00:00
|
|
|
pub fn foo() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(p.cargo("build"), execs().with_status(0));
|
2014-06-19 22:21:00 +00:00
|
|
|
|
2015-06-26 22:51:53 +00:00
|
|
|
assert_that(&p.root().join("target/debug/libfoo.rlib"), existing_file());
|
2018-03-14 15:17:44 +00:00
|
|
|
let fname = format!("{}foo{}", env::consts::DLL_PREFIX, env::consts::DLL_SUFFIX);
|
2015-06-26 22:51:53 +00:00
|
|
|
assert_that(&p.root().join("target/debug").join(&fname), existing_file());
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-06-27 05:53:05 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn self_dependency() {
|
2017-07-22 03:12:21 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-06-28 20:33:29 +00:00
|
|
|
[package]
|
|
|
|
|
|
|
|
name = "test"
|
|
|
|
version = "0.0.0"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies.test]
|
|
|
|
|
|
|
|
path = "."
|
|
|
|
|
2014-08-14 06:08:02 +00:00
|
|
|
[lib]
|
2014-06-28 20:33:29 +00:00
|
|
|
name = "test"
|
2017-07-09 10:03:22 +00:00
|
|
|
path = "src/test.rs"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/test.rs", "fn main() {}")
|
|
|
|
.build();
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build"),
|
|
|
|
execs().with_status(101).with_stderr(
|
|
|
|
"\
|
2018-03-07 22:56:47 +00:00
|
|
|
[ERROR] cyclic package dependency: package `test v0.0.0 ([..])` depends on itself. Cycle:
|
2018-03-14 15:17:44 +00:00
|
|
|
package `test v0.0.0 ([..]foo)`",
|
|
|
|
),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-07-07 21:46:03 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn ignore_broken_symlinks() {
|
2014-12-21 18:45:39 +00:00
|
|
|
// windows and symlinks don't currently agree that well
|
2018-03-14 15:17:44 +00:00
|
|
|
if cfg!(windows) {
|
|
|
|
return;
|
|
|
|
}
|
2014-12-21 18:45:39 +00:00
|
|
|
|
2014-07-07 21:46:03 +00:00
|
|
|
let p = project("foo")
|
2015-03-26 18:17:44 +00:00
|
|
|
.file("Cargo.toml", &basic_bin_manifest("foo"))
|
|
|
|
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]))
|
2017-07-22 03:12:21 +00:00
|
|
|
.symlink("Notafile", "bar")
|
|
|
|
.build();
|
2014-07-07 21:46:03 +00:00
|
|
|
|
2017-07-22 03:12:21 +00:00
|
|
|
assert_that(p.cargo("build"), execs().with_status(0));
|
2014-07-07 21:46:03 +00:00
|
|
|
assert_that(&p.bin("foo"), existing_file());
|
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
process(&p.bin("foo")),
|
|
|
|
execs().with_status(0).with_stdout("i am foo\n"),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-07-06 00:10:23 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn missing_lib_and_bin() {
|
2017-07-22 03:12:21 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-07-06 00:10:23 +00:00
|
|
|
[package]
|
|
|
|
|
|
|
|
name = "test"
|
|
|
|
version = "0.0.0"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build"),
|
|
|
|
execs().with_status(101).with_stderr(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[ERROR] failed to parse manifest at `[..]Cargo.toml`
|
2015-01-16 17:43:28 +00:00
|
|
|
|
|
|
|
Caused by:
|
2015-05-17 16:01:50 +00:00
|
|
|
no targets specified in the manifest
|
2018-03-14 15:17:44 +00:00
|
|
|
either src/lib.rs, src/main.rs, a [lib] section, or [[bin]] section must be present\n",
|
|
|
|
),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-07-09 20:55:00 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn lto_build() {
|
2015-07-22 21:42:37 +00:00
|
|
|
// FIXME: currently this hits a linker bug on 32-bit MSVC
|
|
|
|
if cfg!(all(target_env = "msvc", target_pointer_width = "32")) {
|
2018-03-14 15:17:44 +00:00
|
|
|
return;
|
2015-07-22 21:42:37 +00:00
|
|
|
}
|
|
|
|
|
2017-07-22 03:12:21 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-11-13 02:20:44 +00:00
|
|
|
[package]
|
|
|
|
|
|
|
|
name = "test"
|
|
|
|
version = "0.0.0"
|
|
|
|
authors = []
|
2014-11-14 16:49:01 +00:00
|
|
|
|
|
|
|
[profile.release]
|
2014-11-13 02:20:44 +00:00
|
|
|
lto = true
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build").arg("-v").arg("--release"),
|
|
|
|
execs().with_status(0).with_stderr(&format!(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] test v0.0.0 ({url})
|
2016-11-29 23:11:58 +00:00
|
|
|
[RUNNING] `rustc --crate-name test src[/]main.rs --crate-type bin \
|
2017-01-03 21:22:58 +00:00
|
|
|
--emit=dep-info,link \
|
2014-12-21 18:45:39 +00:00
|
|
|
-C opt-level=3 \
|
2014-11-13 02:20:44 +00:00
|
|
|
-C lto \
|
2016-08-02 06:22:29 +00:00
|
|
|
-C metadata=[..] \
|
2016-10-04 23:16:30 +00:00
|
|
|
--out-dir {dir}[/]target[/]release[/]deps \
|
2016-11-06 02:14:16 +00:00
|
|
|
-L dependency={dir}[/]target[/]release[/]deps`
|
2016-07-25 23:30:03 +00:00
|
|
|
[FINISHED] release [optimized] target(s) in [..]
|
2014-11-13 02:20:44 +00:00
|
|
|
",
|
2018-03-14 15:17:44 +00:00
|
|
|
dir = p.root().display(),
|
|
|
|
url = p.url(),
|
|
|
|
)),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-11-13 02:20:44 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn verbose_build() {
|
2017-07-22 03:12:21 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-07-09 20:55:00 +00:00
|
|
|
[package]
|
|
|
|
|
|
|
|
name = "test"
|
|
|
|
version = "0.0.0"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.build();
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build").arg("-v"),
|
|
|
|
execs().with_status(0).with_stderr(&format!(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] test v0.0.0 ({url})
|
2017-01-03 21:22:58 +00:00
|
|
|
[RUNNING] `rustc --crate-name test src[/]lib.rs --crate-type lib \
|
2017-01-12 05:35:17 +00:00
|
|
|
--emit=dep-info,link -C debuginfo=2 \
|
2016-08-02 06:22:29 +00:00
|
|
|
-C metadata=[..] \
|
Always build libraries into the same location
Previously Cargo would compile a library into a different location depending on
whether it was the "root crate" or not. In the ongoing saga of reducing Cargo's
reliance on the idea of a "root crate" this PR is the next step. With workspaces
the root crate of a compliation changes all the time, so the output needs to be
the same whether a crate is at the root or not.
Fixing this inconsistence in turn fixes bugs like #2855 and #2897 which arise
due to this discrepancy. Additionally, Cargo will no longer recompile a library
when it's used as a "root crate" or not.
This is fixed by taking a few steps:
* Everything is now compiled into the `deps` directory, regardless of whether
it's a root output or not.
* If a "root crate" is being compiled, then the relevant outputs are hard-linked
up one level to where they are today. This means that your binaries, dylibs,
staticlibs, etc, will all show up where they used to.
* The `-C metadata` flag is always omitted for path dependencies now. These
dependencies are always path dependencies and already all have unique crate
names. Additionally, they're the only crates in the DAG without metadata, so
there's no need to provide additional metadata. This in turn means that none
of the file names of the generated crates are mangled.
Closes #2855
2016-07-25 20:27:06 +00:00
|
|
|
--out-dir [..] \
|
2016-11-06 02:14:16 +00:00
|
|
|
-L dependency={dir}[/]target[/]debug[/]deps`
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2014-09-11 14:35:01 +00:00
|
|
|
",
|
2018-03-14 15:17:44 +00:00
|
|
|
dir = p.root().display(),
|
|
|
|
url = p.url(),
|
|
|
|
)),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-07-09 20:55:00 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn verbose_release_build() {
|
2017-07-22 03:12:21 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-07-09 20:55:00 +00:00
|
|
|
[package]
|
|
|
|
|
|
|
|
name = "test"
|
|
|
|
version = "0.0.0"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.build();
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build").arg("-v").arg("--release"),
|
|
|
|
execs().with_status(0).with_stderr(&format!(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] test v0.0.0 ({url})
|
2016-11-29 23:11:58 +00:00
|
|
|
[RUNNING] `rustc --crate-name test src[/]lib.rs --crate-type lib \
|
2017-01-03 21:22:58 +00:00
|
|
|
--emit=dep-info,link \
|
2014-12-21 18:45:39 +00:00
|
|
|
-C opt-level=3 \
|
2016-08-02 06:22:29 +00:00
|
|
|
-C metadata=[..] \
|
Always build libraries into the same location
Previously Cargo would compile a library into a different location depending on
whether it was the "root crate" or not. In the ongoing saga of reducing Cargo's
reliance on the idea of a "root crate" this PR is the next step. With workspaces
the root crate of a compliation changes all the time, so the output needs to be
the same whether a crate is at the root or not.
Fixing this inconsistence in turn fixes bugs like #2855 and #2897 which arise
due to this discrepancy. Additionally, Cargo will no longer recompile a library
when it's used as a "root crate" or not.
This is fixed by taking a few steps:
* Everything is now compiled into the `deps` directory, regardless of whether
it's a root output or not.
* If a "root crate" is being compiled, then the relevant outputs are hard-linked
up one level to where they are today. This means that your binaries, dylibs,
staticlibs, etc, will all show up where they used to.
* The `-C metadata` flag is always omitted for path dependencies now. These
dependencies are always path dependencies and already all have unique crate
names. Additionally, they're the only crates in the DAG without metadata, so
there's no need to provide additional metadata. This in turn means that none
of the file names of the generated crates are mangled.
Closes #2855
2016-07-25 20:27:06 +00:00
|
|
|
--out-dir [..] \
|
2016-11-06 02:14:16 +00:00
|
|
|
-L dependency={dir}[/]target[/]release[/]deps`
|
2016-07-25 23:30:03 +00:00
|
|
|
[FINISHED] release [optimized] target(s) in [..]
|
2014-09-11 14:35:01 +00:00
|
|
|
",
|
2018-03-14 15:17:44 +00:00
|
|
|
dir = p.root().display(),
|
|
|
|
url = p.url(),
|
|
|
|
)),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-07-09 20:55:00 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn verbose_release_build_deps() {
|
2017-07-22 03:12:21 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-07-09 20:55:00 +00:00
|
|
|
[package]
|
|
|
|
|
|
|
|
name = "test"
|
|
|
|
version = "0.0.0"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies.foo]
|
|
|
|
path = "foo"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2014-07-09 20:55:00 +00:00
|
|
|
.file("src/lib.rs", "")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"foo/Cargo.toml",
|
|
|
|
r#"
|
2014-07-09 20:55:00 +00:00
|
|
|
[package]
|
|
|
|
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.0"
|
|
|
|
authors = []
|
2014-07-13 18:33:11 +00:00
|
|
|
|
2014-08-14 06:08:02 +00:00
|
|
|
[lib]
|
2014-07-13 18:33:11 +00:00
|
|
|
name = "foo"
|
|
|
|
crate_type = ["dylib", "rlib"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("foo/src/lib.rs", "")
|
|
|
|
.build();
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build").arg("-v").arg("--release"),
|
|
|
|
execs().with_status(0).with_stderr(&format!(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] foo v0.0.0 ({url}/foo)
|
2016-11-29 23:11:58 +00:00
|
|
|
[RUNNING] `rustc --crate-name foo foo[/]src[/]lib.rs \
|
2017-01-03 21:22:58 +00:00
|
|
|
--crate-type dylib --crate-type rlib \
|
|
|
|
--emit=dep-info,link \
|
|
|
|
-C prefer-dynamic \
|
2014-12-21 18:45:39 +00:00
|
|
|
-C opt-level=3 \
|
2016-08-02 06:22:29 +00:00
|
|
|
-C metadata=[..] \
|
Always build libraries into the same location
Previously Cargo would compile a library into a different location depending on
whether it was the "root crate" or not. In the ongoing saga of reducing Cargo's
reliance on the idea of a "root crate" this PR is the next step. With workspaces
the root crate of a compliation changes all the time, so the output needs to be
the same whether a crate is at the root or not.
Fixing this inconsistence in turn fixes bugs like #2855 and #2897 which arise
due to this discrepancy. Additionally, Cargo will no longer recompile a library
when it's used as a "root crate" or not.
This is fixed by taking a few steps:
* Everything is now compiled into the `deps` directory, regardless of whether
it's a root output or not.
* If a "root crate" is being compiled, then the relevant outputs are hard-linked
up one level to where they are today. This means that your binaries, dylibs,
staticlibs, etc, will all show up where they used to.
* The `-C metadata` flag is always omitted for path dependencies now. These
dependencies are always path dependencies and already all have unique crate
names. Additionally, they're the only crates in the DAG without metadata, so
there's no need to provide additional metadata. This in turn means that none
of the file names of the generated crates are mangled.
Closes #2855
2016-07-25 20:27:06 +00:00
|
|
|
--out-dir [..] \
|
2016-11-06 02:14:16 +00:00
|
|
|
-L dependency={dir}[/]target[/]release[/]deps`
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] test v0.0.0 ({url})
|
2016-11-29 23:11:58 +00:00
|
|
|
[RUNNING] `rustc --crate-name test src[/]lib.rs --crate-type lib \
|
2017-01-03 21:22:58 +00:00
|
|
|
--emit=dep-info,link \
|
2014-12-21 18:45:39 +00:00
|
|
|
-C opt-level=3 \
|
2016-08-02 06:22:29 +00:00
|
|
|
-C metadata=[..] \
|
Always build libraries into the same location
Previously Cargo would compile a library into a different location depending on
whether it was the "root crate" or not. In the ongoing saga of reducing Cargo's
reliance on the idea of a "root crate" this PR is the next step. With workspaces
the root crate of a compliation changes all the time, so the output needs to be
the same whether a crate is at the root or not.
Fixing this inconsistence in turn fixes bugs like #2855 and #2897 which arise
due to this discrepancy. Additionally, Cargo will no longer recompile a library
when it's used as a "root crate" or not.
This is fixed by taking a few steps:
* Everything is now compiled into the `deps` directory, regardless of whether
it's a root output or not.
* If a "root crate" is being compiled, then the relevant outputs are hard-linked
up one level to where they are today. This means that your binaries, dylibs,
staticlibs, etc, will all show up where they used to.
* The `-C metadata` flag is always omitted for path dependencies now. These
dependencies are always path dependencies and already all have unique crate
names. Additionally, they're the only crates in the DAG without metadata, so
there's no need to provide additional metadata. This in turn means that none
of the file names of the generated crates are mangled.
Closes #2855
2016-07-25 20:27:06 +00:00
|
|
|
--out-dir [..] \
|
2016-11-06 02:14:16 +00:00
|
|
|
-L dependency={dir}[/]target[/]release[/]deps \
|
|
|
|
--extern foo={dir}[/]target[/]release[/]deps[/]{prefix}foo{suffix} \
|
|
|
|
--extern foo={dir}[/]target[/]release[/]deps[/]libfoo.rlib`
|
2016-07-25 23:30:03 +00:00
|
|
|
[FINISHED] release [optimized] target(s) in [..]
|
2014-09-11 14:35:01 +00:00
|
|
|
",
|
2018-03-14 15:17:44 +00:00
|
|
|
dir = p.root().display(),
|
|
|
|
url = p.url(),
|
|
|
|
prefix = env::consts::DLL_PREFIX,
|
|
|
|
suffix = env::consts::DLL_SUFFIX
|
|
|
|
)),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-07-10 22:13:53 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn explicit_examples() {
|
2017-07-22 03:12:21 +00:00
|
|
|
let p = project("world")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-07-10 22:13:53 +00:00
|
|
|
[package]
|
|
|
|
name = "world"
|
|
|
|
version = "1.0.0"
|
|
|
|
authors = []
|
|
|
|
|
2014-08-14 06:08:02 +00:00
|
|
|
[lib]
|
2014-07-10 22:13:53 +00:00
|
|
|
name = "world"
|
|
|
|
path = "src/lib.rs"
|
|
|
|
|
|
|
|
[[example]]
|
|
|
|
name = "hello"
|
|
|
|
path = "examples/ex-hello.rs"
|
|
|
|
|
|
|
|
[[example]]
|
|
|
|
name = "goodbye"
|
|
|
|
path = "examples/ex-goodbye.rs"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2014-07-10 22:13:53 +00:00
|
|
|
pub fn get_hello() -> &'static str { "Hello" }
|
|
|
|
pub fn get_goodbye() -> &'static str { "Goodbye" }
|
|
|
|
pub fn get_world() -> &'static str { "World" }
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"examples/ex-hello.rs",
|
|
|
|
r#"
|
2014-07-10 22:13:53 +00:00
|
|
|
extern crate world;
|
|
|
|
fn main() { println!("{}, {}!", world::get_hello(), world::get_world()); }
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"examples/ex-goodbye.rs",
|
|
|
|
r#"
|
2014-07-10 22:13:53 +00:00
|
|
|
extern crate world;
|
|
|
|
fn main() { println!("{}, {}!", world::get_goodbye(), world::get_world()); }
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2014-07-10 22:13:53 +00:00
|
|
|
|
2017-07-22 03:12:21 +00:00
|
|
|
assert_that(p.cargo("test").arg("-v"), execs().with_status(0));
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
process(&p.bin("examples/hello")),
|
|
|
|
execs().with_status(0).with_stdout("Hello, World!\n"),
|
|
|
|
);
|
|
|
|
assert_that(
|
|
|
|
process(&p.bin("examples/goodbye")),
|
|
|
|
execs().with_status(0).with_stdout("Goodbye, World!\n"),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-07-10 22:13:53 +00:00
|
|
|
|
2017-07-09 08:48:54 +00:00
|
|
|
#[test]
|
|
|
|
fn non_existing_example() {
|
2017-07-22 03:12:21 +00:00
|
|
|
let p = project("world")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-07-09 08:48:54 +00:00
|
|
|
[package]
|
|
|
|
name = "world"
|
|
|
|
version = "1.0.0"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[lib]
|
|
|
|
name = "world"
|
|
|
|
path = "src/lib.rs"
|
|
|
|
|
|
|
|
[[example]]
|
|
|
|
name = "hello"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-09 08:48:54 +00:00
|
|
|
.file("src/lib.rs", "")
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2017-07-09 08:48:54 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("test").arg("-v"),
|
|
|
|
execs().with_status(101).with_stderr(
|
|
|
|
"\
|
2017-07-09 08:48:54 +00:00
|
|
|
[ERROR] failed to parse manifest at `[..]`
|
|
|
|
|
|
|
|
Caused by:
|
2018-03-14 15:17:44 +00:00
|
|
|
can't find `hello` example, specify example.path",
|
|
|
|
),
|
|
|
|
);
|
2017-07-09 08:48:54 +00:00
|
|
|
}
|
|
|
|
|
2017-07-09 12:57:25 +00:00
|
|
|
#[test]
|
|
|
|
fn non_existing_binary() {
|
2017-07-22 03:12:21 +00:00
|
|
|
let p = project("world")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-07-09 12:57:25 +00:00
|
|
|
[package]
|
|
|
|
name = "world"
|
|
|
|
version = "1.0.0"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
name = "hello"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-09 12:57:25 +00:00
|
|
|
.file("src/lib.rs", "")
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/bin/ehlo.rs", "")
|
|
|
|
.build();
|
2017-07-09 12:57:25 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build").arg("-v"),
|
|
|
|
execs().with_status(101).with_stderr(
|
|
|
|
"\
|
2017-07-09 12:57:25 +00:00
|
|
|
[ERROR] failed to parse manifest at `[..]`
|
|
|
|
|
|
|
|
Caused by:
|
2018-03-14 15:17:44 +00:00
|
|
|
can't find `hello` bin, specify bin.path",
|
|
|
|
),
|
|
|
|
);
|
2017-07-09 12:57:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn legacy_binary_paths_warinigs() {
|
2017-07-22 03:12:21 +00:00
|
|
|
let p = project("world")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-07-09 12:57:25 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "1.0.0"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
name = "bar"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-09 12:57:25 +00:00
|
|
|
.file("src/lib.rs", "")
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
2017-07-09 12:57:25 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build").arg("-v"),
|
|
|
|
execs().with_status(0).with_stderr_contains(
|
|
|
|
"\
|
2017-07-18 13:05:35 +00:00
|
|
|
[WARNING] path `[..]src[/]main.rs` was erroneously implicitly accepted for binary `bar`,
|
2018-03-14 15:17:44 +00:00
|
|
|
please set bin.path in Cargo.toml",
|
|
|
|
),
|
|
|
|
);
|
2017-07-09 12:57:25 +00:00
|
|
|
|
2017-07-22 03:12:21 +00:00
|
|
|
let p = project("world")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-07-09 12:57:25 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "1.0.0"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
name = "bar"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-09 12:57:25 +00:00
|
|
|
.file("src/lib.rs", "")
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/bin/main.rs", "fn main() {}")
|
|
|
|
.build();
|
2017-07-09 12:57:25 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build").arg("-v"),
|
|
|
|
execs().with_status(0).with_stderr_contains(
|
|
|
|
"\
|
2017-07-18 13:05:35 +00:00
|
|
|
[WARNING] path `[..]src[/]bin[/]main.rs` was erroneously implicitly accepted for binary `bar`,
|
2018-03-14 15:17:44 +00:00
|
|
|
please set bin.path in Cargo.toml",
|
|
|
|
),
|
|
|
|
);
|
2017-07-09 12:57:25 +00:00
|
|
|
|
2017-07-22 03:12:21 +00:00
|
|
|
let p = project("world")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-07-09 12:57:25 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "1.0.0"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
name = "bar"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/bar.rs", "fn main() {}")
|
|
|
|
.build();
|
2017-07-09 12:57:25 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build").arg("-v"),
|
|
|
|
execs().with_status(0).with_stderr_contains(
|
|
|
|
"\
|
2017-07-18 13:05:35 +00:00
|
|
|
[WARNING] path `[..]src[/]bar.rs` was erroneously implicitly accepted for binary `bar`,
|
2018-03-14 15:17:44 +00:00
|
|
|
please set bin.path in Cargo.toml",
|
|
|
|
),
|
|
|
|
);
|
2017-07-09 12:57:25 +00:00
|
|
|
}
|
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn implicit_examples() {
|
2017-07-22 03:12:21 +00:00
|
|
|
let p = project("world")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-07-10 22:13:53 +00:00
|
|
|
[package]
|
|
|
|
name = "world"
|
|
|
|
version = "1.0.0"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2014-07-10 22:13:53 +00:00
|
|
|
pub fn get_hello() -> &'static str { "Hello" }
|
|
|
|
pub fn get_goodbye() -> &'static str { "Goodbye" }
|
|
|
|
pub fn get_world() -> &'static str { "World" }
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"examples/hello.rs",
|
|
|
|
r#"
|
2014-07-10 22:13:53 +00:00
|
|
|
extern crate world;
|
2015-02-27 01:04:25 +00:00
|
|
|
fn main() {
|
|
|
|
println!("{}, {}!", world::get_hello(), world::get_world());
|
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"examples/goodbye.rs",
|
|
|
|
r#"
|
2014-07-10 22:13:53 +00:00
|
|
|
extern crate world;
|
2015-02-27 01:04:25 +00:00
|
|
|
fn main() {
|
|
|
|
println!("{}, {}!", world::get_goodbye(), world::get_world());
|
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2014-07-10 22:13:53 +00:00
|
|
|
|
2017-07-22 03:12:21 +00:00
|
|
|
assert_that(p.cargo("test"), execs().with_status(0));
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
process(&p.bin("examples/hello")),
|
|
|
|
execs().with_status(0).with_stdout("Hello, World!\n"),
|
|
|
|
);
|
|
|
|
assert_that(
|
|
|
|
process(&p.bin("examples/goodbye")),
|
|
|
|
execs().with_status(0).with_stdout("Goodbye, World!\n"),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-07-12 22:30:24 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn standard_build_no_ndebug() {
|
2014-07-12 22:30:24 +00:00
|
|
|
let p = project("world")
|
2015-02-27 01:04:25 +00:00
|
|
|
.file("Cargo.toml", &basic_bin_manifest("foo"))
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"src/foo.rs",
|
|
|
|
r#"
|
2014-07-12 22:30:24 +00:00
|
|
|
fn main() {
|
2015-03-24 00:45:41 +00:00
|
|
|
if cfg!(debug_assertions) {
|
2014-07-12 22:30:24 +00:00
|
|
|
println!("slow")
|
2015-03-24 00:45:41 +00:00
|
|
|
} else {
|
|
|
|
println!("fast")
|
2014-07-12 22:30:24 +00:00
|
|
|
}
|
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2014-07-12 22:30:24 +00:00
|
|
|
|
2017-07-22 03:12:21 +00:00
|
|
|
assert_that(p.cargo("build"), execs().with_status(0));
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
process(&p.bin("foo")),
|
|
|
|
execs().with_status(0).with_stdout("slow\n"),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-07-12 22:30:24 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn release_build_ndebug() {
|
2014-07-12 22:30:24 +00:00
|
|
|
let p = project("world")
|
2015-02-27 01:04:25 +00:00
|
|
|
.file("Cargo.toml", &basic_bin_manifest("foo"))
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"src/foo.rs",
|
|
|
|
r#"
|
2014-07-12 22:30:24 +00:00
|
|
|
fn main() {
|
2015-03-24 00:45:41 +00:00
|
|
|
if cfg!(debug_assertions) {
|
2014-07-12 22:30:24 +00:00
|
|
|
println!("slow")
|
2015-03-24 00:45:41 +00:00
|
|
|
} else {
|
|
|
|
println!("fast")
|
2014-07-12 22:30:24 +00:00
|
|
|
}
|
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2014-07-12 22:30:24 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(p.cargo("build").arg("--release"), execs().with_status(0));
|
|
|
|
assert_that(
|
|
|
|
process(&p.release_bin("foo")),
|
|
|
|
execs().with_status(0).with_stdout("fast\n"),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-07-17 01:44:30 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn inferred_main_bin() {
|
2014-07-17 01:44:30 +00:00
|
|
|
let p = project("world")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-07-17 01:44:30 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
2014-07-17 01:44:30 +00:00
|
|
|
fn main() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2014-07-17 01:44:30 +00:00
|
|
|
|
2017-07-22 03:12:21 +00:00
|
|
|
assert_that(p.cargo("build"), execs().with_status(0));
|
2015-10-28 09:20:00 +00:00
|
|
|
assert_that(process(&p.bin("foo")), execs().with_status(0));
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-07-18 02:53:47 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn deletion_causes_failure() {
|
2014-07-18 02:53:47 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-07-18 02:53:47 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies.bar]
|
|
|
|
path = "bar"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
2014-07-18 02:53:47 +00:00
|
|
|
extern crate bar;
|
|
|
|
fn main() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"bar/Cargo.toml",
|
|
|
|
r#"
|
2014-07-18 02:53:47 +00:00
|
|
|
[package]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("bar/src/lib.rs", "")
|
|
|
|
.build();
|
2014-07-18 02:53:47 +00:00
|
|
|
|
2017-02-15 14:16:41 +00:00
|
|
|
assert_that(p.cargo("build"), execs().with_status(0));
|
2018-03-14 15:17:44 +00:00
|
|
|
p.change_file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-02-15 14:16:41 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
);
|
2017-02-15 14:16:41 +00:00
|
|
|
assert_that(p.cargo("build"), execs().with_status(101));
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-07-18 15:29:40 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn bad_cargo_toml_in_target_dir() {
|
2014-07-18 15:29:40 +00:00
|
|
|
let p = project("world")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-07-18 15:29:40 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
2014-07-18 15:29:40 +00:00
|
|
|
fn main() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("target/Cargo.toml", "bad-toml")
|
|
|
|
.build();
|
2014-07-18 15:29:40 +00:00
|
|
|
|
2017-07-22 03:12:21 +00:00
|
|
|
assert_that(p.cargo("build"), execs().with_status(0));
|
2015-10-28 09:20:00 +00:00
|
|
|
assert_that(process(&p.bin("foo")), execs().with_status(0));
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-07-23 00:53:38 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn lib_with_standard_name() {
|
2014-07-23 00:53:38 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-07-23 00:53:38 +00:00
|
|
|
[package]
|
|
|
|
name = "syntax"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
"
|
2014-07-23 00:53:38 +00:00
|
|
|
pub fn foo() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
"
|
2014-07-23 00:53:38 +00:00
|
|
|
extern crate syntax;
|
|
|
|
fn main() { syntax::foo() }
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2014-07-23 00:53:38 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build"),
|
|
|
|
execs().with_status(0).with_stderr(&format!(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] syntax v0.0.1 ({dir})
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2014-07-23 00:53:38 +00:00
|
|
|
",
|
2018-03-14 15:17:44 +00:00
|
|
|
dir = p.url()
|
|
|
|
)),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-08-04 14:00:17 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn simple_staticlib() {
|
2014-08-04 14:00:17 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-08-04 14:00:17 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
authors = []
|
|
|
|
version = "0.0.1"
|
|
|
|
|
2014-08-14 06:08:02 +00:00
|
|
|
[lib]
|
2014-08-04 14:00:17 +00:00
|
|
|
name = "foo"
|
|
|
|
crate-type = ["staticlib"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/lib.rs", "pub fn foo() {}")
|
|
|
|
.build();
|
2014-08-04 14:00:17 +00:00
|
|
|
|
2015-03-05 20:11:08 +00:00
|
|
|
// env var is a test for #1381
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build").env("RUST_LOG", "nekoneko=trace"),
|
|
|
|
execs().with_status(0),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-08-14 06:02:08 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn staticlib_rlib_and_bin() {
|
2014-09-04 00:36:41 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-09-04 00:36:41 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
authors = []
|
|
|
|
version = "0.0.1"
|
|
|
|
|
|
|
|
[lib]
|
|
|
|
name = "foo"
|
|
|
|
crate-type = ["staticlib", "rlib"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2014-09-04 00:36:41 +00:00
|
|
|
.file("src/lib.rs", "pub fn foo() {}")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
2014-09-04 00:36:41 +00:00
|
|
|
extern crate foo;
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
foo::foo();
|
2018-03-14 15:17:44 +00:00
|
|
|
}"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2014-09-04 00:36:41 +00:00
|
|
|
|
2017-07-22 03:12:21 +00:00
|
|
|
assert_that(p.cargo("build").arg("-v"), execs().with_status(0));
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-09-04 00:36:41 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn opt_out_of_bin() {
|
2014-08-14 06:02:08 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-08-14 06:02:08 +00:00
|
|
|
bin = []
|
|
|
|
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
authors = []
|
|
|
|
version = "0.0.1"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2014-08-14 06:02:08 +00:00
|
|
|
.file("src/lib.rs", "")
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/main.rs", "bad syntax")
|
|
|
|
.build();
|
|
|
|
assert_that(p.cargo("build"), execs().with_status(0));
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-08-14 06:02:08 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn single_lib() {
|
2014-08-14 06:02:08 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-08-14 06:02:08 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
authors = []
|
|
|
|
version = "0.0.1"
|
|
|
|
|
|
|
|
[lib]
|
|
|
|
name = "foo"
|
|
|
|
path = "src/bar.rs"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/bar.rs", "")
|
|
|
|
.build();
|
|
|
|
assert_that(p.cargo("build"), execs().with_status(0));
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-08-14 06:08:02 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn freshness_ignores_excluded() {
|
2014-08-16 00:57:16 +00:00
|
|
|
let foo = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-08-16 00:57:16 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.0"
|
|
|
|
authors = []
|
2015-01-19 22:27:51 +00:00
|
|
|
build = "build.rs"
|
2014-08-16 00:57:16 +00:00
|
|
|
exclude = ["src/b*.rs"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2015-01-19 22:27:51 +00:00
|
|
|
.file("build.rs", "fn main() {}")
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/lib.rs", "pub fn bar() -> i32 { 1 }")
|
|
|
|
.build();
|
2016-05-26 00:06:25 +00:00
|
|
|
foo.root().move_into_the_past();
|
2014-08-16 00:57:16 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
foo.cargo("build"),
|
|
|
|
execs().with_status(0).with_stderr(&format!(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] foo v0.0.0 ({url})
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
url = foo.url()
|
|
|
|
)),
|
|
|
|
);
|
2014-08-16 00:57:16 +00:00
|
|
|
|
|
|
|
// Smoke test to make sure it doesn't compile again
|
|
|
|
println!("first pass");
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(foo.cargo("build"), execs().with_status(0).with_stdout(""));
|
2014-08-16 00:57:16 +00:00
|
|
|
|
|
|
|
// Modify an ignored file and make sure we don't rebuild
|
|
|
|
println!("second pass");
|
2014-12-21 23:19:44 +00:00
|
|
|
File::create(&foo.root().join("src/bar.rs")).unwrap();
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(foo.cargo("build"), execs().with_status(0).with_stdout(""));
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-08-16 01:15:13 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn rebuild_preserves_out_dir() {
|
2015-01-19 22:27:51 +00:00
|
|
|
let foo = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-08-16 01:15:13 +00:00
|
|
|
[package]
|
2015-01-19 22:27:51 +00:00
|
|
|
name = "foo"
|
|
|
|
version = "0.0.0"
|
|
|
|
authors = []
|
|
|
|
build = 'build.rs'
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"build.rs",
|
|
|
|
r#"
|
2015-02-06 07:27:53 +00:00
|
|
|
use std::env;
|
2015-03-26 18:17:44 +00:00
|
|
|
use std::fs::File;
|
|
|
|
use std::path::Path;
|
2014-08-16 01:15:13 +00:00
|
|
|
|
2015-01-19 22:27:51 +00:00
|
|
|
fn main() {
|
2015-03-26 18:17:44 +00:00
|
|
|
let path = Path::new(&env::var("OUT_DIR").unwrap()).join("foo");
|
2015-02-13 04:10:07 +00:00
|
|
|
if env::var_os("FIRST").is_some() {
|
2014-08-16 01:15:13 +00:00
|
|
|
File::create(&path).unwrap();
|
|
|
|
} else {
|
|
|
|
File::create(&path).unwrap();
|
|
|
|
}
|
2015-01-19 22:27:51 +00:00
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/lib.rs", "pub fn bar() -> i32 { 1 }")
|
|
|
|
.build();
|
2016-05-26 00:06:25 +00:00
|
|
|
foo.root().move_into_the_past();
|
2014-08-16 01:15:13 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
foo.cargo("build").env("FIRST", "1"),
|
|
|
|
execs().with_status(0).with_stderr(&format!(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] foo v0.0.0 ({url})
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
url = foo.url()
|
|
|
|
)),
|
|
|
|
);
|
2014-08-16 01:15:13 +00:00
|
|
|
|
2014-12-21 23:19:44 +00:00
|
|
|
File::create(&foo.root().join("src/bar.rs")).unwrap();
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
foo.cargo("build"),
|
|
|
|
execs().with_status(0).with_stderr(&format!(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] foo v0.0.0 ({url})
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
url = foo.url()
|
|
|
|
)),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-09-07 18:48:35 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn dep_no_libs() {
|
2014-09-07 18:48:35 +00:00
|
|
|
let foo = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-09-07 18:48:35 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.0"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies.bar]
|
|
|
|
path = "bar"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2015-02-13 04:10:07 +00:00
|
|
|
.file("src/lib.rs", "pub fn bar() -> i32 { 1 }")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"bar/Cargo.toml",
|
|
|
|
r#"
|
2014-09-07 18:48:35 +00:00
|
|
|
[package]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.0.0"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("bar/src/main.rs", "")
|
|
|
|
.build();
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(foo.cargo("build"), execs().with_status(0));
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-10-03 01:37:27 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn recompile_space_in_name() {
|
2014-10-03 01:37:27 +00:00
|
|
|
let foo = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-10-03 01:37:27 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.0"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[lib]
|
|
|
|
name = "foo"
|
|
|
|
path = "src/my lib.rs"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/my lib.rs", "")
|
|
|
|
.build();
|
|
|
|
assert_that(foo.cargo("build"), execs().with_status(0));
|
2016-05-26 00:06:25 +00:00
|
|
|
foo.root().move_into_the_past();
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(foo.cargo("build"), execs().with_status(0).with_stdout(""));
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-10-17 21:02:16 +00:00
|
|
|
|
2015-02-27 01:04:25 +00:00
|
|
|
#[cfg(unix)]
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn ignore_bad_directories() {
|
2015-02-27 01:04:25 +00:00
|
|
|
use std::os::unix::prelude::*;
|
2014-10-17 21:02:16 +00:00
|
|
|
let foo = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-10-17 21:02:16 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.0"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.build();
|
2015-02-27 01:04:25 +00:00
|
|
|
let dir = foo.root().join("tmp");
|
|
|
|
fs::create_dir(&dir).unwrap();
|
|
|
|
let stat = fs::metadata(&dir).unwrap();
|
|
|
|
let mut perms = stat.permissions();
|
|
|
|
perms.set_mode(0o644);
|
|
|
|
fs::set_permissions(&dir, perms.clone()).unwrap();
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(foo.cargo("build"), execs().with_status(0));
|
2015-02-27 01:04:25 +00:00
|
|
|
perms.set_mode(0o755);
|
|
|
|
fs::set_permissions(&dir, perms).unwrap();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-10-24 15:48:00 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn bad_cargo_config() {
|
2014-10-24 15:48:00 +00:00
|
|
|
let foo = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-10-24 15:48:00 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.0"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2014-10-24 15:48:00 +00:00
|
|
|
.file("src/lib.rs", "")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
".cargo/config",
|
|
|
|
r#"
|
2014-10-24 15:48:00 +00:00
|
|
|
this is not valid toml
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
foo.cargo("build").arg("-v"),
|
|
|
|
execs().with_status(101).with_stderr(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[ERROR] Couldn't load Cargo configuration
|
2014-10-24 15:48:00 +00:00
|
|
|
|
|
|
|
Caused by:
|
2015-01-14 18:11:08 +00:00
|
|
|
could not parse TOML configuration in `[..]`
|
2014-10-24 15:48:00 +00:00
|
|
|
|
|
|
|
Caused by:
|
2015-01-14 02:43:33 +00:00
|
|
|
could not parse input as TOML
|
2014-10-24 15:48:00 +00:00
|
|
|
|
2017-02-10 20:01:52 +00:00
|
|
|
Caused by:
|
|
|
|
expected an equals, found an identifier at line 2
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-10-21 16:36:55 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn cargo_platform_specific_dependency() {
|
2016-05-26 00:06:25 +00:00
|
|
|
let host = rustc_host();
|
2014-10-21 16:36:55 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
&format!(
|
|
|
|
r#"
|
2014-10-21 16:36:55 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["wycats@example.com"]
|
2015-04-29 17:23:08 +00:00
|
|
|
build = "build.rs"
|
2014-10-21 16:36:55 +00:00
|
|
|
|
2015-04-29 17:23:08 +00:00
|
|
|
[target.{host}.dependencies]
|
|
|
|
dep = {{ path = "dep" }}
|
|
|
|
[target.{host}.build-dependencies]
|
|
|
|
build = {{ path = "build" }}
|
|
|
|
[target.{host}.dev-dependencies]
|
|
|
|
dev = {{ path = "dev" }}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
host = host
|
|
|
|
),
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
2015-04-29 17:23:08 +00:00
|
|
|
extern crate dep;
|
|
|
|
fn main() { dep::dep() }
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"tests/foo.rs",
|
|
|
|
r#"
|
2015-04-29 17:23:08 +00:00
|
|
|
extern crate dev;
|
|
|
|
#[test]
|
|
|
|
fn foo() { dev::dev() }
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"build.rs",
|
|
|
|
r#"
|
2015-04-29 17:23:08 +00:00
|
|
|
extern crate build;
|
|
|
|
fn main() { build::build(); }
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"dep/Cargo.toml",
|
|
|
|
r#"
|
2014-10-21 16:36:55 +00:00
|
|
|
[project]
|
2015-04-29 17:23:08 +00:00
|
|
|
name = "dep"
|
2014-10-21 16:36:55 +00:00
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["wycats@example.com"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2015-04-29 17:23:08 +00:00
|
|
|
.file("dep/src/lib.rs", "pub fn dep() {}")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"build/Cargo.toml",
|
|
|
|
r#"
|
2015-04-29 17:23:08 +00:00
|
|
|
[project]
|
|
|
|
name = "build"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["wycats@example.com"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2015-04-29 17:23:08 +00:00
|
|
|
.file("build/src/lib.rs", "pub fn build() {}")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"dev/Cargo.toml",
|
|
|
|
r#"
|
2015-04-29 17:23:08 +00:00
|
|
|
[project]
|
|
|
|
name = "dev"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["wycats@example.com"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("dev/src/lib.rs", "pub fn dev() {}")
|
|
|
|
.build();
|
2014-10-21 16:36:55 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(p.cargo("build"), execs().with_status(0));
|
2014-10-21 16:36:55 +00:00
|
|
|
|
|
|
|
assert_that(&p.bin("foo"), existing_file());
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(p.cargo("test"), execs().with_status(0));
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-10-21 16:36:55 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn bad_platform_specific_dependency() {
|
2014-10-21 16:36:55 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-10-21 16:36:55 +00:00
|
|
|
[project]
|
|
|
|
|
|
|
|
name = "foo"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["wycats@example.com"]
|
|
|
|
|
2015-04-29 17:23:08 +00:00
|
|
|
[target.wrong-target.dependencies.bar]
|
2014-10-21 16:36:55 +00:00
|
|
|
path = "bar"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/main.rs", &main_file(r#""{}", bar::gimme()"#, &["bar"]))
|
|
|
|
.file(
|
|
|
|
"bar/Cargo.toml",
|
|
|
|
r#"
|
2014-10-21 16:36:55 +00:00
|
|
|
[project]
|
|
|
|
|
|
|
|
name = "bar"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["wycats@example.com"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"bar/src/lib.rs",
|
|
|
|
r#"
|
2014-10-21 16:36:55 +00:00
|
|
|
extern crate baz;
|
|
|
|
|
|
|
|
pub fn gimme() -> String {
|
|
|
|
format!("")
|
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2014-10-21 16:36:55 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(p.cargo("build"), execs().with_status(101));
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-10-21 16:36:55 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn cargo_platform_specific_dependency_wrong_platform() {
|
2014-10-21 16:36:55 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-10-21 16:36:55 +00:00
|
|
|
[project]
|
|
|
|
|
|
|
|
name = "foo"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["wycats@example.com"]
|
|
|
|
|
|
|
|
[target.non-existing-triplet.dependencies.bar]
|
|
|
|
path = "bar"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
2014-10-21 16:36:55 +00:00
|
|
|
fn main() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"bar/Cargo.toml",
|
|
|
|
r#"
|
2014-10-21 16:36:55 +00:00
|
|
|
[project]
|
|
|
|
|
|
|
|
name = "bar"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["wycats@example.com"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"bar/src/lib.rs",
|
|
|
|
r#"
|
2014-10-21 16:36:55 +00:00
|
|
|
invalid rust file, should not be compiled
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2014-10-21 16:36:55 +00:00
|
|
|
|
2017-07-22 03:12:21 +00:00
|
|
|
p.cargo("build").exec_with_output().unwrap();
|
2014-10-21 16:36:55 +00:00
|
|
|
|
|
|
|
assert_that(&p.bin("foo"), existing_file());
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(process(&p.bin("foo")), execs().with_status(0));
|
2014-10-21 16:36:55 +00:00
|
|
|
|
2015-02-27 01:04:25 +00:00
|
|
|
let loc = p.root().join("Cargo.lock");
|
|
|
|
let mut lockfile = String::new();
|
2018-03-14 15:17:44 +00:00
|
|
|
File::open(&loc)
|
|
|
|
.unwrap()
|
|
|
|
.read_to_string(&mut lockfile)
|
|
|
|
.unwrap();
|
2015-02-27 01:04:25 +00:00
|
|
|
assert!(lockfile.contains("bar"))
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-11-20 04:36:26 +00:00
|
|
|
|
2017-01-18 07:56:22 +00:00
|
|
|
#[test]
|
|
|
|
fn example_as_lib() {
|
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-01-18 07:56:22 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[[example]]
|
|
|
|
name = "ex"
|
|
|
|
crate-type = ["lib"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-01-18 07:56:22 +00:00
|
|
|
.file("src/lib.rs", "")
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("examples/ex.rs", "")
|
|
|
|
.build();
|
2017-01-18 07:56:22 +00:00
|
|
|
|
2017-07-22 03:12:21 +00:00
|
|
|
assert_that(p.cargo("build").arg("--example=ex"), execs().with_status(0));
|
2017-01-19 20:43:56 +00:00
|
|
|
assert_that(&p.example_lib("ex", "lib"), existing_file());
|
2017-01-18 07:56:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn example_as_rlib() {
|
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-01-18 07:56:22 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[[example]]
|
|
|
|
name = "ex"
|
|
|
|
crate-type = ["rlib"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-01-18 07:56:22 +00:00
|
|
|
.file("src/lib.rs", "")
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("examples/ex.rs", "")
|
|
|
|
.build();
|
2017-01-18 07:56:22 +00:00
|
|
|
|
2017-07-22 03:12:21 +00:00
|
|
|
assert_that(p.cargo("build").arg("--example=ex"), execs().with_status(0));
|
2017-01-19 20:43:56 +00:00
|
|
|
assert_that(&p.example_lib("ex", "rlib"), existing_file());
|
2017-01-18 07:56:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn example_as_dylib() {
|
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-01-18 07:56:22 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[[example]]
|
|
|
|
name = "ex"
|
|
|
|
crate-type = ["dylib"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-01-18 07:56:22 +00:00
|
|
|
.file("src/lib.rs", "")
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("examples/ex.rs", "")
|
|
|
|
.build();
|
2017-01-18 07:56:22 +00:00
|
|
|
|
2017-07-22 03:12:21 +00:00
|
|
|
assert_that(p.cargo("build").arg("--example=ex"), execs().with_status(0));
|
2017-01-19 20:43:56 +00:00
|
|
|
assert_that(&p.example_lib("ex", "dylib"), existing_file());
|
2017-01-18 07:56:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn example_as_proc_macro() {
|
2017-01-20 06:50:13 +00:00
|
|
|
if !is_nightly() {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-01-18 07:56:22 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-01-18 07:56:22 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[[example]]
|
|
|
|
name = "ex"
|
|
|
|
crate-type = ["proc-macro"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-01-18 07:56:22 +00:00
|
|
|
.file("src/lib.rs", "")
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("examples/ex.rs", "#![feature(proc_macro)]")
|
|
|
|
.build();
|
2017-01-18 07:56:22 +00:00
|
|
|
|
2017-07-22 03:12:21 +00:00
|
|
|
assert_that(p.cargo("build").arg("--example=ex"), execs().with_status(0));
|
2017-01-19 20:43:56 +00:00
|
|
|
assert_that(&p.example_lib("ex", "proc-macro"), existing_file());
|
2017-01-18 07:56:22 +00:00
|
|
|
}
|
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn example_bin_same_name() {
|
2014-11-20 04:36:26 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-11-20 04:36:26 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2014-11-20 04:36:26 +00:00
|
|
|
.file("src/main.rs", "fn main() {}")
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("examples/foo.rs", "fn main() {}")
|
|
|
|
.build();
|
2014-11-20 04:36:26 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
p.cargo("test")
|
|
|
|
.arg("--no-run")
|
|
|
|
.arg("-v")
|
2014-11-20 04:36:26 +00:00
|
|
|
.exec_with_output()
|
2014-12-21 23:19:44 +00:00
|
|
|
.unwrap();
|
2014-11-20 04:36:26 +00:00
|
|
|
|
2015-03-21 03:23:53 +00:00
|
|
|
assert_that(&p.bin("foo"), is_not(existing_file()));
|
2016-10-04 23:16:30 +00:00
|
|
|
// We expect a file of the form bin/foo-{metadata_hash}
|
2014-11-20 04:36:26 +00:00
|
|
|
assert_that(&p.bin("examples/foo"), existing_file());
|
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
p.cargo("test")
|
|
|
|
.arg("--no-run")
|
|
|
|
.arg("-v")
|
|
|
|
.exec_with_output()
|
|
|
|
.unwrap();
|
2014-11-20 04:36:26 +00:00
|
|
|
|
2015-03-21 03:23:53 +00:00
|
|
|
assert_that(&p.bin("foo"), is_not(existing_file()));
|
2016-10-04 23:16:30 +00:00
|
|
|
// We expect a file of the form bin/foo-{metadata_hash}
|
2014-11-20 04:36:26 +00:00
|
|
|
assert_that(&p.bin("examples/foo"), existing_file());
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-12-08 22:50:16 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn compile_then_delete() {
|
2014-12-08 22:50:16 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-12-08 22:50:16 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
2014-12-08 22:50:16 +00:00
|
|
|
|
2017-07-22 03:12:21 +00:00
|
|
|
assert_that(p.cargo("run").arg("-v"), execs().with_status(0));
|
2014-12-08 22:50:16 +00:00
|
|
|
assert_that(&p.bin("foo"), existing_file());
|
2014-12-11 23:16:43 +00:00
|
|
|
if cfg!(windows) {
|
2015-03-16 13:27:58 +00:00
|
|
|
// On windows unlinking immediately after running often fails, so sleep
|
2016-05-26 00:06:25 +00:00
|
|
|
sleep_ms(100);
|
2014-12-11 23:16:43 +00:00
|
|
|
}
|
2015-02-27 01:04:25 +00:00
|
|
|
fs::remove_file(&p.bin("foo")).unwrap();
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(p.cargo("run").arg("-v"), execs().with_status(0));
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-01-04 09:16:33 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn transitive_dependencies_not_available() {
|
2015-01-04 09:16:33 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2015-01-04 09:16:33 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
2015-02-09 16:16:08 +00:00
|
|
|
[dependencies.aaaaa]
|
2015-01-04 09:16:33 +00:00
|
|
|
path = "a"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
"extern crate bbbbb; extern crate aaaaa; fn main() {}",
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"a/Cargo.toml",
|
|
|
|
r#"
|
2015-01-04 09:16:33 +00:00
|
|
|
[package]
|
2015-02-09 16:16:08 +00:00
|
|
|
name = "aaaaa"
|
2015-01-04 09:16:33 +00:00
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
2015-02-09 16:16:08 +00:00
|
|
|
[dependencies.bbbbb]
|
2015-01-04 09:16:33 +00:00
|
|
|
path = "../b"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2015-02-09 16:16:08 +00:00
|
|
|
.file("a/src/lib.rs", "extern crate bbbbb;")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"b/Cargo.toml",
|
|
|
|
r#"
|
2015-01-04 09:16:33 +00:00
|
|
|
[package]
|
2015-02-09 16:16:08 +00:00
|
|
|
name = "bbbbb"
|
2015-01-04 09:16:33 +00:00
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("b/src/lib.rs", "")
|
|
|
|
.build();
|
2015-01-04 09:16:33 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build").arg("-v"),
|
2018-03-14 15:43:41 +00:00
|
|
|
execs()
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr_contains("[..] can't find crate for `bbbbb`[..]"),
|
2018-03-14 15:17:44 +00:00
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-01-29 05:50:06 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn cyclic_deps_rejected() {
|
2015-01-29 05:50:06 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2015-01-29 05:50:06 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies.a]
|
|
|
|
path = "a"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2015-01-29 05:50:06 +00:00
|
|
|
.file("src/lib.rs", "")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"a/Cargo.toml",
|
|
|
|
r#"
|
2015-01-29 05:50:06 +00:00
|
|
|
[package]
|
|
|
|
name = "a"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies.foo]
|
|
|
|
path = ".."
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("a/src/lib.rs", "")
|
|
|
|
.build();
|
2015-01-29 05:50:06 +00:00
|
|
|
|
2017-07-22 03:12:21 +00:00
|
|
|
assert_that(p.cargo("build").arg("-v"),
|
2015-01-29 05:50:06 +00:00
|
|
|
execs().with_status(101)
|
2018-03-08 18:37:30 +00:00
|
|
|
.with_stderr(
|
2018-03-07 22:56:47 +00:00
|
|
|
r#"[ERROR] cyclic package dependency: package `a v0.0.1 ([..])` depends on itself. Cycle:
|
|
|
|
package `a v0.0.1 ([..]a)`
|
|
|
|
... which is depended on by `foo v0.0.1 ([..]foo)`[..]"#));
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-03-20 20:40:27 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn predictable_filenames() {
|
2015-04-29 17:12:23 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2015-04-29 17:12:23 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[lib]
|
|
|
|
name = "foo"
|
2016-01-25 18:20:23 +00:00
|
|
|
crate-type = ["dylib", "rlib"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.build();
|
2015-04-29 17:12:23 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(p.cargo("build").arg("-v"), execs().with_status(0));
|
2015-04-29 17:12:23 +00:00
|
|
|
assert_that(&p.root().join("target/debug/libfoo.rlib"), existing_file());
|
2018-03-14 15:17:44 +00:00
|
|
|
let dylib_name = format!("{}foo{}", env::consts::DLL_PREFIX, env::consts::DLL_SUFFIX);
|
|
|
|
assert_that(
|
|
|
|
&p.root().join("target/debug").join(dylib_name),
|
|
|
|
existing_file(),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-04-29 17:12:23 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn dashes_to_underscores() {
|
2015-03-20 20:40:27 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2015-03-20 20:40:27 +00:00
|
|
|
[package]
|
|
|
|
name = "foo-bar"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2015-03-20 20:40:27 +00:00
|
|
|
.file("src/lib.rs", "")
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/main.rs", "extern crate foo_bar; fn main() {}")
|
|
|
|
.build();
|
2015-03-20 20:40:27 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(p.cargo("build").arg("-v"), execs().with_status(0));
|
2015-03-20 20:40:27 +00:00
|
|
|
assert_that(&p.bin("foo-bar"), existing_file());
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-03-20 20:40:27 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn dashes_in_crate_name_bad() {
|
2015-03-20 20:40:27 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2015-03-20 20:40:27 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[lib]
|
|
|
|
name = "foo-bar"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2015-03-20 20:40:27 +00:00
|
|
|
.file("src/lib.rs", "")
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/main.rs", "extern crate foo_bar; fn main() {}")
|
|
|
|
.build();
|
2015-03-20 20:40:27 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(p.cargo("build").arg("-v"), execs().with_status(101));
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-04-29 16:42:29 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn rustc_env_var() {
|
2015-05-18 21:55:42 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2015-05-18 21:55:42 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.build();
|
2015-05-18 21:55:42 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build")
|
|
|
|
.env("RUSTC", "rustc-that-does-not-exist")
|
|
|
|
.arg("-v"),
|
|
|
|
execs().with_status(101).with_stderr(
|
|
|
|
"\
|
2016-09-14 18:10:30 +00:00
|
|
|
[ERROR] could not execute process `rustc-that-does-not-exist -vV` ([..])
|
2015-05-18 21:55:42 +00:00
|
|
|
|
|
|
|
Caused by:
|
2015-08-03 17:04:22 +00:00
|
|
|
[..]
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
),
|
|
|
|
);
|
2015-05-18 21:55:42 +00:00
|
|
|
assert_that(&p.bin("a"), is_not(existing_file()));
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-05-18 21:55:42 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn filtering() {
|
2015-04-29 16:42:29 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2015-04-29 16:42:29 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2015-04-29 16:42:29 +00:00
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.file("src/bin/a.rs", "fn main() {}")
|
|
|
|
.file("src/bin/b.rs", "fn main() {}")
|
|
|
|
.file("examples/a.rs", "fn main() {}")
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("examples/b.rs", "fn main() {}")
|
|
|
|
.build();
|
2015-04-29 16:42:29 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(p.cargo("build").arg("--lib"), execs().with_status(0));
|
2015-04-29 16:42:29 +00:00
|
|
|
assert_that(&p.bin("a"), is_not(existing_file()));
|
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build").arg("--bin=a").arg("--example=a"),
|
|
|
|
execs().with_status(0),
|
|
|
|
);
|
2015-04-29 16:42:29 +00:00
|
|
|
assert_that(&p.bin("a"), existing_file());
|
|
|
|
assert_that(&p.bin("b"), is_not(existing_file()));
|
|
|
|
assert_that(&p.bin("examples/a"), existing_file());
|
|
|
|
assert_that(&p.bin("examples/b"), is_not(existing_file()));
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-05-18 15:32:35 +00:00
|
|
|
|
2017-04-05 18:50:22 +00:00
|
|
|
#[test]
|
|
|
|
fn filtering_implicit_bins() {
|
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-04-05 18:50:22 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-04-05 18:50:22 +00:00
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.file("src/bin/a.rs", "fn main() {}")
|
|
|
|
.file("src/bin/b.rs", "fn main() {}")
|
|
|
|
.file("examples/a.rs", "fn main() {}")
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("examples/b.rs", "fn main() {}")
|
|
|
|
.build();
|
2017-04-05 18:50:22 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(p.cargo("build").arg("--bins"), execs().with_status(0));
|
2017-04-05 18:50:22 +00:00
|
|
|
assert_that(&p.bin("a"), existing_file());
|
|
|
|
assert_that(&p.bin("b"), existing_file());
|
|
|
|
assert_that(&p.bin("examples/a"), is_not(existing_file()));
|
|
|
|
assert_that(&p.bin("examples/b"), is_not(existing_file()));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn filtering_implicit_examples() {
|
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-04-05 18:50:22 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-04-05 18:50:22 +00:00
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.file("src/bin/a.rs", "fn main() {}")
|
|
|
|
.file("src/bin/b.rs", "fn main() {}")
|
|
|
|
.file("examples/a.rs", "fn main() {}")
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("examples/b.rs", "fn main() {}")
|
|
|
|
.build();
|
2017-04-05 18:50:22 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(p.cargo("build").arg("--examples"), execs().with_status(0));
|
2017-04-05 18:50:22 +00:00
|
|
|
assert_that(&p.bin("a"), is_not(existing_file()));
|
|
|
|
assert_that(&p.bin("b"), is_not(existing_file()));
|
|
|
|
assert_that(&p.bin("examples/a"), existing_file());
|
|
|
|
assert_that(&p.bin("examples/b"), existing_file());
|
|
|
|
}
|
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn ignore_dotfile() {
|
2015-05-18 15:32:35 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2015-05-18 15:32:35 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2015-05-18 15:32:35 +00:00
|
|
|
.file("src/bin/.a.rs", "")
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/bin/a.rs", "fn main() {}")
|
|
|
|
.build();
|
2015-05-18 15:32:35 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(p.cargo("build"), execs().with_status(0));
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
Allow specifying a custom output directory
This commit adds support to allow specifying a custom output directory to Cargo.
First, the `build.target-dir` configuration key is checked, and failing that the
`CARGO_TARGET_DIR` environment variable is checked, and failing that the root
package's directory joined with the directory name "target" is used.
There are a few caveats to switching target directories, however:
* If the target directory is in the current source tree, and the folder name is
not called "target", then Cargo may walk the output directory when determining
whether a tree is fresh.
* If the target directory is not called "target", then Cargo may look inside it
currently for `Cargo.toml` files to learn about local packages.
* Concurrent usage of Cargo will still result in badness (#354), and this is now
exascerbated because many Cargo projects can share the same output directory.
* The top-level crate is not cached for future compilations, so if a crate is
built into directory `foo` and then that crate is later used as a dependency,
it will be recompiled.
The naming limitations can be overcome in time, but for now it greatly
simplifies the crawling routines and shouldn't have much of a negative impact
other than some Cargo runtimes (which can in turn be negated by following the
"target" name convention).
Closes #482
2015-05-28 22:39:20 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn ignore_dotdirs() {
|
2015-08-29 09:20:13 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2015-08-29 09:20:13 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2015-08-29 09:20:13 +00:00
|
|
|
.file("src/bin/a.rs", "fn main() {}")
|
|
|
|
.file(".git/Cargo.toml", "")
|
2017-07-22 03:12:21 +00:00
|
|
|
.file(".pc/dummy-fix.patch/Cargo.toml", "")
|
|
|
|
.build();
|
2015-08-29 09:20:13 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(p.cargo("build"), execs().with_status(0));
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-08-29 09:20:13 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn dotdir_root() {
|
2015-10-02 22:19:39 +00:00
|
|
|
let p = ProjectBuilder::new("foo", root().join(".foo"))
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2015-10-02 22:19:39 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/bin/a.rs", "fn main() {}")
|
|
|
|
.build();
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(p.cargo("build"), execs().with_status(0));
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-10-02 22:19:39 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
2018-04-16 23:50:30 +00:00
|
|
|
fn custom_target_dir_env() {
|
Allow specifying a custom output directory
This commit adds support to allow specifying a custom output directory to Cargo.
First, the `build.target-dir` configuration key is checked, and failing that the
`CARGO_TARGET_DIR` environment variable is checked, and failing that the root
package's directory joined with the directory name "target" is used.
There are a few caveats to switching target directories, however:
* If the target directory is in the current source tree, and the folder name is
not called "target", then Cargo may walk the output directory when determining
whether a tree is fresh.
* If the target directory is not called "target", then Cargo may look inside it
currently for `Cargo.toml` files to learn about local packages.
* Concurrent usage of Cargo will still result in badness (#354), and this is now
exascerbated because many Cargo projects can share the same output directory.
* The top-level crate is not cached for future compilations, so if a crate is
built into directory `foo` and then that crate is later used as a dependency,
it will be recompiled.
The naming limitations can be overcome in time, but for now it greatly
simplifies the crawling routines and shouldn't have much of a negative impact
other than some Cargo runtimes (which can in turn be negated by following the
"target" name convention).
Closes #482
2015-05-28 22:39:20 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
Allow specifying a custom output directory
This commit adds support to allow specifying a custom output directory to Cargo.
First, the `build.target-dir` configuration key is checked, and failing that the
`CARGO_TARGET_DIR` environment variable is checked, and failing that the root
package's directory joined with the directory name "target" is used.
There are a few caveats to switching target directories, however:
* If the target directory is in the current source tree, and the folder name is
not called "target", then Cargo may walk the output directory when determining
whether a tree is fresh.
* If the target directory is not called "target", then Cargo may look inside it
currently for `Cargo.toml` files to learn about local packages.
* Concurrent usage of Cargo will still result in badness (#354), and this is now
exascerbated because many Cargo projects can share the same output directory.
* The top-level crate is not cached for future compilations, so if a crate is
built into directory `foo` and then that crate is later used as a dependency,
it will be recompiled.
The naming limitations can be overcome in time, but for now it greatly
simplifies the crawling routines and shouldn't have much of a negative impact
other than some Cargo runtimes (which can in turn be negated by following the
"target" name convention).
Closes #482
2015-05-28 22:39:20 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
Allow specifying a custom output directory
This commit adds support to allow specifying a custom output directory to Cargo.
First, the `build.target-dir` configuration key is checked, and failing that the
`CARGO_TARGET_DIR` environment variable is checked, and failing that the root
package's directory joined with the directory name "target" is used.
There are a few caveats to switching target directories, however:
* If the target directory is in the current source tree, and the folder name is
not called "target", then Cargo may walk the output directory when determining
whether a tree is fresh.
* If the target directory is not called "target", then Cargo may look inside it
currently for `Cargo.toml` files to learn about local packages.
* Concurrent usage of Cargo will still result in badness (#354), and this is now
exascerbated because many Cargo projects can share the same output directory.
* The top-level crate is not cached for future compilations, so if a crate is
built into directory `foo` and then that crate is later used as a dependency,
it will be recompiled.
The naming limitations can be overcome in time, but for now it greatly
simplifies the crawling routines and shouldn't have much of a negative impact
other than some Cargo runtimes (which can in turn be negated by following the
"target" name convention).
Closes #482
2015-05-28 22:39:20 +00:00
|
|
|
|
|
|
|
let exe_name = format!("foo{}", env::consts::EXE_SUFFIX);
|
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build").env("CARGO_TARGET_DIR", "foo/target"),
|
|
|
|
execs().with_status(0),
|
|
|
|
);
|
|
|
|
assert_that(
|
|
|
|
&p.root().join("foo/target/debug").join(&exe_name),
|
|
|
|
existing_file(),
|
|
|
|
);
|
|
|
|
assert_that(
|
|
|
|
&p.root().join("target/debug").join(&exe_name),
|
|
|
|
is_not(existing_file()),
|
|
|
|
);
|
Allow specifying a custom output directory
This commit adds support to allow specifying a custom output directory to Cargo.
First, the `build.target-dir` configuration key is checked, and failing that the
`CARGO_TARGET_DIR` environment variable is checked, and failing that the root
package's directory joined with the directory name "target" is used.
There are a few caveats to switching target directories, however:
* If the target directory is in the current source tree, and the folder name is
not called "target", then Cargo may walk the output directory when determining
whether a tree is fresh.
* If the target directory is not called "target", then Cargo may look inside it
currently for `Cargo.toml` files to learn about local packages.
* Concurrent usage of Cargo will still result in badness (#354), and this is now
exascerbated because many Cargo projects can share the same output directory.
* The top-level crate is not cached for future compilations, so if a crate is
built into directory `foo` and then that crate is later used as a dependency,
it will be recompiled.
The naming limitations can be overcome in time, but for now it greatly
simplifies the crawling routines and shouldn't have much of a negative impact
other than some Cargo runtimes (which can in turn be negated by following the
"target" name convention).
Closes #482
2015-05-28 22:39:20 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(p.cargo("build"), execs().with_status(0));
|
|
|
|
assert_that(
|
|
|
|
&p.root().join("foo/target/debug").join(&exe_name),
|
|
|
|
existing_file(),
|
|
|
|
);
|
|
|
|
assert_that(
|
|
|
|
&p.root().join("target/debug").join(&exe_name),
|
|
|
|
existing_file(),
|
|
|
|
);
|
Allow specifying a custom output directory
This commit adds support to allow specifying a custom output directory to Cargo.
First, the `build.target-dir` configuration key is checked, and failing that the
`CARGO_TARGET_DIR` environment variable is checked, and failing that the root
package's directory joined with the directory name "target" is used.
There are a few caveats to switching target directories, however:
* If the target directory is in the current source tree, and the folder name is
not called "target", then Cargo may walk the output directory when determining
whether a tree is fresh.
* If the target directory is not called "target", then Cargo may look inside it
currently for `Cargo.toml` files to learn about local packages.
* Concurrent usage of Cargo will still result in badness (#354), and this is now
exascerbated because many Cargo projects can share the same output directory.
* The top-level crate is not cached for future compilations, so if a crate is
built into directory `foo` and then that crate is later used as a dependency,
it will be recompiled.
The naming limitations can be overcome in time, but for now it greatly
simplifies the crawling routines and shouldn't have much of a negative impact
other than some Cargo runtimes (which can in turn be negated by following the
"target" name convention).
Closes #482
2015-05-28 22:39:20 +00:00
|
|
|
|
|
|
|
fs::create_dir(p.root().join(".cargo")).unwrap();
|
2018-03-14 15:17:44 +00:00
|
|
|
File::create(p.root().join(".cargo/config"))
|
|
|
|
.unwrap()
|
|
|
|
.write_all(
|
|
|
|
br#"
|
Allow specifying a custom output directory
This commit adds support to allow specifying a custom output directory to Cargo.
First, the `build.target-dir` configuration key is checked, and failing that the
`CARGO_TARGET_DIR` environment variable is checked, and failing that the root
package's directory joined with the directory name "target" is used.
There are a few caveats to switching target directories, however:
* If the target directory is in the current source tree, and the folder name is
not called "target", then Cargo may walk the output directory when determining
whether a tree is fresh.
* If the target directory is not called "target", then Cargo may look inside it
currently for `Cargo.toml` files to learn about local packages.
* Concurrent usage of Cargo will still result in badness (#354), and this is now
exascerbated because many Cargo projects can share the same output directory.
* The top-level crate is not cached for future compilations, so if a crate is
built into directory `foo` and then that crate is later used as a dependency,
it will be recompiled.
The naming limitations can be overcome in time, but for now it greatly
simplifies the crawling routines and shouldn't have much of a negative impact
other than some Cargo runtimes (which can in turn be negated by following the
"target" name convention).
Closes #482
2015-05-28 22:39:20 +00:00
|
|
|
[build]
|
2016-02-06 20:25:52 +00:00
|
|
|
target-dir = "foo/target"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
assert_that(
|
|
|
|
p.cargo("build").env("CARGO_TARGET_DIR", "bar/target"),
|
|
|
|
execs().with_status(0),
|
|
|
|
);
|
|
|
|
assert_that(
|
|
|
|
&p.root().join("bar/target/debug").join(&exe_name),
|
|
|
|
existing_file(),
|
|
|
|
);
|
|
|
|
assert_that(
|
|
|
|
&p.root().join("foo/target/debug").join(&exe_name),
|
|
|
|
existing_file(),
|
|
|
|
);
|
|
|
|
assert_that(
|
|
|
|
&p.root().join("target/debug").join(&exe_name),
|
|
|
|
existing_file(),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-06-10 01:40:50 +00:00
|
|
|
|
2018-04-16 23:50:30 +00:00
|
|
|
#[test]
|
|
|
|
fn custom_target_dir_line_parameter() {
|
|
|
|
let p = project("foo")
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
let exe_name = format!("foo{}", env::consts::EXE_SUFFIX);
|
|
|
|
|
|
|
|
assert_that(
|
|
|
|
p.cargo("build").arg("--target-dir").arg("foo/target"),
|
|
|
|
execs().with_status(0),
|
|
|
|
);
|
|
|
|
assert_that(
|
|
|
|
&p.root().join("foo/target/debug").join(&exe_name),
|
|
|
|
existing_file(),
|
|
|
|
);
|
|
|
|
assert_that(
|
|
|
|
&p.root().join("target/debug").join(&exe_name),
|
|
|
|
is_not(existing_file()),
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_that(p.cargo("build"), execs().with_status(0));
|
|
|
|
assert_that(
|
|
|
|
&p.root().join("foo/target/debug").join(&exe_name),
|
|
|
|
existing_file(),
|
|
|
|
);
|
|
|
|
assert_that(
|
|
|
|
&p.root().join("target/debug").join(&exe_name),
|
|
|
|
existing_file(),
|
|
|
|
);
|
|
|
|
|
|
|
|
fs::create_dir(p.root().join(".cargo")).unwrap();
|
|
|
|
File::create(p.root().join(".cargo/config"))
|
|
|
|
.unwrap()
|
|
|
|
.write_all(
|
|
|
|
br#"
|
|
|
|
[build]
|
|
|
|
target-dir = "foo/target"
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
assert_that(
|
|
|
|
p.cargo("build").arg("--target-dir").arg("bar/target"),
|
|
|
|
execs().with_status(0),
|
|
|
|
);
|
|
|
|
assert_that(
|
|
|
|
&p.root().join("bar/target/debug").join(&exe_name),
|
|
|
|
existing_file(),
|
|
|
|
);
|
|
|
|
assert_that(
|
|
|
|
&p.root().join("foo/target/debug").join(&exe_name),
|
|
|
|
existing_file(),
|
|
|
|
);
|
|
|
|
assert_that(
|
|
|
|
&p.root().join("target/debug").join(&exe_name),
|
|
|
|
existing_file(),
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_that(
|
|
|
|
p.cargo("build")
|
|
|
|
.arg("--target-dir")
|
|
|
|
.arg("foobar/target")
|
|
|
|
.env("CARGO_TARGET_DIR", "bar/target"),
|
|
|
|
execs().with_status(0),
|
|
|
|
);
|
|
|
|
assert_that(
|
|
|
|
&p.root().join("foobar/target/debug").join(&exe_name),
|
|
|
|
existing_file(),
|
|
|
|
);
|
|
|
|
assert_that(
|
|
|
|
&p.root().join("bar/target/debug").join(&exe_name),
|
|
|
|
existing_file(),
|
|
|
|
);
|
|
|
|
assert_that(
|
|
|
|
&p.root().join("foo/target/debug").join(&exe_name),
|
|
|
|
existing_file(),
|
|
|
|
);
|
|
|
|
assert_that(
|
|
|
|
&p.root().join("target/debug").join(&exe_name),
|
|
|
|
existing_file(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn rustc_no_trans() {
|
|
|
|
if !is_nightly() {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let p = project("foo")
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
assert_that(
|
|
|
|
p.cargo("rustc").arg("-v").arg("--").arg("-Zno-trans"),
|
|
|
|
execs().with_status(0),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn build_multiple_packages() {
|
2015-07-16 20:35:40 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2015-07-16 20:35:40 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies.d1]
|
|
|
|
path = "d1"
|
|
|
|
[dependencies.d2]
|
|
|
|
path = "d2"
|
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
name = "foo"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2015-07-16 20:35:40 +00:00
|
|
|
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]))
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"d1/Cargo.toml",
|
|
|
|
r#"
|
2015-07-16 20:35:40 +00:00
|
|
|
[package]
|
|
|
|
name = "d1"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
name = "d1"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2015-07-16 20:35:40 +00:00
|
|
|
.file("d1/src/lib.rs", "")
|
|
|
|
.file("d1/src/main.rs", "fn main() { println!(\"d1\"); }")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"d2/Cargo.toml",
|
|
|
|
r#"
|
2015-07-16 20:35:40 +00:00
|
|
|
[package]
|
|
|
|
name = "d2"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
name = "d2"
|
|
|
|
doctest = false
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("d2/src/main.rs", "fn main() { println!(\"d2\"); }")
|
|
|
|
.build();
|
2015-07-16 20:35:40 +00:00
|
|
|
|
2018-03-16 17:03:27 +00:00
|
|
|
assert_that(p.cargo("build -p d1 -p d2 -p foo"), execs().with_status(0));
|
2015-07-16 20:35:40 +00:00
|
|
|
|
|
|
|
assert_that(&p.bin("foo"), existing_file());
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
process(&p.bin("foo")),
|
|
|
|
execs().with_status(0).with_stdout("i am foo\n"),
|
|
|
|
);
|
2015-07-16 20:35:40 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
let d1_path = &p.build_dir()
|
|
|
|
.join("debug")
|
|
|
|
.join(format!("d1{}", env::consts::EXE_SUFFIX));
|
|
|
|
let d2_path = &p.build_dir()
|
|
|
|
.join("debug")
|
|
|
|
.join(format!("d2{}", env::consts::EXE_SUFFIX));
|
2015-07-16 20:35:40 +00:00
|
|
|
|
2015-09-24 21:47:50 +00:00
|
|
|
assert_that(d1_path, existing_file());
|
2017-01-10 12:02:08 +00:00
|
|
|
assert_that(process(d1_path), execs().with_status(0).with_stdout("d1"));
|
2015-09-24 21:47:50 +00:00
|
|
|
|
|
|
|
assert_that(d2_path, existing_file());
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(process(d2_path), execs().with_status(0).with_stdout("d2"));
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-09-15 23:02:37 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn invalid_spec() {
|
2015-09-15 23:02:37 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2015-09-15 23:02:37 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies.d1]
|
|
|
|
path = "d1"
|
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
name = "foo"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-09 12:57:25 +00:00
|
|
|
.file("src/bin/foo.rs", &main_file(r#""i am foo""#, &[]))
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"d1/Cargo.toml",
|
|
|
|
r#"
|
2015-09-15 23:02:37 +00:00
|
|
|
[package]
|
|
|
|
name = "d1"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
name = "d1"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2015-09-15 23:02:37 +00:00
|
|
|
.file("d1/src/lib.rs", "")
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("d1/src/main.rs", "fn main() { println!(\"d1\"); }")
|
|
|
|
.build();
|
2015-09-15 23:02:37 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build").arg("-p").arg("notAValidDep"),
|
2018-03-14 15:43:41 +00:00
|
|
|
execs()
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr("[ERROR] package id specification `notAValidDep` matched no packages"),
|
2018-03-14 15:17:44 +00:00
|
|
|
);
|
2015-09-15 23:02:37 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build")
|
|
|
|
.arg("-p")
|
|
|
|
.arg("d1")
|
|
|
|
.arg("-p")
|
|
|
|
.arg("notAValidDep"),
|
2018-03-14 15:43:41 +00:00
|
|
|
execs()
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr("[ERROR] package id specification `notAValidDep` matched no packages"),
|
2018-03-14 15:17:44 +00:00
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-10-07 17:37:56 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn manifest_with_bom_is_ok() {
|
2015-10-07 17:37:56 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
"\u{FEFF}
|
2015-10-07 17:37:56 +00:00
|
|
|
[package]
|
|
|
|
name = \"foo\"
|
|
|
|
version = \"0.0.1\"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.build();
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(p.cargo("build").arg("-v"), execs().with_status(0));
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2016-05-13 18:35:52 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn panic_abort_compiles_with_panic_abort() {
|
2016-05-13 18:35:52 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2016-05-13 18:35:52 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[profile.dev]
|
|
|
|
panic = 'abort'
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.build();
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build").arg("-v"),
|
|
|
|
execs()
|
|
|
|
.with_status(0)
|
|
|
|
.with_stderr_contains("[..] -C panic=abort [..]"),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2016-06-09 20:55:17 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn explicit_color_config_is_propagated_to_rustc() {
|
2017-02-15 14:16:41 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-02-15 14:16:41 +00:00
|
|
|
[package]
|
2016-06-09 20:55:17 +00:00
|
|
|
|
2017-02-15 14:16:41 +00:00
|
|
|
name = "test"
|
|
|
|
version = "0.0.0"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.build();
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build").arg("-v").arg("--color").arg("always"),
|
|
|
|
execs()
|
|
|
|
.with_status(0)
|
|
|
|
.with_stderr_contains("[..]rustc [..] src[/]lib.rs --color always[..]"),
|
|
|
|
);
|
2016-06-09 20:55:17 +00:00
|
|
|
|
2017-02-15 14:16:41 +00:00
|
|
|
assert_that(p.cargo("clean"), execs().with_status(0));
|
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build").arg("-v").arg("--color").arg("never"),
|
|
|
|
execs().with_status(0).with_stderr(
|
|
|
|
"\
|
2016-06-09 20:55:17 +00:00
|
|
|
[COMPILING] test v0.0.0 ([..])
|
Always build libraries into the same location
Previously Cargo would compile a library into a different location depending on
whether it was the "root crate" or not. In the ongoing saga of reducing Cargo's
reliance on the idea of a "root crate" this PR is the next step. With workspaces
the root crate of a compliation changes all the time, so the output needs to be
the same whether a crate is at the root or not.
Fixing this inconsistence in turn fixes bugs like #2855 and #2897 which arise
due to this discrepancy. Additionally, Cargo will no longer recompile a library
when it's used as a "root crate" or not.
This is fixed by taking a few steps:
* Everything is now compiled into the `deps` directory, regardless of whether
it's a root output or not.
* If a "root crate" is being compiled, then the relevant outputs are hard-linked
up one level to where they are today. This means that your binaries, dylibs,
staticlibs, etc, will all show up where they used to.
* The `-C metadata` flag is always omitted for path dependencies now. These
dependencies are always path dependencies and already all have unique crate
names. Additionally, they're the only crates in the DAG without metadata, so
there's no need to provide additional metadata. This in turn means that none
of the file names of the generated crates are mangled.
Closes #2855
2016-07-25 20:27:06 +00:00
|
|
|
[RUNNING] `rustc [..] --color never [..]`
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
),
|
|
|
|
);
|
2016-06-09 20:55:17 +00:00
|
|
|
}
|
2016-05-10 19:55:19 +00:00
|
|
|
|
2016-08-11 21:47:49 +00:00
|
|
|
#[test]
|
|
|
|
fn compiler_json_error_format() {
|
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2016-08-11 21:47:49 +00:00
|
|
|
[project]
|
|
|
|
|
|
|
|
name = "foo"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["wycats@example.com"]
|
|
|
|
|
|
|
|
[dependencies.bar]
|
|
|
|
path = "bar"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2016-08-11 21:47:49 +00:00
|
|
|
.file("src/main.rs", "fn main() { let unused = 92; }")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"bar/Cargo.toml",
|
|
|
|
r#"
|
2016-08-11 21:47:49 +00:00
|
|
|
[project]
|
|
|
|
|
|
|
|
name = "bar"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["wycats@example.com"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("bar/src/lib.rs", r#"fn dead() {}"#)
|
|
|
|
.build();
|
2016-08-11 21:47:49 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build")
|
|
|
|
.arg("-v")
|
|
|
|
.arg("--message-format")
|
|
|
|
.arg("json"),
|
|
|
|
execs().with_status(0).with_json(
|
|
|
|
r#"
|
2016-08-11 21:47:49 +00:00
|
|
|
{
|
2016-09-28 16:54:35 +00:00
|
|
|
"reason":"compiler-message",
|
2016-08-11 21:47:49 +00:00
|
|
|
"package_id":"bar 0.5.0 ([..])",
|
2017-02-08 15:15:06 +00:00
|
|
|
"target":{
|
|
|
|
"kind":["lib"],
|
|
|
|
"crate_types":["lib"],
|
|
|
|
"name":"bar",
|
|
|
|
"src_path":"[..]lib.rs"
|
|
|
|
},
|
make build tests not depend on minutiæ of rustc output
This little patch arises from the maelstrom of my purity born of pain.
It's the pain of seeing rust-lang/rust#38103 in its perfect
crystalline beauty waste away on page four of
https://github.com/rust-lang/rust/pulls, waiting, ready, itching to
land, dying with anticipation to bring the light of clearer lint group
error messages to Rust users of all creeds and nations, only for its
promise to be cruelly blocked by the fateful, hateful hand of circular
dependency. For it is written in src/tools/cargotest/main.rs that the
Cargo tests must pass before the PR can receive Appveyor's blessing,
but the Cargo tests could not pass (because they depend on fine
details of the output that the PR is meant to change), and the Cargo
tests could not be changed (because updating the test expectation to
match the proposed new compiler output, would fail with the current
compiler).
The Gordian knot is cut in the bowels of cargotest's very notion of
comparison (of JSON objects) itself, by means of introducing a magic
string literal `"{...}"`, which can server as a wildcard for any JSON
sub-object.
And so it will be for the children, and the children's children, and
unto the 1.17.0 and 1.18.0 releases, that Cargo's build test
expectations will faithfully expect the exact JSON output by Cargo
itself, but the string literal `"{...}"` shall be a token upon the
JSON output by rustc, and when I see `"{...}"`, I will pass over you,
and the failure shall not be upon you.
And this day shall be unto you for a memorial.
2017-02-01 04:51:24 +00:00
|
|
|
"message":"{...}"
|
2016-08-11 21:47:49 +00:00
|
|
|
}
|
|
|
|
|
2016-11-23 16:29:36 +00:00
|
|
|
{
|
|
|
|
"reason":"compiler-artifact",
|
|
|
|
"profile": {
|
|
|
|
"debug_assertions": true,
|
2018-03-14 21:37:00 +00:00
|
|
|
"debuginfo": 2,
|
2016-11-23 16:29:36 +00:00
|
|
|
"opt_level": "0",
|
2017-04-07 16:32:42 +00:00
|
|
|
"overflow_checks": true,
|
2016-11-23 16:29:36 +00:00
|
|
|
"test": false
|
|
|
|
},
|
|
|
|
"features": [],
|
|
|
|
"package_id":"bar 0.5.0 ([..])",
|
2017-02-08 15:15:06 +00:00
|
|
|
"target":{
|
|
|
|
"kind":["lib"],
|
|
|
|
"crate_types":["lib"],
|
|
|
|
"name":"bar",
|
|
|
|
"src_path":"[..]lib.rs"
|
|
|
|
},
|
2017-02-22 08:36:44 +00:00
|
|
|
"filenames":["[..].rlib"],
|
|
|
|
"fresh": false
|
2016-11-23 16:29:36 +00:00
|
|
|
}
|
|
|
|
|
2016-08-11 21:47:49 +00:00
|
|
|
{
|
2016-09-28 16:54:35 +00:00
|
|
|
"reason":"compiler-message",
|
2016-08-11 21:47:49 +00:00
|
|
|
"package_id":"foo 0.5.0 ([..])",
|
2017-02-08 15:15:06 +00:00
|
|
|
"target":{
|
|
|
|
"kind":["bin"],
|
|
|
|
"crate_types":["bin"],
|
|
|
|
"name":"foo",
|
|
|
|
"src_path":"[..]main.rs"
|
|
|
|
},
|
make build tests not depend on minutiæ of rustc output
This little patch arises from the maelstrom of my purity born of pain.
It's the pain of seeing rust-lang/rust#38103 in its perfect
crystalline beauty waste away on page four of
https://github.com/rust-lang/rust/pulls, waiting, ready, itching to
land, dying with anticipation to bring the light of clearer lint group
error messages to Rust users of all creeds and nations, only for its
promise to be cruelly blocked by the fateful, hateful hand of circular
dependency. For it is written in src/tools/cargotest/main.rs that the
Cargo tests must pass before the PR can receive Appveyor's blessing,
but the Cargo tests could not pass (because they depend on fine
details of the output that the PR is meant to change), and the Cargo
tests could not be changed (because updating the test expectation to
match the proposed new compiler output, would fail with the current
compiler).
The Gordian knot is cut in the bowels of cargotest's very notion of
comparison (of JSON objects) itself, by means of introducing a magic
string literal `"{...}"`, which can server as a wildcard for any JSON
sub-object.
And so it will be for the children, and the children's children, and
unto the 1.17.0 and 1.18.0 releases, that Cargo's build test
expectations will faithfully expect the exact JSON output by Cargo
itself, but the string literal `"{...}"` shall be a token upon the
JSON output by rustc, and when I see `"{...}"`, I will pass over you,
and the failure shall not be upon you.
And this day shall be unto you for a memorial.
2017-02-01 04:51:24 +00:00
|
|
|
"message":"{...}"
|
2016-08-11 21:47:49 +00:00
|
|
|
}
|
2016-11-23 16:29:36 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
"reason":"compiler-artifact",
|
|
|
|
"package_id":"foo 0.5.0 ([..])",
|
2017-02-08 15:15:06 +00:00
|
|
|
"target":{
|
|
|
|
"kind":["bin"],
|
|
|
|
"crate_types":["bin"],
|
|
|
|
"name":"foo",
|
|
|
|
"src_path":"[..]main.rs"
|
|
|
|
},
|
2016-11-23 16:29:36 +00:00
|
|
|
"profile": {
|
|
|
|
"debug_assertions": true,
|
2018-03-14 21:37:00 +00:00
|
|
|
"debuginfo": 2,
|
2016-11-23 16:29:36 +00:00
|
|
|
"opt_level": "0",
|
2017-04-07 16:32:42 +00:00
|
|
|
"overflow_checks": true,
|
2016-11-23 16:29:36 +00:00
|
|
|
"test": false
|
|
|
|
},
|
|
|
|
"features": [],
|
2018-03-14 21:37:00 +00:00
|
|
|
"filenames": "{...}",
|
2017-02-22 08:36:44 +00:00
|
|
|
"fresh": false
|
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
),
|
|
|
|
);
|
2017-02-22 08:36:44 +00:00
|
|
|
|
|
|
|
// With fresh build, we should repeat the artifacts,
|
|
|
|
// but omit compiler warnings.
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build")
|
|
|
|
.arg("-v")
|
|
|
|
.arg("--message-format")
|
|
|
|
.arg("json"),
|
|
|
|
execs().with_status(0).with_json(
|
|
|
|
r#"
|
2017-02-22 08:36:44 +00:00
|
|
|
{
|
|
|
|
"reason":"compiler-artifact",
|
|
|
|
"profile": {
|
|
|
|
"debug_assertions": true,
|
2018-03-14 21:37:00 +00:00
|
|
|
"debuginfo": 2,
|
2017-02-22 08:36:44 +00:00
|
|
|
"opt_level": "0",
|
2017-04-07 16:32:42 +00:00
|
|
|
"overflow_checks": true,
|
2017-02-22 08:36:44 +00:00
|
|
|
"test": false
|
|
|
|
},
|
|
|
|
"features": [],
|
|
|
|
"package_id":"bar 0.5.0 ([..])",
|
|
|
|
"target":{
|
|
|
|
"kind":["lib"],
|
|
|
|
"crate_types":["lib"],
|
|
|
|
"name":"bar",
|
|
|
|
"src_path":"[..]lib.rs"
|
|
|
|
},
|
|
|
|
"filenames":["[..].rlib"],
|
|
|
|
"fresh": true
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
"reason":"compiler-artifact",
|
|
|
|
"package_id":"foo 0.5.0 ([..])",
|
|
|
|
"target":{
|
|
|
|
"kind":["bin"],
|
|
|
|
"crate_types":["bin"],
|
|
|
|
"name":"foo",
|
|
|
|
"src_path":"[..]main.rs"
|
|
|
|
},
|
|
|
|
"profile": {
|
|
|
|
"debug_assertions": true,
|
2018-03-14 21:37:00 +00:00
|
|
|
"debuginfo": 2,
|
2017-02-22 08:36:44 +00:00
|
|
|
"opt_level": "0",
|
2017-04-07 16:32:42 +00:00
|
|
|
"overflow_checks": true,
|
2017-02-22 08:36:44 +00:00
|
|
|
"test": false
|
|
|
|
},
|
|
|
|
"features": [],
|
2018-03-14 21:37:00 +00:00
|
|
|
"filenames": "{...}",
|
2017-02-22 08:36:44 +00:00
|
|
|
"fresh": true
|
2016-11-23 16:29:36 +00:00
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
),
|
|
|
|
);
|
2016-08-11 21:47:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn wrong_message_format_option() {
|
|
|
|
let p = project("foo")
|
|
|
|
.file("Cargo.toml", &basic_bin_manifest("foo"))
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
2016-08-11 21:47:49 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build").arg("--message-format").arg("XML"),
|
|
|
|
execs().with_status(1).with_stderr_contains(
|
|
|
|
"\
|
2018-03-08 18:48:38 +00:00
|
|
|
error: 'XML' isn't a valid value for '--message-format <FMT>'
|
|
|
|
<tab>[possible values: human, json]
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
),
|
|
|
|
);
|
2016-08-11 21:47:49 +00:00
|
|
|
}
|
|
|
|
|
2016-12-16 13:16:37 +00:00
|
|
|
#[test]
|
|
|
|
fn message_format_json_forward_stderr() {
|
|
|
|
let p = project("foo")
|
|
|
|
.file("Cargo.toml", &basic_bin_manifest("foo"))
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/main.rs", "fn main() { let unused = 0; }")
|
|
|
|
.build();
|
2016-12-16 13:16:37 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("rustc")
|
|
|
|
.arg("--release")
|
|
|
|
.arg("--bin")
|
|
|
|
.arg("foo")
|
|
|
|
.arg("--message-format")
|
|
|
|
.arg("JSON"),
|
|
|
|
execs().with_status(0).with_json(
|
|
|
|
r#"
|
2016-12-16 13:16:37 +00:00
|
|
|
{
|
|
|
|
"reason":"compiler-message",
|
|
|
|
"package_id":"foo 0.5.0 ([..])",
|
2017-02-10 09:35:20 +00:00
|
|
|
"target":{
|
|
|
|
"kind":["bin"],
|
|
|
|
"crate_types":["bin"],
|
|
|
|
"name":"foo",
|
|
|
|
"src_path":"[..]"
|
|
|
|
},
|
make build tests not depend on minutiæ of rustc output
This little patch arises from the maelstrom of my purity born of pain.
It's the pain of seeing rust-lang/rust#38103 in its perfect
crystalline beauty waste away on page four of
https://github.com/rust-lang/rust/pulls, waiting, ready, itching to
land, dying with anticipation to bring the light of clearer lint group
error messages to Rust users of all creeds and nations, only for its
promise to be cruelly blocked by the fateful, hateful hand of circular
dependency. For it is written in src/tools/cargotest/main.rs that the
Cargo tests must pass before the PR can receive Appveyor's blessing,
but the Cargo tests could not pass (because they depend on fine
details of the output that the PR is meant to change), and the Cargo
tests could not be changed (because updating the test expectation to
match the proposed new compiler output, would fail with the current
compiler).
The Gordian knot is cut in the bowels of cargotest's very notion of
comparison (of JSON objects) itself, by means of introducing a magic
string literal `"{...}"`, which can server as a wildcard for any JSON
sub-object.
And so it will be for the children, and the children's children, and
unto the 1.17.0 and 1.18.0 releases, that Cargo's build test
expectations will faithfully expect the exact JSON output by Cargo
itself, but the string literal `"{...}"` shall be a token upon the
JSON output by rustc, and when I see `"{...}"`, I will pass over you,
and the failure shall not be upon you.
And this day shall be unto you for a memorial.
2017-02-01 04:51:24 +00:00
|
|
|
"message":"{...}"
|
2016-12-16 13:16:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
"reason":"compiler-artifact",
|
|
|
|
"package_id":"foo 0.5.0 ([..])",
|
2017-02-10 09:35:20 +00:00
|
|
|
"target":{
|
|
|
|
"kind":["bin"],
|
|
|
|
"crate_types":["bin"],
|
|
|
|
"name":"foo",
|
|
|
|
"src_path":"[..]"
|
|
|
|
},
|
2016-12-16 13:16:37 +00:00
|
|
|
"profile":{
|
2017-10-13 19:13:32 +00:00
|
|
|
"debug_assertions":false,
|
|
|
|
"debuginfo":null,
|
|
|
|
"opt_level":"3",
|
|
|
|
"overflow_checks": false,
|
2016-12-16 13:16:37 +00:00
|
|
|
"test":false
|
|
|
|
},
|
|
|
|
"features":[],
|
2018-03-14 21:37:00 +00:00
|
|
|
"filenames": "{...}",
|
2017-02-22 08:36:44 +00:00
|
|
|
"fresh": false
|
2016-12-16 13:16:37 +00:00
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
),
|
|
|
|
);
|
2016-12-16 13:16:37 +00:00
|
|
|
}
|
|
|
|
|
2016-05-10 19:55:19 +00:00
|
|
|
#[test]
|
|
|
|
fn no_warn_about_package_metadata() {
|
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2016-05-10 19:55:19 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[package.metadata]
|
|
|
|
foo = "bar"
|
|
|
|
a = true
|
|
|
|
b = 3
|
|
|
|
|
|
|
|
[package.metadata.another]
|
|
|
|
bar = 3
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.build();
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build"),
|
|
|
|
execs().with_status(0).with_stderr(
|
|
|
|
"[..] foo v0.0.1 ([..])\n\
|
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]\n",
|
|
|
|
),
|
|
|
|
);
|
2016-05-10 19:55:19 +00:00
|
|
|
}
|
2016-10-25 18:52:47 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn cargo_build_empty_target() {
|
|
|
|
let p = project("foo")
|
|
|
|
.file("Cargo.toml", &basic_bin_manifest("foo"))
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
2016-10-25 18:52:47 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build").arg("--target").arg(""),
|
|
|
|
execs()
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr_contains("[..] target was empty"),
|
|
|
|
);
|
2016-10-25 18:52:47 +00:00
|
|
|
}
|
2017-01-07 11:01:39 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn build_all_workspace() {
|
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-01-07 11:01:39 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
bar = { path = "bar" }
|
|
|
|
|
|
|
|
[workspace]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
2017-01-07 11:01:39 +00:00
|
|
|
fn main() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"bar/Cargo.toml",
|
|
|
|
r#"
|
2017-01-07 11:01:39 +00:00
|
|
|
[project]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.1.0"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"bar/src/lib.rs",
|
|
|
|
r#"
|
2017-01-07 11:01:39 +00:00
|
|
|
pub fn bar() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2017-01-07 11:01:39 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build").arg("--all"),
|
|
|
|
execs().with_status(0).with_stderr(
|
|
|
|
"[..] Compiling bar v0.1.0 ([..])\n\
|
|
|
|
[..] Compiling foo v0.1.0 ([..])\n\
|
|
|
|
[..] Finished dev [unoptimized + debuginfo] target(s) in [..]\n",
|
|
|
|
),
|
|
|
|
);
|
2017-01-07 11:01:39 +00:00
|
|
|
}
|
|
|
|
|
2017-05-12 13:44:15 +00:00
|
|
|
#[test]
|
|
|
|
fn build_all_exclude() {
|
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-05-12 13:44:15 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
|
|
|
|
[workspace]
|
|
|
|
members = ["bar", "baz"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
2017-05-12 13:44:15 +00:00
|
|
|
fn main() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"bar/Cargo.toml",
|
|
|
|
r#"
|
2017-05-12 13:44:15 +00:00
|
|
|
[project]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.1.0"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"bar/src/lib.rs",
|
|
|
|
r#"
|
2017-05-12 13:44:15 +00:00
|
|
|
pub fn bar() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"baz/Cargo.toml",
|
|
|
|
r#"
|
2017-05-12 13:44:15 +00:00
|
|
|
[project]
|
|
|
|
name = "baz"
|
|
|
|
version = "0.1.0"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"baz/src/lib.rs",
|
|
|
|
r#"
|
2017-05-12 13:44:15 +00:00
|
|
|
pub fn baz() {
|
|
|
|
break_the_build();
|
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2017-05-12 13:44:15 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build").arg("--all").arg("--exclude").arg("baz"),
|
|
|
|
execs()
|
|
|
|
.with_status(0)
|
|
|
|
.with_stderr_contains("[..]Compiling foo v0.1.0 [..]")
|
|
|
|
.with_stderr_contains("[..]Compiling bar v0.1.0 [..]")
|
|
|
|
.with_stderr_does_not_contain("[..]Compiling baz v0.1.0 [..]"),
|
|
|
|
);
|
2017-05-12 13:44:15 +00:00
|
|
|
}
|
|
|
|
|
2017-04-10 18:18:08 +00:00
|
|
|
#[test]
|
|
|
|
fn build_all_workspace_implicit_examples() {
|
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-04-10 18:18:08 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
bar = { path = "bar" }
|
|
|
|
|
|
|
|
[workspace]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-04-10 18:18:08 +00:00
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.file("src/bin/a.rs", "fn main() {}")
|
|
|
|
.file("src/bin/b.rs", "fn main() {}")
|
|
|
|
.file("examples/c.rs", "fn main() {}")
|
|
|
|
.file("examples/d.rs", "fn main() {}")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"bar/Cargo.toml",
|
|
|
|
r#"
|
2017-04-10 18:18:08 +00:00
|
|
|
[project]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.1.0"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-04-10 18:18:08 +00:00
|
|
|
.file("bar/src/lib.rs", "")
|
|
|
|
.file("bar/src/bin/e.rs", "fn main() {}")
|
|
|
|
.file("bar/src/bin/f.rs", "fn main() {}")
|
|
|
|
.file("bar/examples/g.rs", "fn main() {}")
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("bar/examples/h.rs", "fn main() {}")
|
|
|
|
.build();
|
2017-04-10 18:18:08 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build").arg("--all").arg("--examples"),
|
|
|
|
execs().with_status(0).with_stderr(
|
|
|
|
"[..] Compiling bar v0.1.0 ([..])\n\
|
|
|
|
[..] Compiling foo v0.1.0 ([..])\n\
|
|
|
|
[..] Finished dev [unoptimized + debuginfo] target(s) in [..]\n",
|
|
|
|
),
|
|
|
|
);
|
2017-04-10 18:18:08 +00:00
|
|
|
assert_that(&p.bin("a"), is_not(existing_file()));
|
|
|
|
assert_that(&p.bin("b"), is_not(existing_file()));
|
|
|
|
assert_that(&p.bin("examples/c"), existing_file());
|
|
|
|
assert_that(&p.bin("examples/d"), existing_file());
|
|
|
|
assert_that(&p.bin("e"), is_not(existing_file()));
|
|
|
|
assert_that(&p.bin("f"), is_not(existing_file()));
|
|
|
|
assert_that(&p.bin("examples/g"), existing_file());
|
|
|
|
assert_that(&p.bin("examples/h"), existing_file());
|
|
|
|
}
|
|
|
|
|
2017-01-07 11:01:39 +00:00
|
|
|
#[test]
|
|
|
|
fn build_all_virtual_manifest() {
|
|
|
|
let p = project("workspace")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-01-07 11:01:39 +00:00
|
|
|
[workspace]
|
|
|
|
members = ["foo", "bar"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"foo/Cargo.toml",
|
|
|
|
r#"
|
2017-01-07 11:01:39 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"foo/src/lib.rs",
|
|
|
|
r#"
|
2017-01-07 11:01:39 +00:00
|
|
|
pub fn foo() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"bar/Cargo.toml",
|
|
|
|
r#"
|
2017-01-07 11:01:39 +00:00
|
|
|
[project]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.1.0"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"bar/src/lib.rs",
|
|
|
|
r#"
|
2017-01-07 11:01:39 +00:00
|
|
|
pub fn bar() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2017-01-07 11:01:39 +00:00
|
|
|
|
|
|
|
// The order in which foo and bar are built is not guaranteed
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build").arg("--all"),
|
|
|
|
execs()
|
|
|
|
.with_status(0)
|
|
|
|
.with_stderr_contains("[..] Compiling bar v0.1.0 ([..])")
|
|
|
|
.with_stderr_contains("[..] Compiling foo v0.1.0 ([..])")
|
|
|
|
.with_stderr(
|
|
|
|
"[..] Compiling [..] v0.1.0 ([..])\n\
|
|
|
|
[..] Compiling [..] v0.1.0 ([..])\n\
|
|
|
|
[..] Finished dev [unoptimized + debuginfo] target(s) in [..]\n",
|
|
|
|
),
|
|
|
|
);
|
2017-01-07 11:01:39 +00:00
|
|
|
}
|
|
|
|
|
2017-05-26 21:00:45 +00:00
|
|
|
#[test]
|
|
|
|
fn build_virtual_manifest_all_implied() {
|
|
|
|
let p = project("workspace")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-05-26 21:00:45 +00:00
|
|
|
[workspace]
|
|
|
|
members = ["foo", "bar"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"foo/Cargo.toml",
|
|
|
|
r#"
|
2017-05-26 21:00:45 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"foo/src/lib.rs",
|
|
|
|
r#"
|
2017-05-26 21:00:45 +00:00
|
|
|
pub fn foo() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"bar/Cargo.toml",
|
|
|
|
r#"
|
2017-05-26 21:00:45 +00:00
|
|
|
[project]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.1.0"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"bar/src/lib.rs",
|
|
|
|
r#"
|
2017-05-26 21:00:45 +00:00
|
|
|
pub fn bar() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2017-05-26 21:00:45 +00:00
|
|
|
|
|
|
|
// The order in which foo and bar are built is not guaranteed
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build"),
|
|
|
|
execs()
|
|
|
|
.with_status(0)
|
|
|
|
.with_stderr_contains("[..] Compiling bar v0.1.0 ([..])")
|
|
|
|
.with_stderr_contains("[..] Compiling foo v0.1.0 ([..])")
|
|
|
|
.with_stderr(
|
|
|
|
"[..] Compiling [..] v0.1.0 ([..])\n\
|
|
|
|
[..] Compiling [..] v0.1.0 ([..])\n\
|
|
|
|
[..] Finished dev [unoptimized + debuginfo] target(s) in [..]\n",
|
|
|
|
),
|
|
|
|
);
|
2017-05-26 21:00:45 +00:00
|
|
|
}
|
|
|
|
|
2017-07-27 20:44:45 +00:00
|
|
|
#[test]
|
|
|
|
fn build_virtual_manifest_one_project() {
|
|
|
|
let p = project("workspace")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-07-27 20:44:45 +00:00
|
|
|
[workspace]
|
|
|
|
members = ["foo", "bar"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"foo/Cargo.toml",
|
|
|
|
r#"
|
2017-07-27 20:44:45 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"foo/src/lib.rs",
|
|
|
|
r#"
|
2017-07-27 20:44:45 +00:00
|
|
|
pub fn foo() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"bar/Cargo.toml",
|
|
|
|
r#"
|
2017-07-27 20:44:45 +00:00
|
|
|
[project]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.1.0"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"bar/src/lib.rs",
|
|
|
|
r#"
|
2017-07-27 20:44:45 +00:00
|
|
|
pub fn bar() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2017-07-27 20:44:45 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build").arg("-p").arg("foo"),
|
|
|
|
execs()
|
|
|
|
.with_status(0)
|
2018-04-19 05:13:30 +00:00
|
|
|
.with_stderr_does_not_contain("[..]bar[..]")
|
2018-03-14 15:17:44 +00:00
|
|
|
.with_stderr_contains("[..] Compiling foo v0.1.0 ([..])")
|
|
|
|
.with_stderr(
|
|
|
|
"[..] Compiling [..] v0.1.0 ([..])\n\
|
|
|
|
[..] Finished dev [unoptimized + debuginfo] target(s) in [..]\n",
|
|
|
|
),
|
|
|
|
);
|
2017-07-27 20:44:45 +00:00
|
|
|
}
|
|
|
|
|
2017-04-10 18:18:08 +00:00
|
|
|
#[test]
|
|
|
|
fn build_all_virtual_manifest_implicit_examples() {
|
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-04-10 18:18:08 +00:00
|
|
|
[workspace]
|
|
|
|
members = ["foo", "bar"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"foo/Cargo.toml",
|
|
|
|
r#"
|
2017-04-10 18:18:08 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-04-10 18:18:08 +00:00
|
|
|
.file("foo/src/lib.rs", "")
|
|
|
|
.file("foo/src/bin/a.rs", "fn main() {}")
|
|
|
|
.file("foo/src/bin/b.rs", "fn main() {}")
|
|
|
|
.file("foo/examples/c.rs", "fn main() {}")
|
|
|
|
.file("foo/examples/d.rs", "fn main() {}")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"bar/Cargo.toml",
|
|
|
|
r#"
|
2017-04-10 18:18:08 +00:00
|
|
|
[project]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.1.0"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-04-10 18:18:08 +00:00
|
|
|
.file("bar/src/lib.rs", "")
|
|
|
|
.file("bar/src/bin/e.rs", "fn main() {}")
|
|
|
|
.file("bar/src/bin/f.rs", "fn main() {}")
|
|
|
|
.file("bar/examples/g.rs", "fn main() {}")
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("bar/examples/h.rs", "fn main() {}")
|
|
|
|
.build();
|
2017-04-10 18:18:08 +00:00
|
|
|
|
|
|
|
// The order in which foo and bar are built is not guaranteed
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build").arg("--all").arg("--examples"),
|
|
|
|
execs()
|
|
|
|
.with_status(0)
|
|
|
|
.with_stderr_contains("[..] Compiling bar v0.1.0 ([..])")
|
|
|
|
.with_stderr_contains("[..] Compiling foo v0.1.0 ([..])")
|
|
|
|
.with_stderr(
|
|
|
|
"[..] Compiling [..] v0.1.0 ([..])\n\
|
|
|
|
[..] Compiling [..] v0.1.0 ([..])\n\
|
|
|
|
[..] Finished dev [unoptimized + debuginfo] target(s) in [..]\n",
|
|
|
|
),
|
|
|
|
);
|
2017-04-10 18:18:08 +00:00
|
|
|
assert_that(&p.bin("a"), is_not(existing_file()));
|
|
|
|
assert_that(&p.bin("b"), is_not(existing_file()));
|
|
|
|
assert_that(&p.bin("examples/c"), existing_file());
|
|
|
|
assert_that(&p.bin("examples/d"), existing_file());
|
|
|
|
assert_that(&p.bin("e"), is_not(existing_file()));
|
|
|
|
assert_that(&p.bin("f"), is_not(existing_file()));
|
|
|
|
assert_that(&p.bin("examples/g"), existing_file());
|
|
|
|
assert_that(&p.bin("examples/h"), existing_file());
|
|
|
|
}
|
|
|
|
|
2017-01-07 11:01:39 +00:00
|
|
|
#[test]
|
|
|
|
fn build_all_member_dependency_same_name() {
|
|
|
|
let p = project("workspace")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-01-07 11:01:39 +00:00
|
|
|
[workspace]
|
|
|
|
members = ["a"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"a/Cargo.toml",
|
|
|
|
r#"
|
2017-01-07 11:01:39 +00:00
|
|
|
[project]
|
|
|
|
name = "a"
|
|
|
|
version = "0.1.0"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
a = "0.1.0"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"a/src/lib.rs",
|
|
|
|
r#"
|
2017-01-07 11:01:39 +00:00
|
|
|
pub fn a() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2017-01-07 11:01:39 +00:00
|
|
|
|
|
|
|
Package::new("a", "0.1.0").publish();
|
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build").arg("--all"),
|
|
|
|
execs().with_status(0).with_stderr(
|
|
|
|
"[..] Updating registry `[..]`\n\
|
|
|
|
[..] Downloading a v0.1.0 ([..])\n\
|
|
|
|
[..] Compiling a v0.1.0\n\
|
|
|
|
[..] Compiling a v0.1.0 ([..])\n\
|
|
|
|
[..] Finished dev [unoptimized + debuginfo] target(s) in [..]\n",
|
|
|
|
),
|
|
|
|
);
|
2017-01-07 11:01:39 +00:00
|
|
|
}
|
|
|
|
|
2017-01-28 23:56:30 +00:00
|
|
|
#[test]
|
|
|
|
fn run_proper_binary() {
|
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-01-28 23:56:30 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
authors = []
|
|
|
|
version = "0.0.0"
|
|
|
|
[[bin]]
|
|
|
|
name = "main"
|
|
|
|
[[bin]]
|
|
|
|
name = "other"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-01-28 23:56:30 +00:00
|
|
|
.file("src/lib.rs", "")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"src/bin/main.rs",
|
|
|
|
r#"
|
2017-01-28 23:56:30 +00:00
|
|
|
fn main() {
|
|
|
|
panic!("This should never be run.");
|
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/bin/other.rs",
|
|
|
|
r#"
|
2017-01-28 23:56:30 +00:00
|
|
|
fn main() {
|
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2017-01-28 23:56:30 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("run").arg("--bin").arg("other"),
|
|
|
|
execs().with_status(0),
|
|
|
|
);
|
2017-01-28 23:56:30 +00:00
|
|
|
}
|
2017-03-11 09:36:14 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn run_proper_binary_main_rs() {
|
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-03-11 09:36:14 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
authors = []
|
|
|
|
version = "0.0.0"
|
|
|
|
[[bin]]
|
|
|
|
name = "foo"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-03-11 09:36:14 +00:00
|
|
|
.file("src/lib.rs", "")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"src/bin/main.rs",
|
|
|
|
r#"
|
2017-03-11 09:36:14 +00:00
|
|
|
fn main() {
|
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2017-03-11 09:36:14 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("run").arg("--bin").arg("foo"),
|
|
|
|
execs().with_status(0),
|
|
|
|
);
|
2017-03-11 09:36:14 +00:00
|
|
|
}
|
2017-04-04 21:58:31 +00:00
|
|
|
|
2017-05-14 20:47:24 +00:00
|
|
|
#[test]
|
|
|
|
fn run_proper_alias_binary_from_src() {
|
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-05-14 20:47:24 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
authors = []
|
|
|
|
version = "0.0.0"
|
|
|
|
[[bin]]
|
|
|
|
name = "foo"
|
|
|
|
[[bin]]
|
|
|
|
name = "bar"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/foo.rs",
|
|
|
|
r#"
|
2017-05-14 20:47:24 +00:00
|
|
|
fn main() {
|
|
|
|
println!("foo");
|
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/bar.rs",
|
|
|
|
r#"
|
2017-05-14 20:47:24 +00:00
|
|
|
fn main() {
|
|
|
|
println!("bar");
|
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2017-05-14 20:47:24 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(p.cargo("build").arg("--all"), execs().with_status(0));
|
|
|
|
assert_that(
|
|
|
|
process(&p.bin("foo")),
|
|
|
|
execs().with_status(0).with_stdout("foo\n"),
|
|
|
|
);
|
|
|
|
assert_that(
|
|
|
|
process(&p.bin("bar")),
|
|
|
|
execs().with_status(0).with_stdout("bar\n"),
|
|
|
|
);
|
2017-05-14 20:47:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn run_proper_alias_binary_main_rs() {
|
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-05-14 20:47:24 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
authors = []
|
|
|
|
version = "0.0.0"
|
|
|
|
[[bin]]
|
|
|
|
name = "foo"
|
|
|
|
[[bin]]
|
|
|
|
name = "bar"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
2017-05-14 20:47:24 +00:00
|
|
|
fn main() {
|
|
|
|
println!("main");
|
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2017-05-14 20:47:24 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(p.cargo("build").arg("--all"), execs().with_status(0));
|
|
|
|
assert_that(
|
|
|
|
process(&p.bin("foo")),
|
|
|
|
execs().with_status(0).with_stdout("main\n"),
|
|
|
|
);
|
|
|
|
assert_that(
|
|
|
|
process(&p.bin("bar")),
|
|
|
|
execs().with_status(0).with_stdout("main\n"),
|
|
|
|
);
|
2017-05-14 20:47:24 +00:00
|
|
|
}
|
|
|
|
|
2017-04-04 21:58:31 +00:00
|
|
|
#[test]
|
|
|
|
fn run_proper_binary_main_rs_as_foo() {
|
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-04-04 21:58:31 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
authors = []
|
|
|
|
version = "0.0.0"
|
|
|
|
[[bin]]
|
|
|
|
name = "foo"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/foo.rs",
|
|
|
|
r#"
|
2017-04-04 21:58:31 +00:00
|
|
|
fn main() {
|
|
|
|
panic!("This should never be run.");
|
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
2017-04-04 21:58:31 +00:00
|
|
|
fn main() {
|
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2017-04-04 21:58:31 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("run").arg("--bin").arg("foo"),
|
|
|
|
execs().with_status(0),
|
|
|
|
);
|
2017-04-04 21:58:31 +00:00
|
|
|
}
|
2017-03-31 16:39:19 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn rustc_wrapper() {
|
|
|
|
// We don't have /usr/bin/env on Windows.
|
2018-03-14 15:17:44 +00:00
|
|
|
if cfg!(windows) {
|
|
|
|
return;
|
|
|
|
}
|
2017-03-31 16:39:19 +00:00
|
|
|
|
|
|
|
let p = project("foo")
|
|
|
|
.file("Cargo.toml", &basic_bin_manifest("foo"))
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]))
|
|
|
|
.build();
|
2017-03-31 16:39:19 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build")
|
|
|
|
.arg("-v")
|
|
|
|
.env("RUSTC_WRAPPER", "/usr/bin/env"),
|
|
|
|
execs()
|
|
|
|
.with_stderr_contains("[RUNNING] `/usr/bin/env rustc --crate-name foo [..]")
|
|
|
|
.with_status(0),
|
|
|
|
);
|
2017-03-31 16:39:19 +00:00
|
|
|
}
|
2017-04-24 20:41:27 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn cdylib_not_lifted() {
|
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-04-24 20:41:27 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
authors = []
|
|
|
|
version = "0.1.0"
|
|
|
|
|
|
|
|
[lib]
|
|
|
|
crate-type = ["cdylib"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.build();
|
2017-04-24 20:41:27 +00:00
|
|
|
|
2017-07-22 03:12:21 +00:00
|
|
|
assert_that(p.cargo("build"), execs().with_status(0));
|
2017-04-24 20:41:27 +00:00
|
|
|
|
|
|
|
let files = if cfg!(windows) {
|
|
|
|
vec!["foo.dll.lib", "foo.dll.exp", "foo.dll"]
|
|
|
|
} else if cfg!(target_os = "macos") {
|
|
|
|
vec!["libfoo.dylib"]
|
|
|
|
} else {
|
|
|
|
vec!["libfoo.so"]
|
|
|
|
};
|
|
|
|
|
|
|
|
for file in files {
|
|
|
|
println!("checking: {}", file);
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
&p.root().join("target/debug/deps").join(&file),
|
|
|
|
existing_file(),
|
|
|
|
);
|
2017-04-24 20:41:27 +00:00
|
|
|
}
|
|
|
|
}
|
2017-04-21 06:17:52 +00:00
|
|
|
|
2017-10-03 11:44:35 +00:00
|
|
|
#[test]
|
|
|
|
fn cdylib_final_outputs() {
|
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-10-03 11:44:35 +00:00
|
|
|
[project]
|
2017-10-05 01:37:04 +00:00
|
|
|
name = "foo-bar"
|
2017-10-03 11:44:35 +00:00
|
|
|
authors = []
|
|
|
|
version = "0.1.0"
|
|
|
|
|
|
|
|
[lib]
|
|
|
|
crate-type = ["cdylib"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.build();
|
2017-10-03 11:44:35 +00:00
|
|
|
|
2017-07-22 03:12:21 +00:00
|
|
|
assert_that(p.cargo("build"), execs().with_status(0));
|
2017-10-03 11:44:35 +00:00
|
|
|
|
|
|
|
let files = if cfg!(windows) {
|
2017-10-05 01:37:04 +00:00
|
|
|
vec!["foo_bar.dll.lib", "foo_bar.dll"]
|
2017-10-03 11:44:35 +00:00
|
|
|
} else if cfg!(target_os = "macos") {
|
2017-10-05 01:37:04 +00:00
|
|
|
vec!["libfoo_bar.dylib"]
|
2017-10-03 11:44:35 +00:00
|
|
|
} else {
|
2017-10-05 01:37:04 +00:00
|
|
|
vec!["libfoo_bar.so"]
|
2017-10-03 11:44:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
for file in files {
|
|
|
|
println!("checking: {}", file);
|
|
|
|
assert_that(&p.root().join("target/debug").join(&file), existing_file());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-21 06:17:52 +00:00
|
|
|
#[test]
|
|
|
|
fn deterministic_cfg_flags() {
|
|
|
|
// This bug is non-deterministic
|
|
|
|
|
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-04-21 06:17:52 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
authors = []
|
|
|
|
build = "build.rs"
|
|
|
|
|
|
|
|
[features]
|
|
|
|
default = ["f_a", "f_b", "f_c", "f_d"]
|
|
|
|
f_a = []
|
|
|
|
f_b = []
|
|
|
|
f_c = []
|
|
|
|
f_d = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"build.rs",
|
|
|
|
r#"
|
2017-04-21 06:17:52 +00:00
|
|
|
fn main() {
|
|
|
|
println!("cargo:rustc-cfg=cfg_a");
|
|
|
|
println!("cargo:rustc-cfg=cfg_b");
|
|
|
|
println!("cargo:rustc-cfg=cfg_c");
|
|
|
|
println!("cargo:rustc-cfg=cfg_d");
|
|
|
|
println!("cargo:rustc-cfg=cfg_e");
|
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
2017-04-21 06:17:52 +00:00
|
|
|
fn main() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2017-04-21 06:17:52 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build").arg("-v"),
|
|
|
|
execs().with_status(0).with_stderr(
|
|
|
|
"\
|
2017-04-21 06:17:52 +00:00
|
|
|
[COMPILING] foo v0.1.0 [..]
|
|
|
|
[RUNNING] [..]
|
|
|
|
[RUNNING] [..]
|
|
|
|
[RUNNING] `rustc --crate-name foo [..] \
|
2017-05-16 15:11:23 +00:00
|
|
|
--cfg[..]default[..]--cfg[..]f_a[..]--cfg[..]f_b[..]\
|
|
|
|
--cfg[..]f_c[..]--cfg[..]f_d[..] \
|
2017-04-21 06:17:52 +00:00
|
|
|
--cfg cfg_a --cfg cfg_b --cfg cfg_c --cfg cfg_d --cfg cfg_e`
|
2018-03-14 15:17:44 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]",
|
|
|
|
),
|
|
|
|
);
|
2017-04-21 06:17:52 +00:00
|
|
|
}
|
2017-06-16 19:41:27 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn explicit_bins_without_paths() {
|
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-06-16 19:41:27 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
name = "foo"
|
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
name = "bar"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-06-16 19:41:27 +00:00
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/bin/bar.rs", "fn main() {}")
|
|
|
|
.build();
|
2017-06-16 19:41:27 +00:00
|
|
|
|
2017-07-22 03:12:21 +00:00
|
|
|
assert_that(p.cargo("build"), execs().with_status(0));
|
2017-06-16 19:41:27 +00:00
|
|
|
}
|
2017-06-16 20:38:54 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn no_bin_in_src_with_lib() {
|
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-06-16 20:38:54 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
name = "foo"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-06-16 20:38:54 +00:00
|
|
|
.file("src/lib.rs", "")
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/foo.rs", "fn main() {}")
|
|
|
|
.build();
|
2017-06-16 20:38:54 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build"),
|
|
|
|
execs().with_status(101).with_stderr_contains(
|
|
|
|
"\
|
2017-07-09 12:57:25 +00:00
|
|
|
[ERROR] failed to parse manifest at `[..]`
|
|
|
|
|
|
|
|
Caused by:
|
2018-03-14 15:17:44 +00:00
|
|
|
can't find `foo` bin, specify bin.path",
|
|
|
|
),
|
|
|
|
);
|
2017-06-16 20:38:54 +00:00
|
|
|
}
|
2017-06-23 15:37:26 +00:00
|
|
|
|
|
|
|
#[test]
|
2017-10-23 09:18:12 +00:00
|
|
|
fn inferred_bins() {
|
2017-06-23 15:37:26 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-06-23 15:37:26 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-06-23 15:37:26 +00:00
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.file("src/bin/bar.rs", "fn main() {}")
|
2017-10-23 09:18:12 +00:00
|
|
|
.file("src/bin/baz/main.rs", "fn main() {}")
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2017-06-23 15:37:26 +00:00
|
|
|
|
2017-07-22 03:12:21 +00:00
|
|
|
assert_that(p.cargo("build"), execs().with_status(0));
|
2017-06-23 15:37:26 +00:00
|
|
|
assert_that(&p.bin("foo"), existing_file());
|
|
|
|
assert_that(&p.bin("bar"), existing_file());
|
2017-10-23 09:18:12 +00:00
|
|
|
assert_that(&p.bin("baz"), existing_file());
|
2017-06-27 17:51:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2017-10-23 09:18:12 +00:00
|
|
|
fn inferred_bins_duplicate_name() {
|
2017-06-27 17:51:56 +00:00
|
|
|
// this should fail, because we have two binaries with the same name
|
|
|
|
let p = project("bar")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-06-27 17:51:56 +00:00
|
|
|
[package]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.1.0"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-06-27 17:51:56 +00:00
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.file("src/bin/foo.rs", "fn main() {}")
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/bin/foo/main.rs", "fn main() {}")
|
|
|
|
.build();
|
2017-06-27 17:51:56 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build"),
|
|
|
|
execs().with_status(101).with_stderr_contains(
|
2018-03-14 15:43:41 +00:00
|
|
|
"[..]found duplicate binary name foo, but all binary targets must have a unique name[..]",
|
2018-03-14 15:17:44 +00:00
|
|
|
),
|
|
|
|
);
|
2017-06-27 17:51:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2017-10-23 09:18:12 +00:00
|
|
|
fn inferred_bin_path() {
|
2017-06-27 17:51:56 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-06-27 17:51:56 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
name = "bar"
|
|
|
|
# Note, no `path` key!
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/bin/bar/main.rs", "fn main() {}")
|
|
|
|
.build();
|
2017-06-27 17:51:56 +00:00
|
|
|
|
2017-07-22 03:12:21 +00:00
|
|
|
assert_that(p.cargo("build"), execs().with_status(0));
|
2017-06-27 17:51:56 +00:00
|
|
|
assert_that(&p.bin("bar"), existing_file());
|
2017-06-23 15:37:26 +00:00
|
|
|
}
|
2017-01-29 22:55:47 +00:00
|
|
|
|
2017-09-15 13:37:34 +00:00
|
|
|
#[test]
|
|
|
|
fn inferred_examples() {
|
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-09-15 13:37:34 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-09-15 13:37:34 +00:00
|
|
|
.file("src/lib.rs", "fn main() {}")
|
|
|
|
.file("examples/bar.rs", "fn main() {}")
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("examples/baz/main.rs", "fn main() {}")
|
|
|
|
.build();
|
2017-09-15 13:37:34 +00:00
|
|
|
|
2017-07-22 03:12:21 +00:00
|
|
|
assert_that(p.cargo("test"), execs().with_status(0));
|
2017-09-15 13:37:34 +00:00
|
|
|
assert_that(&p.bin("examples/bar"), existing_file());
|
|
|
|
assert_that(&p.bin("examples/baz"), existing_file());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn inferred_tests() {
|
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-09-15 13:37:34 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-09-15 13:37:34 +00:00
|
|
|
.file("src/lib.rs", "fn main() {}")
|
|
|
|
.file("tests/bar.rs", "fn main() {}")
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("tests/baz/main.rs", "fn main() {}")
|
|
|
|
.build();
|
2017-09-15 13:37:34 +00:00
|
|
|
|
|
|
|
assert_that(
|
2017-07-22 03:12:21 +00:00
|
|
|
p.cargo("test").arg("--test=bar").arg("--test=baz"),
|
2018-03-14 15:17:44 +00:00
|
|
|
execs().with_status(0),
|
|
|
|
);
|
2017-09-15 13:37:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2017-10-23 09:18:12 +00:00
|
|
|
fn inferred_benchmarks() {
|
2017-09-15 13:37:34 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-09-15 13:37:34 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-09-15 13:37:34 +00:00
|
|
|
.file("src/lib.rs", "fn main() {}")
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("benches/bar.rs", "fn main() {}")
|
2017-10-23 09:18:12 +00:00
|
|
|
.file("benches/baz/main.rs", "fn main() {}")
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2017-09-15 13:37:34 +00:00
|
|
|
|
|
|
|
assert_that(
|
2017-10-23 09:18:12 +00:00
|
|
|
p.cargo("bench").arg("--bench=bar").arg("--bench=baz"),
|
2018-03-14 15:17:44 +00:00
|
|
|
execs().with_status(0),
|
|
|
|
);
|
2017-09-15 13:37:34 +00:00
|
|
|
}
|
|
|
|
|
2017-01-29 22:55:47 +00:00
|
|
|
#[test]
|
|
|
|
fn same_metadata_different_directory() {
|
|
|
|
// A top-level crate built in two different workspaces should have the
|
|
|
|
// same metadata hash.
|
|
|
|
let p = project("foo1")
|
|
|
|
.file("Cargo.toml", &basic_bin_manifest("foo"))
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]))
|
|
|
|
.build();
|
2017-01-29 22:55:47 +00:00
|
|
|
let output = t!(String::from_utf8(
|
2018-03-14 15:17:44 +00:00
|
|
|
t!(p.cargo("build").arg("-v").exec_with_output()).stderr,
|
2017-01-29 22:55:47 +00:00
|
|
|
));
|
|
|
|
let metadata = output
|
|
|
|
.split_whitespace()
|
2017-09-24 14:26:37 +00:00
|
|
|
.find(|arg| arg.starts_with("metadata="))
|
2017-01-29 22:55:47 +00:00
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
let p = project("foo2")
|
|
|
|
.file("Cargo.toml", &basic_bin_manifest("foo"))
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]))
|
|
|
|
.build();
|
2017-01-29 22:55:47 +00:00
|
|
|
|
|
|
|
assert_that(
|
2017-07-22 03:12:21 +00:00
|
|
|
p.cargo("build").arg("-v"),
|
2018-03-14 15:17:44 +00:00
|
|
|
execs()
|
|
|
|
.with_status(0)
|
|
|
|
.with_stderr_contains(format!("[..]{}[..]", metadata)),
|
2017-01-29 22:55:47 +00:00
|
|
|
);
|
|
|
|
}
|
2017-08-09 21:54:09 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn building_a_dependent_crate_witout_bin_should_fail() {
|
|
|
|
Package::new("testless", "0.1.0")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-08-09 21:54:09 +00:00
|
|
|
[project]
|
|
|
|
name = "testless"
|
|
|
|
version = "0.1.0"
|
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
name = "a_bin"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-08-09 21:54:09 +00:00
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.publish();
|
|
|
|
|
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-08-09 21:54:09 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
testless = "0.1.0"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.build();
|
2017-08-09 21:54:09 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build"),
|
|
|
|
execs()
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr_contains("[..]can't find `a_bin` bin, specify bin.path"),
|
|
|
|
);
|
2017-08-09 21:54:09 +00:00
|
|
|
}
|
2017-10-13 19:13:32 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn uplift_dsym_of_bin_on_mac() {
|
Avoid rebuilding a project when cwd changes
This commit is targeted at solving a use case which typically comes up during CI
builds -- the `target` directory is cached between builds but the cwd of the
build changes over time. For example the following scenario can happen:
1. A project is compiled at `/projects/a`.
2. The `target` directory is cached.
3. A new build is started in `/projects/b`.
4. The previous `target` directory is restored to `/projects/b`.
5. The build start, and Cargo rebuilds everything.
The last piece of behavior is indeed unfortunate! Cargo's internal hashing
currently isn't that resilient to changing cwd and this PR aims to help improve
the situation!
The first point of too-much-hashing came up with `Target::src_path`. Each
`Target` was hashed and stored for all compilations, and the `src_path` field
was an absolute path on the filesystem to the file that needed to be compiled.
This path then changed over time when cwd changed, but otherwise everything else
remained the same!
This commit updates the handling of the `src_path` field to simply ignore it
when hashing. Instead the path we actually pass to rustc is later calculated and
then passed to the fingerprint calculation.
The next problem this fixes is that the dep info files were augmented after
creation to have the cwd of the compiler at the time to find the files at a
later date. This, unfortunately, would cause issues if the cwd itself changed.
Instead the cwd is now left out of dep-info files (they're no longer augmented)
and instead the cwd is recalculated when parsing the dep info later.
The final problem that this commit fixes is actually an existing issue in Cargo
today. Right now you can actually execute `cargo build` from anywhere in a
project and Cargo will execute the build. Unfortunately though the argument to
rustc was actually different depending on what directory you were in (the
compiler was invoked with a path relative to cwd). This path ends up being used
for metadata like debuginfo which means that different directories would cause
different artifacts to be created, but Cargo wouldn't rerun the compiler!
To fix this issue the matter of cwd is now entirely excluded from compilation
command lines. Instead rustc is unconditionally invoked with a relative path
*if* the path is underneath the workspace root, and otherwise it's invoked as an
absolute path (in which case the cwd doesn't matter).
Once all these fixes were added up it means that now we can have projects where
if you move the entire directory Cargo won't rebuild the original source!
Note that this may be a bit of a breaking change, however. This means that the
paths in error messages for cargo will no longer be unconditionally relative to
the current working directory, but rather relative to the root of the workspace
itself. Unfortunately this is moreso of a feature right now rather than a bug,
so it may be one that we just have to stomach.
2017-12-06 22:53:09 +00:00
|
|
|
if !cfg!(any(target_os = "macos", target_os = "ios")) {
|
2018-03-14 15:17:44 +00:00
|
|
|
return;
|
Avoid rebuilding a project when cwd changes
This commit is targeted at solving a use case which typically comes up during CI
builds -- the `target` directory is cached between builds but the cwd of the
build changes over time. For example the following scenario can happen:
1. A project is compiled at `/projects/a`.
2. The `target` directory is cached.
3. A new build is started in `/projects/b`.
4. The previous `target` directory is restored to `/projects/b`.
5. The build start, and Cargo rebuilds everything.
The last piece of behavior is indeed unfortunate! Cargo's internal hashing
currently isn't that resilient to changing cwd and this PR aims to help improve
the situation!
The first point of too-much-hashing came up with `Target::src_path`. Each
`Target` was hashed and stored for all compilations, and the `src_path` field
was an absolute path on the filesystem to the file that needed to be compiled.
This path then changed over time when cwd changed, but otherwise everything else
remained the same!
This commit updates the handling of the `src_path` field to simply ignore it
when hashing. Instead the path we actually pass to rustc is later calculated and
then passed to the fingerprint calculation.
The next problem this fixes is that the dep info files were augmented after
creation to have the cwd of the compiler at the time to find the files at a
later date. This, unfortunately, would cause issues if the cwd itself changed.
Instead the cwd is now left out of dep-info files (they're no longer augmented)
and instead the cwd is recalculated when parsing the dep info later.
The final problem that this commit fixes is actually an existing issue in Cargo
today. Right now you can actually execute `cargo build` from anywhere in a
project and Cargo will execute the build. Unfortunately though the argument to
rustc was actually different depending on what directory you were in (the
compiler was invoked with a path relative to cwd). This path ends up being used
for metadata like debuginfo which means that different directories would cause
different artifacts to be created, but Cargo wouldn't rerun the compiler!
To fix this issue the matter of cwd is now entirely excluded from compilation
command lines. Instead rustc is unconditionally invoked with a relative path
*if* the path is underneath the workspace root, and otherwise it's invoked as an
absolute path (in which case the cwd doesn't matter).
Once all these fixes were added up it means that now we can have projects where
if you move the entire directory Cargo won't rebuild the original source!
Note that this may be a bit of a breaking change, however. This means that the
paths in error messages for cargo will no longer be unconditionally relative to
the current working directory, but rather relative to the root of the workspace
itself. Unfortunately this is moreso of a feature right now rather than a bug,
so it may be one that we just have to stomach.
2017-12-06 22:53:09 +00:00
|
|
|
}
|
2017-10-13 19:13:32 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-10-13 19:13:32 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-10-13 19:13:32 +00:00
|
|
|
.file("src/main.rs", "fn main() { panic!(); }")
|
|
|
|
.file("src/bin/b.rs", "fn main() { panic!(); }")
|
|
|
|
.file("examples/c.rs", "fn main() { panic!(); }")
|
|
|
|
.file("tests/d.rs", "fn main() { panic!(); }")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
assert_that(
|
2018-03-14 15:17:44 +00:00
|
|
|
p.cargo("build")
|
|
|
|
.arg("--bins")
|
|
|
|
.arg("--examples")
|
|
|
|
.arg("--tests"),
|
|
|
|
execs().with_status(0),
|
2017-10-13 19:13:32 +00:00
|
|
|
);
|
|
|
|
assert_that(&p.bin("foo.dSYM"), existing_dir());
|
|
|
|
assert_that(&p.bin("b.dSYM"), existing_dir());
|
2017-10-28 19:47:29 +00:00
|
|
|
assert!(
|
|
|
|
p.bin("b.dSYM")
|
|
|
|
.symlink_metadata()
|
|
|
|
.expect("read metadata from b.dSYM")
|
|
|
|
.file_type()
|
|
|
|
.is_symlink()
|
|
|
|
);
|
2017-10-13 19:13:32 +00:00
|
|
|
assert_that(&p.bin("c.dSYM"), is_not(existing_dir()));
|
|
|
|
assert_that(&p.bin("d.dSYM"), is_not(existing_dir()));
|
|
|
|
}
|
2017-10-08 22:23:21 +00:00
|
|
|
|
2018-03-14 19:21:02 +00:00
|
|
|
#[test]
|
|
|
|
fn uplift_pdb_of_bin_on_windows() {
|
|
|
|
if !cfg!(all(target_os = "windows", target_env = "msvc")) {
|
2018-03-14 15:17:44 +00:00
|
|
|
return;
|
2018-03-14 19:21:02 +00:00
|
|
|
}
|
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2018-03-14 19:21:02 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2018-03-14 19:21:02 +00:00
|
|
|
.file("src/main.rs", "fn main() { panic!(); }")
|
|
|
|
.file("src/bin/b.rs", "fn main() { panic!(); }")
|
|
|
|
.file("examples/c.rs", "fn main() { panic!(); }")
|
|
|
|
.file("tests/d.rs", "fn main() { panic!(); }")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
assert_that(
|
2018-03-14 15:17:44 +00:00
|
|
|
p.cargo("build")
|
|
|
|
.arg("--bins")
|
|
|
|
.arg("--examples")
|
|
|
|
.arg("--tests"),
|
|
|
|
execs().with_status(0),
|
2018-03-14 19:21:02 +00:00
|
|
|
);
|
|
|
|
assert_that(&p.target_debug_dir().join("foo.pdb"), existing_file());
|
|
|
|
assert_that(&p.target_debug_dir().join("b.pdb"), existing_file());
|
|
|
|
assert_that(&p.target_debug_dir().join("c.pdb"), is_not(existing_file()));
|
|
|
|
assert_that(&p.target_debug_dir().join("d.pdb"), is_not(existing_file()));
|
|
|
|
}
|
|
|
|
|
2017-10-08 22:23:21 +00:00
|
|
|
// Make sure that `cargo build` chooses the correct profile for building
|
|
|
|
// targets based on filters (assuming --profile is not specified).
|
|
|
|
#[test]
|
|
|
|
fn build_filter_infer_profile() {
|
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-10-08 22:23:21 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-10-08 22:23:21 +00:00
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.file("tests/t1.rs", "")
|
|
|
|
.file("benches/b1.rs", "")
|
|
|
|
.file("examples/ex1.rs", "fn main() {}")
|
|
|
|
.build();
|
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build").arg("-v"),
|
|
|
|
execs()
|
|
|
|
.with_status(0)
|
|
|
|
.with_stderr_contains(
|
|
|
|
"\
|
|
|
|
[RUNNING] `rustc --crate-name foo src[/]lib.rs --crate-type lib \
|
|
|
|
--emit=dep-info,link[..]",
|
|
|
|
)
|
|
|
|
.with_stderr_contains(
|
|
|
|
"\
|
|
|
|
[RUNNING] `rustc --crate-name foo src[/]main.rs --crate-type bin \
|
|
|
|
--emit=dep-info,link[..]",
|
|
|
|
),
|
|
|
|
);
|
2017-10-08 22:23:21 +00:00
|
|
|
|
|
|
|
p.root().join("target").rm_rf();
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build").arg("-v").arg("--test=t1"),
|
|
|
|
execs()
|
|
|
|
.with_status(0)
|
|
|
|
.with_stderr_contains(
|
|
|
|
"\
|
|
|
|
[RUNNING] `rustc --crate-name foo src[/]lib.rs --crate-type lib \
|
|
|
|
--emit=dep-info,link[..]",
|
|
|
|
)
|
|
|
|
.with_stderr_contains(
|
2018-03-14 15:43:41 +00:00
|
|
|
"[RUNNING] `rustc --crate-name t1 tests[/]t1.rs --emit=dep-info,link[..]",
|
2018-03-14 15:17:44 +00:00
|
|
|
)
|
|
|
|
.with_stderr_contains(
|
|
|
|
"\
|
|
|
|
[RUNNING] `rustc --crate-name foo src[/]main.rs --crate-type bin \
|
|
|
|
--emit=dep-info,link[..]",
|
|
|
|
),
|
|
|
|
);
|
2017-10-08 22:23:21 +00:00
|
|
|
|
|
|
|
p.root().join("target").rm_rf();
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build").arg("-v").arg("--bench=b1"),
|
|
|
|
execs()
|
|
|
|
.with_status(0)
|
|
|
|
.with_stderr_contains(
|
|
|
|
"\
|
|
|
|
[RUNNING] `rustc --crate-name foo src[/]lib.rs --crate-type lib \
|
|
|
|
--emit=dep-info,link[..]",
|
|
|
|
)
|
|
|
|
.with_stderr_contains(
|
|
|
|
"\
|
|
|
|
[RUNNING] `rustc --crate-name b1 benches[/]b1.rs --emit=dep-info,link \
|
|
|
|
-C opt-level=3[..]",
|
|
|
|
)
|
|
|
|
.with_stderr_contains(
|
|
|
|
"\
|
|
|
|
[RUNNING] `rustc --crate-name foo src[/]main.rs --crate-type bin \
|
|
|
|
--emit=dep-info,link[..]",
|
|
|
|
),
|
|
|
|
);
|
2017-10-08 22:23:21 +00:00
|
|
|
}
|
2017-10-30 21:42:47 +00:00
|
|
|
|
2018-03-15 15:20:15 +00:00
|
|
|
#[test]
|
2018-03-19 17:20:54 +00:00
|
|
|
fn targets_selected_default() {
|
2018-03-15 15:20:15 +00:00
|
|
|
let p = project("foo")
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
authors = []
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
|
|
|
assert_that(
|
2018-03-19 17:20:54 +00:00
|
|
|
p.cargo("build").arg("-v"),
|
2018-03-15 15:20:15 +00:00
|
|
|
execs().with_status(0)
|
|
|
|
// bin
|
|
|
|
.with_stderr_contains("\
|
|
|
|
[RUNNING] `rustc --crate-name foo src[/]main.rs --crate-type bin \
|
|
|
|
--emit=dep-info,link[..]")
|
|
|
|
// bench
|
2018-03-19 17:20:54 +00:00
|
|
|
.with_stderr_does_not_contain("\
|
2018-03-15 15:20:15 +00:00
|
|
|
[RUNNING] `rustc --crate-name foo src[/]main.rs --emit=dep-info,link \
|
|
|
|
-C opt-level=3 --test [..]")
|
|
|
|
// unit test
|
2018-03-19 17:20:54 +00:00
|
|
|
.with_stderr_does_not_contain("\
|
2018-03-15 15:20:15 +00:00
|
|
|
[RUNNING] `rustc --crate-name foo src[/]main.rs --emit=dep-info,link \
|
|
|
|
-C debuginfo=2 --test [..]"),
|
|
|
|
);
|
2018-03-19 17:20:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn targets_selected_all() {
|
|
|
|
let p = project("foo")
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
authors = []
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
2018-03-15 15:20:15 +00:00
|
|
|
assert_that(
|
2018-03-19 17:20:54 +00:00
|
|
|
p.cargo("build").arg("-v").arg("--all-targets"),
|
2018-03-15 15:20:15 +00:00
|
|
|
execs().with_status(0)
|
|
|
|
// bin
|
|
|
|
.with_stderr_contains("\
|
|
|
|
[RUNNING] `rustc --crate-name foo src[/]main.rs --crate-type bin \
|
|
|
|
--emit=dep-info,link[..]")
|
|
|
|
// bench
|
2018-03-19 17:20:54 +00:00
|
|
|
.with_stderr_contains("\
|
2018-03-15 15:20:15 +00:00
|
|
|
[RUNNING] `rustc --crate-name foo src[/]main.rs --emit=dep-info,link \
|
|
|
|
-C opt-level=3 --test [..]")
|
|
|
|
// unit test
|
2018-03-19 17:20:54 +00:00
|
|
|
.with_stderr_contains("\
|
2018-03-15 15:20:15 +00:00
|
|
|
[RUNNING] `rustc --crate-name foo src[/]main.rs --emit=dep-info,link \
|
|
|
|
-C debuginfo=2 --test [..]"),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-10-30 21:42:47 +00:00
|
|
|
#[test]
|
|
|
|
fn all_targets_no_lib() {
|
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-10-30 21:42:47 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-10-30 21:42:47 +00:00
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build").arg("-v").arg("--all-targets"),
|
2017-10-30 21:42:47 +00:00
|
|
|
execs().with_status(0)
|
|
|
|
// bin
|
|
|
|
.with_stderr_contains("\
|
|
|
|
[RUNNING] `rustc --crate-name foo src[/]main.rs --crate-type bin \
|
|
|
|
--emit=dep-info,link[..]")
|
|
|
|
// bench
|
|
|
|
.with_stderr_contains("\
|
|
|
|
[RUNNING] `rustc --crate-name foo src[/]main.rs --emit=dep-info,link \
|
|
|
|
-C opt-level=3 --test [..]")
|
|
|
|
// unit test
|
|
|
|
.with_stderr_contains("\
|
|
|
|
[RUNNING] `rustc --crate-name foo src[/]main.rs --emit=dep-info,link \
|
2018-03-14 15:17:44 +00:00
|
|
|
-C debuginfo=2 --test [..]"),
|
|
|
|
);
|
2017-10-30 21:42:47 +00:00
|
|
|
}
|
2017-12-09 14:24:08 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn no_linkable_target() {
|
|
|
|
// Issue 3169. This is currently not an error as per discussion in PR #4797
|
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-12-09 14:24:08 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
authors = []
|
|
|
|
[dependencies]
|
|
|
|
the_lib = { path = "the_lib" }
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-12-09 14:24:08 +00:00
|
|
|
.file("src/main.rs", "fn main() {}")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"the_lib/Cargo.toml",
|
|
|
|
r#"
|
2017-12-09 14:24:08 +00:00
|
|
|
[package]
|
|
|
|
name = "the_lib"
|
|
|
|
version = "0.1.0"
|
|
|
|
[lib]
|
|
|
|
name = "the_lib"
|
|
|
|
crate-type = ["staticlib"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-12-09 14:24:08 +00:00
|
|
|
.file("the_lib/src/lib.rs", "pub fn foo() {}")
|
|
|
|
.build();
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build"),
|
|
|
|
execs().with_status(0).with_stderr_contains(
|
|
|
|
"\
|
|
|
|
[WARNING] The package `the_lib` provides no linkable [..] \
|
|
|
|
while compiling `foo`. [..] in `the_lib`'s Cargo.toml. [..]",
|
|
|
|
),
|
|
|
|
);
|
2017-12-09 14:24:08 +00:00
|
|
|
}
|
2018-02-15 15:01:36 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn avoid_dev_deps() {
|
|
|
|
Package::new("foo", "1.0.0").publish();
|
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2018-02-15 15:01:36 +00:00
|
|
|
[package]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.1.0"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dev-dependencies]
|
|
|
|
baz = "1.0.0"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2018-02-15 15:01:36 +00:00
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
|
|
|
|
2018-03-15 15:17:00 +00:00
|
|
|
assert_that(p.cargo("build"), execs().with_status(101));
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build")
|
|
|
|
.masquerade_as_nightly_cargo()
|
|
|
|
.arg("-Zavoid-dev-deps"),
|
|
|
|
execs().with_status(0),
|
|
|
|
);
|
2018-02-15 15:01:36 +00:00
|
|
|
}
|
2018-03-09 08:03:36 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn invalid_jobs() {
|
|
|
|
let p = project("foo")
|
|
|
|
.file("Cargo.toml", &basic_bin_manifest("foo"))
|
|
|
|
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]))
|
|
|
|
.build();
|
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build").arg("--jobs").arg("over9000"),
|
2018-03-14 15:43:41 +00:00
|
|
|
execs()
|
|
|
|
.with_status(1)
|
|
|
|
.with_stderr("error: Invalid value: could not parse `over9000` as a number"),
|
2018-03-14 15:17:44 +00:00
|
|
|
);
|
2018-03-09 08:03:36 +00:00
|
|
|
}
|