Skip to content

Commit 0bfe614

Browse files
committed
Revert "Simplify setting up LLVM as bazel external repo"
This breaks the rules for creating repository dependencies when invoked from another workspace. See comment on https://reviews.llvm.org/D107714 This reverts commit 934f084. Differential Revision: https://reviews.llvm.org/D108245
1 parent 16890e0 commit 0bfe614

File tree

3 files changed

+34
-15
lines changed

3 files changed

+34
-15
lines changed

utils/bazel/WORKSPACE

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,13 @@ http_archive(
1616
],
1717
)
1818

19-
new_local_repository(
20-
name = "llvm-archive",
21-
path = "../../",
22-
build_file_content = "# empty",
23-
)
24-
25-
load("@llvm-archive//utils/bazel:configure.bzl", "llvm_configure")
19+
load(":configure.bzl", "llvm_configure")
2620

27-
llvm_configure(name = "llvm-project")
21+
llvm_configure(
22+
name = "llvm-project",
23+
overlay_path = "llvm-project-overlay",
24+
src_path = "../..",
25+
)
2826

2927
load(":terminfo.bzl", "llvm_terminfo_from_env")
3028

utils/bazel/configure.bzl

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"""Helper macros to configure the LLVM overlay project."""
66

77
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
8+
load("@bazel_skylib//lib:paths.bzl", "paths")
89
load(":zlib.bzl", "llvm_zlib_disable", "llvm_zlib_system")
910
load(":terminfo.bzl", "llvm_terminfo_disable", "llvm_terminfo_system")
1011

@@ -32,11 +33,23 @@ DEFAULT_TARGETS = [
3233
]
3334

3435
def _overlay_directories(repository_ctx):
35-
src_path = repository_ctx.path(Label("//:WORKSPACE")).dirname
36-
bazel_path = src_path.get_child("utils").get_child("bazel")
37-
overlay_path = bazel_path.get_child("llvm-project-overlay")
38-
script_path = bazel_path.get_child("overlay_directories.py")
36+
src_workspace_path = str(repository_ctx.path(
37+
repository_ctx.attr.src_workspace,
38+
).dirname)
39+
40+
src_path = paths.join(src_workspace_path, repository_ctx.attr.src_path)
41+
42+
overlay_workspace_path = str(repository_ctx.path(
43+
repository_ctx.attr.overlay_workspace,
44+
).dirname)
45+
overlay_path = paths.join(
46+
overlay_workspace_path,
47+
repository_ctx.attr.overlay_path,
48+
)
3949

50+
overlay_script = repository_ctx.path(
51+
repository_ctx.attr._overlay_script,
52+
)
4053
python_bin = repository_ctx.which("python3")
4154
if not python_bin:
4255
# Windows typically just defines "python" as python3. The script itself
@@ -48,7 +61,7 @@ def _overlay_directories(repository_ctx):
4861

4962
cmd = [
5063
python_bin,
51-
script_path,
64+
overlay_script,
5265
"--src",
5366
src_path,
5467
"--overlay",
@@ -85,6 +98,14 @@ llvm_configure = repository_rule(
8598
local = True,
8699
configure = True,
87100
attrs = {
101+
"_overlay_script": attr.label(
102+
default = Label("//:overlay_directories.py"),
103+
allow_single_file = True,
104+
),
105+
"overlay_workspace": attr.label(default = Label("//:WORKSPACE")),
106+
"overlay_path": attr.string(default = DEFAULT_OVERLAY_PATH),
107+
"src_workspace": attr.label(default = Label("//:WORKSPACE")),
108+
"src_path": attr.string(mandatory = True),
88109
"targets": attr.string_list(default = DEFAULT_TARGETS),
89110
},
90111
)

utils/bazel/examples/http_archive/WORKSPACE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ http_archive(
1414
name = "bazel_skylib",
1515
sha256 = "97e70364e9249702246c0e9444bccdc4b847bed1eb03c5a3ece4f83dfe6abc44",
1616
urls = [
17-
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/{version}/bazel-skylib-{version}.tar.gz".format(version = SKYLIB_VERSION),
18-
"https://github.com/bazelbuild/bazel-skylib/releases/download/{version}/bazel-skylib-{version}.tar.gz".format(version = SKYLIB_VERSION),
17+
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/{version}/bazel-skylib-{version}.tar.gz".format(version=SKYLIB_VERSION),
18+
"https://github.com/bazelbuild/bazel-skylib/releases/download/{version}/bazel-skylib-{version}.tar.gz".format(version=SKYLIB_VERSION),
1919
],
2020
)
2121

0 commit comments

Comments
 (0)