Skip to content

Flip incompatible_disable_autoloads_in_main_repo #28

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
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,4 @@ disclosure timeline.
See [CONTRIBUTING.md](CONTRIBUTING.md)

[![Build status](https://badge.buildkite.com/1fd282f8ad98c3fb10758a821e5313576356709dd7d11e9618.svg?status=master)](https://buildkite.com/bazel/bazel-bazel)

Binary file added chair.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions examples/py/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
load("@rules_python//python:py_binary.bzl", "py_binary")
load("@rules_python//python:py_library.bzl", "py_library")
Comment on lines +1 to +2

Choose a reason for hiding this comment

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

medium

For consistency and to reduce boilerplate, you can combine these two load statements into a single one from @rules_python//python:defs.bzl.

load("@rules_python//python:defs.bzl", "py_binary", "py_library")


py_library(
name = "lib",
srcs = ["lib.py"],
Expand Down
4 changes: 4 additions & 0 deletions examples/py_native/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
load("@rules_python//python:py_binary.bzl", "py_binary")
load("@rules_python//python:py_library.bzl", "py_library")
load("@rules_python//python:py_test.bzl", "py_test")

filegroup(
name = "srcs",
srcs = glob(["*.py"]) + [
Expand Down
2 changes: 2 additions & 0 deletions examples/py_native/fibonacci/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
load("@rules_python//python:py_library.bzl", "py_library")

filegroup(
name = "srcs",
srcs = glob(["*.py"]) + [
Comment on lines +1 to 5
Copy link

Choose a reason for hiding this comment

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

Unused Rule Import in Python Example

The py_library rule is loaded but not used in the file. Unused imports create maintenance burden and potential confusion. This can lead to reliability issues when dependencies change.

Suggested change
load("@rules_python//python:py_library.bzl", "py_library")
filegroup(
name = "srcs",
srcs = glob(["*.py"]) + [
filegroup(
name = "srcs",
srcs = glob(["*.py"]) + [
Standards
  • ISO-IEC-25010-Reliability-Maturity
  • ISO-IEC-25010-Functional-Correctness-Appropriateness

Expand Down
4 changes: 4 additions & 0 deletions examples/shell/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
load("@rules_shell//shell:sh_binary.bzl", "sh_binary")
load("@rules_shell//shell:sh_library.bzl", "sh_library")
load("@rules_shell//shell:sh_test.bzl", "sh_test")
Comment on lines +1 to +3

Choose a reason for hiding this comment

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

medium

These load statements can be combined into a single one from @rules_shell//shell:shell.bzl for better readability and conciseness.

load("@rules_shell//shell:shell.bzl", "sh_binary", "sh_library", "sh_test")


package(default_visibility = ["//visibility:public"])

sh_binary(
Expand Down
1 change: 1 addition & 0 deletions src/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ load("@bazel_pip_dev_deps//:requirements.bzl", "requirement")
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load("@rules_java//java:java_binary.bzl", "java_binary")
load("@rules_python//python:defs.bzl", "py_binary", "py_library")
load("@rules_shell//shell:sh_binary.bzl", "sh_binary")
load("//src:build_defs.bzl", "transition_java_language_8_archive")
load("//src:release_archive.bzl", "release_archive")
load(":embedded_tools.bzl", "srcsfile")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public final class BuildLanguageOptions extends OptionsBase {

@Option(
name = "incompatible_disable_autoloads_in_main_repo",
defaultValue = "false",
defaultValue = "true",
documentationCategory = OptionDocumentationCategory.STARLARK_SEMANTICS,
effectTags = {OptionEffectTag.LOADING_AND_ANALYSIS},
metadataTags = {OptionMetadataTag.INCOMPATIBLE_CHANGE},
Expand Down Expand Up @@ -950,7 +950,7 @@ public StarlarkSemantics toStarlarkSemantics() {
public static final String INCOMPATIBLE_STOP_EXPORTING_LANGUAGE_MODULES =
"-incompatible_stop_exporting_language_modules";
public static final String INCOMPATIBLE_DISABLE_AUTOLOADS_IN_MAIN_REPO =
"-incompatible_disable_autoloads_in_main_repo";
"+incompatible_disable_autoloads_in_main_repo";
public static final String INCOMPATIBLE_ALLOW_TAGS_PROPAGATION =
"+incompatible_allow_tags_propagation";
public static final String EXPERIMENTAL_BUILTINS_DUMMY = "-experimental_builtins_dummy";
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/google/devtools/build/skyframe/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
load("@com_google_protobuf//bazel:java_proto_library.bzl", "java_proto_library")
load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library")
load("@rules_java//java:defs.bzl", "java_library")
load("//tools/build_rules:utilities.bzl", "java_library_srcs")
Expand Down
1 change: 1 addition & 0 deletions src/main/starlark/tests/builtins_bzl/builtin_test_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ function setup_tests() {
add_bazel_skylib "MODULE.bazel"
add_rules_python "MODULE.bazel"
add_platforms "MODULE.bazel"
add_rules_shell "MODULE.bazel"
src=$(get_runfiles_dir $1)
dest="${2:-$1}"
if [ ! -e "$src" ]; then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ load(
"runfiles_test",
"wrapped_cc_lib",
)
load("@rules_cc//cc:cc_library.bzl", "cc_library")
load("@rules_cc//cc:cc_binary.bzl", "cc_binary")
load("@rules_cc//cc:cc_import.bzl", "cc_import")
Comment on lines +18 to +20

Choose a reason for hiding this comment

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

medium

These load statements from @rules_cc can be combined into a single one from defs.bzl for better maintainability.

load("@rules_cc//cc:defs.bzl", "cc_library", "cc_binary", "cc_import")

load("@rules_shell//shell:sh_test.bzl", "sh_test")

LINKABLE_MORE_THAN_ONCE = "LINKABLE_MORE_THAN_ONCE"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
load(":starlark_tests.bzl", "analysis_test_suite")
load("@rules_cc//cc:cc_library.bzl", "cc_library")
load("@rules_cc//cc:cc_import.bzl", "cc_import")
load("@rules_shell//shell:sh_test.bzl", "sh_test")

cc_static_library(
name = "static",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ protected ImmutableList<ToolsSetup> getAdditionalTools() {

@Test
public void testCompileAndRunHelloWorldStub() throws Exception {
context().write(MODULE_DOT_BAZEL, "bazel_dep(name = 'rules_python', version = '0.40.0')");

Comment on lines +41 to +42
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

⚠️ Potential issue

MODULE.bazel likely needs a module() declaration

Overwriting MODULE.bazel with only a bazel_dep(...) may fail if the underlying test harness doesn’t pre-populate module(...). Safer to include it here.

Apply:

-    context().write(MODULE_DOT_BAZEL, "bazel_dep(name = 'rules_python', version = '0.40.0')");
+    context().write(
+        MODULE_DOT_BAZEL,
+        "module(name = 'test')",
+        "bazel_dep(name = 'rules_python', version = '0.40.0')"
+    );

Optionally, consider sourcing the version from a shared location to avoid drift.

🤖 Prompt for AI Agents
In
src/test/java/com/google/devtools/build/lib/blackbox/tests/PythonBlackBoxTest.java
at lines 41-42, the MODULE.bazel file is overwritten with only a bazel_dep
declaration, which may cause failures if the test harness expects a module()
declaration. Fix this by adding a module() declaration before the bazel_dep line
in the write call. Optionally, refactor the version string to be sourced from a
shared constant or configuration to prevent version drift.

Copy link

Choose a reason for hiding this comment

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

Missing Module Declaration in Python Test

MODULE.bazel is overwritten with only a bazel_dep declaration without a module() declaration, which will cause failures if the test harness expects a module() declaration.

Suggested change
context().write(MODULE_DOT_BAZEL, "module(name = 'test')", "bazel_dep(name = 'rules_python', version = '0.40.0')");
Standards
  • Bazel Module System Requirements

writeHelloWorldFiles();

BuilderRunner bazel = context().bazel();
Expand All @@ -51,7 +53,11 @@ public void testCompileAndRunHelloWorldStub() throws Exception {
}

private void writeHelloWorldFiles() throws IOException {
context().write("python/hello/BUILD", "py_binary(name = 'hello', srcs = ['hello.py'])");
context()
.write(
"python/hello/BUILD",
"load('@rules_python//python:py_binary.bzl', 'py_binary')",
"py_binary(name = 'hello', srcs = ['hello.py'])");
context().write("python/hello/hello.py", String.format("print ('%s')", HELLO));
}
}
65 changes: 30 additions & 35 deletions src/test/py/bazel/bazel_external_repository_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,23 +66,20 @@ def tearDown(self):
def testNewHttpArchive(self):
ip, port = self._http_server.server_address
rule_definition = [
(
'http_archive ='
' use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl",'
' "http_archive")'
),
'bazel_dep(name = "rules_python", version = "0.40.0")',
'http_archive = use_repo_rule(',
' "@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")',
'http_archive(',
' name = "hello_archive",',
' urls = ["http://%s:%s/hello-1.0.0.tar.gz"],' % (ip, port),
(
' sha256 = '
'"154740b327bcfee5669ef2ce0a04bf0904227a3bfe0fee08a5aaca96ea5a601a",'
),
' sha256 = ',
' "154740b327bcfee5669ef2ce0a04bf0904227a3bfe0fee08a5aaca96ea5a601a",',
' strip_prefix = "hello-1.0.0",',
' build_file = "@//third_party:hello.BUILD",',
')',
]
build_file = [
'load("@rules_python//python:py_library.bzl", "py_library")',
'py_library(',
' name = "hello",',
' srcs = ["hello.py"],',
Expand Down Expand Up @@ -189,20 +186,16 @@ def testNewHttpTarWithSparseFile(self):

ip, port = self._http_server.server_address
rule_definition = [
(
'http_archive ='
' use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl",'
' "http_archive")'
),
'bazel_dep(name = "rules_python", version = "0.40.0")',
'http_archive = use_repo_rule(',
' "@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")',
'http_archive(',
' name = "sparse_archive",',
' urls = ["http://%s:%s/sparse_archive.tar"],' % (ip, port),
' build_file = "@//:sparse_archive.BUILD",',
' sha256 = ',
(
' "a1a2b2ce4acd51a8cc1ab80adce6f134ac73e885219911a960a42000e312bb65",'
')'
),
' "a1a2b2ce4acd51a8cc1ab80adce6f134ac73e885219911a960a42000e312bb65",',
')',
]
self.ScratchFile('MODULE.bazel', rule_definition)
self.ScratchFile(
Expand All @@ -224,13 +217,12 @@ def testNewHttpTarWithSparseFile(self):
self.ScratchFile(
'BUILD',
[
'load("@rules_python//python:py_test.bzl", "py_test")',
'py_test(',
' name = "test",',
' srcs = ["test.py"],',
(
' args = ["$(rlocationpath @sparse_archive//:sparse_file)"],'
' data = ['
),
' args = ["$(rlocationpath @sparse_archive//:sparse_file)"],',
' data = [',
' "@sparse_archive//:sparse_file",',
' "@bazel_tools//tools/python/runfiles",',
' ],)',
Expand Down Expand Up @@ -260,10 +252,11 @@ def _CreatePyWritingStarlarkRule(self, print_string):
def testNewLocalRepositoryNoticesFileChangeInRepoRoot(self):
"""Regression test for https://github.com/bazelbuild/bazel/issues/7063."""
rule_definition = [
'bazel_dep(name = "rules_python", version = "0.40.0")',
'new_local_repository = use_repo_rule(',
(
'new_local_repository ='
' use_repo_rule("@bazel_tools//tools/build_defs/repo:local.bzl",'
' "new_local_repository")'
' "@bazel_tools//tools/build_defs/repo:local.bzl",'
' "new_local_repository")'
),
'new_local_repository(',
' name = "r",',
Expand All @@ -273,11 +266,15 @@ def testNewLocalRepositoryNoticesFileChangeInRepoRoot(self):
]
self.ScratchFile('MODULE.bazel', rule_definition)
self._CreatePyWritingStarlarkRule('hello!')
self.ScratchFile('BUILD', [
'load("@r//:foo.bzl", "gen_py")',
'gen_py(name = "gen")',
'py_binary(name = "bin", srcs = [":gen"], main = "gen.py")',
])
self.ScratchFile(
'BUILD',
[
'load("@r//:foo.bzl", "gen_py")',
'load("@rules_python//python:py_binary.bzl", "py_binary")',
'gen_py(name = "gen")',
'py_binary(name = "bin", srcs = [":gen"], main = "gen.py")',
],
)

_, stdout, _ = self.RunBazel(['run', '//:bin'])
self.assertIn('hello!', os.linesep.join(stdout))
Expand All @@ -294,11 +291,9 @@ def setUpOtherRepoMyRepo(self):
self.ScratchFile(
'my_repo/MODULE.bazel',
[
(
'local_repository ='
' use_repo_rule("@bazel_tools//tools/build_defs/repo:local.bzl",'
' "local_repository")'
),
'local_repository = use_repo_rule(',
' "@bazel_tools//tools/build_defs/repo:local.bzl",',
' "local_repository")',
'local_repository(name = "other_repo", path="../other_repo")',
],
)
Expand Down
Loading