aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2022-05-09 05:57:39 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2022-05-09 05:57:39 +0000
commit31468a20c287708f1e0428e4362f431c2a758688 (patch)
tree37b3036cc2a5c53c9a2da2fd51b44994ab148e8f
parentaf1387dd6501df4cf83ae221922b8ae4f831a397 (diff)
parente1351bc691d4fc4c610eb79c39251792423533a6 (diff)
downloadbazel_common_rules-android13-frc-extservices-release.tar.gz
Snap for 8558685 from e1351bc691d4fc4c610eb79c39251792423533a6 to tm-frc-extservices-releaset_frc_ext_330443000android13-frc-extservices-release
Change-Id: I212de9f6c2be3e60adc7728e4f5af7a9946a5cb3
-rw-r--r--dist/dist.bzl25
-rw-r--r--dist/dist.py28
2 files changed, 27 insertions, 26 deletions
diff --git a/dist/dist.bzl b/dist/dist.bzl
index ac21e21..2b11f81 100644
--- a/dist/dist.bzl
+++ b/dist/dist.bzl
@@ -26,17 +26,10 @@ def _generate_dist_manifest_impl(ctx):
content = dist_archives_manifest_content,
)
- default_args_manifest = ctx.actions.declare_file(ctx.attr.name + "_default_args.txt")
- ctx.actions.write(
- output = default_args_manifest,
- content = "\n".join(ctx.attr.default_args),
- )
-
# Create the runfiles object.
runfiles = ctx.runfiles(files = all_dist_files + all_dist_archives + [
dist_manifest,
dist_archives_manifest,
- default_args_manifest,
])
return [DefaultInfo(runfiles = runfiles)]
@@ -59,9 +52,6 @@ In the case of targets, the rule copies the list of `files` from the target's De
In the case of targets, the rule copies the list of `files` from the target's DefaultInfo provider.
""",
),
- "default_args": attr.string_list(
- doc = "Default arguments provided to the script.",
- ),
},
)
@@ -71,7 +61,8 @@ def copy_to_dist_dir(
archives = None,
flat = None,
prefix = None,
- archive_prefix = None):
+ archive_prefix = None,
+ dist_dir = None):
"""A dist rule to copy files out of Bazel's output directory into a custom location.
Example:
@@ -79,6 +70,9 @@ def copy_to_dist_dir(
bazel run //path/to/my:dist_target -- --dist_dir=/tmp/dist
```
+ Run `bazel run //path/to/my:dist_target -- --help` for explanations of
+ options.
+
Args:
name: name of this rule
data: A list of labels, whose outputs are copied to `--dist_dir`.
@@ -90,6 +84,11 @@ def copy_to_dist_dir(
to apply within dist_dir for copied files.
archive_prefix: If specified, `--archive_prefix <prefix>` is provided to the script by
default. Path prefix to apply within dist_dir for extracted archives.
+ dist_dir: If specified, `--dist_dir <dist_dir>` is provided to the script by default.
+
+ In particular, if this is a relative path, it is interpreted as a relative path
+ under workspace root when the target is executed with `bazel run`.
+ See details by running the target with `--help`.
"""
default_args = []
@@ -99,12 +98,13 @@ def copy_to_dist_dir(
default_args += ["--prefix", prefix]
if archive_prefix != None:
default_args += ["--archive_prefix", archive_prefix]
+ if dist_dir != None:
+ default_args += ["--dist_dir", dist_dir]
_generate_dist_manifest(
name = name + "_dist_manifest",
data = data,
archives = archives,
- default_args = default_args,
)
copy_file(
@@ -123,4 +123,5 @@ def copy_to_dist_dir(
python_version = "PY3",
visibility = ["//visibility:public"],
data = [name + "_dist_manifest"],
+ args = default_args,
)
diff --git a/dist/dist.py b/dist/dist.py
index b124e11..c6d3f13 100644
--- a/dist/dist.py
+++ b/dist/dist.py
@@ -58,20 +58,21 @@ def copy_files_to_dist_dir(files, archives, dist_dir, flat, prefix,
archive_prefix):
for src in files:
- if not os.path.isfile(src):
- continue
-
src_relpath = os.path.basename(src) if flat else src
src_relpath = os.path.join(prefix, src_relpath)
src_abspath = os.path.abspath(src)
dst = os.path.join(dist_dir, src_relpath)
- dst_dirname = os.path.dirname(dst)
- print("[dist] Copying file: %s" % dst)
- if not os.path.exists(dst_dirname):
- os.makedirs(dst_dirname)
+ if os.path.isfile(src):
+ dst_dirname = os.path.dirname(dst)
+ print("[dist] Copying file: %s" % dst)
+ if not os.path.exists(dst_dirname):
+ os.makedirs(dst_dirname)
- shutil.copyfile(src_abspath, dst, follow_symlinks=True)
+ shutil.copyfile(src_abspath, dst, follow_symlinks=True)
+ elif os.path.isdir(src):
+ print("[dist] Copying dir: %s" % dst)
+ shutil.copytree(src_abspath, dst)
for archive in archives:
try:
@@ -94,7 +95,10 @@ def main():
parser = argparse.ArgumentParser(
description="Dist Bazel output files into a custom directory.")
parser.add_argument(
- "--dist_dir", required=True, help="absolute path to the dist dir")
+ "--dist_dir", required=True, help="""path to the dist dir.
+ If relative, it is interpreted as relative to Bazel workspace root
+ set by the BUILD_WORKSPACE_DIRECTORY environment variable, or
+ PWD if BUILD_WORKSPACE_DIRECTORY is not set.""")
parser.add_argument(
"--flat",
action="store_true",
@@ -107,11 +111,7 @@ def main():
help="Path prefix to apply within dist_dir for extracted archives. " +
"Supported archives: tar.")
- default_args = files_to_dist("*_default_args.txt")
- argv = default_args + sys.argv[1:]
- if default_args:
- print("[dist] args: {}".format(" ".join(argv)))
- args = parser.parse_args(argv)
+ args = parser.parse_args(sys.argv[1:])
if not os.path.isabs(args.dist_dir):
# BUILD_WORKSPACE_DIRECTORY is the root of the Bazel workspace containing