Skip to content

Commit 06d6dd5

Browse files
Update actual lock target
1 parent e904488 commit 06d6dd5

6 files changed

+18972
-1
lines changed

0001-Add-apex_http_archive.patch

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
From e859c13e36e0f15167b5fbcc4970768c4d973d3d Mon Sep 17 00:00:00 2001
2+
From: "kilian.funk" <[email protected]>
3+
Date: Thu, 19 Sep 2024 17:35:38 -0700
4+
Subject: [PATCH] Add apex_http_archive
5+
6+
---
7+
repos/config/detail/generate_ros2_config.py | 17 +++++++++++++++++
8+
repos/config/detail/lock_repos.py | 6 +++---
9+
2 files changed, 20 insertions(+), 3 deletions(-)
10+
11+
diff --git a/repos/config/detail/generate_ros2_config.py b/repos/config/detail/generate_ros2_config.py
12+
index 184315b..428e7e0 100755
13+
--- a/repos/config/detail/generate_ros2_config.py
14+
+++ b/repos/config/detail/generate_ros2_config.py
15+
@@ -21,6 +21,7 @@ HEADER = """#
16+
# To update, call `bazel run @rules_ros//repos/config:repos_lock.update` with the right distro set in the WORKSPACE
17+
#
18+
19+
+load("@apex//tools/bazel/rules_repo:defs.bzl", "apex_http_archive")
20+
load("@bazel_tools//tools/build_defs/repo:utils.bzl", _maybe = "maybe")
21+
load("@rules_ros//repos/config/detail:git_repository.bzl", "git_repository")
22+
load("@rules_ros//repos/config/detail:http_archive.bzl", "http_archive")
23+
@@ -43,6 +44,7 @@ def build_load_command(repo, spec):
24+
"git": build_git_load_command,
25+
"http_archive": build_http_archive_load_command,
26+
"local": build_local_load_command,
27+
+ "apex_http_archive": build_apex_http_archive_load_command
28+
}
29+
if spec.get('type') not in builder.keys():
30+
return f"""
31+
@@ -60,6 +62,21 @@ def build_build_files_attr(build_files):
32+
}},"""
33+
34+
35+
+def build_apex_http_archive_load_command(repo, spec):
36+
+ spec_string = "\n ".join(
37+
+ f'{k} = "{v}",'
38+
+ for k,v in spec.items()
39+
+ if k not in ["type", "bazel"]
40+
+ )
41+
+ return f"""\
42+
+ _maybe(
43+
+ name = "{repo.replace('/','.')}",
44+
+ {spec_string}
45+
+ repo_rule = apex_http_archive,
46+
+ )
47+
+"""
48+
+
49+
+
50+
def build_http_archive_load_command(repo, spec):
51+
return f"""\
52+
_maybe(
53+
diff --git a/repos/config/detail/lock_repos.py b/repos/config/detail/lock_repos.py
54+
index 08eebc4..40a458d 100755
55+
--- a/repos/config/detail/lock_repos.py
56+
+++ b/repos/config/detail/lock_repos.py
57+
@@ -23,7 +23,7 @@ import hashlib
58+
from pathlib import Path
59+
from generate_ros2_config import print_setup_file
60+
61+
-REPO_TYPES = ["git", "tar"]
62+
+REPO_TYPES = ["git", "tar", "apex_http_archive"]
63+
64+
def main():
65+
parser = argparse.ArgumentParser(description='Generate a Bazel setup file containing repo '
66+
@@ -55,7 +55,7 @@ def main():
67+
68+
69+
def fetch_dependency_details(*, use_tar, type, **kwargs):
70+
- if type == "tar" or use_tar:
71+
+ if type in ["tar", "apex_http_archive"] or use_tar:
72+
return fetch_http_details(type = type, **kwargs)
73+
return fetch_git_details(type = type, **kwargs)
74+
75+
@@ -64,7 +64,7 @@ def add_attributes(dictionary, additional_attributes):
76+
dictionary[k] = v
77+
78+
def fetch_http_details(*, type, version = None, url = None, **kwargs):
79+
- forward_type = "http_archive"
80+
+ forward_type = "apex_http_archive" if type == "apex_http_archive" else "http_archive"
81+
if "sha256" in kwargs:
82+
return { "type": forward_type}
83+
with tempfile.TemporaryDirectory() as tempdir:
84+
--
85+
2.34.1
86+
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
From 62a75641a0909673f60870a07fb9abcb42338b74 Mon Sep 17 00:00:00 2001
2+
From: Revati Naik <[email protected]>
3+
Date: Tue, 11 Feb 2025 11:27:10 -0800
4+
Subject: [PATCH 1/2] Create a MACRO for the py_binary rule
5+
6+
---
7+
repos/config/defs.bzl | 3 ++-
8+
repos/config/detail/generate_repos_lock.bzl | 24 +++++++++++++++++++++
9+
repos/config/detail/ros2_config.bzl | 20 +++++++++++++++--
10+
3 files changed, 44 insertions(+), 3 deletions(-)
11+
create mode 100644 repos/config/detail/generate_repos_lock.bzl
12+
13+
diff --git a/repos/config/defs.bzl b/repos/config/defs.bzl
14+
index ed10d70..ef35ef9 100644
15+
--- a/repos/config/defs.bzl
16+
+++ b/repos/config/defs.bzl
17+
@@ -46,11 +46,12 @@ def configure_ros2(*, name = "ros2_config", repos_index_overlays = [], distro):
18+
fail("repos_index_overlays needs to be a list of *.repos files")
19+
_configure_ros2(name = name, distro_src = distro_src, repos_index_overlays = repos_index_overlays)
20+
21+
-def configure_repos(*, name = "ros2_config", repos_index, repos_index_overlays = [], setup_file):
22+
+def configure_repos(*, name, repos_index, setup_file, repos_index_overlays = []):
23+
"""Configure ROS 2 repositories based on the custom *.repos file."""
24+
25+
if not type(repos_index_overlays) == type([]):
26+
fail("repos_index_overlays needs to be a list of *.repos files")
27+
+
28+
ros2_config(
29+
name = name,
30+
repos_index = repos_index,
31+
diff --git a/repos/config/detail/generate_repos_lock.bzl b/repos/config/detail/generate_repos_lock.bzl
32+
new file mode 100644
33+
index 0000000..0d9bdf5
34+
--- /dev/null
35+
+++ b/repos/config/detail/generate_repos_lock.bzl
36+
@@ -0,0 +1,24 @@
37+
+load("@python_deps//:requirements.bzl", "requirement")
38+
+load("@rules_python//python:defs.bzl", "py_binary")
39+
+
40+
+def generate_repos_lock(name, repos_file, setup_file, overlay_files):
41+
+ """Macro to create a py_binary for generating repos_lock.update"""
42+
+
43+
+ py_binary(
44+
+ name = name,
45+
+ srcs = [
46+
+ Label("generate_ros2_config.py"),
47+
+ Label("lock_repos.py"),
48+
+ ],
49+
+ args = [
50+
+ "$(execpath {})".format(repos_file),
51+
+ "$(execpath {})".format(setup_file),
52+
+ ] + ["$(execpath {})".format(f) for f in overlay_files],
53+
+ data = [
54+
+ repos_file,
55+
+ setup_file,
56+
+ ] + overlay_files,
57+
+ main = Label("lock_repos.py"),
58+
+ visibility = ["//visibility:public"],
59+
+ deps = [requirement("pyyaml")],
60+
+ )
61+
\ No newline at end of file
62+
diff --git a/repos/config/detail/ros2_config.bzl b/repos/config/detail/ros2_config.bzl
63+
index 0e9102c..7fa83e3 100644
64+
--- a/repos/config/detail/ros2_config.bzl
65+
+++ b/repos/config/detail/ros2_config.bzl
66+
@@ -30,13 +30,29 @@ _archive_attrs = {
67+
),
68+
}
69+
70+
+BUILD_FILE_CONTENT = """\
71+
+load("@rules_ros//repos/config/detail:generate_repos_lock.bzl", "generate_repos_lock")
72+
+
73+
+generate_repos_lock(
74+
+ name = "repos_lock.update",
75+
+ repos_file = ":repos_index_file.repos", # Custom repos file
76+
+ setup_file = ":repos_setup_file.bzl", # Custom setup file
77+
+ overlay_files = [
78+
+ ":repos_overlay_files.repos",
79+
+ ],
80+
+)
81+
+
82+
+exports_files(glob(["**/*"]))
83+
+"""
84+
+
85+
+
86+
def _ros2_config_impl(ctx):
87+
ctx.file("repos_index_file.bzl", content = "REPOS_INDEX_FILE = '{}'".format(ctx.attr.repos_index))
88+
- ctx.file("repos_overlay_files.bzl", content = "REPOS_OVERLAY_FILES = {}".format(["{}".format(l) for l in ctx.attr.repos_index_overlays]))
89+
+ ctx.file("repos_overlay_files.bzl", content = "REPOS_OVERLAY_FILES = {}".format(["{}".format(i) for i in ctx.attr.repos_index_overlays]))
90+
ctx.file("repos_setup_file.bzl", content = "REPOS_SETUP_FILE = '{}'".format(ctx.attr.setup_file))
91+
ctx.symlink(ctx.attr.setup_file, "setup.bzl")
92+
ctx.file("WORKSPACE", content = "workspace(name = {})".format(ctx.name), executable = False)
93+
- ctx.file("BUILD.bazel", content = "exports_files(glob(['**/*']))", executable = False)
94+
+ ctx.file("BUILD.bazel", content = BUILD_FILE_CONTENT, executable = False)
95+
96+
return update_attrs(ctx.attr, _archive_attrs.keys(), {})
97+
98+
--
99+
2.34.1
100+
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
From 208e21581dc16a9fb20841d230a0c5577bb61e41 Mon Sep 17 00:00:00 2001
2+
From: Revati Naik <[email protected]>
3+
Date: Tue, 11 Feb 2025 13:46:31 -0800
4+
Subject: [PATCH 2/2] Fix the generation fo repos lock file
5+
6+
---
7+
repos/config/detail/generate_repos_lock.bzl | 23 +++++++++------------
8+
repos/config/detail/ros2_config.bzl | 4 ++--
9+
2 files changed, 12 insertions(+), 15 deletions(-)
10+
11+
diff --git a/repos/config/detail/generate_repos_lock.bzl b/repos/config/detail/generate_repos_lock.bzl
12+
index 0d9bdf5..f1d7d80 100644
13+
--- a/repos/config/detail/generate_repos_lock.bzl
14+
+++ b/repos/config/detail/generate_repos_lock.bzl
15+
@@ -1,4 +1,7 @@
16+
load("@python_deps//:requirements.bzl", "requirement")
17+
+load("@ros2_config//:repos_index_file.bzl", "REPOS_INDEX_FILE")
18+
+load("@ros2_config//:repos_overlay_files.bzl", "REPOS_OVERLAY_FILES")
19+
+load("@ros2_config//:repos_setup_file.bzl", "REPOS_SETUP_FILE")
20+
load("@rules_python//python:defs.bzl", "py_binary")
21+
22+
def generate_repos_lock(name, repos_file, setup_file, overlay_files):
23+
@@ -6,19 +9,13 @@ def generate_repos_lock(name, repos_file, setup_file, overlay_files):
24+
25+
py_binary(
26+
name = name,
27+
- srcs = [
28+
- Label("generate_ros2_config.py"),
29+
- Label("lock_repos.py"),
30+
- ],
31+
+ srcs = ["lock_repos.py", "generate_ros2_config.py"],
32+
+ main = "lock_repos.py",
33+
+ data = [REPOS_INDEX_FILE, REPOS_SETUP_FILE] + REPOS_OVERLAY_FILES,
34+
args = [
35+
- "$(execpath {})".format(repos_file),
36+
- "$(execpath {})".format(setup_file),
37+
- ] + ["$(execpath {})".format(f) for f in overlay_files],
38+
- data = [
39+
- repos_file,
40+
- setup_file,
41+
- ] + overlay_files,
42+
- main = Label("lock_repos.py"),
43+
- visibility = ["//visibility:public"],
44+
+ "$(execpath {})".format(REPOS_INDEX_FILE),
45+
+ "$(execpath {})".format(REPOS_SETUP_FILE),
46+
+ ] + ["$(execpath {})".format(f) for f in REPOS_OVERLAY_FILES],
47+
deps = [requirement("pyyaml")],
48+
+ visibility = ["//visibility:public"],
49+
)
50+
\ No newline at end of file
51+
diff --git a/repos/config/detail/ros2_config.bzl b/repos/config/detail/ros2_config.bzl
52+
index 7fa83e3..f067301 100644
53+
--- a/repos/config/detail/ros2_config.bzl
54+
+++ b/repos/config/detail/ros2_config.bzl
55+
@@ -35,10 +35,10 @@ load("@rules_ros//repos/config/detail:generate_repos_lock.bzl", "generate_repos_
56+
57+
generate_repos_lock(
58+
name = "repos_lock.update",
59+
- repos_file = ":repos_index_file.repos", # Custom repos file
60+
+ repos_file = ":repos_index_file.bzl", # Custom repos file
61+
setup_file = ":repos_setup_file.bzl", # Custom setup file
62+
overlay_files = [
63+
- ":repos_overlay_files.repos",
64+
+ ":repos_overlay_files.bzl",
65+
],
66+
)
67+
68+
--
69+
2.34.1
70+

repos/config/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ exports_files(["bazel.repos"] + glob(["*.lock.bzl"]))
1616

1717
alias(
1818
name = "repos_lock.update",
19-
actual = "//repos/config/detail:repos_lock.update",
19+
actual = "@ros2_config//:repos_lock.update",
2020
)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
REPOS_INDEX_FILE="$1"
4+
REPOS_SETUP_FILE="$2"
5+
6+
REPOS_SETUP_FILE_SHA256=$(grep "SHA256" "${REPOS_SETUP_FILE}" | cut -f 5 -d ' ')
7+
8+
if [[ -z "${REPOS_SETUP_FILE_SHA256}" ]]; then
9+
echo "${REPOS_SETUP_FILE} DOES NOT HAVE A SHA256 COMMENT. TERMINATING"
10+
exit -1
11+
elif [[ "${REPOS_SETUP_FILE_SHA256}" =~ ^[a-f0-9]{65}$ ]]; then
12+
echo "${REPOS_SETUP_FILE} INVALID SHA256 COMMENT of ${REPOS_SETUP_FILE_SHA256}. TERMINATING"
13+
exit -1
14+
fi
15+
16+
REPOS_INDEX_FILE_SHA256=$(sha256sum "${REPOS_INDEX_FILE}" | cut -f 1 -d ' ')
17+
18+
if [ "${REPOS_INDEX_FILE_SHA256}" != "${REPOS_SETUP_FILE_SHA256}" ]; then
19+
echo "SHA256 MISMATCH. RUN 'bazel run @rules_ros//repos/config:repos_lock.update' THEN TRY AGAIN"
20+
exit -1
21+
fi
22+
23+
exit 0

0 commit comments

Comments
 (0)