Skip to content
Merged
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
2 changes: 2 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,7 @@ filegroup(
"//kotlin:module_srcs",
"//kotlin/private:module_srcs",
"//kotlin/private/toolchain:module_srcs",
"//kotlin/private/toolchain/impl:module_srcs",
"//kotlin/tests/fixtures/kotlin-app/cli:module_srcs",
"//kubernetes/private/quality:module_srcs",
"//lua:module_srcs",
Expand Down Expand Up @@ -834,6 +835,7 @@ filegroup(
"//swift:module_srcs",
"//swift/private:module_srcs",
"//swift/private/lock:module_srcs",
"//swift/private/platforms:module_srcs",
"//swift/private/quality:module_srcs",
"//swift/private/toolchain:module_srcs",
"//swift/private/tools/lock:module_srcs",
Expand Down
2 changes: 1 addition & 1 deletion docs/design/nested-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ Measured on Linux x86_64 with the pinned Bazel 9.3.1, an empty module and one wr
- `bazel run //tools/testing:nested_cache_update -- <test label>` runs the tests online with `DX_NESTED_BAZEL_NETWORK=1`. In that record mode the test writes `<set>.txt` and `<set>.MODULE.bazel.lock` to its undeclared outputs, and the tool copies them to `tools/testing/nested_cache`.
- Other hosts record through evidence.yml with `flags=--config=nested_record`; `harness.txt` is the union of the host records.
- The test calls `case.use_lock("<set>")` where it needs the checked-in lock; in record mode that call removes the lock and registers the workspace.
- `bazel run //tools/testing:nested_cache_update -- --from <dir>...` merges the records of several hosts. Each `<dir>` holds `<set>.txt` and `<set>.MODULE.bazel.lock`: an unpacked evidence artifact's `test.outputs/nested_cache` or the local testlogs. The tool unions the lists by URL, fails when one URL has two sha256 values, fails when the locks differ, and writes the result to `tools/testing/nested_cache`.
- `bazel run //tools/testing:nested_cache_update -- --from <dir>...` merges the records of several hosts. Each `<dir>` holds `<set>.txt` and a `<stem>.MODULE.bazel.lock` per `use_lock` stem: an unpacked evidence artifact's `test.outputs/nested_cache` or the local testlogs. The tool unions the lists by URL, fails when one URL has two sha256 values, fails when the locks of one stem differ, and writes the result to `tools/testing/nested_cache`.
- A full re-record runs on linux_x86_64, macos_arm64 and windows_x86_64 through `evidence.yml` with `flags=--config=nested_record`, then merges the three artifacts with `--from`.
- The list is the registry files, module archives, patches and overlays of the lock, and every checksummed download in the Bazel workspace rules log. Nothing is edited by hand.

Expand Down
6 changes: 6 additions & 0 deletions kotlin/private/toolchain/impl/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,9 @@ real_source_target(
starlark_srcs = ["BUILD.bazel"],
tags = ["corpus"],
)

filegroup(
name = "module_srcs",
srcs = ["BUILD.bazel"],
visibility = ["//:__subpackages__"],
)
9 changes: 9 additions & 0 deletions swift/private/platforms/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,12 @@ real_source_target(
],
tags = ["corpus"],
)

filegroup(
name = "module_srcs",
srcs = glob([
"*.bzl",
"BUILD.bazel",
]),
visibility = ["//:__subpackages__"],
)
100 changes: 85 additions & 15 deletions tools/testing/nested_bazel_harness_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,87 @@ fn seeded_consumer_resolves_python_interpreters_offline() {
);
}

const DEP: &str = "bazel_dep(name = \"rules_dx\", version = \"0.0.0\")\n";

const PROBE: &str = r#"def _impl(_ctx):
return []

probe = rule(
implementation = _impl,
toolchains = [
config_common.toolchain_type("@bazel_tools//tools/cpp:toolchain_type", mandatory = False),
],
)
"#;

/// Starts a consumer whose only dependency is `mid`, a module that depends on rules_dx.
fn indirect_consumer(name: &str) -> Case {
let case = nested::harness_consumer(name);
let module = dx_testing::read_text(&case.root().join("MODULE.bazel"));
assert!(module.contains(DEP), "{module}");
let module = module.replace(
DEP,
"bazel_dep(name = \"mid\", version = \"0.0.0\")\nlocal_path_override(module_name = \"mid\", path = \"mid\")\n",
);
case.write(
"MODULE.bazel",
&format!("{module}{}", nested::compose::rules_flutter_override()),
);
let rules = resolve_runfiles("MODULE.bazel");
let rules = std::path::absolute(&rules).unwrap_or_else(|error| panic!("{rules:?}: {error}"));
let rules = rules.parent().expect("rules_dx runfiles directory");
case.write("patches/rules_flutter/BUILD.bazel", "");
for patch in nested::compose::RULES_FLUTTER_PATCHES {
let rel = format!("patches/rules_flutter/{patch}.patch");
case.write(&rel, &dx_testing::read_text(&rules.join(&rel)));
}
case.write(
"mid/MODULE.bazel",
&format!("module(name = \"mid\", version = \"0.0.0\")\n{DEP}"),
);
case.write("mid/BUILD.bazel", "");
case.write(".bazelrc", "");
case.write("probe.bzl", PROBE);
case.write(
"BUILD.bazel",
"load(\":probe.bzl\", \"probe\")\n\nprobe(name = \"probe\")\n",
);
case.use_lock("indirect");
case
}

/// The `Selected` lines of the C++ toolchain resolution of `//:probe`.
fn selected_cc(case: &Case, flags: &[&str]) -> Vec<String> {
let mut args = vec![
"cquery",
"--color=no",
"--curses=no",
"--toolchain_resolution_debug=@bazel_tools//tools/cpp:toolchain_type",
"--repo_env=BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1",
];
args.extend_from_slice(flags);
args.push("//:probe");
let run = case.bazel(&args);
assert!(run.status.success(), "{}", run.combined());
run.combined()
.lines()
.filter(|line| line.contains("Selected") && line.contains("tools/cpp:toolchain_type"))
.map(str::to_owned)
.collect()
}

#[test]
fn an_indirect_consumer_resolves_no_gated_rules_dx_toolchain() {
let case = indirect_consumer("indirect");
let selected = selected_cc(&case, &[]);
assert!(selected.is_empty(), "{selected:?}");
let enabled = selected_cc(&case, &["--@@rules_dx+//config:toolchains=true"]);
assert!(
!enabled.is_empty() && enabled.iter().all(|line| line.contains("@@llvm+//toolchain:")),
"{enabled:?}"
);
}

#[test]
fn a_server_restart_refetches_no_repository() {
if nested::recording() {
Expand Down Expand Up @@ -127,24 +208,13 @@ fn a_download_outside_the_cache_sets_fails_with_its_url() {
fn nested_commands_see_no_host_path_and_a_home_under_the_test_tmpdir() {
let tmpdir = std::path::PathBuf::from(std::env::var_os("TEST_TMPDIR").expect("TEST_TMPDIR"));
let case = nested::case("environment");
std::fs::write(
case.join("MODULE.bazel"),
"module(name = \"environment\")\n",
)
.unwrap_or_else(|error| panic!("write MODULE.bazel: {error}"));
std::fs::write(case.join("MODULE.bazel"), "module(name = \"environment\")\n")
.unwrap_or_else(|error| panic!("write MODULE.bazel: {error}"));
let run = case.bazel(&["info", "output_base"]);
assert!(run.status.success(), "{}", run.combined());
let output_base = std::path::PathBuf::from(run.stdout.trim());
assert!(
output_base.starts_with(&tmpdir),
"{}",
output_base.display()
);
assert!(
case.root().starts_with(&tmpdir),
"{}",
case.root().display()
);
assert!(output_base.starts_with(&tmpdir), "{}", output_base.display());
assert!(case.root().starts_with(&tmpdir), "{}", case.root().display());
let environ = std::fs::read(format!("/proc/{}/environ", case.servers()[0])).expect("environ");
let environ = String::from_utf8_lossy(&environ);
let vars: Vec<&str> = environ.split('\0').collect();
Expand Down
2 changes: 1 addition & 1 deletion tools/testing/nested_cache/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ exports_files(
filegroup(
name = "harness_locks",
testonly = True,
srcs = ["harness.MODULE.bazel.lock"],
srcs = glob(["*.MODULE.bazel.lock"]),
visibility = ["//visibility:public"],
)

Expand Down
3 changes: 0 additions & 3 deletions tools/testing/nested_cache/harness.MODULE.bazel.lock
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,6 @@
"https://bcr.bazel.build/modules/rules_java/9.3.0/MODULE.bazel": "f657c72d65ac449caae9abf2e68e66c0d36f9416848c4c4903d0b3234229e7f2",
"https://bcr.bazel.build/modules/rules_java/9.9.0/MODULE.bazel": "6b2092957b4849ffcbb84d5c7fe0d5a4582f5e3062bc84d607122ac4ef832e55",
"https://bcr.bazel.build/modules/rules_java/9.9.0/source.json": "9c4e694db18812d19b5c1e279ba9dffc1adc3fcac163896829f374a7c426fe12",
"https://bcr.bazel.build/modules/rules_julia/0.8.0/MODULE.bazel": "8d0283ad5e93092dcf7f1c6320c844b30cae1e1b52c7a15c221da090a98f02d4",
"https://bcr.bazel.build/modules/rules_julia/0.8.0/source.json": "8911ab3baabdf30d74a36423ab2890d9d6b32b0174afd1807b7ba7bfaee06a8b",
"https://bcr.bazel.build/modules/rules_jvm_external/4.4.2/MODULE.bazel": "a56b85e418c83eb1839819f0b515c431010160383306d13ec21959ac412d2fe7",
"https://bcr.bazel.build/modules/rules_jvm_external/5.1/MODULE.bazel": "33f6f999e03183f7d088c9be518a63467dfd0be94a11d0055fe2d210f89aa909",
"https://bcr.bazel.build/modules/rules_jvm_external/5.2/MODULE.bazel": "d9351ba35217ad0de03816ef3ed63f89d411349353077348a45348b096615036",
Expand Down Expand Up @@ -419,7 +417,6 @@
"https://bcr.bazel.build/modules/rules_shell/0.3.0/MODULE.bazel": "de4402cd12f4cc8fda2354fce179fdb068c0b9ca1ec2d2b17b3e21b24c1a937b",
"https://bcr.bazel.build/modules/rules_shell/0.4.1/MODULE.bazel": "00e501db01bbf4e3e1dd1595959092c2fadf2087b2852d3f553b5370f5633592",
"https://bcr.bazel.build/modules/rules_shell/0.6.1/MODULE.bazel": "72e76b0eea4e81611ef5452aa82b3da34caca0c8b7b5c0c9584338aa93bae26b",
"https://bcr.bazel.build/modules/rules_shell/0.7.1/MODULE.bazel": "257dd8d667371de804918dfceb86f6ddd2e1b5e025f5d9322878d4a73dc8aa58",
"https://bcr.bazel.build/modules/rules_shell/0.8.0/MODULE.bazel": "f6a89f1d6a669a26f28fe814503857055d76306b79cfc11d12399af08d0b80ae",
"https://bcr.bazel.build/modules/rules_shell/0.8.0/source.json": "eb53cc815bc503c6683c5fe12d943f98883f81fc22f51403ec8a95610cba4195",
"https://bcr.bazel.build/modules/rules_swift/1.16.0/MODULE.bazel": "4a09f199545a60d09895e8281362b1ff3bb08bbde69c6fc87aff5b92fcc916ca",
Expand Down
Loading
Loading