-
Notifications
You must be signed in to change notification settings - Fork 444
enable_workspace when bazel verison > 8 #1387
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
base: main
Are you sure you want to change the base?
enable_workspace when bazel verison > 8 #1387
Conversation
If you don't want workspace enabled and are on version 8, unused_deps did not work due to the lack of workspace support. You could either fix this by adding it to your project's bazelrc however we conditionally enable it here depending on the version of bazel being executed. This does have the side-effect that it seems to cause a rebuild due to the arguments of the CLI changing.
| func bazelMajorVersion() (int, error) { | ||
| out, err := cmdWithStderr(*buildTool, "version").Output() | ||
| if err != nil { | ||
| return 0, err | ||
| } | ||
| lines := strings.Split(string(out), "\n") | ||
| for _, line := range lines { | ||
| if strings.HasPrefix(line, "Build label: ") { | ||
| version := strings.TrimPrefix(line, "Build label: ") | ||
| parts := strings.Split(version, ".") | ||
| if len(parts) < 1 { | ||
| return 0, fmt.Errorf("could not parse version from 'bazel version' output: %s", version) | ||
| } | ||
| var major int | ||
| _, err := fmt.Sscanf(parts[0], "%d", &major) | ||
| if err != nil { | ||
| return 0, fmt.Errorf("could not parse major version from 'bazel version' output: %s", version) | ||
| } | ||
| return major, nil | ||
| } | ||
| } | ||
| return 0, errors.New("could not find version in 'bazel version' output") | ||
| } | ||
|
|
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.
We could also use this to conditionally, create a MODULE.bazel file and then use override_module instead of repository; I guess both approaches could work and that would probably needed eventually for Bazel 9+ when WORKSPACE is gone.
|
cc @meteorcloudy - I am not sure this is the right thing to do as we are moving away from WORKSPACE |
|
Yes, I think we should move buildtools towards being more MODULE.bazel native. |
If you don't want workspace enabled and are on version 8, unused_deps did not work due to the lack of workspace support.
You could either fix this by adding it to your project's bazelrc however we conditionally enable it here depending on the version of bazel being executed.
This does have the side-effect that it seems to cause a rebuild due to the arguments of the CLI changing.