Fix unit tests on Android (#10224)

# Description

* The path to the binaries for tests is slightly incorrect. It is
missing the build target when it is set with the `CARGO_BUILD_TARGET`
environment variable. For example, when `CARGO_BUILD_TARGET` is set to
`aarch64-linux-android`, the path to the `nu` binary is:

  `./target/aarch64-linux-android/debug/nu`

  rather than

  `./target/debug/nu`

This is common on Termux since the default target that rustc detects can
cause problems on some projects, such as [python's `cryptography`
package](https://github.com/pyca/cryptography/issues/7248).
  
This technically isn't a problem specific to Android, but is more likely
to happen on Android due to the latter.
* Additionally, the existing variable named `NUSHELL_CARGO_TARGET` is in
fact the profile, not the build target, so this was renamed to
`NUSHELL_CARGO_PROFILE`. This change is included because without the
rename, the build system would be using `CARGO_BUILD_TARGET` for the
build target and `NUSHELL_CARGO_TARGET` for the build profile, which is
confusing.
* `std path add` tests were missing `android` test

# User-Facing Changes

For those who would like to build nushell on Termux, the unit tests will
pass now.
This commit is contained in:
Skyler Hawthorne 2023-09-05 04:17:34 -04:00 committed by GitHub
parent eca9f461da
commit 9a4dad6ca1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 25 additions and 16 deletions

View file

@ -7,7 +7,7 @@ on:
name: continuous-integration name: continuous-integration
env: env:
NUSHELL_CARGO_TARGET: ci NUSHELL_CARGO_PROFILE: ci
NU_LOG_LEVEL: DEBUG NU_LOG_LEVEL: DEBUG
CLIPPY_OPTIONS: "-D warnings -D clippy::unwrap_used" CLIPPY_OPTIONS: "-D warnings -D clippy::unwrap_used"

View file

@ -27,7 +27,13 @@ def path_add [] {
assert equal (get_path) ["fooooo", "foo", "bar", "baz"] assert equal (get_path) ["fooooo", "foo", "bar", "baz"]
load-env {$path_name: []} load-env {$path_name: []}
let target_paths = {linux: "foo", windows: "bar", macos: "baz"}
let target_paths = {
linux: "foo",
windows: "bar",
macos: "baz",
android: "quux",
}
std path add $target_paths std path add $target_paths
assert equal (get_path) [($target_paths | get $nu.os-info.name)] assert equal (get_path) [($target_paths | get $nu.os-info.name)]

View file

@ -23,7 +23,7 @@ pub fn ensure_plugins_built() {
let cargo_path = env!("CARGO"); let cargo_path = env!("CARGO");
let mut arguments = vec!["build", "--package", "nu_plugin_*", "--quiet"]; let mut arguments = vec!["build", "--package", "nu_plugin_*", "--quiet"];
let profile = std::env::var("NUSHELL_CARGO_TARGET"); let profile = std::env::var("NUSHELL_CARGO_PROFILE");
if let Ok(profile) = &profile { if let Ok(profile) = &profile {
arguments.push("--profile"); arguments.push("--profile");
arguments.push(profile); arguments.push(profile);

View file

@ -233,18 +233,21 @@ pub fn root() -> PathBuf {
} }
pub fn binaries() -> PathBuf { pub fn binaries() -> PathBuf {
let mut build_type = "debug".to_string(); let build_target = std::env::var("CARGO_BUILD_TARGET").unwrap_or(String::new());
if !cfg!(debug_assertions) {
build_type = "release".to_string() let profile = if let Ok(env_profile) = std::env::var("NUSHELL_CARGO_PROFILE") {
} env_profile
if let Ok(target) = std::env::var("NUSHELL_CARGO_TARGET") { } else if cfg!(debug_assertions) {
build_type = target; "debug".into()
} } else {
"release".into()
};
std::env::var("CARGO_TARGET_DIR") std::env::var("CARGO_TARGET_DIR")
.ok() .map(PathBuf::from)
.map(|target_dir| PathBuf::from(target_dir).join(&build_type)) .unwrap_or_else(|_| root().join("target"))
.unwrap_or_else(|| root().join(format!("target/{}", &build_type))) .join(build_target)
.join(profile)
} }
pub fn fixtures() -> PathBuf { pub fn fixtures() -> PathBuf {

View file

@ -45,7 +45,7 @@ let start = (date now)
# Some of the internal tests rely on the exact cargo profile # Some of the internal tests rely on the exact cargo profile
# (This is somewhat criminal itself) # (This is somewhat criminal itself)
# but we have to signal to the tests that we use the `ci` `--profile` # but we have to signal to the tests that we use the `ci` `--profile`
$env.NUSHELL_CARGO_TARGET = "ci" $env.NUSHELL_CARGO_PROFILE = "ci"
# Manual gathering of coverage to catch invocation of the `nu` binary. # Manual gathering of coverage to catch invocation of the `nu` binary.
# This is relevant for tests using the `nu!` macro from `nu-test-support` # This is relevant for tests using the `nu!` macro from `nu-test-support`

View file

@ -17,7 +17,7 @@ REPO_ROOT=$(dirname $DIR)
# Some of the internal tests rely on the exact cargo profile # Some of the internal tests rely on the exact cargo profile
# (This is somewhat criminal itself) # (This is somewhat criminal itself)
# but we have to signal to the tests that we use the `ci` `--profile` # but we have to signal to the tests that we use the `ci` `--profile`
export NUSHELL_CARGO_TARGET=ci export NUSHELL_CARGO_PROFILE=ci
# Manual gathering of coverage to catch invocation of the `nu` binary. # Manual gathering of coverage to catch invocation of the `nu` binary.
# This is relevant for tests using the `nu!` macro from `nu-test-support` # This is relevant for tests using the `nu!` macro from `nu-test-support`

View file

@ -436,7 +436,7 @@ def compute-coverage [] {
# - https://github.com/andythigpen/nvim-coverage (probably needs some additional config) # - https://github.com/andythigpen/nvim-coverage (probably needs some additional config)
export def cov [] { export def cov [] {
let start = (date now) let start = (date now)
$env.NUSHELL_CARGO_TARGET = "ci" $env.NUSHELL_CARGO_PROFILE = "ci"
compute-coverage compute-coverage