Skip to content

Commit 3fdd677

Browse files
authored
Update scie-pants to scie-jump 0.11.1. (#199)
This pulls in a fix for handling of regex env var removal when the ambient env contains non-utf8 entries. Out of the 4 ways Pants can be run, threeare still broken, but these breaks are inside Pants itself. Two breaks occur when using pantsd. There is one in the native client and one in the `PyNailgunClient`. Another occurs using `--no-pants` with the native client. For more about those issues, see: pantsbuild/pants#19199 Fixes #198
1 parent 921034e commit 3fdd677

File tree

7 files changed

+100
-10
lines changed

7 files changed

+100
-10
lines changed

CHANGES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Release Notes
22

3+
## 0.8.2
4+
5+
This release fixes handling of environment variables when non-utf8 variables are present in the
6+
ambient environment.
7+
38
## 0.8.1
49

510
This release adjusts the `PANTS_SHA` and `PANTS_VERSION` environment variables to be ignored, if

Cargo.lock

Lines changed: 8 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ members = [
66
[package]
77
name = "scie-pants"
88
description = "Protects your Pants from the elements."
9-
version = "0.8.1"
9+
version = "0.8.2"
1010
edition = "2021"
1111
authors = [
1212
"John Sirois <[email protected]>",

package/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ lazy_static = "1.4"
1717
log = { workspace = true }
1818
once_cell = "1.17"
1919
pretty_env_logger = "0.5"
20+
regex = "1.8"
2021
sha2 = "0.10"
2122
tempfile = { workspace = true }
2223
termcolor = "1.2"

package/pbt.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Python Build Tool: A BusyBox that provides `python`, `pip`, `pex`, `pex3` and `p
88
version = "0.7.0"
99

1010
[lift.scie-jump]
11-
version = "0.11.0"
11+
version = "0.11.1"
1212

1313
[[lift.interpreters]]
1414
id = "cpython"

package/scie-pants.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ version = "0.7.0"
1212
lazy_argv1 = "{scie.env.PANTS_BOOTSTRAP_URLS={scie.lift}}"
1313

1414
[lift.scie-jump]
15-
version = "0.11.0"
15+
version = "0.11.1"
1616

1717
[[lift.interpreters]]
1818
id = "cpython38"

package/src/test.rs

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
// Licensed under the Apache License, Version 2.0 (see LICENSE).
33

44
use std::env;
5+
use std::ffi::OsString;
56
use std::io::Write;
67
use std::path::{Path, PathBuf};
78
use std::process::{Command, Output, Stdio};
89

910
use anyhow::{Context, Result};
11+
use regex::Regex;
1012
use tempfile::TempDir;
1113
use termcolor::{Color, WriteColor};
1214

@@ -130,6 +132,9 @@ pub(crate) fn run_integration_tests(
130132
test_caching_issue_129(scie_pants_scie);
131133
test_custom_pants_toml_issue_153(scie_pants_scie);
132134
test_pants_native_client_perms_issue_182(scie_pants_scie);
135+
136+
#[cfg(unix)]
137+
test_non_utf8_env_vars_issue_198(scie_pants_scie);
133138
}
134139

135140
// Max Python supported is 3.8 and only Linux and macOS x86_64 wheels were released.
@@ -888,3 +893,81 @@ fn test_pants_native_client_perms_issue_182(scie_pants_scie: &Path) {
888893
decode_output(output.unwrap().stdout).unwrap().trim()
889894
);
890895
}
896+
897+
#[cfg(unix)]
898+
fn test_non_utf8_env_vars_issue_198(scie_pants_scie: &Path) {
899+
integration_test!(
900+
"Verifying scie-pants is robust to environments with non-utf8 env vars present ({issue})",
901+
issue = issue_link(198)
902+
);
903+
904+
let tmpdir = create_tempdir().unwrap();
905+
906+
let pants_release = "2.17.0a1";
907+
let pants_toml_content = format!(
908+
r#"
909+
[GLOBAL]
910+
pants_version = "{pants_release}"
911+
"#
912+
);
913+
let pants_toml = tmpdir.path().join("pants.toml");
914+
write_file(&pants_toml, false, pants_toml_content).unwrap();
915+
916+
use std::os::unix::ffi::OsStringExt;
917+
env::set_var("FOO", OsString::from_vec(vec![b'B', 0xa5, b'R']));
918+
919+
let err = execute(
920+
Command::new(scie_pants_scie)
921+
.arg("-V")
922+
.env("RUST_LOG", "trace")
923+
.stderr(Stdio::piped())
924+
.current_dir(&tmpdir),
925+
)
926+
.unwrap_err();
927+
let error_text = err.to_string();
928+
// N.B.: This is a very hacky way to confirm the `scie-jump` is done processing env vars and has
929+
// exec'd the `scie-pants` native client; which then proceeds to choke on env vars in the same
930+
// way scie-jump <= 0.11.0 did using `env::vars()`.
931+
assert!(Regex::new(concat!(
932+
r#"exe: ".*/bindings/venvs/2\.17\.0a1/lib/python3\.9/"#,
933+
r#"site-packages/pants/bin/native_client""#
934+
))
935+
.unwrap()
936+
.find(&error_text)
937+
.is_some());
938+
assert!(error_text.contains("[DEBUG TimerFinished] jump::prepare_boot(), Elapsed="));
939+
assert!(error_text
940+
.contains(r#"panicked at 'called `Result::unwrap()` on an `Err` value: "B\xA5R"'"#));
941+
942+
// The error path we test below requires flowing through the pantsd path via PyNailgunClient.
943+
let err = execute(
944+
Command::new(scie_pants_scie)
945+
.arg("--pantsd")
946+
.arg("-V")
947+
.env("PANTS_NO_NATIVE_CLIENT", "1")
948+
.stderr(Stdio::piped())
949+
.current_dir(&tmpdir),
950+
)
951+
.unwrap_err();
952+
// Here we're asking the native client to exit very early before it processed `env::vars()`; so
953+
// the execution makes it into Python code that calls
954+
// `PyNailgunClient(...).execute(command, args, modified_env)`. That's Rust code implementing a
955+
// Python extension object that also wrongly assumes utf8 when converting env vars.
956+
assert!(err.to_string().contains(concat!(
957+
r#"UnicodeEncodeError: 'utf-8' codec can't encode character '\udca5' in "#,
958+
"position 1: surrogates not allowed"
959+
)));
960+
961+
let output = execute(
962+
Command::new(scie_pants_scie)
963+
.arg("--no-pantsd")
964+
.arg("-V")
965+
.env("PANTS_NO_NATIVE_CLIENT", "1")
966+
.stdout(Stdio::piped())
967+
.current_dir(&tmpdir),
968+
)
969+
.unwrap();
970+
assert_eq!(pants_release, decode_output(output.stdout).unwrap().trim());
971+
972+
env::remove_var("FOO");
973+
}

0 commit comments

Comments
 (0)