Skip to content

Commit 38aee31

Browse files
googlewaltcopybara-github
authored andcommitted
Add --incompatible_objc_provider_remove_compile_info flag
When set to true, the flag turns off the compile info/merge_zip Starlark APIs in ObjcProvider. RELNOTES: --incompatible_objc_provider_remove_compile_info turns off the compile info/mege_zip Starlark APIs in ObjcProvider. See #11359. PiperOrigin-RevId: 316568134
1 parent afec50e commit 38aee31

File tree

8 files changed

+319
-100
lines changed

8 files changed

+319
-100
lines changed

src/main/java/com/google/devtools/build/lib/packages/StarlarkSemanticsOptions.java

+13
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,18 @@ public class StarlarkSemanticsOptions extends OptionsBase implements Serializabl
621621
+ "instead of linkopts to cc_toolchain_config")
622622
public boolean incompatibleLinkoptsToLinkLibs;
623623

624+
@Option(
625+
name = "incompatible_objc_provider_remove_compile_info",
626+
defaultValue = "false",
627+
documentationCategory = OptionDocumentationCategory.STARLARK_SEMANTICS,
628+
effectTags = {OptionEffectTag.BUILD_FILE_SEMANTICS},
629+
metadataTags = {
630+
OptionMetadataTag.INCOMPATIBLE_CHANGE,
631+
OptionMetadataTag.TRIGGERED_BY_ALL_INCOMPATIBLE_CHANGES
632+
},
633+
help = "If set to true, the ObjcProvider's APIs for compile info/merge_zip will be removed.")
634+
public boolean incompatibleObjcProviderRemoveCompileInfo;
635+
624636
@Option(
625637
name = "max_computation_steps",
626638
defaultValue = "0",
@@ -697,6 +709,7 @@ public StarlarkSemantics toStarlarkSemantics() {
697709
.incompatibleRequireLinkerInputCcApi(incompatibleRequireLinkerInputCcApi)
698710
.incompatibleRestrictStringEscapes(incompatibleRestrictStringEscapes)
699711
.incompatibleLinkoptsToLinkLibs(incompatibleLinkoptsToLinkLibs)
712+
.incompatibleObjcProviderRemoveCompileInfo(incompatibleObjcProviderRemoveCompileInfo)
700713
.maxComputationSteps(maxComputationSteps)
701714
.recordRuleInstantiationCallstack(recordRuleInstantiationCallstack)
702715
.build();

src/main/java/com/google/devtools/build/lib/rules/objc/AppleStarlarkCommon.java

+15-2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import com.google.devtools.build.lib.syntax.Location;
4848
import com.google.devtools.build.lib.syntax.Sequence;
4949
import com.google.devtools.build.lib.syntax.Starlark;
50+
import com.google.devtools.build.lib.syntax.StarlarkSemantics;
5051
import com.google.devtools.build.lib.syntax.StarlarkThread;
5152
import com.google.devtools.build.lib.syntax.StarlarkValue;
5253
import java.util.Map;
@@ -62,6 +63,15 @@ public class AppleStarlarkCommon
6263
XcodeConfigInfo,
6364
ApplePlatform> {
6465

66+
@VisibleForTesting
67+
public static final String DEPRECATED_KEY_ERROR =
68+
"Key '%s' no longer supported in ObjcProvider (use CcInfo instead).";
69+
70+
@VisibleForTesting
71+
public static final String BAD_DIRECT_DEP_PROVIDERS_ERROR =
72+
"Argument 'direct_dep_providers' no longer supported. Please use 'strict_include' field "
73+
+ "in ObjcProvider.";
74+
6575
@VisibleForTesting
6676
public static final String BAD_KEY_ERROR =
6777
"Argument %s not a recognized key,"
@@ -188,8 +198,8 @@ public SplitTransitionProviderApi getMultiArchSplitProvider() {
188198
// This method is registered statically for Starlark, and never called directly.
189199
public ObjcProvider newObjcProvider(Boolean usesSwift, Dict<?, ?> kwargs, StarlarkThread thread)
190200
throws EvalException {
191-
ObjcProvider.StarlarkBuilder resultBuilder =
192-
new ObjcProvider.StarlarkBuilder(thread.getSemantics());
201+
StarlarkSemantics semantics = thread.getSemantics();
202+
ObjcProvider.StarlarkBuilder resultBuilder = new ObjcProvider.StarlarkBuilder(semantics);
193203
if (usesSwift) {
194204
resultBuilder.add(ObjcProvider.FLAG, ObjcProvider.Flag.USES_SWIFT);
195205
}
@@ -202,6 +212,9 @@ public ObjcProvider newObjcProvider(Boolean usesSwift, Dict<?, ?> kwargs, Starla
202212
} else if (entry.getKey().equals("providers")) {
203213
resultBuilder.addProvidersFromStarlark(entry.getValue());
204214
} else if (entry.getKey().equals("direct_dep_providers")) {
215+
if (semantics.incompatibleObjcProviderRemoveCompileInfo()) {
216+
throw new EvalException(null, BAD_DIRECT_DEP_PROVIDERS_ERROR);
217+
}
205218
resultBuilder.addDirectDepProvidersFromStarlark(entry.getValue());
206219
} else {
207220
throw new EvalException(null, String.format(BAD_KEY_ERROR, entry.getKey()));

src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProvider.java

+78-49
Original file line numberDiff line numberDiff line change
@@ -318,10 +318,13 @@ public enum Flag {
318318

319319
private final CcCompilationContext ccCompilationContext;
320320

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 =
323326
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);
325328

326329
/** All keys in ObjcProvider that will be passed in the corresponding Starlark provider. */
327330
static final ImmutableList<Key<?>> KEYS_FOR_STARLARK =
@@ -990,6 +993,10 @@ public Builder(StarlarkSemantics semantics) {
990993
this.starlarkSemantics = semantics;
991994
}
992995

996+
public StarlarkSemantics getStarlarkSemantics() {
997+
return starlarkSemantics;
998+
}
999+
9931000
private static void maybeAddEmptyBuilder(Map<Key<?>, NestedSetBuilder<?>> set, Key<?> key) {
9941001
set.computeIfAbsent(key, k -> new NestedSetBuilder<>(k.order));
9951002
}
@@ -1185,53 +1192,17 @@ public StarlarkBuilder(StarlarkSemantics semantics) {
11851192
*/
11861193
void addElementsFromStarlark(Key<?> key, Object starlarkToAdd) throws EvalException {
11871194
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);
12131205
}
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()));
12351206
}
12361207
} else {
12371208
uncheckedAddTransitive(key, toAdd);
@@ -1242,6 +1213,64 @@ void addElementsFromStarlark(Key<?> key, Object starlarkToAdd) throws EvalExcept
12421213
}
12431214
}
12441215

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+
12451274
/**
12461275
* Adds the given providers from Starlark. An error is thrown if toAdd is not an iterable of
12471276
* ObjcProvider instances.

src/main/java/com/google/devtools/build/lib/skylarkbuildapi/apple/ObjcProviderApi.java

+17-8
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import com.google.devtools.build.lib.skylarkbuildapi.FileApi;
1919
import com.google.devtools.build.lib.skylarkbuildapi.cpp.CcCompilationContextApi;
2020
import com.google.devtools.build.lib.syntax.Sequence;
21+
import com.google.devtools.build.lib.syntax.StarlarkSemantics.FlagIdentifier;
2122
import com.google.devtools.build.lib.syntax.StarlarkValue;
2223
import net.starlark.java.annot.StarlarkBuiltin;
2324
import net.starlark.java.annot.StarlarkDocumentationCategory;
@@ -38,7 +39,8 @@ public interface ObjcProviderApi<FileApiT extends FileApi> extends StarlarkValue
3839
structField = true,
3940
doc =
4041
"A set of strings from 'defines' attributes. These are to be passed as '-D' flags to "
41-
+ "all invocations of the compiler for this target and all depending targets.")
42+
+ "all invocations of the compiler for this target and all depending targets.",
43+
disableWithFlag = FlagIdentifier.INCOMPATIBLE_OBJC_PROVIDER_REMOVE_COMPILE_INFO)
4244
Depset /*<String>*/ defineForStarlark();
4345

4446
@StarlarkMethod(
@@ -60,7 +62,8 @@ public interface ObjcProviderApi<FileApiT extends FileApi> extends StarlarkValue
6062
structField = true,
6163
doc =
6264
"Exec paths of .framework directories corresponding to frameworks to include "
63-
+ "in search paths, but not to link.")
65+
+ "in search paths, but not to link.",
66+
disableWithFlag = FlagIdentifier.INCOMPATIBLE_OBJC_PROVIDER_REMOVE_COMPILE_INFO)
6467
Depset /*<String>*/ frameworkIncludeForStarlark();
6568

6669
@StarlarkMethod(
@@ -72,7 +75,8 @@ public interface ObjcProviderApi<FileApiT extends FileApi> extends StarlarkValue
7275
@StarlarkMethod(
7376
name = "header",
7477
structField = true,
75-
doc = "All header files. These may be either public or private headers.")
78+
doc = "All header files. These may be either public or private headers.",
79+
disableWithFlag = FlagIdentifier.INCOMPATIBLE_OBJC_PROVIDER_REMOVE_COMPILE_INFO)
7680
Depset /*<FileApiT>*/ headerForStarlark();
7781

7882
@StarlarkMethod(
@@ -94,7 +98,8 @@ public interface ObjcProviderApi<FileApiT extends FileApi> extends StarlarkValue
9498
structField = true,
9599
doc =
96100
"Include search paths specified with '-I' on the command line. Also known as "
97-
+ "header search paths (and distinct from <em>user</em> header search paths).")
101+
+ "header search paths (and distinct from <em>user</em> header search paths).",
102+
disableWithFlag = FlagIdentifier.INCOMPATIBLE_OBJC_PROVIDER_REMOVE_COMPILE_INFO)
98103
Depset includeForStarlark();
99104

100105
@StarlarkMethod(
@@ -108,13 +113,15 @@ public interface ObjcProviderApi<FileApiT extends FileApi> extends StarlarkValue
108113
@StarlarkMethod(
109114
name = "include_system",
110115
structField = true,
111-
doc = "System include search paths (typically specified with -isystem).")
116+
doc = "System include search paths (typically specified with -isystem).",
117+
disableWithFlag = FlagIdentifier.INCOMPATIBLE_OBJC_PROVIDER_REMOVE_COMPILE_INFO)
112118
Depset systemIncludeForStarlark();
113119

114120
@StarlarkMethod(
115121
name = "iquote",
116122
structField = true,
117-
doc = "User header search paths (typically specified with -iquote).")
123+
doc = "User header search paths (typically specified with -iquote).",
124+
disableWithFlag = FlagIdentifier.INCOMPATIBLE_OBJC_PROVIDER_REMOVE_COMPILE_INFO)
118125
Depset quoteIncludeForStarlark();
119126

120127
@StarlarkMethod(
@@ -168,7 +175,8 @@ public interface ObjcProviderApi<FileApiT extends FileApi> extends StarlarkValue
168175
doc =
169176
"Merge zips to include in the bundle. The entries of these zip files are included "
170177
+ "in the final bundle with the same path. The entries in the merge zips should not "
171-
+ "include the bundle root path (e.g. 'Foo.app').")
178+
+ "include the bundle root path (e.g. 'Foo.app').",
179+
disableWithFlag = FlagIdentifier.INCOMPATIBLE_OBJC_PROVIDER_REMOVE_COMPILE_INFO)
172180
Depset /*<FileApiT>*/ mergeZip();
173181

174182
@StarlarkMethod(
@@ -276,6 +284,7 @@ public interface ObjcProviderApi<FileApiT extends FileApi> extends StarlarkValue
276284
doc =
277285
"Returns the embedded <code>CcCompilationContext</code> that contains the"
278286
+ "provider's compilation information.",
279-
structField = true)
287+
structField = true,
288+
disableWithFlag = FlagIdentifier.INCOMPATIBLE_OBJC_PROVIDER_REMOVE_COMPILE_INFO)
280289
CcCompilationContextApi<FileApiT> getCcCompilationContext();
281290
}

src/main/java/com/google/devtools/build/lib/syntax/StarlarkSemantics.java

+9
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ private FlagIdentifier() {} // uninstantiable
9999
public static final String INCOMPATIBLE_NO_ATTR_LICENSE = "incompatible_no_attr_license";
100100
public static final String INCOMPATIBLE_ALLOW_TAGS_PROPAGATION =
101101
"incompatible_allow_tags_propagation";
102+
public static final String INCOMPATIBLE_OBJC_PROVIDER_REMOVE_COMPILE_INFO =
103+
"incompatible_objc_provider_remove_compile_info";
102104
public static final String INCOMPATIBLE_REQUIRE_LINKER_INPUT_CC_API =
103105
"incompatible_require_linker_input_cc_api";
104106
public static final String INCOMPATIBLE_LINKOPTS_TO_LINKLIBS =
@@ -147,6 +149,8 @@ public boolean flagValue(String flag) {
147149
return incompatibleNoAttrLicense();
148150
case FlagIdentifier.INCOMPATIBLE_ALLOW_TAGS_PROPAGATION:
149151
return experimentalAllowTagsPropagation();
152+
case FlagIdentifier.INCOMPATIBLE_OBJC_PROVIDER_REMOVE_COMPILE_INFO:
153+
return incompatibleObjcProviderRemoveCompileInfo();
150154
case FlagIdentifier.INCOMPATIBLE_REQUIRE_LINKER_INPUT_CC_API:
151155
return incompatibleRequireLinkerInputCcApi();
152156
case FlagIdentifier.INCOMPATIBLE_LINKOPTS_TO_LINKLIBS:
@@ -264,6 +268,8 @@ boolean isFeatureEnabledBasedOnTogglingFlags(String enablingFlag, String disabli
264268

265269
public abstract boolean incompatibleDepsetForLibrariesToLinkGetter();
266270

271+
public abstract boolean incompatibleObjcProviderRemoveCompileInfo();
272+
267273
public abstract boolean incompatibleRequireLinkerInputCcApi();
268274

269275
public abstract boolean incompatibleRestrictStringEscapes();
@@ -347,6 +353,7 @@ public static Builder builderWithDefaults() {
347353
.internalStarlarkFlagTestCanary(false)
348354
.incompatibleDoNotSplitLinkingCmdline(true)
349355
.incompatibleDepsetForLibrariesToLinkGetter(true)
356+
.incompatibleObjcProviderRemoveCompileInfo(false)
350357
.incompatibleRequireLinkerInputCcApi(false)
351358
.incompatibleRestrictStringEscapes(false)
352359
.incompatibleUseCcConfigureFromRulesCc(false)
@@ -432,6 +439,8 @@ public abstract static class Builder {
432439

433440
public abstract Builder incompatibleDepsetForLibrariesToLinkGetter(boolean value);
434441

442+
public abstract Builder incompatibleObjcProviderRemoveCompileInfo(boolean value);
443+
435444
public abstract Builder incompatibleRequireLinkerInputCcApi(boolean value);
436445

437446
public abstract Builder incompatibleRestrictStringEscapes(boolean value);

src/test/java/com/google/devtools/build/lib/packages/StarlarkSemanticsConsistencyTest.java

+2
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ private static StarlarkSemanticsOptions buildRandomOptions(Random rand) throws E
155155
"--incompatible_no_implicit_file_export=" + rand.nextBoolean(),
156156
"--incompatible_no_rule_outputs_param=" + rand.nextBoolean(),
157157
"--incompatible_no_support_tools_in_action_inputs=" + rand.nextBoolean(),
158+
"--incompatible_objc_provider_remove_compile_info=" + rand.nextBoolean(),
158159
"--incompatible_run_shell_command_string=" + rand.nextBoolean(),
159160
"--incompatible_string_replace_count=" + rand.nextBoolean(),
160161
"--incompatible_visibility_private_attributes_at_definition=" + rand.nextBoolean(),
@@ -207,6 +208,7 @@ private static StarlarkSemantics buildRandomSemantics(Random rand) {
207208
.incompatibleNoImplicitFileExport(rand.nextBoolean())
208209
.incompatibleNoRuleOutputsParam(rand.nextBoolean())
209210
.incompatibleNoSupportToolsInActionInputs(rand.nextBoolean())
211+
.incompatibleObjcProviderRemoveCompileInfo(rand.nextBoolean())
210212
.incompatibleRunShellCommandString(rand.nextBoolean())
211213
.incompatibleStringReplaceCount(rand.nextBoolean())
212214
.incompatibleVisibilityPrivateAttributesAtDefinition(rand.nextBoolean())

0 commit comments

Comments
 (0)