@@ -27,13 +27,28 @@ def _expand_path(path, platform):
27
27
return ("arch" , path )
28
28
return ("generic" , path )
29
29
30
- def _detect_platform (ctx ):
31
- if ctx .target_platform_has_constraint (ctx .attr ._windows [platform_common .ConstraintValueInfo ]):
32
- return "win64"
33
- elif ctx .target_platform_has_constraint (ctx .attr ._macos [platform_common .ConstraintValueInfo ]):
34
- return "osx64"
30
+ def _platform_select (
31
+ ctx = None ,
32
+ * ,
33
+ linux ,
34
+ windows ,
35
+ macos ):
36
+ if ctx :
37
+ if ctx .target_platform_has_constraint (ctx .attr ._windows [platform_common .ConstraintValueInfo ]):
38
+ return windows
39
+ elif ctx .target_platform_has_constraint (ctx .attr ._macos [platform_common .ConstraintValueInfo ]):
40
+ return macos
41
+ else :
42
+ return linux
35
43
else :
36
- return "linux64"
44
+ return select ({
45
+ "@platforms//os:linux" : linux ,
46
+ "@platforms//os:macos" : macos ,
47
+ "@platforms//os:windows" : windows ,
48
+ })
49
+
50
+ def _detect_platform (ctx = None ):
51
+ return _platform_select (ctx , linux = "linux64" , macos = "osx64" , windows = "win64" )
37
52
38
53
def codeql_pkg_files (
39
54
* ,
@@ -160,11 +175,11 @@ def _zipmerge_impl(ctx):
160
175
platform = _detect_platform (ctx )
161
176
filename = "%s-%s.zip" % (ctx .attr .zip_name , platform if ctx .attr .kind == "arch" else "generic" )
162
177
output = ctx .actions .declare_file (filename )
163
- args = [output .path , "--prefix=%s" % ctx .attr .zip_prefix , ctx .file .base .path ]
178
+ args = [output .path , "--prefix=%s" % ctx .attr .prefix , ctx .file .base .path ]
164
179
for zip , prefix in ctx .attr .zips .items ():
165
180
zip_kind , expanded_prefix = _expand_path (prefix , platform )
166
181
if zip_kind == ctx .attr .kind :
167
- args .append ("--prefix=%s/%s" % (ctx .attr .zip_prefix , expanded_prefix .rstrip ("/" )))
182
+ args .append ("--prefix=%s/%s" % (ctx .attr .prefix , expanded_prefix .rstrip ("/" )))
168
183
args += [f .path for f in zip .files .to_list ()]
169
184
zips .append (zip .files )
170
185
ctx .actions .run (
@@ -200,7 +215,7 @@ _zipmerge = rule(
200
215
),
201
216
"zip_name" : attr .string (doc = "Prefix to use for the output file name" ),
202
217
"kind" : attr .string (doc = "Which zip kind to consider" , values = ["generic" , "arch" ]),
203
- "zip_prefix " : attr .string (doc = "Prefix posix path to add to the zip contents in the archive" ),
218
+ "prefix " : attr .string (doc = "Prefix posix path to add to the zip contents in the archive" ),
204
219
"_zipmerge" : attr .label (default = "//misc/bazel/internal/zipmerge" , executable = True , cfg = "exec" ),
205
220
} | _PLAT_DETECTION_ATTRS ,
206
221
)
@@ -245,25 +260,35 @@ def codeql_pack(
245
260
kind = kind ,
246
261
visibility = ["//visibility:private" ],
247
262
)
248
- pkg_zip (
249
- name = internal (kind + "-zip-base" ),
250
- srcs = [internal (kind )],
251
- visibility = ["//visibility:private" ],
252
- )
253
- _zipmerge (
254
- name = internal (kind + "-zip" ),
255
- base = internal (kind + "-zip-base" ),
263
+ if zips :
264
+ pkg_zip (
265
+ name = internal (kind + "-zip-base" ),
266
+ srcs = [internal (kind )],
267
+ visibility = ["//visibility:private" ],
268
+ )
269
+ _zipmerge (
270
+ name = internal (kind + "-zip" ),
271
+ base = internal (kind + "-zip-base" ),
272
+ zips = zips ,
273
+ zip_name = zip_filename ,
274
+ kind = kind ,
275
+ prefix = name ,
276
+ visibility = visibility ,
277
+ )
278
+ else :
279
+ pkg_zip (
280
+ name = internal (kind + "-zip" ),
281
+ srcs = [internal (kind )],
282
+ visibility = ["//visibility:private" ],
283
+ package_dir = name ,
284
+ package_file_name = name + "-" + (_detect_platform () if kind == "arch" else "generic" ) + ".zip" ,
285
+ )
286
+ if zips :
287
+ _imported_zips_manifest (
288
+ name = internal ("zip-manifest" ),
256
289
zips = zips ,
257
- zip_name = zip_filename ,
258
- zip_prefix = name , # this is prefixing the zip contents with the pack name
259
- kind = kind ,
260
- visibility = visibility ,
290
+ visibility = ["//visibility:private" ],
261
291
)
262
- _imported_zips_manifest (
263
- name = internal ("zip-manifest" ),
264
- zips = zips ,
265
- visibility = ["//visibility:private" ],
266
- )
267
292
268
293
pkg_install (
269
294
name = internal ("script" ),
@@ -283,18 +308,20 @@ def codeql_pack(
283
308
data = [
284
309
internal ("build-file" ),
285
310
internal ("script" ),
311
+ ] + ([
286
312
internal ("zip-manifest" ),
287
313
"//misc/bazel/internal/ripunzip" ,
288
- ],
314
+ ] if zips else []) ,
289
315
deps = ["@rules_python//python/runfiles" ],
290
316
args = [
291
317
"--build-file=$(rlocationpath %s)" % internal ("build-file" ),
292
318
"--pkg-install-script=$(rlocationpath %s)" % internal ("script" ),
293
319
"--destdir" ,
294
320
install_dest ,
321
+ ] + ([
295
322
"--ripunzip=$(rlocationpath //misc/bazel/internal/ripunzip)" ,
296
323
"--zip-manifest=$(rlocationpath %s)" % internal ("zip-manifest" ),
297
- ],
324
+ ] if zips else []) ,
298
325
visibility = visibility ,
299
326
)
300
327
native .filegroup (
0 commit comments