-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix(env): cargo:rerun-if-env-changed doesn't work with env configuration #14058
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,165 @@ use cargo_test_support::project; | |
use cargo_test_support::sleep_ms; | ||
use cargo_test_support::str; | ||
|
||
#[cargo_test] | ||
fn rerun_if_env_changes_config() { | ||
let p = project() | ||
.file("Cargo.toml", &basic_manifest("foo", "0.1.0")) | ||
.file("src/main.rs", "fn main() {}") | ||
.file( | ||
".cargo/config.toml", | ||
r#" | ||
[env] | ||
FOO = "good" | ||
"#, | ||
) | ||
.file( | ||
"build.rs", | ||
r#" | ||
fn main() { | ||
println!("cargo:rerun-if-env-changed=FOO"); | ||
if let Ok(foo) = std::env::var("FOO") { | ||
assert!(&foo != "bad"); | ||
} | ||
} | ||
"#, | ||
) | ||
.build(); | ||
|
||
p.cargo("check") | ||
.with_stderr_data(str![[r#" | ||
[COMPILING] foo v0.1.0 ([ROOT]/foo) | ||
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s | ||
|
||
"#]]) | ||
.run(); | ||
|
||
p.change_file( | ||
".cargo/config.toml", | ||
r#" | ||
[env] | ||
FOO = "bad" | ||
"#, | ||
); | ||
|
||
p.cargo("check") | ||
.with_stderr_data(str![[r#" | ||
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s | ||
|
||
"#]]) | ||
.run(); | ||
|
||
p.cargo("clean").run(); | ||
p.cargo("check") | ||
.with_status(101) | ||
.with_stderr_data( | ||
"\ | ||
[COMPILING] foo v0.1.0 ([ROOT]/foo) | ||
[ERROR] failed to run custom build command for `foo v0.1.0 ([..])` | ||
...", | ||
) | ||
.run(); | ||
} | ||
|
||
#[cfg(windows)] | ||
#[cargo_test] | ||
fn rerun_if_env_changes_config_windows() { | ||
let p = project() | ||
.file("Cargo.toml", &basic_manifest("foo", "0.1.0")) | ||
.file("src/main.rs", "fn main() {}") | ||
.file( | ||
".cargo/config.toml", | ||
r#" | ||
[env] | ||
FOO = "good" | ||
"#, | ||
) | ||
.file( | ||
"build.rs", | ||
r#" | ||
fn main() { | ||
println!("cargo:rerun-if-env-changed=Foo"); | ||
if let Ok(foo) = std::env::var("Foo") { | ||
assert!(&foo != "bad"); | ||
} | ||
} | ||
"#, | ||
) | ||
.build(); | ||
|
||
p.cargo("check") | ||
.with_stderr_data(str![[r#" | ||
[COMPILING] foo v0.1.0 ([ROOT]/foo) | ||
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s | ||
|
||
"#]]) | ||
.run(); | ||
|
||
p.change_file( | ||
".cargo/config.toml", | ||
r#" | ||
[env] | ||
FOO = "bad" | ||
"#, | ||
); | ||
|
||
p.cargo("check") | ||
.with_stderr_data(str![[r#" | ||
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s | ||
|
||
"#]]) | ||
.run(); | ||
|
||
p.cargo("clean").run(); | ||
p.cargo("check") | ||
.with_status(101) | ||
.with_stderr_data( | ||
"\ | ||
[COMPILING] foo v0.1.0 ([ROOT]/foo) | ||
[ERROR] failed to run custom build command for `foo v0.1.0 ([..])` | ||
...", | ||
) | ||
.run(); | ||
} | ||
|
||
#[cargo_test] | ||
fn rerun_if_env_changes_cargo_set_env_variable() { | ||
let p = project() | ||
.file("src/main.rs", "fn main() {}") | ||
.file( | ||
"build.rs", | ||
r#" | ||
fn main() { | ||
println!("cargo:rerun-if-env-changed=OUT_DIR"); | ||
} | ||
"#, | ||
) | ||
.build(); | ||
|
||
p.cargo("check") | ||
.with_stderr_data(str![[r#" | ||
[COMPILING] foo v0.0.1 ([ROOT]/foo) | ||
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s | ||
|
||
"#]]) | ||
.run(); | ||
|
||
p.change_file( | ||
".cargo/config.toml", | ||
r#" | ||
[env] | ||
OUT_DIR = "somedir" | ||
"#, | ||
); | ||
Comment on lines
+133
to
+139
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The intention of this test is for detecting changes made by cargo, and not the user. Us manually setting one runs counter to that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not too sure what the concern is. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Setting There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, that. The intent of my comment was to say that we should not test this with |
||
|
||
p.cargo("check") | ||
.with_stderr_data(str![[r#" | ||
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s | ||
|
||
"#]]) | ||
.run(); | ||
} | ||
|
||
#[cargo_test] | ||
fn rerun_if_env_changes() { | ||
let p = project() | ||
|
Uh oh!
There was an error while loading. Please reload this page.