Skip to content
Open
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
18 changes: 17 additions & 1 deletion crate_universe/src/cli/vendor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,22 @@ fn bzlmod_tidy(bin: &Path, workspace_dir: &Path) -> anyhow::Result<ExitStatus> {
Ok(status)
}

/// Check if bzlmod is enabled in the workspace
fn is_bzlmod_enabled(bin: &Path, workspace_dir: &Path) -> bool {
let output = process::Command::new(bin)
.current_dir(workspace_dir)
.arg("info")
.arg("starlark-semantics")
.output();

match output {
Ok(output) if output.status.success() => {
!String::from_utf8_lossy(&output.stdout).contains("enable_bzlmod=false")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When is this set? I don't see when I run this command in rules_rust which should be using bzlmod. Is there maybe something that can be checked in the crates_vendor rule that would more accurately detect this? If so that could be added via a new command line arg.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think its only available if you have --noenable_bzlmod set

}
_ => true, // Assume enabled if we can't determine
}
}

/// Info about a Bazel workspace
struct BazelInfo {
/// The version of Bazel being used
Expand Down Expand Up @@ -313,7 +329,7 @@ pub fn vendor(opt: VendorOptions) -> anyhow::Result<()> {
// Optionally perform bazel mod tidy to update the MODULE.bazel file
if bazel_info.release >= semver::Version::new(7, 0, 0) {
let module_bazel = opt.workspace_dir.join("MODULE.bazel");
if module_bazel.exists() {
if module_bazel.exists() && is_bzlmod_enabled(&opt.bazel, &opt.workspace_dir) {
bzlmod_tidy(&opt.bazel, &opt.workspace_dir)?;
}
}
Expand Down