Snap for 9489562 from ddd2d82d10e21fb4137d2db3c1b848d6f1832acc to android13-gs-pixel-5.10-release

Change-Id: I7513c325b34f87f36c4eab75625d1b2623209224
diff --git a/dist/dist.bzl b/dist/dist.bzl
index 2ecc8c2..6f333c7 100644
--- a/dist/dist.bzl
+++ b/dist/dist.bzl
@@ -62,6 +62,7 @@
         archives = None,
         flat = None,
         prefix = None,
+        strip_components = 0,
         archive_prefix = None,
         dist_dir = None,
         log = None,
@@ -83,6 +84,9 @@
           extracted to `--dist_dir`.
         flat: If true, `--flat` is provided to the script by default. Flatten the distribution
           directory.
+        strip_components: If specified, `--strip_components <prefix>` is provided to the script. Strip
+          leading components from the existing copied file paths before applying --prefix
+          (if specified).
         prefix: If specified, `--prefix <prefix>` is provided to the script by default. Path prefix
           to apply within dist_dir for copied files.
         archive_prefix: If specified, `--archive_prefix <prefix>` is provided to the script by
@@ -105,6 +109,10 @@
     default_args = []
     if flat:
         default_args.append("--flat")
+    if strip_components != None:
+        if strip_components < 0:
+            fail("strip_components must greater than 0, but is %s" % strip_components)
+        default_args += ["--strip_components", str(strip_components)]
     if prefix != None:
         default_args += ["--prefix", prefix]
     if archive_prefix != None:
diff --git a/dist/dist.py b/dist/dist.py
index c9538c4..fe64961 100644
--- a/dist/dist.py
+++ b/dist/dist.py
@@ -56,11 +56,17 @@
 
 
 def copy_files_to_dist_dir(files, archives, dist_dir, flat, prefix,
-    archive_prefix, **ignored):
+    strip_components, archive_prefix, **ignored):
     logging.info("Copying to %s", dist_dir)
 
     for src in files:
-        src_relpath = os.path.basename(src) if flat else src
+        if flat:
+            src_relpath = os.path.basename(src)
+        elif strip_components > 0:
+            src_relpath = src.split('/', strip_components)[-1]
+        else:
+            src_relpath = src
+
         src_relpath = os.path.join(prefix, src_relpath)
         src_abspath = os.path.abspath(src)
 
@@ -114,6 +120,9 @@
         action="store_true",
         help="ignore subdirectories in the manifest")
     parser.add_argument(
+        "--strip_components", type=int, default=0,
+        help="number of leading components to strip from paths before applying --prefix")
+    parser.add_argument(
         "--prefix", default="",
         help="path prefix to apply within dist_dir for copied files")
     parser.add_argument(
diff --git a/exec/tests/BUILD b/exec/tests/BUILD
index cadb9ff..299fe45 100644
--- a/exec/tests/BUILD
+++ b/exec/tests/BUILD
@@ -77,6 +77,9 @@
     srcs = ["exec_test.py"],
     args = ["$(location :combined)"],
     data = [":combined"],
+    deps = [
+        "@io_abseil_py//absl/testing:absltest",
+    ],
 )
 
 test_suite(
diff --git a/exec/tests/exec_test.py b/exec/tests/exec_test.py
index b7c6d52..056fb08 100644
--- a/exec/tests/exec_test.py
+++ b/exec/tests/exec_test.py
@@ -17,6 +17,7 @@
 import subprocess
 import unittest
 
+from absl.testing import absltest
 
 def load_arguments():
     parser = argparse.ArgumentParser()
@@ -46,4 +47,4 @@
 if __name__ == '__main__':
     arguments, unknown = load_arguments()
     sys.argv[1:] = unknown
-    unittest.main()
+    absltest.main()
diff --git a/workspace/BUILD b/workspace/BUILD
new file mode 100644
index 0000000..c8bc792
--- /dev/null
+++ b/workspace/BUILD
@@ -0,0 +1,27 @@
+# Copyright (C) 2022 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
+
+bzl_library(
+    name = "workspace",
+    srcs = [
+        "external.bzl",
+        # The Bazel prebuilt is not updated to define
+        # @bazel_tools//tools/build_defs/repo:lib,
+        # so using sources directly for now.
+        "@bazel_tools//tools:bzl_srcs",
+    ],
+    visibility = ["//visibility:public"],
+)
diff --git a/workspace/README.md b/workspace/README.md
new file mode 100644
index 0000000..15c5406
--- /dev/null
+++ b/workspace/README.md
@@ -0,0 +1 @@
+These extensions are expected to be loaded by `WORKSPACE` files only.
diff --git a/workspace/external.bzl b/workspace/external.bzl
new file mode 100644
index 0000000..8964ec5
--- /dev/null
+++ b/workspace/external.bzl
@@ -0,0 +1,53 @@
+# Copyright (C) 2022 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
+
+def import_external_repositories(
+        bazel_skylib = None,
+        io_abseil_py = None,
+        io_bazel_stardoc = None):
+    """Import repositories in 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.
+
+    Caller of this function (in the `WORKSPACE` file) should manage a list
+    of repositories imported by providing them in the arguments.
+
+    Args:
+        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`.
+    """
+    if bazel_skylib:
+        maybe(
+            repo_rule = native.local_repository,
+            name = "bazel_skylib",
+            path = "external/bazel-skylib",
+        )
+
+    if io_abseil_py:
+        maybe(
+            repo_rule = native.local_repository,
+            name = "io_abseil_py",
+            path = "external/python/absl-py",
+        )
+
+    if io_bazel_stardoc:
+        maybe(
+            repo_rule = native.local_repository,
+            name = "io_bazel_stardoc",
+            path = "external/stardoc",
+        )