Revert "Simplify setting up LLVM as bazel external repo"
authorGeoffrey Martin-Noble <gcmn@google.com>
Tue, 17 Aug 2021 21:45:43 +0000 (14:45 -0700)
committerGeoffrey Martin-Noble <gcmn@google.com>
Tue, 17 Aug 2021 21:48:40 +0000 (14:48 -0700)
This breaks the rules for creating repository dependencies when invoked
from another workspace. See comment on https://reviews.llvm.org/D107714

This reverts commit 934f084ad42231d225bd0eee3342f4b5f7e1ce6e.

Differential Revision: https://reviews.llvm.org/D108245

utils/bazel/WORKSPACE
utils/bazel/configure.bzl
utils/bazel/examples/http_archive/WORKSPACE

index d5d518b..84ac1e5 100644 (file)
@@ -16,15 +16,13 @@ http_archive(
     ],
 )
 
-new_local_repository(
-    name = "llvm-archive",
-    path = "../../",
-    build_file_content = "# empty",
-)
-
-load("@llvm-archive//utils/bazel:configure.bzl", "llvm_configure")
+load(":configure.bzl", "llvm_configure")
 
-llvm_configure(name = "llvm-project")
+llvm_configure(
+    name = "llvm-project",
+    overlay_path = "llvm-project-overlay",
+    src_path = "../..",
+)
 
 load(":terminfo.bzl", "llvm_terminfo_from_env")
 
index 4c5ab8b..585f3e4 100644 (file)
@@ -5,6 +5,7 @@
 """Helper macros to configure the LLVM overlay project."""
 
 load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
+load("@bazel_skylib//lib:paths.bzl", "paths")
 load(":zlib.bzl", "llvm_zlib_disable", "llvm_zlib_system")
 load(":terminfo.bzl", "llvm_terminfo_disable", "llvm_terminfo_system")
 
@@ -32,11 +33,23 @@ DEFAULT_TARGETS = [
 ]
 
 def _overlay_directories(repository_ctx):
-    src_path = repository_ctx.path(Label("//:WORKSPACE")).dirname
-    bazel_path = src_path.get_child("utils").get_child("bazel")
-    overlay_path = bazel_path.get_child("llvm-project-overlay")
-    script_path = bazel_path.get_child("overlay_directories.py")
+    src_workspace_path = str(repository_ctx.path(
+        repository_ctx.attr.src_workspace,
+    ).dirname)
+
+    src_path = paths.join(src_workspace_path, repository_ctx.attr.src_path)
+
+    overlay_workspace_path = str(repository_ctx.path(
+        repository_ctx.attr.overlay_workspace,
+    ).dirname)
+    overlay_path = paths.join(
+        overlay_workspace_path,
+        repository_ctx.attr.overlay_path,
+    )
 
+    overlay_script = repository_ctx.path(
+        repository_ctx.attr._overlay_script,
+    )
     python_bin = repository_ctx.which("python3")
     if not python_bin:
         # Windows typically just defines "python" as python3. The script itself
@@ -48,7 +61,7 @@ def _overlay_directories(repository_ctx):
 
     cmd = [
         python_bin,
-        script_path,
+        overlay_script,
         "--src",
         src_path,
         "--overlay",
@@ -85,6 +98,14 @@ llvm_configure = repository_rule(
     local = True,
     configure = True,
     attrs = {
+        "_overlay_script": attr.label(
+            default = Label("//:overlay_directories.py"),
+            allow_single_file = True,
+        ),
+        "overlay_workspace": attr.label(default = Label("//:WORKSPACE")),
+        "overlay_path": attr.string(default = DEFAULT_OVERLAY_PATH),
+        "src_workspace": attr.label(default = Label("//:WORKSPACE")),
+        "src_path": attr.string(mandatory = True),
         "targets": attr.string_list(default = DEFAULT_TARGETS),
     },
 )
index 81e9a8d..cadeefb 100644 (file)
@@ -14,8 +14,8 @@ http_archive(
     name = "bazel_skylib",
     sha256 = "97e70364e9249702246c0e9444bccdc4b847bed1eb03c5a3ece4f83dfe6abc44",
     urls = [
-        "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/{version}/bazel-skylib-{version}.tar.gz".format(version = SKYLIB_VERSION),
-        "https://github.com/bazelbuild/bazel-skylib/releases/download/{version}/bazel-skylib-{version}.tar.gz".format(version = SKYLIB_VERSION),
+        "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/{version}/bazel-skylib-{version}.tar.gz".format(version=SKYLIB_VERSION),
+        "https://github.com/bazelbuild/bazel-skylib/releases/download/{version}/bazel-skylib-{version}.tar.gz".format(version=SKYLIB_VERSION),
     ],
 )