@@ -318,10 +318,13 @@ public enum Flag {
318
318
319
319
private final CcCompilationContext ccCompilationContext ;
320
320
321
- /** Keys corresponding to compile information that has been migrated to CcCompilationContext. */
322
- static final ImmutableSet <Key <?>> KEYS_FOR_COMPILE_INFO =
321
+ /**
322
+ * Keys that are deprecated and will be removed. These include compile information that has been
323
+ * migrated to CcCompilationContext, plus MERGE_ZIP.
324
+ */
325
+ static final ImmutableSet <Key <?>> DEPRECATED_KEYS =
323
326
ImmutableSet .<Key <?>>of (
324
- DEFINE , FRAMEWORK_SEARCH_PATHS , HEADER , INCLUDE , INCLUDE_SYSTEM , IQUOTE );
327
+ DEFINE , FRAMEWORK_SEARCH_PATHS , HEADER , INCLUDE , INCLUDE_SYSTEM , IQUOTE , MERGE_ZIP );
325
328
326
329
/** All keys in ObjcProvider that will be passed in the corresponding Starlark provider. */
327
330
static final ImmutableList <Key <?>> KEYS_FOR_STARLARK =
@@ -990,6 +993,10 @@ public Builder(StarlarkSemantics semantics) {
990
993
this .starlarkSemantics = semantics ;
991
994
}
992
995
996
+ public StarlarkSemantics getStarlarkSemantics () {
997
+ return starlarkSemantics ;
998
+ }
999
+
993
1000
private static void maybeAddEmptyBuilder (Map <Key <?>, NestedSetBuilder <?>> set , Key <?> key ) {
994
1001
set .computeIfAbsent (key , k -> new NestedSetBuilder <>(k .order ));
995
1002
}
@@ -1185,53 +1192,17 @@ public StarlarkBuilder(StarlarkSemantics semantics) {
1185
1192
*/
1186
1193
void addElementsFromStarlark (Key <?> key , Object starlarkToAdd ) throws EvalException {
1187
1194
NestedSet <?> toAdd = ObjcProviderStarlarkConverters .convertToJava (key , starlarkToAdd );
1188
- if (KEYS_FOR_COMPILE_INFO .contains (key )) {
1189
- String keyName = key .getStarlarkKeyName ();
1190
-
1191
- if (key == DEFINE ) {
1192
- ccCompilationContextBuilder .addDefines (
1193
- Depset .noneableCast (starlarkToAdd , String .class , keyName ));
1194
- } else if (key == FRAMEWORK_SEARCH_PATHS ) {
1195
- // Due to legacy reasons, There is a mismatch between the starlark interface for the
1196
- // framework search path, and the internal representation. The interface specifies that
1197
- // framework_search_paths include the framework directories, but internally we only store
1198
- // their parents. We will eventually clean up the interface, but for now we need to do
1199
- // this ugly conversion.
1200
-
1201
- ImmutableList <PathFragment > frameworks =
1202
- Depset .noneableCast (starlarkToAdd , String .class , keyName ).toList ().stream ()
1203
- .map (x -> PathFragment .create (x ))
1204
- .collect (ImmutableList .toImmutableList ());
1205
-
1206
- ImmutableList .Builder <PathFragment > frameworkSearchPaths = ImmutableList .builder ();
1207
- for (PathFragment framework : frameworks ) {
1208
- if (!framework .getSafePathString ().endsWith (FRAMEWORK_SUFFIX )) {
1209
- throw new EvalException (
1210
- null , String .format (AppleStarlarkCommon .BAD_FRAMEWORK_PATH_ERROR , framework ));
1211
- }
1212
- frameworkSearchPaths .add (framework .getParentDirectory ());
1195
+ if (DEPRECATED_KEYS .contains (key )) {
1196
+ if (getStarlarkSemantics ().incompatibleObjcProviderRemoveCompileInfo ()) {
1197
+ if (!KEYS_FOR_DIRECT .contains (key )) {
1198
+ throw new EvalException (
1199
+ null ,
1200
+ String .format (AppleStarlarkCommon .DEPRECATED_KEY_ERROR , key .getStarlarkKeyName ()));
1201
+ }
1202
+ } else {
1203
+ if (!addCompileElementsFromStarlark (key , starlarkToAdd )) {
1204
+ uncheckedAddTransitive (key , toAdd );
1213
1205
}
1214
- ccCompilationContextBuilder .addFrameworkIncludeDirs (frameworkSearchPaths .build ());
1215
- } else if (key == HEADER ) {
1216
- ImmutableList <Artifact > hdrs =
1217
- Depset .noneableCast (starlarkToAdd , Artifact .class , keyName ).toList ();
1218
- ccCompilationContextBuilder .addDeclaredIncludeSrcs (hdrs );
1219
- ccCompilationContextBuilder .addTextualHdrs (hdrs );
1220
- } else if (key == INCLUDE ) {
1221
- ccCompilationContextBuilder .addIncludeDirs (
1222
- Depset .noneableCast (starlarkToAdd , String .class , keyName ).toList ().stream ()
1223
- .map (x -> PathFragment .create (x ))
1224
- .collect (ImmutableList .toImmutableList ()));
1225
- } else if (key == INCLUDE_SYSTEM ) {
1226
- ccCompilationContextBuilder .addSystemIncludeDirs (
1227
- Depset .noneableCast (starlarkToAdd , String .class , keyName ).toList ().stream ()
1228
- .map (x -> PathFragment .create (x ))
1229
- .collect (ImmutableList .toImmutableList ()));
1230
- } else if (key == IQUOTE ) {
1231
- ccCompilationContextBuilder .addQuoteIncludeDirs (
1232
- Depset .noneableCast (starlarkToAdd , String .class , keyName ).toList ().stream ()
1233
- .map (x -> PathFragment .create (x ))
1234
- .collect (ImmutableList .toImmutableList ()));
1235
1206
}
1236
1207
} else {
1237
1208
uncheckedAddTransitive (key , toAdd );
@@ -1242,6 +1213,64 @@ void addElementsFromStarlark(Key<?> key, Object starlarkToAdd) throws EvalExcept
1242
1213
}
1243
1214
}
1244
1215
1216
+ private boolean addCompileElementsFromStarlark (Key <?> key , Object starlarkToAdd )
1217
+ throws EvalException {
1218
+ String keyName = key .getStarlarkKeyName ();
1219
+
1220
+ if (key == DEFINE ) {
1221
+ ccCompilationContextBuilder .addDefines (
1222
+ Depset .noneableCast (starlarkToAdd , String .class , keyName ));
1223
+ return true ;
1224
+ } else if (key == FRAMEWORK_SEARCH_PATHS ) {
1225
+ // Due to legacy reasons, There is a mismatch between the starlark interface for the
1226
+ // framework search path, and the internal representation. The interface specifies that
1227
+ // framework_search_paths include the framework directories, but internally we only store
1228
+ // their parents. We will eventually clean up the interface, but for now we need to do
1229
+ // this ugly conversion.
1230
+
1231
+ ImmutableList <PathFragment > frameworks =
1232
+ Depset .noneableCast (starlarkToAdd , String .class , keyName ).toList ().stream ()
1233
+ .map (PathFragment ::create )
1234
+ .collect (ImmutableList .toImmutableList ());
1235
+
1236
+ ImmutableList .Builder <PathFragment > frameworkSearchPaths = ImmutableList .builder ();
1237
+ for (PathFragment framework : frameworks ) {
1238
+ if (!framework .getSafePathString ().endsWith (FRAMEWORK_SUFFIX )) {
1239
+ throw new EvalException (
1240
+ null , String .format (AppleStarlarkCommon .BAD_FRAMEWORK_PATH_ERROR , framework ));
1241
+ }
1242
+ frameworkSearchPaths .add (framework .getParentDirectory ());
1243
+ }
1244
+ ccCompilationContextBuilder .addFrameworkIncludeDirs (frameworkSearchPaths .build ());
1245
+ return true ;
1246
+ } else if (key == HEADER ) {
1247
+ ImmutableList <Artifact > hdrs =
1248
+ Depset .noneableCast (starlarkToAdd , Artifact .class , keyName ).toList ();
1249
+ ccCompilationContextBuilder .addDeclaredIncludeSrcs (hdrs );
1250
+ ccCompilationContextBuilder .addTextualHdrs (hdrs );
1251
+ return true ;
1252
+ } else if (key == INCLUDE ) {
1253
+ ccCompilationContextBuilder .addIncludeDirs (
1254
+ Depset .noneableCast (starlarkToAdd , String .class , keyName ).toList ().stream ()
1255
+ .map (PathFragment ::create )
1256
+ .collect (ImmutableList .toImmutableList ()));
1257
+ return true ;
1258
+ } else if (key == INCLUDE_SYSTEM ) {
1259
+ ccCompilationContextBuilder .addSystemIncludeDirs (
1260
+ Depset .noneableCast (starlarkToAdd , String .class , keyName ).toList ().stream ()
1261
+ .map (PathFragment ::create )
1262
+ .collect (ImmutableList .toImmutableList ()));
1263
+ return true ;
1264
+ } else if (key == IQUOTE ) {
1265
+ ccCompilationContextBuilder .addQuoteIncludeDirs (
1266
+ Depset .noneableCast (starlarkToAdd , String .class , keyName ).toList ().stream ()
1267
+ .map (PathFragment ::create )
1268
+ .collect (ImmutableList .toImmutableList ()));
1269
+ return true ;
1270
+ }
1271
+ return false ;
1272
+ }
1273
+
1245
1274
/**
1246
1275
* Adds the given providers from Starlark. An error is thrown if toAdd is not an iterable of
1247
1276
* ObjcProvider instances.
0 commit comments