diff options
author | aiuto <aiuto@google.com> | 2021-06-09 12:10:35 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-09 12:10:35 -0400 |
commit | b6e2d2445d1163d5bc7bcca2a377cd76fb5feaa0 (patch) | |
tree | 0a959a03e8a7c3565d54eb553e28e6965f6d655b /pkg/pkg.bzl | |
parent | 6130561fc9de66d61a2962e5d007c5a07383ee56 (diff) | |
download | rules_pkg-b6e2d2445d1163d5bc7bcca2a377cd76fb5feaa0.tar.gz |
Change compute_data_path to use ctx as an input instead of output_file. (#359)
* Change compute_data_path to use ctx as an input instead of output_file.
Side effect is that we can no longer use mock-ish python tests of the Starlark code, so I had to pull a bunch of tests from path_test.py to path_test.bzl.
This is a refactoring before the PR where we introduce pkg_files* support for pkg_tar & pkg_zip. The intent for that PR is that there will be a helper method like
```
add_pkg_srcs(ctx, manifest, ctx.attr.srcs)
```
That will call compute_data_path and then use that per file in ctx.attr.srcs to compute the destination path. Using ctx instead of an arbitrary output file feels cleaner.
This was more broadly tested in the work in this branch, https://github.com/aiuto/rules_pkg/tree/tar_pkg_files.
There I have most of the full PR, but pulling this out makes an easier review.
Diffstat (limited to 'pkg/pkg.bzl')
-rw-r--r-- | pkg/pkg.bzl | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/pkg/pkg.bzl b/pkg/pkg.bzl index a4412f1..6d311e7 100644 --- a/pkg/pkg.bzl +++ b/pkg/pkg.bzl @@ -52,8 +52,8 @@ def _pkg_tar_impl(ctx): outputs, output_file, output_name = setup_output_files(ctx) # Compute the relative path - data_path = compute_data_path(output_file, ctx.attr.strip_prefix) - data_path_without_prefix = compute_data_path(output_file, ".") + data_path = compute_data_path(ctx, ctx.attr.strip_prefix) + data_path_without_prefix = compute_data_path(ctx, ".") # Find a list of path remappings to apply. remap_paths = ctx.attr.remap_paths @@ -510,11 +510,9 @@ def _pkg_zip_impl(ctx): args.add("-t", ctx.attr.timestamp) args.add("-m", ctx.attr.mode) + data_path = compute_data_path(ctx, ctx.attr.strip_prefix) for f in ctx.files.srcs: - arg = "%s=%s" % ( - _quote(f.path), - dest_path(f, compute_data_path(output_file, ctx.attr.strip_prefix)), - ) + arg = "%s=%s" % (_quote(f.path), dest_path(f, data_path)) args.add(arg) args.set_param_file_format("multiline") |