1# Copyright (C) 2022 The Android Open Source Project 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") 16 17def import_external_repositories( 18 workspace_root = None, 19 bazel_skylib = None, 20 io_abseil_py = None, 21 io_bazel_stardoc = None): 22 """Import repositories in `{root}/external/` that are common to Bazel builds for Android. 23 24 In particular, these external projects are shared by Android platform 25 repo manifest and Android kernel repo manifest. 26 27 Caller of this function (in the `WORKSPACE` file) should manage a list 28 of repositories imported by providing them in the arguments. 29 30 Args: 31 workspace_root: Root under which the `external/` directory may be found, relative 32 to the main workspace. 33 34 When calling `import_external_repositories` in the main workspace's 35 `WORKSPACE` file, leave `root = None`. 36 bazel_skylib: If `True`, load `bazel_skylib`. 37 io_abseil_py: If `True`, load `io_abseil_py`. 38 io_bazel_stardoc: If `True`, load `io_bazel_stardoc`. 39 """ 40 workspace_prefix = workspace_root or "" 41 if workspace_prefix: 42 workspace_prefix += "/" 43 44 if bazel_skylib: 45 maybe( 46 repo_rule = native.local_repository, 47 name = "bazel_skylib", 48 path = "{}external/bazel-skylib".format(workspace_prefix), 49 ) 50 51 if io_abseil_py: 52 maybe( 53 repo_rule = native.local_repository, 54 name = "io_abseil_py", 55 path = "{}external/python/absl-py".format(workspace_prefix), 56 ) 57 58 if io_bazel_stardoc: 59 maybe( 60 repo_rule = native.local_repository, 61 name = "io_bazel_stardoc", 62 path = "{}external/stardoc".format(workspace_prefix), 63 ) 64