Skip to content
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

[tmp] rules java testing #24742

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
11 changes: 11 additions & 0 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ tasks:
shell_commands:
- rm -rf $HOME/bazeltest
- mkdir $HOME/bazeltest
- sh setup_local_registry.sh
build_flags:
- "--config=ci-linux"
build_targets:
Expand Down Expand Up @@ -50,6 +51,7 @@ tasks:
shell_commands:
- rm -rf $HOME/bazeltest
- mkdir $HOME/bazeltest
- sh setup_local_registry.sh
build_flags:
- "--config=ci-linux"
build_targets:
Expand All @@ -64,6 +66,7 @@ tasks:
shell_commands:
- rm -rf $HOME/bazeltest
- mkdir $HOME/bazeltest
- sh setup_local_registry.sh
build_flags:
- "--config=ci-linux"
build_targets:
Expand Down Expand Up @@ -100,6 +103,7 @@ tasks:
shell_commands:
- rm -rf $HOME/bazeltest
- mkdir $HOME/bazeltest
- sh setup_local_registry.sh
build_flags:
- "--config=ci-linux"
build_targets:
Expand All @@ -119,6 +123,7 @@ tasks:
shell_commands:
- rm -rf $HOME/bazeltest
- mkdir $HOME/bazeltest
- sh setup_local_registry.sh
build_flags:
- "--config=ci-linux"
build_targets:
Expand Down Expand Up @@ -152,6 +157,7 @@ tasks:
- rm -rf $HOME/bazeltest
- mkdir $HOME/bazeltest
- ln -sf $OUTPUT_BASE/external $HOME/bazeltest/external
- sh setup_local_registry.sh
build_flags:
- "--config=ci-macos"
build_targets:
Expand Down Expand Up @@ -194,6 +200,7 @@ tasks:
- rm -rf $HOME/bazeltest
- mkdir $HOME/bazeltest
- ln -sf $OUTPUT_BASE/external $HOME/bazeltest/external
- sh setup_local_registry.sh
build_flags:
- "--config=ci-macos"
build_targets:
Expand Down Expand Up @@ -234,6 +241,7 @@ tasks:
setup:
- mkdir C:\b
- mklink /J C:\b\bazeltest_external %OUTPUT_BASE:/=\%\external
- START "" C:\python3\python.exe third_party/local-bazel-registry/server.py
build_flags:
- "--config=ci-windows"
build_targets:
Expand Down Expand Up @@ -285,6 +293,7 @@ tasks:
setup:
- mkdir C:\b
- mklink /J C:\b\bazeltest_external %OUTPUT_BASE:/=\%\external
- START "" C:\python3\python.exe third_party/local-bazel-registry/server.py
build_flags:
- "--config=ci-windows"
- "--config=windows_arm64"
Expand Down Expand Up @@ -356,6 +365,8 @@ tasks:
docs_ubuntu2004:
platform: ubuntu2004
name: "Docs"
shell_commands:
- sh setup_local_registry.sh
build_flags:
- "--config=docs"
build_targets:
Expand Down
3 changes: 3 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,6 @@ test:ci-windows --test_env=JAVA_HOME
test:ci-windows --test_env=TEST_INSTALL_BASE=C:/b/bazeltest_install_base
test:ci-windows --test_env=REPOSITORY_CACHE=C:/b/bazeltest_repo_cache
test:ci-windows --test_tag_filters=-no_windows,-slow

common --registry=http://localhost:8000/
common --registry=https://bcr.bazel.build/
7 changes: 6 additions & 1 deletion BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ filegroup(
genrule(
name = "generate_dist_lockfile",
srcs = [
".bazelrc",
"bazel_downloader.cfg",
"MODULE.bazel",
"//third_party/remoteapis:MODULE.bazel",
"//third_party:BUILD",
Expand All @@ -102,7 +104,10 @@ genrule(
"$$ROOT/$(location //src:bazel) --batch --output_user_root=$$TMPDIR/output_user_root query --check_direct_dependencies=error --lockfile_mode=update :all",
"mv MODULE.bazel.lock $$ROOT/$@",
]),
tags = ["requires-network"],
tags = [
"local",
"requires-network",
],
tools = ["//src:bazel"],
)

Expand Down
2 changes: 1 addition & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ bazel_dep(name = "zstd-jni", version = "1.5.2-3.bcr.1")
bazel_dep(name = "blake3", version = "1.5.1.bcr.1")
bazel_dep(name = "zlib", version = "1.3.1.bcr.3")
bazel_dep(name = "rules_cc", version = "0.0.17")
bazel_dep(name = "rules_java", version = "8.6.1")
bazel_dep(name = "rules_java", version = "999.999.999")
bazel_dep(name = "rules_graalvm", version = "0.11.1")
bazel_dep(name = "rules_proto", version = "7.0.2")
bazel_dep(name = "rules_jvm_external", version = "6.5")
Expand Down
185 changes: 181 additions & 4 deletions MODULE.bazel.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions distdir.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ def _repo_cache_tar_impl(ctx):

if "sha256" in artifact:
sha256 = artifact["sha256"]
if sha256 == "not found" and "localhost:8000" in url:
continue
output_file = "content_addressable/sha256/%s/file" % sha256
ctx.download(url, output_file, sha256, executable = False)
archive_files.append(output_file)
Expand Down
4 changes: 4 additions & 0 deletions setup_local_registry.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

cd third_party/local-bazel-registry
python3 -m http.server 8000 &
2 changes: 1 addition & 1 deletion src/MODULE.tools
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ use_repo(buildozer_binary, "buildozer_binary")
# Dependencies used to auto-load removed symbols and rules from Bazel (due to Starlarkification)
# See also: --incompatible_autoload_externally, AutoloadSymbols
bazel_dep(name = "protobuf", version = "29.0", repo_name = "com_google_protobuf")
bazel_dep(name = "rules_java", version = "8.6.1")
bazel_dep(name = "rules_java", version = "999.999.999")
bazel_dep(name = "rules_cc", version = "0.0.17")
bazel_dep(name = "rules_python", version = "0.40.0")
bazel_dep(name = "rules_shell", version = "0.2.0")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public class BazelRepositoryModule extends BlazeModule {

// Default list of registries.
public static final ImmutableSet<String> DEFAULT_REGISTRIES =
ImmutableSet.of("https://bcr.bazel.build/");
ImmutableSet.of("https://bcr.bazel.build/", "http://localhost:8000");

// A map of repository handlers that can be looked up by rule class name.
private final ImmutableMap<String, RepositoryFunction> repositoryHandlers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ public void setup(BlackBoxTestContext context) throws IOException {
}

lines.add("common --noenable_workspace");
lines.add("common --registry=http://localhost:8000/");
lines.add("common --registry=https://bcr.bazel.build/");

context.write(".bazelrc", lines);
}
Expand Down
1 change: 1 addition & 0 deletions src/test/py/bazel/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ py_test(
srcs = ["bzlmod/bazel_lockfile_test.py"],
shard_count = 5,
tags = [
"manual",
"requires-network",
],
deps = [
Expand Down
2 changes: 2 additions & 0 deletions src/test/py/bazel/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ def setUp(self):
# Disable WORKSPACE in python tests by default
# TODO(pcloudy): Remove when --enable_workspace defaults to false
f.write('common --noenable_workspace\n')
f.write('common --registry=http://localhost:8000/\n')
f.write('common --registry=https://bcr.bazel.build/\n')

# An empty MODULE.bazel and a corresponding MODULE.bazel.lock will prevent
# tests from accessing BCR
Expand Down
6 changes: 5 additions & 1 deletion src/test/shell/bazel/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -1199,7 +1199,10 @@ sh_test(
"@bazel_tools//tools/bash/runfiles",
],
exec_compatible_with = ["//:highcpu_machine"],
tags = ["block-network"],
tags = [
"block-network",
"manual",
],
)

sh_test(
Expand All @@ -1219,6 +1222,7 @@ sh_test(
exec_compatible_with = ["//:highcpu_machine"],
tags = [
"block-network",
"manual",
"no_windows",
],
)
Expand Down
3 changes: 3 additions & 0 deletions src/test/shell/testenv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,9 @@ common --nolegacy_external_runfiles
build --java_runtime_version=21
build --tool_java_runtime_version=21

common --registry=http://localhost:8000/
common --registry=https://bcr.bazel.build/

${EXTRA_BAZELRC:-}
EOF

Expand Down
1 change: 1 addition & 0 deletions src/test/tools/bzlmod/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ sh_test(
"//src:bazel",
"//src/test/shell/bazel:test-deps",
],
tags = ["manual"],
deps = ["@bazel_tools//tools/bash/runfiles"],
)
115 changes: 111 additions & 4 deletions src/test/tools/bzlmod/MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/test/tools/bzlmod/update_default_lock_file.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ function generate_lock_file() {
cd "${tmpdir}"
touch MODULE.bazel
echo 'common --incompatible_use_plus_in_repo_names' > .bazelrc
echo 'common --registry=http://localhost:8000/' >> .bazelrc
echo 'common --registry=https://bcr.bazel.build/' >> .bazelrc
bazel=$(rlocation io_bazel/src/bazel)

echo "Running: $bazel mod deps $@"
Expand Down
20 changes: 20 additions & 0 deletions third_party/local-bazel-registry/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

# Prepare a local rules_java release

1. Update the version in the rules_java MODULE.bazel file to 999.999.999
2. bazel build //distro:rules_java-999.999.999
3. Note the path to the output tar.gz file and the MODULE.bazel file

# Setting up Bazel

1. Copy both the above rules_java tar.gz file & MODULE.bazel file to
third_party/local-bazel-registry/modules/rules_java/999.999.999/
3. Update the sha256 integrity in modules/rules_java/999.999.999/source.json
echo -n sha256-; cat rules_java-999.999.999.tar.gz | openssl dgst -sha256 -binary | base64
4. Update the rules_java version in MODULE.bazel & MODULE.tools to 999.999.999
5. Run a local http server to serve the registry
python -m http.server 8000 --directory third_party/local-bazel-registry/
5. Update lock files

Commit & push and run CI! Ignore RBE / Windows because running a local server is
tricky there.
4 changes: 4 additions & 0 deletions third_party/local-bazel-registry/bazel_registry.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"mirrors": [],
"FAKE_KEY_FOR_UNIQUE_HASH" : false
}
Loading
Loading