Repository navigation
Expand file tree
/
Copy pathBUCK.v2
More file actions
337 lines (300 loc) · 14.2 KB
/
Copy pathBUCK.v2
File metadata and controls
337 lines (300 loc) · 14.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
# BUCK.v2, not BUCK: on case-insensitive checkouts (macOS APFS, Windows
# NTFS) a root `BUCK` file and the `buck/` directory collide, and the root
# package vanishes. Buck2 reads BUCK.v2 before BUCK.
load("//buck:nix.bzl", "nix_owned")
load("//nix/buck:assembly_attrs.bzl", "ASSEMBLY_CHECKS", "ASSEMBLY_PACKAGES")
load("//buck:artifacts.bzl", "ASSEMBLY_ARTIFACTS")
load("//buck:mix_artifacts.bzl", "MIX_ANTITHESIS_ARTIFACTS", "MIX_ARTIFACTS")
load("//buck:assemble.bzl", "nix_assemble")
load("//buck:nix.bzl", "nix_store_run", "owned_set")
load("//buck:mix.bzl", "mix_sources")
load("//buck:checks.bzl", "conflict_markers", "contract_check", "repo_check")
load("//buck:python.bzl", "py_static")
load("//nix/verification/tests/machines:suites.bzl", "MACHINE_PACKAGES", "MACHINE_TESTS")
# Repository-root files: flake, lock files, configuration. Generated
# Antithesis staging and materialization trees are runtime inputs, not source
# inventory; excluding them keeps a staged closure from changing every root
# assembly action and from exposing literal backslash filenames to Buck2.
repository_sources = native.glob(
["**", "**/.*", "**/.*/**"],
exclude = [
"BUCK",
"BUCK.v2",
"antithesis/build/contexts/**",
"antithesis/build/selected-test/**",
"antithesis/build/.context-*",
"antithesis/build/.context-*/**",
"antithesis/runtime",
"antithesis/runtime/**",
],
)
nix_owned(srcs = repository_sources)
# Packages with nix_owned files besides the root. The flake reads all of them;
# the repository-wide checks below cover them and the toolchains cell.
OWNED_PACKAGES = [
"//.agents",
"//antithesis",
"//audi",
"//brady",
"//.claude",
"//docs",
"//elixir",
"//enrico",
"//fleet",
"//fleet/hosts/overalls",
"//fleet/hosts/salopettes",
"//galileo",
"//.github",
"//lilly",
"//lyra",
"//marshall",
"//marvin",
"//mila",
"//nix",
"//nix/platform",
"//.oss-scanner",
"//peach",
"//porsche",
"//protocol",
"//scripts",
"//secrets",
"//susan",
"//tools",
"//vendor",
"//ziggy",
"//buck",
"//nix/domains/artifacts/guest/github",
"//buck/probes",
] + MACHINE_PACKAGES
ALL_OWNED_FILES = [":srcs_files", "toolchains//:srcs_files"] + [p + ":srcs_files" for p in OWNED_PACKAGES]
# Owned sources that the flake reads. The package and check assemblies below
# copy all of them until per-component rules narrow their inputs (M11).
owned_set(
name = "flake_srcs",
deps = [":srcs"] + [p + ":srcs" for p in OWNED_PACKAGES],
visibility = ["PUBLIC"],
)
# lib.assemble's package outputs (nix/assemble/outputs.nix), assembled
# over the Buck2 artifacts like hosts and machine tests (ADR-0269). CI
# evaluates each affected one (`[drv]`); //mila:journey-fixture runs one.
# The Mila journey fixture keeps every other leaf a Nix build. The plain
# Ubuntu runners in mila-builds.yml substitute it from Cachix, which holds
# what publish-cache.yml builds (`//:check-mila-journey-fixture`). Those
# runners have no Namespace cache and could not compile the Buck2 Rust leaves
# in their budget. The Mix releases have no Nix build (ADR-0269 M6), so it
# takes the two its VM runs from Buck2 (contract
# nix-leaf-outputs-take-only-their-releases): the runner builds those two.
_NIX_LEAF_OUTPUTS = {
"mila-journey-fixture": {app: MIX_ARTIFACTS[app] for app in ["marshall", "porsche"]},
}
# Operator tools that read no Buck2-built leaf (stable nixpkgs, the public
# registry and the editor sources only). Assembling them without artifacts
# spares `tools/buck2 run //:host` from building every leaf first, and is
# sound only while no swapped leaf is in their closure; otherwise they would
# ship a Nix-built copy that bypasses the parity tests. Contract
# tool-outputs-read-no-swapped-leaf (//buck:tool_outputs_leaf_free).
_TOOL_OUTPUTS = ["host", "security-secrets", "security-user-recipients", "tool-mila-linux-journeys", "tool-mila-linux-native", "tool-mila-linux-release", "tool-mila-rust", "tool-update-vscode-extensions"]
# Package outputs other packages consume: //mila:journey-fixture runs one, and
# the OSS scanner image carries the Marshall release (//.oss-scanner:image).
_PACKAGE_VISIBILITY = {
"mila-journey-fixture": ["//mila:"],
"service-marshall": ["//.oss-scanner:"],
"tool-mila-linux-journeys": ["//mila:"],
"tool-mila-rust": ["//mila:"],
}
[nix_assemble(
name = "package-" + attr,
attr = "outputPackages.\"{}\"".format(attr),
# The Antithesis contexts' package sets take the harness, guest and
# integrated-host releases (lib.assemble routes them).
artifacts = _NIX_LEAF_OUTPUTS[attr] if attr in _NIX_LEAF_OUTPUTS else {} if attr in _TOOL_OUTPUTS else ASSEMBLY_ARTIFACTS | (
MIX_ANTITHESIS_ARTIFACTS if attr.startswith("antithesis-") else {}
),
labels = ["flake_output"],
visibility = _PACKAGE_VISIBILITY.get(attr, []),
) for attr in ASSEMBLY_PACKAGES]
# Operator commands from package outputs (`nix run .#<app>` before M11):
# tools/buck2 run //:host -- --help
[nix_store_run(
name = name,
package = ":package-" + package,
program = "bin/" + program,
) for name, package, program in [
("host", "host", "host"),
("secrets", "security-secrets", "overalls-secrets"),
("update-vscode-extensions", "tool-update-vscode-extensions", "update-vscode-extensions"),
]]
filegroup(name = "flake", srcs = ["flake.lock", "flake.nix"], visibility = ["PUBLIC"])
export_file(name = "clippy.toml", src = "clippy.toml", visibility = ["PUBLIC"])
# The Buck2 project files that offline updater fixtures copy (ADR-0271).
filegroup(name = "buck_project", srcs = [".buckconfig", ".gitignore"], visibility = ["PUBLIC"])
# Root manifests that Nix builds read: the Cargo workspace (ADR-0273), its
# clippy.toml, and pyproject.toml for the ruff checks inside machine tests.
filegroup(name = "workspace_files", srcs = ["Cargo.lock", "Cargo.toml", "clippy.toml", "pyproject.toml"], visibility = ["PUBLIC"])
# Contract ci-isolated-heavy-builds: see buck/CONTRACTS. Each build closure
# approaches a CI runner's 116 GB store volume (60-80 GB measured), so
# publish-cache.yml builds each on a runner of its own.
_ISOLATED_BUILDS = [
"fleet-guest-trust-configuration",
"foreign-linux-guest-filesystem",
"inception-image-builder",
"ubuntu-build-boundaries",
"ubuntu-guest-unit",
]
# lib.assemble's checks (nix/assemble/outputs.nix): release probes,
# evaluation checks, the nix-compact checks and fleet-builds-configuration.
# Machine tests are nixos_machine_test targets, never lib.assemble checks
# (contract machine-test-from-buck). publish-cache.yml builds every one;
# ci.yml evaluates each affected one (`[drv]`).
_ASSEMBLED_CHECKS = ASSEMBLY_CHECKS
[fail("check {} is also a machine test".format(attr)) for attr in ASSEMBLY_CHECKS if attr in MACHINE_TESTS]
[fail("isolated build {} is not an assembled check".format(attr)) for attr in _ISOLATED_BUILDS if attr not in _ASSEMBLED_CHECKS]
[nix_assemble(
name = "check-" + attr,
attr = "checks.\"{}\"".format(attr),
artifacts = _NIX_LEAF_OUTPUTS.get(attr, ASSEMBLY_ARTIFACTS),
labels = ["flake_output", "check"] + (["isolated_build"] if attr in _ISOLATED_BUILDS else []),
) for attr in _ASSEMBLED_CHECKS]
# Repository-wide checks (M7). Each is a cached build action; `buck2 test`
# reads its stamp. Sub-targets check single files for precommit (M8).
# ruff format, ruff check and ty over every owned Python file and
# pyproject.toml; `:py-static[ruff/<path>]` checks one file.
py_static(name = "py-static", owned = ALL_OWNED_FILES, labels = ["check", "precommit"])
# Merge-conflict markers in every owned file; `:conflict-markers[<path>]`
# checks one file.
conflict_markers(name = "conflict-markers", owned = ALL_OWNED_FILES, labels = ["check", "precommit"])
# Repository-wide checks that `tools/precommit` (buck/bxl/precommit.bxl) runs
# once each, only when a file matching `include` changes (M8). Each target
# carries the `precommit` label; see the buck2 skill for the convention.
_ELIXIR = "$(exe toolchains//:elixir)/bin/elixir"
_NODE = "$(exe toolchains//:node)/node"
_CONTRACT_ENV = {"OVERALLS_CODE_CONTRACTS_NODE_MODULES": "$(exe toolchains//:code_contracts_node_modules)"}
# devenv.lock must agree with flake.lock on the inputs both carry.
repo_check(
name = "package-input-lock",
cmd = [_ELIXIR, "scripts/check_package_input_lock.exs", "flake.lock", "devenv.lock"],
include = ["flake.lock", "devenv.lock", "scripts/check_package_input_lock.exs"],
labels = ["check", "precommit"],
owned = ALL_OWNED_FILES,
path = ["toolchains//:erlang"],
)
# ADR structure and references. The validator also tests that evidence links
# resolve, so the owned-path inventory is an input and any deletion selects it.
repo_check(
name = "adrs",
cmd = [_ELIXIR, "scripts/check_adrs.exs"],
deletions = ["*"],
include = ["docs/architecture/*", "scripts/adr_validator.ex", "scripts/check_adrs.exs"],
inventory = True,
labels = ["check", "precommit"],
owned = ALL_OWNED_FILES,
path = ["toolchains//:erlang"],
)
# Contract syntax and coverage over the repository (`mix contracts.check`
# and the CI gates run the same command); `[contracts/<path>]` checks one
# file with its ancestor CONTRACTS. cc-check comes from the importNpmLock tree
# of tools/code-contracts.
contract_check(name = "contracts", labels = ["check", "precommit"], owned = ALL_OWNED_FILES)
repo_check(
name = "contracts-tests",
cmd = [_NODE, "--test", "scripts/test/check_contracts_test.mjs"],
env = _CONTRACT_ENV,
include = ["scripts/check_contracts.mjs", "scripts/test/check_contracts_test.mjs", "tools/code-contracts/*"],
labels = ["check", "precommit"],
owned = ALL_OWNED_FILES,
path = ["toolchains//:git", "toolchains//:node"],
)
# Third-party fixed-output hashes come only from the pin registry.
repo_check(
name = "pins",
cmd = [_ELIXIR, "scripts/check_pins.exs"],
include = ["*.nix", "nix/domains/artifacts/dependency-hashes.json", "scripts/pins.ex", "scripts/check_pins.exs", "*.csproj", "*/packages.lock.json", "*settings.gradle*", "*/verification-metadata.xml"],
labels = ["check", "precommit"],
local_only = True,
owned = ALL_OWNED_FILES,
path = ["toolchains//:erlang", "toolchains//:git"],
)
# ADR-0265 lint policy for adopted crates.
repo_check(
name = "rust-lints",
cmd = [_ELIXIR, "scripts/check_rust_lints.exs", "--strict"],
include = ["*.rs", "*Cargo.toml", "*clippy.toml", "scripts/rust/*", "scripts/rust_lints.ex", "scripts/check_rust_lints.exs"],
labels = ["check", "precommit"],
local_only = True,
owned = ALL_OWNED_FILES,
path = ["toolchains//:erlang", "toolchains//:git"],
)
# Contract buck2-wrapper-updater-path: see tools/CONTRACTS. tools/buck2 runs
# with only the host updater's commandPath tools (bash, coreutils, findutils,
# git and python3 here; nix, nix-store and curl stubbed), and commandPath
# matches the check's list. Local: the wrapper's shebang is /usr/bin/env.
repo_check(
name = "buck2-updater-path",
cmd = ["$(exe toolchains//:python)", "tools/buck2_updater_path_test.py"],
include = ["tools/buck2", "tools/namespace.buckconfig", "tools/namespace-re-image.lock", "tools/buck2_updater_path_test.py", "nix/domains/system/auto-update/default.nix"],
labels = ["check", "precommit"],
local_only = True,
owned = ALL_OWNED_FILES,
path = ["toolchains//:bash", "toolchains//:findutils", "toolchains//:git", "toolchains//:python"],
)
# The cells' Elixir and OTP must be the .tool-versions ones: the toolchain
# check as a configuration assertion. The store paths are in the command, so a
# toolchain change reruns it.
repo_check(
name = "toolchain-versions",
cmd = [_ELIXIR, "scripts/check_toolchain.exs"],
include = [".tool-versions", "scripts/check_toolchain.exs"],
labels = ["check", "precommit"],
owned = ALL_OWNED_FILES,
path = ["toolchains//:erlang"],
)
# Workflow Rust toolchain literals (runners without Nix) against the single
# toolchain in nix/rust-toolchain.nix (ADR-0273).
repo_check(
name = "rust-toolchain-literals",
cmd = [_ELIXIR, "scripts/check_rust_toolchain_literals.exs"],
include = [".github/workflows/*", ".github/actions/*", "nix/rust-toolchain.nix", "scripts/check_rust_toolchain_literals.exs"],
labels = ["check", "precommit"],
owned = ALL_OWNED_FILES,
path = ["toolchains//:erlang"],
)
# Marshall's browser-script suites and the workspace scripts' type check, the
# `terminal.check` and `workspace.check` gates of the retired `mix precommit`
# alias (ADR-0269 M8). Node and TypeScript come from the cells.
repo_check(
name = "marshall-browser",
cmd = [_NODE, "--test"] + ["marshall/test/browser/{}_test.mjs".format(t) for t in [
"terminals",
"xterm_accessibility",
"repository_launch",
"localization",
"admin_elevation",
"browser_extension_presence",
]],
include = ["marshall/test/browser/*", "marshall/assets/js/*", "marshall/assets/vendor/*"],
labels = ["check", "precommit"],
owned = ALL_OWNED_FILES,
path = ["toolchains//:node"],
)
repo_check(
name = "marshall-workspace-types",
cmd = [_NODE, "$(exe toolchains//:code_contracts_node_modules)/typescript/bin/tsc", "-p", "marshall/assets/tsconfig.workspace.json"],
include = ["marshall/assets/tsconfig.workspace.json", "marshall/assets/js/*"],
labels = ["check", "precommit"],
owned = ALL_OWNED_FILES,
path = ["toolchains//:node"],
)
# The structured-event catalog gate per application (`mix logging.check`).
LOGGING_APPS = ["audi", "brady", "enrico", "galileo", "lilly", "marshall", "peach", "porsche", "susan", "ziggy"]
[repo_check(
name = "logging-" + app,
cmd = [_ELIXIR, "scripts/check_logging.exs", app],
include = [app + "/lib/*.ex", app + "/lib/*.exs", app + "/config/*.ex", app + "/config/*.exs", app + "/mix.exs", "scripts/check_logging.exs"],
labels = ["check", "precommit"],
owned = ["//" + app + ":srcs_files", "//scripts:srcs_files"],
path = ["toolchains//:erlang"],
) for app in LOGGING_APPS]
export_file(name = ".tool-versions", visibility = ["PUBLIC"])
# The whole owned repository, for Mix suites that read it (Marshall's shared
# validator tests): any owned change reruns them.
mix_sources(name = "mix_repository", owned = [":flake_srcs"], visibility = ["PUBLIC"])