Skip to content
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

fix(test_env): export canonical CARGO_BIN_EXE env variable #842

Merged
merged 4 commits into from
Aug 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ default_windows_targets: &default_windows_targets
- "--" # Allows negative patterns; hack for https://github.com/bazelbuild/continuous-integration/pull/245
- "//..."
- "-//bindgen/..."
- "-//test/test_env/..."
- "-//test/proto/..."
- "-//tools/rust_analyzer/..."
- "-//test/rustfmt/..."
Expand Down
3 changes: 3 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ build:rustfmt --output_groups=+rustfmt_checks
# Enable clippy for all targets in the workspace
build:clippy --aspects=//rust:defs.bzl%rust_clippy_aspect
build:clippy --output_groups=+clippy_checks

# https://bazel.googlesource.com/bazel/+/master/site/docs/windows.md#enable-symlink-support
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while doc suggests to enable runfiles (build --enable_runfiles), enabling it makes process_wrapper/std_err test fails somehow.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the failure you see when enabling this?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran some tests and it seems to test no problem for me. Though I used

Suggested change
# https://bazel.googlesource.com/bazel/+/master/site/docs/windows.md#enable-symlink-support
# https://bazel.googlesource.com/bazel/+/master/site/docs/windows.md#enable-symlink-support
startup --windows_enable_symlinks

Per the recommendation from https://docs.bazel.build/versions/main/windows.html

Does that help here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

weirdly I tried again and couldn't repro the error. maybe one off from the system I used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these test failures are by enabling runfiles, which is outside of test_env/.

(03:37:10) FAIL: //test/process_wrapper:stdout_test (see C:/b/h3ziskxk/execroot/rules_rust/bazel-out/x64_windows-fastbuild/testlogs/test/process_wrapper/stdout_test/test_attempts/attempt_1.log)

startup --windows_enable_symlinks
4 changes: 3 additions & 1 deletion rust/private/rustc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,9 @@ def construct_arguments(
if rust_common.crate_info in data:
dep_crate_info = data[rust_common.crate_info]
if dep_crate_info.type == "bin":
env["CARGO_BIN_EXE_" + dep_crate_info.output.basename] = dep_crate_info.output.short_path
# Trying to make CARGO_BIN_EXE_{} canonical across platform by strip out extension if exists
env_basename = dep_crate_info.output.basename[:-(1 + len(dep_crate_info.output.extension))] if len(dep_crate_info.output.extension) > 0 else dep_crate_info.output.basename
env["CARGO_BIN_EXE_" + env_basename] = dep_crate_info.output.short_path

# Update environment with user provided variables.
env.update(expand_dict_value_locations(
Expand Down
7 changes: 6 additions & 1 deletion test/test_env/tests/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,14 @@ fn run() {
// 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("test/test_env/hello-world"),
std::path::Path::new(if std::env::consts::OS == "windows" {
"test/test_env/hello-world.exe"
} else {
"test/test_env/hello-world"
})
);
assert!(!hello_world_bin.is_absolute());
assert!(hello_world_bin.exists());
Expand Down