Skip to content

Commit 41900c4

Browse files
authored
Delegate to ./pants when [DEFAULT] delegate_bootstrap=true. (#75)
The choice of config section for the `pants.toml` config file was made to have something that won't choke the regular Pants configuration verification and also not show up in any online help. Closes #33 When `delegate_bootstrap=true` in the `[DEFAULT]` section of `pants.toml` _and_ `pants_version` is unspecified (`PANTS_SHA` is also considered here) bootstrapping Pants is delegated to `./pants`.
1 parent 4f06c9d commit 41900c4

File tree

4 files changed

+66
-4
lines changed

4 files changed

+66
-4
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ jobs:
5252
uses: actions/cache@v3
5353
with:
5454
path: ${{ env.SCIE_PANTS_DEV_CACHE }}
55-
key: ${{ runner.os }}-${{ runner.arch }}-scie-pants-v1
55+
key: ${{ runner.os }}-${{ runner.arch }}-scie-pants-v2
5656
- name: Build, Package & Integration Tests
5757
if: ${{ matrix.os == 'macOS-11-ARM64' }}
5858
run: |

package/src/main.rs

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,12 @@ fn test(
797797
tools_pex_mismatch_warn: bool,
798798
) -> ExitResult {
799799
build_step!("Running smoke tests");
800+
log!(
801+
Color::Yellow,
802+
"Disabling pants rc files for the smoke tests."
803+
);
804+
env::set_var("PANTS_PANTSRC", "False");
805+
800806
// Max Python supported is 3.9 and only Linux x86_64 and macOS aarch64 and x86_64 wheels were
801807
// released.
802808
if matches!(
@@ -1019,7 +1025,7 @@ index 81e3bd7..4236f4b 100755
10191025
10201026
function activate_venv() {
10211027
diff --git a/pants b/pants
1022-
index b422eff..df13536 100755
1028+
index b422eff..16f0cf5 100755
10231029
--- a/pants
10241030
+++ b/pants
10251031
@@ -70,4 +70,5 @@ function exec_pants_bare() {
@@ -1028,6 +1034,17 @@ index b422eff..df13536 100755
10281034
10291035
+echo >&2 "Pants from sources argv: $@."
10301036
exec_pants_bare "$@"
1037+
diff --git a/pants.toml b/pants.toml
1038+
index ab5cba1..8432bb2 100644
1039+
--- a/pants.toml
1040+
+++ b/pants.toml
1041+
@@ -1,3 +1,6 @@
1042+
+[DEFAULT]
1043+
+delegate_bootstrap = true
1044+
+
1045+
[GLOBAL]
1046+
print_stacktrace = true
1047+
10311048
diff --git a/src/python/pants/VERSION b/src/python/pants/VERSION
10321049
index b70ae75..271706a 100644
10331050
--- a/src/python/pants/VERSION
@@ -1113,6 +1130,28 @@ index b70ae75..271706a 100644
11131130
.current_dir(user_repo_dir),
11141131
"The pants_from_sources mode is working.",
11151132
)?;
1133+
1134+
integration_test!("Verify delegating to `./pants`.");
1135+
let result = execute(
1136+
Command::new(scie_pants_scie)
1137+
.arg("-V")
1138+
.env("SCIE_PANTS_TEST_MODE", "delegate_bootstrap mode")
1139+
.current_dir(pants_2_14_1_clone_dir)
1140+
.stderr(Stdio::piped()),
1141+
)?;
1142+
let stderr = String::from_utf8(result.stderr).map_err(|e| {
1143+
Code::FAILURE.with_message(format!("Failed to decode Pants stderr: {e}"))
1144+
})?;
1145+
let expected_message = "The delegate_bootstrap mode is working.";
1146+
assert!(
1147+
stderr.contains(expected_message),
1148+
"STDERR did not contain '{expected_message}':\n{stderr}"
1149+
);
1150+
let expected_argv_message = "Pants from sources argv: -V.";
1151+
assert!(
1152+
stderr.contains(expected_argv_message),
1153+
"STDERR did not contain '{expected_argv_message}':\n{stderr}"
1154+
);
11161155
}
11171156

11181157
// Max Python supported is 3.8 and only Linux and macOS x86_64 wheels were released.

src/config.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,19 @@ pub(crate) struct DebugPy {
2020
pub(crate) version: Option<String>,
2121
}
2222

23+
#[derive(Default, Deserialize)]
24+
pub(crate) struct Default {
25+
pub(crate) delegate_bootstrap: Option<bool>,
26+
}
27+
2328
#[derive(Deserialize)]
2429
pub(crate) struct Config {
2530
#[serde(default, rename = "GLOBAL")]
2631
pub(crate) global: Global,
2732
#[serde(default)]
2833
pub(crate) debugpy: DebugPy,
34+
#[serde(default, rename = "DEFAULT")]
35+
pub(crate) default: Default,
2936
}
3037

3138
pub(crate) struct PantsConfig {
@@ -45,6 +52,10 @@ impl PantsConfig {
4552
pub(crate) fn debugpy_version(&self) -> Option<String> {
4653
self.config.debugpy.version.clone()
4754
}
55+
56+
pub(crate) fn delegate_bootstrap(&self) -> bool {
57+
self.config.default.delegate_bootstrap.unwrap_or_default()
58+
}
4859
}
4960

5061
impl PantsConfig {

src/main.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,16 @@ fn find_pants_installation() -> Result<Option<PantsConfig>> {
9898
#[time("debug", "scie-pants::{}")]
9999
fn get_pants_process() -> Result<Process> {
100100
let pants_installation = find_pants_installation()?;
101-
let (build_root, configured_pants_version, debugpy_version) =
101+
let (build_root, configured_pants_version, debugpy_version, delegate_bootstrap) =
102102
if let Some(ref pants_config) = pants_installation {
103103
(
104104
Some(pants_config.build_root().to_path_buf()),
105105
pants_config.package_version(),
106106
pants_config.debugpy_version(),
107+
pants_config.delegate_bootstrap(),
107108
)
108109
} else {
109-
(None, None, None)
110+
(None, None, None, false)
110111
};
111112

112113
let env_pants_sha = env_version("PANTS_SHA")?;
@@ -126,6 +127,17 @@ fn get_pants_process() -> Result<Process> {
126127
None
127128
};
128129

130+
if delegate_bootstrap && pants_version == None {
131+
let exe = build_root
132+
.expect("Failed to locate build root")
133+
.join("pants")
134+
.into_os_string();
135+
return Ok(Process {
136+
exe,
137+
..Default::default()
138+
});
139+
}
140+
129141
info!("Found Pants build root at {build_root:?}");
130142
info!("The required Pants version is {pants_version:?}");
131143

0 commit comments

Comments
 (0)