Skip to content

Commit e904488

Browse files
Avoid creating .bzl files in config workspace
1 parent 33ff54f commit e904488

File tree

3 files changed

+22
-19
lines changed

3 files changed

+22
-19
lines changed

repos/config/detail/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,5 @@ py_binary(
3030
deps = [requirement("pyyaml")],
3131
visibility = ["//visibility:public"],
3232
)
33+
34+
exports_files(["generate_ros2_config.py", "lock_repos.py"])
Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
load("@python_deps//:requirements.bzl", "requirement")
2-
load("@ros2_config//:repos_index_file.bzl", "REPOS_INDEX_FILE")
3-
load("@ros2_config//:repos_overlay_files.bzl", "REPOS_OVERLAY_FILES")
4-
load("@ros2_config//:repos_setup_file.bzl", "REPOS_SETUP_FILE")
52
load("@rules_python//python:defs.bzl", "py_binary")
63

7-
def generate_repos_lock(name, repos_file, setup_file, overlay_files):
4+
def generate_repos_lock(*, name, repos_file, setup_file, overlay_files):
85
"""Macro to create a py_binary for generating repos_lock.update"""
96

107
py_binary(
118
name = name,
12-
srcs = ["lock_repos.py", "generate_ros2_config.py"],
13-
main = "lock_repos.py",
14-
data = [REPOS_INDEX_FILE, REPOS_SETUP_FILE] + REPOS_OVERLAY_FILES,
9+
srcs = [Label("lock_repos.py"), Label("generate_ros2_config.py")],
10+
main = Label("lock_repos.py"),
11+
data = [repos_file, setup_file] + overlay_files,
1512
args = [
16-
"$(execpath {})".format(REPOS_INDEX_FILE),
17-
"$(execpath {})".format(REPOS_SETUP_FILE),
18-
] + ["$(execpath {})".format(f) for f in REPOS_OVERLAY_FILES],
13+
"$(execpath {})".format(repos_file),
14+
"$(execpath {})".format(setup_file),
15+
] + ["$(execpath {})".format(f) for f in overlay_files],
1916
deps = [requirement("pyyaml")],
2017
visibility = ["//visibility:public"],
21-
)
18+
)

repos/config/detail/ros2_config.bzl

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,28 @@ load("@rules_ros//repos/config/detail:generate_repos_lock.bzl", "generate_repos_
3535
3636
generate_repos_lock(
3737
name = "repos_lock.update",
38-
repos_file = ":repos_index_file.bzl", # Custom repos file
39-
setup_file = ":repos_setup_file.bzl", # Custom setup file
38+
repos_file = "ros.repos", # Custom repos file
39+
setup_file = "setup.bzl", # Custom setup file
4040
overlay_files = [
41-
":repos_overlay_files.bzl",
41+
{overlays}
4242
],
4343
)
4444
4545
exports_files(glob(["**/*"]))
4646
"""
4747

48-
4948
def _ros2_config_impl(ctx):
50-
ctx.file("repos_index_file.bzl", content = "REPOS_INDEX_FILE = '{}'".format(ctx.attr.repos_index))
51-
ctx.file("repos_overlay_files.bzl", content = "REPOS_OVERLAY_FILES = {}".format(["{}".format(i) for i in ctx.attr.repos_index_overlays]))
52-
ctx.file("repos_setup_file.bzl", content = "REPOS_SETUP_FILE = '{}'".format(ctx.attr.setup_file))
49+
ctx.symlink(ctx.attr.repos_index, "ros.repos")
5350
ctx.symlink(ctx.attr.setup_file, "setup.bzl")
51+
i = 0
52+
overlay_files = []
53+
for file in ctx.attr.repos_index_overlays:
54+
filname = "overlay_{}.bzl".format(i)
55+
ctx.symlink(file, filname)
56+
i += 1
57+
overlay_files.append(filname)
5458
ctx.file("WORKSPACE", content = "workspace(name = {})".format(ctx.name), executable = False)
55-
ctx.file("BUILD.bazel", content = BUILD_FILE_CONTENT, executable = False)
59+
ctx.file("BUILD.bazel", content = BUILD_FILE_CONTENT.format(overlays="\n".join([' "{}",'.format(filename) for filename in overlay_files])), executable = False)
5660

5761
return update_attrs(ctx.attr, _archive_attrs.keys(), {})
5862

0 commit comments

Comments
 (0)