@@ -163,7 +163,6 @@ def _product_to_dto(product):
163
163
def _processed_target (
164
164
* ,
165
165
attrs_info ,
166
- defines ,
167
166
dependencies ,
168
167
inputs ,
169
168
linker_inputs ,
@@ -178,7 +177,6 @@ def _processed_target(
178
177
179
178
Args:
180
179
attrs_info: The `InputFileAttributesInfo` for the target.
181
- defines: The value returned from `_process_defines()`.
182
180
dependencies: A `list` of target ids of direct dependencies of this
183
181
target.
184
182
inputs: A value as returned from `input_files.collect()` that will
@@ -202,7 +200,6 @@ def _processed_target(
202
200
"""
203
201
return struct (
204
202
attrs_info = attrs_info ,
205
- defines = defines ,
206
203
dependencies = dependencies ,
207
204
inputs = inputs ,
208
205
linker_inputs = linker_inputs ,
@@ -600,21 +597,18 @@ The xcodeproj rule requires {} rules to have a single library dep. {} has {}.\
600
597
transitive_infos = transitive_infos ,
601
598
)
602
599
600
+ cc_info = target [CcInfo ] if CcInfo in target else None
601
+ _process_defines (
602
+ cc_info = cc_info ,
603
+ build_settings = build_settings ,
604
+ )
603
605
search_paths = _process_search_paths (
604
- cc_info = target [ CcInfo ] if CcInfo in target else None ,
606
+ cc_info = cc_info ,
605
607
opts_search_paths = opts_search_paths ,
606
608
)
607
609
608
610
return _processed_target (
609
611
attrs_info = attrs_info ,
610
- defines = _process_defines (
611
- attrs_info = attrs_info ,
612
- is_swift = is_swift ,
613
- defines = getattr (ctx .rule .attr , "defines" , []),
614
- local_defines = getattr (ctx .rule .attr , "local_defines" , []),
615
- transitive_infos = transitive_infos ,
616
- build_settings = build_settings ,
617
- ),
618
612
dependencies = dependencies ,
619
613
inputs = inputs ,
620
614
linker_inputs = linker_inputs ,
@@ -766,21 +760,18 @@ def _process_library_target(*, ctx, target, transitive_infos):
766
760
transitive_infos = transitive_infos ,
767
761
)
768
762
763
+ cc_info = target [CcInfo ] if CcInfo in target else None
764
+ _process_defines (
765
+ cc_info = cc_info ,
766
+ build_settings = build_settings ,
767
+ )
769
768
search_paths = _process_search_paths (
770
- cc_info = target [ CcInfo ] if CcInfo in target else None ,
769
+ cc_info = cc_info ,
771
770
opts_search_paths = opts_search_paths ,
772
771
)
773
772
774
773
return _processed_target (
775
774
attrs_info = attrs_info ,
776
- defines = _process_defines (
777
- attrs_info = attrs_info ,
778
- is_swift = SwiftInfo in target ,
779
- defines = getattr (ctx .rule .attr , "defines" , []),
780
- local_defines = getattr (ctx .rule .attr , "local_defines" , []),
781
- transitive_infos = transitive_infos ,
782
- build_settings = build_settings ,
783
- ),
784
775
dependencies = dependencies ,
785
776
inputs = inputs ,
786
777
linker_inputs = linker_inputs ,
@@ -912,14 +903,6 @@ def _process_resource_target(*, ctx, target, transitive_infos):
912
903
913
904
return _processed_target (
914
905
attrs_info = attrs_info ,
915
- defines = _process_defines (
916
- attrs_info = attrs_info ,
917
- is_swift = False ,
918
- defines = [],
919
- local_defines = [],
920
- transitive_infos = transitive_infos ,
921
- build_settings = build_settings ,
922
- ),
923
906
dependencies = dependencies ,
924
907
inputs = inputs ,
925
908
linker_inputs = linker_inputs ,
@@ -994,14 +977,6 @@ def _process_non_xcode_target(*, ctx, target, transitive_infos):
994
977
995
978
return _processed_target (
996
979
attrs_info = attrs_info ,
997
- defines = _process_defines (
998
- attrs_info = attrs_info ,
999
- is_swift = SwiftInfo in target ,
1000
- defines = getattr (ctx .rule .attr , "defines" , []),
1001
- local_defines = getattr (ctx .rule .attr , "local_defines" , []),
1002
- transitive_infos = transitive_infos ,
1003
- build_settings = None ,
1004
- ),
1005
980
dependencies = _process_dependencies (
1006
981
attrs_info = attrs_info ,
1007
982
transitive_infos = transitive_infos ,
@@ -1052,7 +1027,6 @@ def _should_skip_target(*, ctx, target):
1052
1027
1053
1028
def _target_info_fields (
1054
1029
* ,
1055
- defines ,
1056
1030
dependencies ,
1057
1031
inputs ,
1058
1032
linker_inputs ,
@@ -1069,7 +1043,6 @@ def _target_info_fields(
1069
1043
This should be merged with other fields to fully create an `XcodeProjInfo`.
1070
1044
1071
1045
Args:
1072
- defines: Maps to `XcodeProjInfo.defines`.
1073
1046
dependencies: Maps to the `XcodeProjInfo.dependencies` field.
1074
1047
inputs: Maps to the `XcodeProjInfo.inputs` field.
1075
1048
linker_inputs: Maps to the `XcodeProjInfo.linker_inputs` field.
@@ -1087,7 +1060,6 @@ def _target_info_fields(
1087
1060
Returns:
1088
1061
A `dict` containing the following fields:
1089
1062
1090
- * `defines`
1091
1063
* `dependencies`
1092
1064
* `generated_inputs`
1093
1065
* `inputs`
@@ -1102,7 +1074,6 @@ def _target_info_fields(
1102
1074
* `xcode_targets`
1103
1075
"""
1104
1076
return {
1105
- "defines" : defines ,
1106
1077
"dependencies" : dependencies ,
1107
1078
"inputs" : inputs ,
1108
1079
"linker_inputs" : linker_inputs ,
@@ -1132,14 +1103,6 @@ def _skip_target(*, target, transitive_infos):
1132
1103
`transitive_infos`.
1133
1104
"""
1134
1105
return _target_info_fields (
1135
- defines = _process_defines (
1136
- attrs_info = None ,
1137
- is_swift = False ,
1138
- defines = [],
1139
- local_defines = [],
1140
- transitive_infos = transitive_infos ,
1141
- build_settings = None ,
1142
- ),
1143
1106
dependencies = _process_dependencies (
1144
1107
attrs_info = None ,
1145
1108
transitive_infos = transitive_infos ,
@@ -1204,28 +1167,9 @@ def _process_dependencies(*, attrs_info, transitive_infos):
1204
1167
1205
1168
def _process_defines (
1206
1169
* ,
1207
- attrs_info ,
1208
- is_swift ,
1209
- defines ,
1210
- local_defines ,
1211
- transitive_infos ,
1170
+ cc_info ,
1212
1171
build_settings ):
1213
- transitive_cc_defines = []
1214
- for attr , info in transitive_infos :
1215
- if (attrs_info and
1216
- attrs_info .xcode_targets .get (attr ) != info .target_type ):
1217
- continue
1218
- transitive_defines = info .defines
1219
- transitive_cc_defines .extend (transitive_defines .cc_defines )
1220
-
1221
- # We only want to use this target's defines if it's a Swift target
1222
- if is_swift :
1223
- cc_defines = transitive_cc_defines
1224
- else :
1225
- transitive_cc_defines .extend (defines )
1226
- cc_defines = transitive_cc_defines + local_defines
1227
-
1228
- if build_settings :
1172
+ if cc_info and build_settings != None :
1229
1173
# We don't set `SWIFT_ACTIVE_COMPILATION_CONDITIONS` because the way we
1230
1174
# process Swift compile options already accounts for `defines`
1231
1175
@@ -1241,20 +1185,27 @@ def _process_defines(
1241
1185
# becomes an issue in practice, we can refactor `process_copts` to
1242
1186
# support this better.
1243
1187
1188
+ defines = depset (
1189
+ transitive = [
1190
+ cc_info .compilation_context .defines ,
1191
+ cc_info .compilation_context .local_defines ,
1192
+ ],
1193
+ )
1194
+ escaped_defines = [
1195
+ define .replace ("\\ " , "\\ \\ " ).replace ('"' , '\\ "' )
1196
+ for define in defines .to_list ()
1197
+ ]
1198
+
1244
1199
setting = build_settings .get (
1245
1200
"GCC_PREPROCESSOR_DEFINITIONS" ,
1246
1201
[],
1247
- ) + cc_defines
1202
+ ) + escaped_defines
1248
1203
1249
1204
# Remove duplicates
1250
1205
setting = reversed (uniq (reversed (setting )))
1251
1206
1252
1207
set_if_true (build_settings , "GCC_PREPROCESSOR_DEFINITIONS" , setting )
1253
1208
1254
- return struct (
1255
- cc_defines = transitive_cc_defines ,
1256
- )
1257
-
1258
1209
# TODO: Refactor this into a search_paths module
1259
1210
def _process_search_paths (
1260
1211
* ,
@@ -1437,7 +1388,6 @@ def _process_target(*, ctx, target, transitive_infos):
1437
1388
)
1438
1389
1439
1390
return _target_info_fields (
1440
- defines = processed_target .defines ,
1441
1391
dependencies = processed_target .dependencies ,
1442
1392
inputs = processed_target .inputs ,
1443
1393
linker_inputs = processed_target .linker_inputs ,
0 commit comments