Skip to content

Commit

Permalink
[build] Adjust new_release for bzlmod spellings
Browse files Browse the repository at this point in the history
  • Loading branch information
jwnimmer-tri committed Jan 17, 2025
1 parent 02bbf73 commit b683d33
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 13 deletions.
1 change: 0 additions & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,5 @@ use_repo(
# - Provide better configuration options for choosing dependencies.
# - Adjust the wheel build to build more dependencies as Bazel modules.
# - Update the maintainer docs in tools/workspace/README.
# - Debug any new glitches with the new_release automation.
# - Investigate any impact on S3 mirroring.
# - Deprecate non-bzlmod use of Drake downstream.
4 changes: 3 additions & 1 deletion tools/workspace/metadata.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ def generate_repository_metadata(repository_ctx, **kwargs):
dict entry of name="" using the repository_ctx.name. This information can
be loaded later using the tools/workspace/metadata.py library.
"""
canonical_name = repository_ctx.name
apparent_name = canonical_name.split("+")[-1]
repository_ctx.file(
"drake_repository_metadata.json",
content = json.encode(struct(
name = repository_ctx.name,
name = apparent_name,
**kwargs
)),
executable = False,
Expand Down
83 changes: 72 additions & 11 deletions tools/workspace/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,52 @@

import glob
import json
import logging
import os
import subprocess


_REPOSITORIES_WITH_NO_METADATA = [
# Bazel modules.
"eigen",
"fmt",
"spdlog",
"module_eigen",
"module_fmt",
"module_spdlog",
"pkgconfig_eigen",
"pkgconfig_fmt",
"pkgconfig_spdlog",
"platforms",
"rules_cc",
"rules_java",
"rules_license",
"rules_python",
"rules_rust",
"rules_shell",
# Host libraries / binaries.
"gfortran",
"glib",
"glx",
"gurobi",
"lapack",
"libblas",
"liblapack",
"mumps_internal",
"nasm",
"net_sf_jchart2d",
"opencl",
"opengl",
"org_apache_xmlgraphics_commons",
"x11",
"zlib",
# Vendored.
"doxygen",
"snopt",
"spgrid_internal",
]


def _check_output(args):
return subprocess.check_output(args).decode("utf8")

Expand All @@ -31,9 +73,15 @@ def read_repository_metadata(repositories=None):
repositories = set()
for line in package_lines.split("\n"):
if not line.startswith("@"):
# Not a repository.
continue
name = line[1:].split("/")[0]
repositories.add(name)
if line.startswith("@@"):
# A repository that only has a canonical name, not an apparent
# name. That means we don't load it in MODULE.bzl, so we don't
# care about its metadata.
continue
apparent_name = line[1:].split("/")[0]
repositories.add(apparent_name)

# The bazel query only finds build-time dependencies. Drake also
# requires some load-time dependencies such as starlark libraries,
Expand All @@ -49,15 +97,28 @@ def read_repository_metadata(repositories=None):
subprocess.check_call(["bazel", "fetch", "//..."])

# Read the metadata.
for name in sorted(repositories):
json_path = os.path.join(
output_base, "external", name, "drake_repository_metadata.json")
try:
with open(json_path, "r") as f:
data = json.load(f)
result[data["name"]] = data
except IOError:
pass
for apparent_name in sorted(repositories):
found = False
for canonical_name in [
f"+drake_dep_repositories+{apparent_name}",
f"+internal_repositories+{apparent_name}"]:
json_path = os.path.join(
output_base, "external", canonical_name,
"drake_repository_metadata.json")
try:
with open(json_path, "r") as f:
data = json.load(f)
result[data["name"]] = data
except IOError:
pass
if found:
break

# Yell when something went wrong.
if not found and apparent_name not in _REPOSITORIES_WITH_NO_METADATA:
logging.warn(f"Missing metadata for {apparent_name}")
elif found and apparent_name in _REPOSITORIES_WITH_NO_METADATA:
logging.warn(f"Unexpectedly found metadata for {name}")

# Add 'magic' metadata for repositories that don't/can't generate it the
# usual way.
Expand Down

0 comments on commit b683d33

Please sign in to comment.