@@ -216,32 +216,66 @@ def _imported_zips_manifest_impl(ctx):
216216 src = ctx .attr .src [CodeqlFilesInfo ]
217217 zips = [czi for czi in src .zips if czi .arch_specific == ctx .attr .arch_specific ]
218218
219- # zipmerge is run in a build context, so it requries File.path pointers to find the zips
220- # installation runs in a run context, so it requries File.short_path to find the zips
221- # hence we require two separate files, regardless of the format
219+ output = ctx .actions .declare_file (ctx .label .name + ".params" )
222220 ctx .actions .write (
223- ctx .outputs .zipmerge_out ,
224- "\n " .join (["--prefix=%s %s" % (czi .prefix .rstrip ("/" ), czi .src .path ) for czi in zips ]),
225- )
226- ctx .actions .write (
227- ctx .outputs .install_out ,
221+ output ,
228222 "\n " .join (["%s:%s" % (czi .prefix , czi .src .short_path ) for czi in zips ]),
229223 )
230- outputs = [ctx .outputs .zipmerge_out , ctx .outputs .install_out ] + [czi .src for czi in zips ]
231224 return DefaultInfo (
232- files = depset (outputs ),
225+ files = depset ([output ]),
226+ runfiles = ctx .runfiles ([czi .src for czi in zips ]),
233227 )
234228
235- _imported_zips_manifests = rule (
229+ _imported_zips_manifest = rule (
236230 implementation = _imported_zips_manifest_impl ,
237231 attrs = {
238232 "src" : attr .label (providers = [CodeqlFilesInfo ]),
239233 "arch_specific" : attr .bool (),
240- "zipmerge_out" : attr .output (),
241- "install_out" : attr .output (),
234+ "zip_prefix" : attr .string (),
242235 },
243236)
244237
238+ def _zipmerge_impl (ctx ):
239+ src = ctx .attr .src [CodeqlFilesInfo ]
240+ zip_infos = [czi for czi in src .zips if czi .arch_specific == ctx .attr .arch_specific ]
241+ zips = depset ([ctx .file .base_zip ] + [czi .src for czi in zip_infos ])
242+ filename = ctx .attr .zip_name + "-"
243+ if ctx .attr .arch_specific :
244+ filename += _detect_plat (ctx )
245+ else :
246+ filename += "generic"
247+ filename += ".zip"
248+ output = ctx .actions .declare_file (filename )
249+ args = [output .path , ctx .file .base_zip .path ]
250+ for info in zip_infos :
251+ args += [
252+ "--prefix=%s/%s" % (ctx .attr .zip_prefix , info .prefix .rstrip ("/" )),
253+ info .src .path ,
254+ ]
255+
256+ ctx .actions .run (
257+ outputs = [output ],
258+ executable = ctx .executable ._zipmerge ,
259+ inputs = zips ,
260+ arguments = args ,
261+ )
262+
263+ return [
264+ DefaultInfo (files = depset ([output ])),
265+ ]
266+
267+ _zipmerge = rule (
268+ implementation = _zipmerge_impl ,
269+ attrs = {
270+ "src" : attr .label (providers = [CodeqlFilesInfo ]),
271+ "base_zip" : attr .label (allow_single_file = True ),
272+ "zip_name" : attr .string (),
273+ "arch_specific" : attr .bool (),
274+ "zip_prefix" : attr .string (),
275+ "_zipmerge" : attr .label (default = "//misc/bazel/internal/zipmerge" , executable = True , cfg = "exec" ),
276+ } | _PLAT_DETECTION_ATTRS ,
277+ )
278+
245279_extrac_pkg_filegroup = rule (
246280 implementation = _extract_pkg_filegroup_impl ,
247281 attrs = {
@@ -291,30 +325,28 @@ def codeql_pack(
291325 prefix = zip_prefix ,
292326 visibility = ["//visibility:private" ],
293327 )
328+ _imported_zips_manifest (
329+ name = internal (kind + "-zip-manifest" ),
330+ src = name ,
331+ arch_specific = kind == "arch" ,
332+ zip_prefix = zip_prefix ,
333+ visibility = ["//visibility:private" ],
334+ )
294335 pkg_zip (
295336 name = internal (kind + "-zip-base" ),
296337 srcs = [internal (kind + "-zip-contents" )],
297- visibility = visibility ,
338+ visibility = [ "// visibility:private" ] ,
298339 )
299- _imported_zips_manifests (
300- name = internal (kind + "-zip-manifests" ),
340+ _zipmerge (
341+ name = internal (kind + "-zip" ),
342+ base_zip = internal (kind + "-zip-base" ),
343+ zip_name = zip_filename ,
344+ zip_prefix = zip_prefix ,
301345 src = name ,
302- zipmerge_out = internal (kind + "-zipmerge.params" ),
303- install_out = internal (kind + "-install.params" ),
304346 arch_specific = kind == "arch" ,
347+ visibility = visibility ,
305348 )
306- native .genrule (
307- name = internal (kind + "-zip" ),
308- tools = ["//misc/bazel/internal/zipmerge" , internal (kind + "-zipmerge.params" )],
309- srcs = [internal (kind + "-zip-base" ), internal (kind + "-zip-manifests" )],
310- outs = ["%s-%s.zip" % (zip_filename , kind )],
311- cmd = " " .join ([
312- "$(execpath //misc/bazel/internal/zipmerge)" ,
313- "$@" ,
314- "$(execpath %s)" % internal (kind + "-zip-base" ),
315- "$$(cat $(execpath %s))" % internal (kind + "-zipmerge.params" ),
316- ]),
317- )
349+
318350 pkg_install (
319351 name = internal ("script" ),
320352 srcs = [internal ("generic" ), internal ("arch" )],
@@ -333,10 +365,8 @@ def codeql_pack(
333365 data = [
334366 internal ("build-file" ),
335367 internal ("script" ),
336- internal ("generic-install.params" ),
337- internal ("generic-zip-manifests" ),
338- internal ("arch-install.params" ),
339- internal ("arch-zip-manifests" ),
368+ internal ("generic-zip-manifest" ),
369+ internal ("arch-zip-manifest" ),
340370 "//misc/bazel/internal/ripunzip" ,
341371 ],
342372 deps = ["@rules_python//python/runfiles" ],
@@ -346,8 +376,8 @@ def codeql_pack(
346376 "--destdir" ,
347377 install_dest ,
348378 "--ripunzip=$(rlocationpath //misc/bazel/internal/ripunzip)" ,
349- "--zip-manifest=$(rlocationpath %s)" % internal ("generic-install.params " ),
350- "--zip-manifest=$(rlocationpath %s)" % internal ("arch-install.params " ),
379+ "--zip-manifest=$(rlocationpath %s)" % internal ("generic-zip-manifest " ),
380+ "--zip-manifest=$(rlocationpath %s)" % internal ("arch-zip-manifest " ),
351381 ],
352382 visibility = visibility ,
353383 )
0 commit comments