@@ -21,15 +21,15 @@ _PLAT_DETECTION_ATTRS = {
21
21
22
22
_PLAT_PLACEHOLDER = "{CODEQL_PLATFORM}"
23
23
24
- def _process_path (path , plat ):
24
+ def _process_path (path , platform ):
25
25
if _PLAT_PLACEHOLDER in path :
26
- path = path .replace (_PLAT_PLACEHOLDER , plat )
26
+ path = path .replace (_PLAT_PLACEHOLDER , platform )
27
27
return ("arch" , path )
28
28
return ("generic" , path )
29
29
30
- def _detect_plat (ctx ):
30
+ def _detect_platform (ctx ):
31
31
if ctx .target_platform_has_constraint (ctx .attr ._windows [platform_common .ConstraintValueInfo ]):
32
- return "windows64 "
32
+ return "win64 "
33
33
elif ctx .target_platform_has_constraint (ctx .attr ._macos [platform_common .ConstraintValueInfo ]):
34
34
return "osx64"
35
35
else :
@@ -80,7 +80,7 @@ def codeql_pkg_files(
80
80
81
81
def _extract_pkg_filegroup_impl (ctx ):
82
82
src = ctx .attr .src [PackageFilegroupInfo ]
83
- plat = _detect_plat (ctx )
83
+ platform = _detect_platform (ctx )
84
84
85
85
if src .pkg_dirs or src .pkg_symlinks :
86
86
fail ("`pkg_dirs` and `pkg_symlinks` are not supported for codeql packaging rules" )
@@ -89,7 +89,7 @@ def _extract_pkg_filegroup_impl(ctx):
89
89
for pfi , origin in src .pkg_files :
90
90
dest_src_map = {}
91
91
for dest , file in pfi .dest_src_map .items ():
92
- file_kind , dest = _process_path (dest , plat )
92
+ file_kind , dest = _process_path (dest , platform )
93
93
if file_kind == ctx .attr .kind :
94
94
dest_src_map [dest ] = file
95
95
if dest_src_map :
@@ -101,25 +101,33 @@ def _extract_pkg_filegroup_impl(ctx):
101
101
DefaultInfo (files = depset (transitive = files )),
102
102
]
103
103
104
- _extrac_pkg_filegroup = rule (
104
+ _extract_pkg_filegroup = rule (
105
105
implementation = _extract_pkg_filegroup_impl ,
106
+ doc = """
107
+ This internal rule extracts the arch or generic part of a `PackageFilegroupInfo` source, returning a
108
+ `PackageFilegroupInfo` that is a subset of the provided `src`, while expanding `{CODEQL_PLATFORM}` in
109
+ destination paths to the relevant codeql platform (linux64, win64 or osx64).
110
+ The distinction between generic and arch contents is given on a per-file basis depending on the install path
111
+ containing {CODEQL_PLATFORM}, which will typically have been added by a `prefix` attribute to a `pkg_*` rule.
112
+ No `pkg_dirs` or `pkg_symlink` must have been used for assembling the source mapping information: we could
113
+ easily add support for that, but we don't require it for now.
114
+ """ ,
106
115
attrs = {
107
116
"src" : attr .label (providers = [PackageFilegroupInfo , DefaultInfo ]),
108
- "kind" : attr .string (doc = "generic or arch " , values = ["generic" , "arch" ]),
117
+ "kind" : attr .string (doc = "What part to extract " , values = ["generic" , "arch" ]),
109
118
} | _PLAT_DETECTION_ATTRS ,
110
119
)
111
120
112
121
def _imported_zips_manifest_impl (ctx ):
113
- plat = _detect_plat (ctx )
122
+ platform = _detect_platform (ctx )
114
123
115
124
manifest = []
116
125
files = []
117
126
for zip , prefix in ctx .attr .zips .items ():
118
- zip_kind , prefix = _process_path (prefix , plat )
119
- if zip_kind == ctx .attr .kind :
120
- zip_files = zip .files .to_list ()
121
- manifest += ["%s:%s" % (prefix , f .short_path ) for f in zip_files ]
122
- files += zip_files
127
+ _ , prefix = _process_path (prefix , platform )
128
+ zip_files = zip .files .to_list ()
129
+ manifest += ["%s:%s" % (prefix , f .short_path ) for f in zip_files ]
130
+ files += zip_files
123
131
124
132
output = ctx .actions .declare_file (ctx .label .name + ".params" )
125
133
ctx .actions .write (
@@ -133,21 +141,24 @@ def _imported_zips_manifest_impl(ctx):
133
141
134
142
_imported_zips_manifest = rule (
135
143
implementation = _imported_zips_manifest_impl ,
144
+ doc = """
145
+ This internal rule prints a zip manifest file that `misc/bazel/internal/install.py` understands.
146
+ {CODEQL_PLATFORM} can be used as zip prefixes and will be expanded to the relevant codeql platform.
147
+ """ ,
136
148
attrs = {
137
- "zips" : attr .label_keyed_string_dict (allow_files = True ),
138
- "kind" : attr .string (doc = "generic or arch" , values = ["generic" , "arch" ]),
149
+ "zips" : attr .label_keyed_string_dict (doc = "mapping from zip files to install prefixes" , allow_files = True ),
139
150
} | _PLAT_DETECTION_ATTRS ,
140
151
)
141
152
142
153
def _zipmerge_impl (ctx ):
143
154
zips = []
144
155
filename = ctx .attr .zip_name + "-"
145
- plat = _detect_plat (ctx )
146
- filename = "%s-%s.zip" % (ctx .attr .zip_name , plat if ctx .attr .kind == "arch" else "generic" )
156
+ platform = _detect_platform (ctx )
157
+ filename = "%s-%s.zip" % (ctx .attr .zip_name , platform if ctx .attr .kind == "arch" else "generic" )
147
158
output = ctx .actions .declare_file (filename )
148
159
args = [output .path , "--prefix=%s" % ctx .attr .zip_prefix , ctx .file .base .path ]
149
160
for zip , prefix in ctx .attr .zips .items ():
150
- zip_kind , prefix = _process_path (prefix , plat )
161
+ zip_kind , prefix = _process_path (prefix , platform )
151
162
if zip_kind == ctx .attr .kind :
152
163
args .append ("--prefix=%s/%s" % (ctx .attr .zip_prefix , prefix .rstrip ("/" )))
153
164
args += [f .path for f in zip .files .to_list ()]
@@ -165,12 +176,24 @@ def _zipmerge_impl(ctx):
165
176
166
177
_zipmerge = rule (
167
178
implementation = _zipmerge_impl ,
179
+ doc = """
180
+ This internal rule merges a `base` zip file with the ones indicated by the `zips` mapping where the prefix
181
+ indicates a matching kind between arch and generic. An imported zip file will be considered arch-specific
182
+ if its prefix contains `{CODEQL_PLATFORM}` (and this prefix will have that expanded to the appropriate
183
+ platform).
184
+
185
+ The output filename will be either `{zip_name}-generic.zip` or `{zip_name}-{CODEQL_PLATFORM}.zip`, depending on
186
+ the requested `kind`.
187
+ """ ,
168
188
attrs = {
169
- "base" : attr .label (allow_single_file = True ),
170
- "zips" : attr .label_keyed_string_dict (allow_files = True ),
171
- "zip_name" : attr .string (),
172
- "kind" : attr .string (doc = "generic or arch" , values = ["generic" , "arch" ]),
173
- "zip_prefix" : attr .string (),
189
+ "base" : attr .label (
190
+ doc = "Base zip file to which zips from `zips` will be merged with" ,
191
+ allow_single_file = True ,
192
+ ),
193
+ "zips" : attr .label_keyed_string_dict (doc = "mapping from zip files to install prefixes" , allow_files = True ),
194
+ "zip_name" : attr .string (doc = "Prefix to use for the output file name" ),
195
+ "kind" : attr .string (doc = "Which zip kind to consider" , values = ["generic" , "arch" ]),
196
+ "zip_prefix" : attr .string (doc = "Prefix posix path to add to the zip contents in the archive" ),
174
197
"_zipmerge" : attr .label (default = "//misc/bazel/internal/zipmerge" , executable = True , cfg = "exec" ),
175
198
} | _PLAT_DETECTION_ATTRS ,
176
199
)
@@ -190,14 +213,14 @@ def codeql_pack(
190
213
* defines a `<name>-generic-zip` target creating a `<zip_filename>-generic.zip` archive with the generic bits,
191
214
prefixed with `name`
192
215
* defines a `<name>-arch-zip` target creating a `<zip_filename>-<codeql_platform>.zip` archive with the
193
- arch-specific bits, prefixed with `zip_prefix` (` name` by default)
216
+ arch-specific bits, prefixed with `name`
194
217
* defines a runnable `<name>-installer` target that will install the pack in `install_dest`, relative to where the
195
218
rule is used. The install destination can be overridden appending `-- --destdir=...` to the `bazel run`
196
- invocation. This installation does not use the `zip_prefix `.
219
+ invocation. This installation _does not_ prefix the contents with `name `.
197
220
198
221
The distinction between arch-specific and generic contents is made based on whether the paths (including possible
199
222
prefixes added by rules) contain the special `{CODEQL_PLATFORM}` placeholder, which in case it is present will also
200
- be replaced by the appropriate platform (`linux64`, `windows64 ` or `osx64`).
223
+ be replaced by the appropriate platform (`linux64`, `win64 ` or `osx64`).
201
224
"""
202
225
internal = _make_internal (name )
203
226
zip_filename = zip_filename or name
@@ -209,7 +232,7 @@ def codeql_pack(
209
232
** kwargs
210
233
)
211
234
for kind in ("generic" , "arch" ):
212
- _extrac_pkg_filegroup (
235
+ _extract_pkg_filegroup (
213
236
name = internal (kind ),
214
237
src = internal ("base" ),
215
238
kind = kind ,
@@ -229,12 +252,11 @@ def codeql_pack(
229
252
kind = kind ,
230
253
visibility = visibility ,
231
254
)
232
- _imported_zips_manifest (
233
- name = internal (kind + "-zip-manifest" ),
234
- zips = zips ,
235
- kind = kind ,
236
- visibility = ["//visibility:private" ],
237
- )
255
+ _imported_zips_manifest (
256
+ name = internal ("zip-manifest" ),
257
+ zips = zips ,
258
+ visibility = ["//visibility:private" ],
259
+ )
238
260
239
261
pkg_install (
240
262
name = internal ("script" ),
@@ -254,19 +276,17 @@ def codeql_pack(
254
276
data = [
255
277
internal ("build-file" ),
256
278
internal ("script" ),
257
- internal ("generic-zip-manifest" ),
258
- internal ("arch-zip-manifest" ),
279
+ internal ("zip-manifest" ),
259
280
"//misc/bazel/internal/ripunzip" ,
260
281
],
261
282
deps = ["@rules_python//python/runfiles" ],
262
283
args = [
263
284
"--build-file=$(rlocationpath %s)" % internal ("build-file" ),
264
- "--script=$(rlocationpath %s)" % internal ("script" ),
285
+ "--pkg-install- script=$(rlocationpath %s)" % internal ("script" ),
265
286
"--destdir" ,
266
287
install_dest ,
267
288
"--ripunzip=$(rlocationpath //misc/bazel/internal/ripunzip)" ,
268
- "--zip-manifest=$(rlocationpath %s)" % internal ("generic-zip-manifest" ),
269
- "--zip-manifest=$(rlocationpath %s)" % internal ("arch-zip-manifest" ),
289
+ "--zip-manifest=$(rlocationpath %s)" % internal ("zip-manifest" ),
270
290
],
271
291
visibility = visibility ,
272
292
)
0 commit comments