@@ -51,7 +51,6 @@ FLAGS = struct(
51
51
f : str (Label ("//python/config_settings:" + f ))
52
52
for f in [
53
53
"python_version" ,
54
- "pip_whl" ,
55
54
"pip_whl_glibc_version" ,
56
55
"pip_whl_muslc_version" ,
57
56
"pip_whl_osx_arch" ,
@@ -116,6 +115,7 @@ def pip_config_settings(
116
115
]
117
116
118
117
alias_rule = alias_rule or native .alias
118
+ config_setting_rule = config_setting_rule or _dist_config_setting
119
119
120
120
for version in ["default" ] + python_versions :
121
121
is_python = "is_python_{}" .format (version )
@@ -135,22 +135,16 @@ def pip_config_settings(
135
135
constraint_values .append ("@platforms//cpu:" + cpu )
136
136
suffix += "_" + cpu
137
137
138
- _sdist_config_setting (
139
- name = "sdist" + suffix ,
140
- constraint_values = constraint_values ,
141
- visibility = visibility ,
142
- config_setting_rule = config_setting_rule ,
143
- )
144
- for python_version in python_versions :
145
- _sdist_config_setting (
146
- name = "cp{}_sdist{}" .format (python_version , suffix ),
138
+ for python_version in ["" ] + python_versions :
139
+ sdist = "cp{}_sdist" .format (python_version ) if python_version else "sdist"
140
+ config_setting_rule (
141
+ name = "is_{}{}" .format (sdist , suffix ),
147
142
python_version = python_version ,
143
+ flag_values = {_flags .dist : "" },
144
+ is_pip_whl = FLAGS .is_pip_whl_no ,
148
145
constraint_values = constraint_values ,
149
146
visibility = visibility ,
150
- config_setting_rule = config_setting_rule ,
151
147
)
152
-
153
- for python_version in ["" ] + python_versions :
154
148
_whl_config_settings (
155
149
suffix = suffix ,
156
150
plat_flag_values = _plat_flag_values (
@@ -162,25 +156,28 @@ def pip_config_settings(
162
156
),
163
157
constraint_values = constraint_values ,
164
158
python_version = python_version ,
159
+ is_pip_whl = FLAGS .is_pip_whl_only ,
165
160
visibility = visibility ,
166
161
config_setting_rule = config_setting_rule ,
167
162
)
168
163
169
- def _whl_config_settings (* , suffix , plat_flag_values , ** kwargs ):
164
+ def _whl_config_settings (* , suffix , plat_flag_values , config_setting_rule , ** kwargs ):
170
165
# With the following three we cover different per-version wheels
171
166
python_version = kwargs .get ("python_version" )
172
167
py = "cp{}_py" .format (python_version ) if python_version else "py"
173
168
pycp = "cp{}_cp3x" .format (python_version ) if python_version else "cp3x"
174
169
175
- flag_values = {}
170
+ flag_values = {
171
+ _flags .dist : "" ,
172
+ }
176
173
177
- for n , f in {
178
- "{}_none_any{}" .format (py , suffix ): _flags .whl_py2_py3 ,
179
- "{}3_none_any{}" .format (py , suffix ): _flags .whl_py3 ,
180
- "{}3_abi3_any{}" .format (py , suffix ): _flags .whl_py3_abi3 ,
181
- "{}_none_any{}" .format (pycp , suffix ): _flags .whl_pycp3x ,
182
- "{}_abi3_any{}" .format (pycp , suffix ): _flags .whl_pycp3x_abi3 ,
183
- "{}_cp_any{}" .format (pycp , suffix ): _flags .whl_pycp3x_abicp ,
174
+ for name , f in {
175
+ "is_ {}_none_any{}" .format (py , suffix ): _flags .whl_py2_py3 ,
176
+ "is_ {}3_none_any{}" .format (py , suffix ): _flags .whl_py3 ,
177
+ "is_ {}3_abi3_any{}" .format (py , suffix ): _flags .whl_py3_abi3 ,
178
+ "is_ {}_none_any{}" .format (pycp , suffix ): _flags .whl_pycp3x ,
179
+ "is_ {}_abi3_any{}" .format (pycp , suffix ): _flags .whl_pycp3x_abi3 ,
180
+ "is_ {}_cp_any{}" .format (pycp , suffix ): _flags .whl_pycp3x_abicp ,
184
181
}.items ():
185
182
if f in flag_values :
186
183
# This should never happen as all of the different whls should have
@@ -189,8 +186,8 @@ def _whl_config_settings(*, suffix, plat_flag_values, **kwargs):
189
186
else :
190
187
flag_values [f ] = ""
191
188
192
- _whl_config_setting (
193
- name = n ,
189
+ config_setting_rule (
190
+ name = name ,
194
191
flag_values = flag_values ,
195
192
** kwargs
196
193
)
@@ -200,13 +197,13 @@ def _whl_config_settings(*, suffix, plat_flag_values, **kwargs):
200
197
for (suffix , flag_values ) in plat_flag_values :
201
198
flag_values = flag_values | generic_flag_values
202
199
203
- for n , f in {
204
- "{}_none_{}" .format (py , suffix ): _flags .whl_plat ,
205
- "{}3_none_{}" .format (py , suffix ): _flags .whl_plat_py3 ,
206
- "{}3_abi3_{}" .format (py , suffix ): _flags .whl_plat_py3_abi3 ,
207
- "{}_none_{}" .format (pycp , suffix ): _flags .whl_plat_pycp3x ,
208
- "{}_abi3_{}" .format (pycp , suffix ): _flags .whl_plat_pycp3x_abi3 ,
209
- "{}_cp_{}" .format (pycp , suffix ): _flags .whl_plat_pycp3x_abicp ,
200
+ for name , f in {
201
+ "is_ {}_none_{}" .format (py , suffix ): _flags .whl_plat ,
202
+ "is_ {}3_none_{}" .format (py , suffix ): _flags .whl_plat_py3 ,
203
+ "is_ {}3_abi3_{}" .format (py , suffix ): _flags .whl_plat_py3_abi3 ,
204
+ "is_ {}_none_{}" .format (pycp , suffix ): _flags .whl_plat_pycp3x ,
205
+ "is_ {}_abi3_{}" .format (pycp , suffix ): _flags .whl_plat_pycp3x_abi3 ,
206
+ "is_ {}_cp_{}" .format (pycp , suffix ): _flags .whl_plat_pycp3x_abicp ,
210
207
}.items ():
211
208
if f in flag_values :
212
209
# This should never happen as all of the different whls should have
@@ -215,8 +212,8 @@ def _whl_config_settings(*, suffix, plat_flag_values, **kwargs):
215
212
else :
216
213
flag_values [f ] = ""
217
214
218
- _whl_config_setting (
219
- name = n ,
215
+ config_setting_rule (
216
+ name = name ,
220
217
flag_values = flag_values ,
221
218
** kwargs
222
219
)
@@ -287,29 +284,23 @@ def _plat_flag_values(os, cpu, osx_versions, glibc_versions, muslc_versions):
287
284
288
285
return ret
289
286
290
- def _whl_config_setting (* , name , flag_values , config_setting_rule = None , ** kwargs ):
291
- config_setting_rule = config_setting_rule or _config_setting_or
292
- config_setting_rule (
293
- name = "is_" + name ,
294
- flag_values = flag_values ,
295
- use_whl_flag = FLAGS .is_pip_whl_only ,
296
- ** kwargs
297
- )
298
-
299
- def _sdist_config_setting (* , name , config_setting_rule = None , ** kwargs ):
300
- config_setting_rule = config_setting_rule or _config_setting_or
301
- config_setting_rule (
302
- name = "is_" + name ,
303
- use_whl_flag = FLAGS .is_pip_whl_no ,
304
- ** kwargs
305
- )
287
+ def _dist_config_setting (* , name , is_pip_whl , python_version = "" , ** kwargs ):
288
+ """A macro to create a target that matches is_pip_whl_auto and one more value.
306
289
307
- def _config_setting_or (* , name , use_whl_flag , python_version = "" , ** kwargs ):
290
+ Args:
291
+ name: The name of the public target.
292
+ is_pip_whl: The config setting to match in addition to
293
+ `is_pip_whl_auto` when evaluating the config setting.
294
+ python_version: The python version to match.
295
+ **kwargs: The kwargs passed to the config_setting rule. Visibility of
296
+ the main alias target is also taken from the kwargs.
297
+ """
308
298
if python_version :
309
299
_name = name .replace ("is_cp{}" .format (python_version ), "_is" )
310
300
else :
311
301
_name = "_" + name
312
302
303
+ # First match by the python version
313
304
is_python = ":is_python_" + (python_version or "default" )
314
305
visibility = kwargs .get ("visibility" )
315
306
native .alias (
@@ -326,20 +317,17 @@ def _config_setting_or(*, name, use_whl_flag, python_version = "", **kwargs):
326
317
# `python_version` setting.
327
318
return
328
319
329
- match_name = "_{}_1" .format (name )
330
- native .config_setting (
331
- name = match_name ,
332
- flag_values = {
333
- _flags .dist : "" ,
334
- } | kwargs .pop ("flag_values" , {}),
335
- ** kwargs
336
- )
320
+ config_setting_name = "_{}_setting" .format (name )
321
+ native .config_setting (name = config_setting_name , ** kwargs )
322
+
323
+ # Next match by the `pip_whl` flag value and then match by the flags that
324
+ # are intrinsic to the distribution.
337
325
native .alias (
338
326
name = _name ,
339
327
actual = select ({
340
- FLAGS .is_pip_whl_auto : match_name ,
341
- use_whl_flag : match_name ,
342
- "//conditions:default" : use_whl_flag ,
328
+ "//conditions:default" : FLAGS .is_pip_whl_auto ,
329
+ FLAGS . is_pip_whl_auto : config_setting_name ,
330
+ is_pip_whl : config_setting_name ,
343
331
}),
344
332
visibility = visibility ,
345
333
)
0 commit comments