Skip to content

Commit 721c2c1

Browse files
committed
bazel: Fix workspace/bzlmod detection
currently it assumes bzlmod if it sees a MODULE.bazel Signed-off-by: Ryan Northey <ryan@synca.io>
1 parent 8cc8c2f commit 721c2c1

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

crate_universe/src/cli/vendor.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,22 @@ fn bzlmod_tidy(bin: &Path, workspace_dir: &Path) -> anyhow::Result<ExitStatus> {
120120
Ok(status)
121121
}
122122

123+
/// Check if bzlmod is enabled in the workspace
124+
fn is_bzlmod_enabled(bin: &Path, workspace_dir: &Path) -> bool {
125+
let output = process::Command::new(bin)
126+
.current_dir(workspace_dir)
127+
.arg("info")
128+
.arg("starlark-semantics")
129+
.output();
130+
131+
match output {
132+
Ok(output) if output.status.success() => {
133+
!String::from_utf8_lossy(&output.stdout).contains("enable_bzlmod=false")
134+
}
135+
_ => true, // Assume enabled if we can't determine
136+
}
137+
}
138+
123139
/// Info about a Bazel workspace
124140
struct BazelInfo {
125141
/// The version of Bazel being used
@@ -313,7 +329,7 @@ pub fn vendor(opt: VendorOptions) -> anyhow::Result<()> {
313329
// Optionally perform bazel mod tidy to update the MODULE.bazel file
314330
if bazel_info.release >= semver::Version::new(7, 0, 0) {
315331
let module_bazel = opt.workspace_dir.join("MODULE.bazel");
316-
if module_bazel.exists() {
332+
if module_bazel.exists() && is_bzlmod_enabled(&opt.bazel, &opt.workspace_dir) {
317333
bzlmod_tidy(&opt.bazel, &opt.workspace_dir)?;
318334
}
319335
}

0 commit comments

Comments
 (0)