-
Notifications
You must be signed in to change notification settings - Fork 402
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
Do not use test launcher when not needed #960
Merged
hlopko
merged 3 commits into
bazelbuild:main
from
hlopko:stop_using_test_launcher_when_possible
Sep 30, 2021
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
load( | ||
"//rust:rust.bzl", | ||
"rust_binary", | ||
"rust_test", | ||
) | ||
|
||
rust_binary( | ||
name = "hello-world", | ||
srcs = ["src/main.rs"], | ||
edition = "2018", | ||
) | ||
|
||
filegroup( | ||
name = "hello_world_main", | ||
srcs = ["src/main.rs"], | ||
) | ||
|
||
rust_test( | ||
name = "test", | ||
srcs = ["tests/run.rs"], | ||
data = [ | ||
":hello-world", | ||
":hello_world_main", | ||
], | ||
edition = "2018", | ||
env = { | ||
"FERRIS_SAYS": "Hello fellow Rustaceans!", | ||
"HELLO_WORLD_BIN_ROOTPATH": "$(rootpath :hello-world)", | ||
"HELLO_WORLD_SRC_EXECPATH": "$(execpath :hello_world_main)", | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
fn main() { | ||
println!("Hello world"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#[test] | ||
fn run() { | ||
let path = env!("CARGO_BIN_EXE_hello-world"); | ||
let output = std::process::Command::new(path) | ||
.output() | ||
.expect("Failed to run process"); | ||
assert_eq!(&b"Hello world\n"[..], output.stdout.as_slice()); | ||
|
||
// Test the `env` attribute of `rust_test` at run time | ||
assert_eq!( | ||
std::env::var("FERRIS_SAYS").unwrap(), | ||
"Hello fellow Rustaceans!" | ||
); | ||
|
||
// Test the behavior of `rootpath` and that a binary can be found relative to current_dir | ||
let hello_world_bin = | ||
std::path::PathBuf::from(std::env::var_os("HELLO_WORLD_BIN_ROOTPATH").unwrap()); | ||
|
||
assert_eq!( | ||
hello_world_bin.as_path(), | ||
std::path::Path::new(if std::env::consts::OS == "windows" { | ||
"test/test_env_launcher/hello-world.exe" | ||
} else { | ||
"test/test_env_launcher/hello-world" | ||
}) | ||
); | ||
assert!(!hello_world_bin.is_absolute()); | ||
assert!(hello_world_bin.exists()); | ||
|
||
// Ensure `execpath` expanded variables map to real files and have absolute paths | ||
let hello_world_src = | ||
std::path::PathBuf::from(std::env::var("HELLO_WORLD_SRC_EXECPATH").unwrap()); | ||
assert!(hello_world_src.is_absolute()); | ||
assert!(hello_world_src.exists()); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm, on second though, I feel like this is something that should be an incompatibility flag. I don't think it's too difficult to have users join
pwd
and their value themselves. I'm definitely interested in continuing to useexecpath
but also want to have debugger support. Mayberules_rust
can provide some utility crate for expandingexecpath
into absolute paths? Not saying that utility has to be done in this PR just trying to figure out if there's a path to completely abolish the launcher and maintain the ability to use absolute paths.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you're saying that you support my followup PR to remove the launcher alltogether using an incompatible flag, and that this PR is good to go.
Or did you mean that this PR needs an incompatible flag?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking that there'd be no changes in behavior outside that flag. So unless it's flipped you'd still use the launcher. But perhaps that's more restrictive than necessary. But I wonder if anyone would run into issues in this change or be confused why two seemingly similar tests might behave differently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is my question and I think it does but hard to really make up my mind since my attention is currently divided 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My experience is that people encounter issues and confusion when using the launcher. Except really unlikely situations I don't think we would be breaking people by not using the launcher. Of course if we stop producing absolute paths that can really break people and we should guard it with an incompatible change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you think this PR warrants the incompatible flag, I d make it a different one from the one that removes absolute paths, since they both have different fallout impact and migration stories.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can accept this as a middle ground but hope that we can work quickly together to get a feature flag up. As mentioned in another comment. I think the solution for absolute paths would actually be in Bazel proper and not the rules here.