Skip to content

Commit d05ee87

Browse files
committed
reuse build manifest function
1 parent 8f19069 commit d05ee87

File tree

1 file changed

+12
-36
lines changed

1 file changed

+12
-36
lines changed

python/private/zipapp/py_zipapp_rule.bzl

Lines changed: 12 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -18,33 +18,6 @@ def _is_symlink(f):
1818
else:
1919
return "-1"
2020

21-
def _build_zip_main_hash_files_manifest(ctx, manifest, runfiles, inputs):
22-
manifest.add_all(
23-
# NOTE: Accessing runfiles.empty_filenames materializes them. A lambda
24-
# is used to defer that.
25-
[lambda: runfiles.empty_filenames],
26-
map_each = _map_zip_empty_filenames,
27-
allow_closure = True,
28-
)
29-
30-
manifest.add_all(runfiles.files, map_each = _map_zip_runfiles)
31-
manifest.add_all(runfiles.symlinks, map_each = _map_zip_symlinks)
32-
manifest.add_all(runfiles.root_symlinks, map_each = _map_zip_root_symlinks)
33-
34-
inputs.add(runfiles.files)
35-
inputs.add([entry.target_file for entry in runfiles.symlinks.to_list()])
36-
inputs.add([entry.target_file for entry in runfiles.root_symlinks.to_list()])
37-
38-
zip_repo_mapping_manifest = maybe_create_repo_mapping(
39-
ctx = ctx,
40-
runfiles = runfiles,
41-
)
42-
if zip_repo_mapping_manifest:
43-
manifest.add(
44-
"rf-root-symlink|0|_repo_mapping|" + zip_repo_mapping_manifest.path,
45-
)
46-
inputs.add(zip_repo_mapping_manifest)
47-
4821
def _create_zipapp_main_py(ctx, py_runtime, py_executable, stage2_bootstrap, runfiles):
4922
venv_python_exe = py_executable.venv_python_exe
5023
if venv_python_exe:
@@ -82,7 +55,7 @@ def _create_zipapp_main_py(ctx, py_runtime, py_executable, stage2_bootstrap, run
8255

8356
inputs = builders.DepsetBuilder()
8457
inputs.add(py_runtime.zip_main_template)
85-
_build_zip_main_hash_files_manifest(ctx, hash_files_manifest, runfiles, inputs)
58+
_build_manifest(ctx, hash_files_manifest, runfiles, inputs)
8659

8760
actions_run(
8861
ctx,
@@ -107,9 +80,7 @@ def _map_zip_symlinks(entry):
10780
def _map_zip_root_symlinks(entry):
10881
return "rf-root-symlink|" + _is_symlink(entry.target_file) + "|" + entry.path + "|" + entry.target_file.path
10982

110-
def _build_manifest(ctx, manifest, runfiles, zip_main):
111-
manifest.add("regular|0|__main__.py|{}".format(zip_main.path))
112-
83+
def _build_manifest(ctx, manifest, runfiles, inputs):
11384
manifest.add_all(
11485
# NOTE: Accessing runfiles.empty_filenames materializes them. A lambda
11586
# is used to defer that.
@@ -122,7 +93,10 @@ def _build_manifest(ctx, manifest, runfiles, zip_main):
12293
manifest.add_all(runfiles.symlinks, map_each = _map_zip_symlinks)
12394
manifest.add_all(runfiles.root_symlinks, map_each = _map_zip_root_symlinks)
12495

125-
inputs = [zip_main]
96+
inputs.add(runfiles.files)
97+
inputs.add([entry.target_file for entry in runfiles.symlinks.to_list()])
98+
inputs.add([entry.target_file for entry in runfiles.root_symlinks.to_list()])
99+
126100
zip_repo_mapping_manifest = maybe_create_repo_mapping(
127101
ctx = ctx,
128102
runfiles = runfiles,
@@ -134,8 +108,7 @@ def _build_manifest(ctx, manifest, runfiles, zip_main):
134108
zip_repo_mapping_manifest.path,
135109
format = "rf-root-symlink|0|_repo_mapping|%s",
136110
)
137-
inputs.append(zip_repo_mapping_manifest)
138-
return inputs
111+
inputs.add(zip_repo_mapping_manifest)
139112

140113
def _create_zip(ctx, py_runtime, py_executable, stage2_bootstrap):
141114
output = ctx.actions.declare_file(ctx.label.name + ".zip")
@@ -160,7 +133,10 @@ def _create_zip(ctx, py_runtime, py_executable, stage2_bootstrap):
160133
stage2_bootstrap,
161134
runfiles,
162135
)
163-
inputs = _build_manifest(ctx, manifest, runfiles, zip_main)
136+
inputs = builders.DepsetBuilder()
137+
manifest.add("regular|0|__main__.py|{}".format(zip_main.path))
138+
inputs.add(zip_main)
139+
_build_manifest(ctx, manifest, runfiles, inputs)
164140

165141
zipper_args = ctx.actions.args()
166142
zipper_args.add(output)
@@ -177,7 +153,7 @@ def _create_zip(ctx, py_runtime, py_executable, stage2_bootstrap):
177153
ctx,
178154
executable = ctx.attr._zipper,
179155
arguments = [manifest, zipper_args],
180-
inputs = depset(inputs, transitive = [runfiles.files]),
156+
inputs = inputs.build(),
181157
outputs = [output],
182158
mnemonic = "PyZipAppCreateZip",
183159
progress_message = "Reticulating zipapp archive: %{label} into %{output}",

0 commit comments

Comments
 (0)