-
Notifications
You must be signed in to change notification settings - Fork 133
Add Bazel 8 compatibility with automatic bzlmod/WORKSPACE detection #752
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
Open
janwinkler1
wants to merge
1
commit into
bazelbuild:main
Choose a base branch
from
janwinkler1:bump-bazel8
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+312
−1,123
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 7.6.2 | ||
| 8.2.1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") | ||
|
|
||
| go_library( | ||
| name = "utils", | ||
| srcs = ["compatibility.go"], | ||
| importpath = "github.com/bazelbuild/bazel-watcher/internal/utils", | ||
| visibility = ["//visibility:public"], | ||
| ) | ||
|
|
||
| go_test( | ||
| name = "utils_test", | ||
| srcs = ["compatibility_test.go"], | ||
| embed = [":utils"], | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| package utils | ||
|
|
||
| import ( | ||
| "os" | ||
| "strings" | ||
| ) | ||
|
|
||
| // EnsureBazel8Compatibility adds appropriate --enable_bzlmod or --enable_workspace | ||
| // flags to bazel arguments when running with Bazel 8+, which requires explicit | ||
| // selection between bzlmod and WORKSPACE modes. | ||
| func EnsureBazel8Compatibility(args []string) []string { | ||
| // If user already specified a mode, respect their choice | ||
| for _, arg := range args { | ||
| if strings.HasPrefix(arg, "--enable_bzlmod") || strings.HasPrefix(arg, "--enable_workspace") { | ||
| return args | ||
| } | ||
| } | ||
|
|
||
| // Check for local_repository usage (forces WORKSPACE mode) | ||
| if hasLocalRepository() { | ||
| return append(args, "--enable_workspace") | ||
| } | ||
|
|
||
| // Auto-detect based on project files in current directory | ||
| if _, err := os.Stat("MODULE.bazel"); err == nil { | ||
| return append(args, "--enable_bzlmod") | ||
| } | ||
| if _, err := os.Stat("WORKSPACE"); err == nil { | ||
| return append(args, "--enable_workspace") | ||
| } | ||
| if _, err := os.Stat("WORKSPACE.bazel"); err == nil { | ||
| return append(args, "--enable_workspace") | ||
| } | ||
|
|
||
| // Default to bzlmod for new projects | ||
| return append(args, "--enable_bzlmod") | ||
| } | ||
|
|
||
| func hasLocalRepository() bool { | ||
| workspaceData, err := os.ReadFile("WORKSPACE") | ||
| if err != nil { | ||
| return false // No WORKSPACE file or can't read it | ||
| } | ||
|
|
||
| for _, line := range strings.Split(string(workspaceData), "\n") { | ||
| if strings.HasPrefix(strings.TrimSpace(line), "local_repository(") { | ||
| return true | ||
| } | ||
| } | ||
| return false | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hey @janwinkler1 with changes like this, and where bazel changes an
--experimental_<something>into a--<something>do we need to start determining the bazel version before choosing which arguments pass-through ? Or should we keep a super-set of all arguments, and let bazel figure out which don't work for its version ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chickenandpork TBH i am a bit torn on what the best approach might be. AFAIU
bazel 7: WORKSPACE is the default, BZLMOD needs to be enabled
bazel 8: WORKSPACE needs to be enabled, BZLMOD is the default
bazel 9: according to https://bazel.build/about/roadmap WORKSPACE might not even be supported anymore, BZLMOD is the default
therefore, if we want to cater all versions, something where bazel "figures this out itself" might be the best option? altough not the safest?
but ATM i was too invested with trying to fight windows, without a windows PC :/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@janwinkler1 your efforts are appreciated too -- I don't think any of us has a Windows box online :)
The CI presents its own challenges.
Are you on the ibazel slack channel ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chickenandpork thank you! no i am not :)