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: 1 addition & 1 deletion .github/workflows/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
- `pin-android-maven.yml`: dispatch-only. Runs `REPIN=1 bazel run @rules_android_maven//:pin` on `ubuntu-latest` and uploads `rules_android_maven_install.json` as an artifact to commit after a rules_android or rules_flutter bump, so the lock is not resolved through Coursier on a throttled network (#7184).
- `lock-refresh.yml`: dispatch-only. Runs `bazel mod deps --lockfile_mode=update` on the five platforms, merges them with `producers_bin --lock-merge`, which starts from the `linux_x86_64` lock and replaces each extension's `os:<os>,arch:<arch>` entry whole with the one from that platform's own lock (and deep-merges `facts`); it fails when a platform lock is missing, a directory is not a known platform, or an extension has a key other than `general` or a platform factor, normalises the result with Bazel and uploads the locks as an artifact to commit. Run it with `--ref <branch>` after changing `MODULE.bazel` when an extension is locked per platform; one host only writes its own entries. With `nested` set, it also runs the nested tests in record mode on `linux_x86_64`, `macos_arm64` and `windows_x86_64` and merges their records into `tools/testing/nested_cache` with `nested_cache_update --from`; dispatch it that way after a `bazel_dep` bump. With the `pr` input, the merge job also commits the merged locks and nested cache sets to that pull request's branch, using the dx-update app token, and does nothing when they are unchanged.
- `verify-pins.yml`: weekly `//core/quality/artifacts:update -- --verify-only`. It fails naming each stale record.
- `patch-upstream.yml`: weekly `//patches:upstream`. It reads the `Upstream:` header of each patch under `patches/` and opens, or updates, the issue "patches: upstream fixes released" when an upstream pull request is merged and in a release, a ref was closed without a merge, or a patch has no header.
- `patch-upstream.yml`: weekly `//patches:upstream`. It reads the `Upstream:` header of each patch under `patches/` and the `# Upstream:` carry markers in `BUILD` and `.bzl` files, and opens, or updates, the issue "patches: upstream fixes released" when an upstream pull request is merged and in a release, a ref was closed without a merge, or a patch has no header.
- `release-cells.yml`: reusable, read-only. Builds, independently rebuilds and qualifies one archive per `//deploy/private/release:release_matrix` cell on its native runner (a consumer Bazel build included), then verifies all records. The `windows_accept_licenses` input (by default the Visual Studio Build Tools licence) lists the licence ids the Windows cells' consumers accept at `dx init`; it is the only place the release names a licence. Artifacts: `release-cell-<name>` per cell and the combined `release-cells`; outputs: `version`, `sha`, `workflow_ref`. It fails when any cell is rejected, and a rejected cell never stops the others.
- `release-tools.yml`: reusable, read-only. Builds the deadnix, selene, topiary and progenitor binaries on `linux-x86_64`, `linux-arm64`, `macos-arm64` and `windows-x86_64`, ad-hoc signs the `macos-arm64` ones, builds static kcov on the two Linux hosts as `dx-kcov-<host>`, and uploads `release-tool-<host>`, holding the binaries, their licences, the deadnix source crate and the kcov source archive. Its `python-tools` job builds the `dx-python-tools-<host>.tar.gz` bundles of the core Python quality tools for every release host on `linux-x86_64` and uploads `release-tool-python-tools`. Its `go` job cross-builds the `dx-go-<host>` Go tool multicall and `dx-oapi-codegen-<host>` for every release host on `linux-x86_64`, checks each binary's format, copies `dx-oapi-codegen-LICENSE`, runs the Linux ones and uploads `release-tool-go`.
- `release.yml`: calls `release-cells.yml` for the five platform archives and `release-tools.yml` for the tool binaries, builds the `rules_dx-<version>.tar.gz` source archive (after `release_driver` checks the tag against the candidate commit), then attests the manifest and uploads them through `release_driver` with the raw dx and dx gazelle binaries, `.sha256` files, the `dx-sha256sums.txt` and `dx-gazelle-sha256sums.txt` and `dx-tool-sha256sums.txt` manifests, and `source.json` to the release, then runs `dx security --verify` on `dx-linux-x86_64.tar.gz` and the source archive and on a one-byte-modified copy of each. The `dry_run` dispatch input runs the same `source`, `attest` and `assets` chain on the cells' version, skips every step that needs a pushed tag, signing or publishing, and still checks the `release-assets` paths. No asset is ever replaced once uploaded: a rerun skips identical assets and fails on a different one.
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/patch-upstream.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ jobs:
number=$(gh issue list --state open --search "in:title \"$title\"" --json number,title \
--jq "map(select(.title == \"$title\")) | .[0].number // empty")
if [ ! -s report.md ]; then
echo "Every patch's upstream fix is still unreleased."
echo "Every patch's and carry's upstream fix is still unreleased."
exit 0
fi
{
echo "The weekly \`patch-upstream\` run found patches under \`patches/\` that need a person. See [patches/README.md]($GITHUB_SERVER_URL/$GH_REPO/blob/main/patches/README.md) for how to drop a patch."
echo "The weekly \`patch-upstream\` run found patches under \`patches/\` or carries that need a person. See [patches/README.md]($GITHUB_SERVER_URL/$GH_REPO/blob/main/patches/README.md) for how to drop a patch or carry."
echo
cat report.md
} > body.md
Expand Down
5 changes: 5 additions & 0 deletions cc/private/toolchain/clang_cl/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ package(default_visibility = [
"@dx_cc_toolchains//:__pkg__",
])

# Upstream: hermeticbuild/hermetic-llvm#973
# llvm's clang-cl toolchain sets LIB to a placeholder. Once an llvm release has
# the fix, bump llvm and delete the search_path, *_link_lib_env and link_lib_env
# targets below and the link_lib_env parameter of clang_cl_toolchains in
# toolchains.bzl (#11967).
search_path(
name = "dynamic_crt_link_lib_path",
directories = [
Expand Down
12 changes: 9 additions & 3 deletions patches/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ py_unittest_test(
],
)

# Lists patches whose upstream fix is in a release. Run by
# Lists patches and carries whose upstream fix is in a release. Run by
# .github/workflows/patch-upstream.yml, which files the result as an issue.
py_binary(
name = "upstream",
Expand All @@ -42,8 +42,14 @@ py_unittest_test(
"headers_test.py",
"upstream.py",
],
data = ["@dx_test_tags_sources//:patch_headers.json"],
env = {"DX_PATCH_HEADERS_JSON": "$(rlocationpath @dx_test_tags_sources//:patch_headers.json)"},
data = [
"@dx_test_tags_sources//:patch_headers.json",
"@dx_test_tags_sources//:sources.json",
],
env = {
"DX_PATCH_HEADERS_JSON": "$(rlocationpath @dx_test_tags_sources//:patch_headers.json)",
"DX_SOURCES_JSON": "$(rlocationpath @dx_test_tags_sources//:sources.json)",
},
)

genrule(
Expand Down
2 changes: 2 additions & 0 deletions patches/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ Bazel applies a `single_version_override` only in the root module, the one you r

When the upstream fix is in a release rules_dx uses, delete the patch file, its label and its row, then run `bazel run //patches:update_readme` again.

Some upstream fixes are carried as rules_dx code instead of a patch, such as extra toolchain args. Mark such a carry with a `# Upstream: owner/repo#N` comment line in its `BUILD.bazel` or `.bzl` file, above the code to delete. The weekly check reads these lines like patch headers, and `//patches:headers_test` fails a pull request whose marker is unreadable. When the fix is in a release, bump the module and delete the carry and its marker.

## Patches in MODULE.bazel overrides

| Module | Version | Patches | Why |
Expand Down
25 changes: 24 additions & 1 deletion patches/headers_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Checks that every patch under patches/ has a readable Upstream header."""
"""Checks that every patch under patches/ has a readable Upstream header, and
that every `# Upstream:` carry marker in a BUILD or .bzl file is readable."""

import json
import os
Expand All @@ -23,6 +24,11 @@ def problem(text):
value = upstream.header(text)
if value is None:
return "no Upstream: line above the diff"
return _value_problem(value)


def _value_problem(value):
"""Returns why an Upstream value is unreadable, or None when it is fine."""
if upstream._FIXED.match(value):
return None
try:
Expand Down Expand Up @@ -56,6 +62,23 @@ def test_every_patch_has_a_header(self):
" as patches/README.md step 1 describes:\n" + "\n".join(failures)
)

def test_every_carry_marker_is_readable(self):
with open(runfile(os.environ["DX_SOURCES_JSON"]), encoding="utf-8") as handle:
sources = json.load(handle)
failures = []
for path, text in sorted(sources.items()):
if not upstream.is_carry_file(path):
continue
for value in upstream.carry_headers(text):
reason = _value_problem(value)
if reason:
failures.append("%s: %s" % (path, reason))
if failures:
self.fail(
"These BUILD or .bzl files have an unreadable # Upstream: line,"
" as patches/README.md describes:\n" + "\n".join(failures)
)


if __name__ == "__main__":
unittest.main()
92 changes: 69 additions & 23 deletions patches/upstream.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
an issue. The report lists refs whose pull request is merged, or closed by the
commit that landed it, and contained in a release tag, patches marked fixed in a
release, refs that were closed without a merge, and patches with no header.

A carry is rules_dx code that stands in for an upstream fix, such as extra
toolchain args. It names the fix in a comment line of a BUILD or .bzl file,
which the report reads like a patch header:

# Upstream: hermeticbuild/hermetic-llvm#973
"""

import json
Expand All @@ -21,6 +27,7 @@
import urllib.request

_HEADER = re.compile(r"^Upstream:\s*(.+?)\s*$")
_CARRY = re.compile(r"^\s*#\s*Upstream:\s*(.+?)\s*$")
_REF = re.compile(r"^([\w.-]+/[\w.-]+)#(\d+)$")
_FIXED = re.compile(r"^fixed upstream in (\S+)$")
# Keep in sync with _DIFF_START in tools/ci/repos.bzl.
Expand All @@ -46,6 +53,17 @@ def header(text):
return None


def carry_headers(text):
"""Returns the value of every `# Upstream:` comment line in a BUILD or .bzl file."""
return [match.group(1) for match in map(_CARRY.match, text.splitlines()) if match]


def is_carry_file(name):
"""Returns whether a file name is one that may hold carry markers."""
base = name.replace(os.sep, "/").rpartition("/")[2]
return base in ("BUILD", "BUILD.bazel") or base.endswith(".bzl")


def refs(value):
"""Returns [(repo, number)] for a header value; [] for `none (...)`.

Expand Down Expand Up @@ -150,39 +168,67 @@ def patch_files(root):
return sorted(found)


def carry_files(workspace):
"""Returns every BUILD and .bzl file under workspace, sorted.

Skips hidden directories, Bazel's convenience symlinks and node_modules.
"""
found = []
for directory, dirs, files in os.walk(workspace):
dirs[:] = [d for d in dirs if not d.startswith((".", "bazel-")) and d != "node_modules"]
found.extend(os.path.join(directory, name) for name in files if is_carry_file(name))
return sorted(found)


def _classify(api, name, value, released, closed, bad):
"""Appends one header or carry value of file name to its report section."""
fixed = _FIXED.match(value)
if fixed:
released.append("- `%s`: fixed in %s" % (name, fixed.group(1)))
return
try:
found = refs(value)
except ValueError as error:
bad.append("- `%s`: %s" % (name, error))
return
for repo, number in found:
try:
state, tag = status(api, repo, number)
except ValueError as error:
bad.append("- `%s`: %s" % (name, error))
continue
link = "https://github.com/%s/pull/%d" % (repo, number)
if state == "released":
released.append("- `%s`: [%s#%d](%s) is in %s" % (name, repo, number, link, tag))
elif state == "closed":
closed.append("- `%s`: [%s#%d](%s)" % (name, repo, number, link))


def report(api, root):
"""Returns the Markdown report, or "" when nothing needs a person."""
"""Returns the Markdown report, or "" when nothing needs a person.

root is the patches directory; carries are read from its parent, the
workspace. A file without a carry marker is never listed as missing one.
"""
released, closed, missing, bad = [], [], [], []
workspace = os.path.dirname(root)
for path in patch_files(root):
# Forward slashes on every host, so the issue body reads the same.
name = os.path.relpath(path, os.path.dirname(root)).replace(os.sep, "/")
name = os.path.relpath(path, workspace).replace(os.sep, "/")
with open(path, encoding="utf-8") as handle:
value = header(handle.read())
if value is None:
missing.append("- `%s`" % name)
continue
fixed = _FIXED.match(value)
if fixed:
released.append("- `%s`: fixed in %s" % (name, fixed.group(1)))
continue
try:
found = refs(value)
except ValueError as error:
bad.append("- `%s`: %s" % (name, error))
continue
for repo, number in found:
try:
state, tag = status(api, repo, number)
except ValueError as error:
bad.append("- `%s`: %s" % (name, error))
continue
link = "https://github.com/%s/pull/%d" % (repo, number)
if state == "released":
released.append("- `%s`: [%s#%d](%s) is in %s" % (name, repo, number, link, tag))
elif state == "closed":
closed.append("- `%s`: [%s#%d](%s)" % (name, repo, number, link))
_classify(api, name, value, released, closed, bad)
for path in carry_files(workspace):
name = os.path.relpath(path, workspace).replace(os.sep, "/")
with open(path, encoding="utf-8") as handle:
values = carry_headers(handle.read())
for value in values:
_classify(api, name, value, released, closed, bad)
sections = [
("Upstream fix released: bump the module and delete the patch", released),
("Upstream fix released: bump the module and delete the patch or carry", released),
("Upstream ref closed without a merge: find where the fix went", closed),
("No `Upstream:` header", missing),
("Unreadable `Upstream:` header", bad),
Expand Down
41 changes: 41 additions & 0 deletions patches/upstream_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ def test_none_needs_reason(self):
upstream.refs("https://github.com/a/b/pull/1")


def test_carry_headers(self):
text = "# Upstream: a/b#1\n #Upstream: c/d#2 \n# Upstream prebuilt on linux\nUpstream: e/f#3\n"
self.assertEqual(upstream.carry_headers(text), ["a/b#1", "c/d#2"])
self.assertTrue(upstream.is_carry_file("BUILD"))
self.assertTrue(upstream.is_carry_file("BUILD.bazel"))
self.assertTrue(upstream.is_carry_file("defs.bzl"))
self.assertFalse(upstream.is_carry_file("notes.txt"))


class ReportTest(unittest.TestCase):
def test_sorts_patches_by_upstream_state(self):
api = FakeGitHub({
Expand Down Expand Up @@ -93,6 +102,38 @@ def test_empty_when_nothing_to_do(self):
_write(root, "m/open.patch", "Upstream: o/r#3\n--- a/x\n")
self.assertEqual(upstream.report(api, root), "")

def test_reports_carries(self):
api = FakeGitHub({
"/repos/o/r/issues/1": {"state": "closed", "pull_request": {}},
"/repos/o/r/pulls/1": {"merged": True, "merge_commit_sha": "abc", "merged_at": "2026-02-01T00:00:00Z"},
"/repos/o/r/releases?per_page=20": [
{"tag_name": "v2", "draft": False, "prerelease": False, "published_at": "2026-03-01T00:00:00Z"},
],
"/repos/o/r/compare/v2...abc": {"status": "behind"},
"/repos/o/r/issues/3": {"state": "open", "pull_request": {}},
})
with tempfile.TemporaryDirectory() as tmp:
root = os.path.join(tmp, "patches")
os.makedirs(root)
_write(tmp, "cc/x/BUILD.bazel", "x = 1\n # Upstream: o/r#1\n")
_write(tmp, "cc/x/defs.bzl", "# Upstream: o/r#3\n")
_write(tmp, "cc/y/BUILD.bazel", "# Upstream: see docs\n")
_write(tmp, "cc/z/BUILD.bazel", "# Upstream prebuilt on linux\n")
_write(tmp, ".git/BUILD.bazel", "# Upstream: o/r#1\n")
_write(tmp, "cc/x/notes.txt", "# Upstream: o/r#1\n")
text = upstream.report(api, root)
self.assertIn(
"## Upstream fix released: bump the module and delete the patch or carry\n\n"
"- `cc/x/BUILD.bazel`: [o/r#1](https://github.com/o/r/pull/1) is in v2\n",
text,
)
self.assertIn("## Unreadable `Upstream:` header\n\n- `cc/y/BUILD.bazel`: not an owner/repo#N ref", text)
self.assertNotIn("defs.bzl", text)
self.assertNotIn("cc/z", text)
self.assertNotIn(".git", text)
self.assertNotIn("notes.txt", text)
self.assertNotIn("No `Upstream:` header", text)


if __name__ == "__main__":
unittest.main()
Loading