Skip to content

Commit

Permalink
fix(test_env): export canonical CARGO_BIN_EXE env variable (#842)
Browse files Browse the repository at this point in the history
* fix(test_env): export canonical CARGO_BIN_EXE env variable

* test(test_env): update test cases

* build(bazelrc): enable symlink for windows platform

Co-authored-by: UebelAndre <github@uebelandre.com>
  • Loading branch information
kwonoj and UebelAndre committed Aug 20, 2021
1 parent c2a8afa commit 8ae83f0
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
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
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

0 comments on commit 8ae83f0

Please sign in to comment.