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

Set _PANTS_OVERRIDE_VERSION when delegate_bootstrap has been overridden. #100

Merged
merged 2 commits into from
Feb 4, 2023
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
149 changes: 87 additions & 62 deletions package/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,7 @@ macro_rules! build_step {

macro_rules! integration_test {
($msg:expr $(,)?) => {
log!(Color::Magenta, ">> {}", $msg);
};
($msg:expr, $($arg:tt)*) => {
log!(Color::Magenta, ">> {}", format!($msg, $($arg)*));
log!(Color::Magenta, ">> {}", format!($msg));
};
}

Expand Down Expand Up @@ -1083,75 +1080,103 @@ index b70ae75..271706a 100644
rename(&venv_root_tmp.into_path(), &pants_2_14_1_venv_dir)?;
}

let test_pants_from_sources = |command: &mut Command, expected_message: &str| {
let result = execute(
command
.arg("-V")
.env("PANTS_VENV_DIR_PREFIX", &pants_2_14_1_venv_dir)
.stderr(Stdio::piped()),
)?;
let stderr = String::from_utf8(result.stderr).map_err(|e| {
Code::FAILURE.with_message(format!("Failed to decode Pants stderr: {e}"))
let decode_output = |output: Vec<u8>| {
let res = String::from_utf8(output).map_err(|e| {
Code::FAILURE.with_message(format!("Failed to decode Pants output: {e}"))
})?;
assert!(
stderr.contains(expected_message),
"STDERR did not contain '{expected_message}':\n{stderr}"
);
let expected_argv_message = "Pants from sources argv: --no-verify-config -V.";
assert!(
stderr.contains(expected_argv_message),
"STDERR did not contain '{expected_argv_message}':\n{stderr}"
);
Ok(())
Ok(res)
};
let test_pants_from_sources = |command: &mut Command, expected_messages: Vec<&str>| {
let result = execute(command.arg("-V").stderr(Stdio::piped()))?;
let stderr = decode_output(result.stderr.clone())?;
for expected_message in expected_messages {
assert!(
stderr.contains(expected_message),
"STDERR did not contain '{expected_message}':\n{stderr}"
);
}
Ok(result)
};

test_pants_from_sources(
Command::new(scie_pants_scie)
.env("PANTS_SOURCE", &pants_2_14_1_clone_dir)
.env("SCIE_PANTS_TEST_MODE", "PANTS_SOURCE mode"),
"The PANTS_SOURCE mode is working.",
.env("SCIE_PANTS_TEST_MODE", "PANTS_SOURCE mode")
.env("PANTS_VENV_DIR_PREFIX", &pants_2_14_1_venv_dir),
vec![
"The PANTS_SOURCE mode is working.",
"Pants from sources argv: --no-verify-config -V.",
],
)?;

integration_test!("Verify pants_from_sources mode.");
let side_by_side_root = create_tempdir()?;
let pants_dir = side_by_side_root.path().join("pants");
softlink(&pants_2_14_1_clone_dir, &pants_dir)?;
let user_repo_dir = side_by_side_root.path().join("user-repo");
ensure_directory(&user_repo_dir, true)?;
touch(user_repo_dir.join("pants.toml").as_path())?;
touch(user_repo_dir.join("BUILD_ROOT").as_path())?;

let pants_from_sources = side_by_side_root.path().join("pants_from_sources");
softlink(scie_pants_scie, &pants_from_sources)?;

test_pants_from_sources(
Command::new(pants_from_sources)
.env("SCIE_PANTS_TEST_MODE", "pants_from_sources mode")
.current_dir(user_repo_dir),
"The pants_from_sources mode is working.",
)?;
{
let side_by_side_root = create_tempdir()?;
let pants_dir = side_by_side_root.path().join("pants");
softlink(&pants_2_14_1_clone_dir, &pants_dir)?;
let user_repo_dir = side_by_side_root.path().join("user-repo");
ensure_directory(&user_repo_dir, true)?;
touch(user_repo_dir.join("pants.toml").as_path())?;
touch(user_repo_dir.join("BUILD_ROOT").as_path())?;

let pants_from_sources = side_by_side_root.path().join("pants_from_sources");
softlink(scie_pants_scie, &pants_from_sources)?;

test_pants_from_sources(
Command::new(pants_from_sources)
.env("SCIE_PANTS_TEST_MODE", "pants_from_sources mode")
.env("PANTS_VENV_DIR_PREFIX", &pants_2_14_1_venv_dir)
.current_dir(user_repo_dir),
vec![
"The pants_from_sources mode is working.",
"Pants from sources argv: --no-verify-config -V.",
],
)?;
}

integration_test!("Verify delegating to `./pants`.");
let result = execute(
Command::new(scie_pants_scie)
.arg("-V")
.env("SCIE_PANTS_TEST_MODE", "delegate_bootstrap mode")
.current_dir(pants_2_14_1_clone_dir)
.stderr(Stdio::piped()),
)?;
let stderr = String::from_utf8(result.stderr).map_err(|e| {
Code::FAILURE.with_message(format!("Failed to decode Pants stderr: {e}"))
})?;
let expected_message = "The delegate_bootstrap mode is working.";
assert!(
stderr.contains(expected_message),
"STDERR did not contain '{expected_message}':\n{stderr}"
);
let expected_argv_message = "Pants from sources argv: -V.";
assert!(
stderr.contains(expected_argv_message),
"STDERR did not contain '{expected_argv_message}':\n{stderr}"
);
{
test_pants_from_sources(
Command::new(scie_pants_scie)
.env("SCIE_PANTS_TEST_MODE", "delegate_bootstrap mode")
.current_dir(&pants_2_14_1_clone_dir),
vec![
"The delegate_bootstrap mode is working.",
"Pants from sources argv: -V.",
],
)?;
}

let pants_release = "2.16.0.dev5";
integration_test!("Verify usage of a Pants {pants_release} on the pants repo.");
{
let result = test_pants_from_sources(
Command::new(scie_pants_scie)
.env("PANTS_VERSION", pants_release)
.env(
"PANTS_BACKEND_PACKAGES",
"-[\
'internal_plugins.test_lockfile_fixtures',\
'pants.backend.explorer',\
]",
)
.current_dir(&pants_2_14_1_clone_dir)
.stdout(Stdio::piped()),
vec![],
)?;
let expected_message = pants_release;
let stdout = decode_output(result.stdout)?;
assert!(
stdout.contains(expected_message),
"STDOUT did not contain '{expected_message}':\n{stdout}"
);
let unexpected_message = "Pants from sources argv";
let stderr = decode_output(result.stderr)?;
assert!(
!stderr.contains(unexpected_message),
"STDERR unexpectedly contained '{unexpected_message}':\n{stderr}"
);
}
}

// Max Python supported is 3.8 and only Linux and macOS x86_64 wheels were released.
Expand Down
5 changes: 4 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ fn get_pants_process() -> Result<Process> {
None
};

if delegate_bootstrap && pants_version == None {
if delegate_bootstrap && pants_version.is_none() {
let exe = build_root
.expect("Failed to locate build root")
.join("pants")
Expand Down Expand Up @@ -179,6 +179,9 @@ fn get_pants_process() -> Result<Process> {
));
}
if let Some(version) = pants_version {
if delegate_bootstrap {
env.push(("_PANTS_OVERRIDE_VERSION".into(), version.clone().into()));
}
env.push(("PANTS_VERSION".into(), version.into()));
} else {
// Ensure the install binding always re-runs when no Pants version is found so that the
Expand Down