aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYifan Hong <elsk@google.com>2022-09-20 12:30:59 -0700
committerYifan Hong <elsk@google.com>2022-09-20 12:31:00 -0700
commit9610c355d5baf34ce5818280fe7bc86e01dceadb (patch)
treedc1d269bae04dbe38b07d032da2c0bd511f7ee4a
parenta0c815852dbd172ea2af3f8a2c6c70b0982bca9b (diff)
downloadbazel_common_rules-9610c355d5baf34ce5818280fe7bc86e01dceadb.tar.gz
external: allow to import external packages from <subdirectory>/external.
When the workspace is embedded in some other parent workspace, the relative path to external/ may be <path_to_subworkspace>/external. Allow to configure this. Bug: 242752091 Test: manual Change-Id: I60507c440f9900c89cb92d11ba8584f7f76ebd5c
-rw-r--r--workspace/external.bzl18
1 files changed, 14 insertions, 4 deletions
diff --git a/workspace/external.bzl b/workspace/external.bzl
index 8964ec5..15a29f4 100644
--- a/workspace/external.bzl
+++ b/workspace/external.bzl
@@ -15,10 +15,11 @@
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
def import_external_repositories(
+ workspace_root = None,
bazel_skylib = None,
io_abseil_py = None,
io_bazel_stardoc = None):
- """Import repositories in external/ that are common to Bazel builds for Android.
+ """Import repositories in `{root}/external/` that are common to Bazel builds for Android.
In particular, these external projects are shared by Android platform
repo manifest and Android kernel repo manifest.
@@ -27,27 +28,36 @@ def import_external_repositories(
of repositories imported by providing them in the arguments.
Args:
+ workspace_root: Root under which the `external/` directory may be found, relative
+ to the main workspace.
+
+ When calling `import_external_repositories` in the main workspace's
+ `WORKSPACE` file, leave `root = None`.
bazel_skylib: If `True`, load `bazel_skylib`.
io_abseil_py: If `True`, load `io_abseil_py`.
io_bazel_stardoc: If `True`, load `io_bazel_stardoc`.
"""
+ workspace_prefix = workspace_root or ""
+ if workspace_prefix:
+ workspace_prefix += "/"
+
if bazel_skylib:
maybe(
repo_rule = native.local_repository,
name = "bazel_skylib",
- path = "external/bazel-skylib",
+ path = "{}external/bazel-skylib".format(workspace_prefix),
)
if io_abseil_py:
maybe(
repo_rule = native.local_repository,
name = "io_abseil_py",
- path = "external/python/absl-py",
+ path = "{}external/python/absl-py".format(workspace_prefix),
)
if io_bazel_stardoc:
maybe(
repo_rule = native.local_repository,
name = "io_bazel_stardoc",
- path = "external/stardoc",
+ path = "{}external/stardoc".format(workspace_prefix),
)