Adds --incompatible_disable_objc_library_resources to disable resource attributes in objc_library.
RELNOTES: Adds --incompatible_disable_objc_library_resources to disable resource attributes in objc_library. Please migrate these attributes to `data` instead.
PiperOrigin-RevId: 234864141
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCommandLineOptions.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCommandLineOptions.java
index 045c80b..39209e3 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCommandLineOptions.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCommandLineOptions.java
@@ -310,6 +310,18 @@
)
public boolean strictObjcModuleMaps;
+ @Option(
+ name = "incompatible_disable_objc_library_resources",
+ defaultValue = "false",
+ documentationCategory = OptionDocumentationCategory.UNDOCUMENTED,
+ effectTags = {OptionEffectTag.UNKNOWN},
+ metadataTags = {
+ OptionMetadataTag.INCOMPATIBLE_CHANGE,
+ OptionMetadataTag.TRIGGERED_BY_ALL_INCOMPATIBLE_CHANGES
+ },
+ help = "If enabled, objc_library resource attributes are disallowed.")
+ public boolean disableObjcLibraryResources;
+
@Override
public FragmentOptions getHost() {
ObjcCommandLineOptions host = (ObjcCommandLineOptions) super.getHost();
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcConfiguration.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcConfiguration.java
index 3c797eb..390935e 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcConfiguration.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcConfiguration.java
@@ -70,6 +70,7 @@
private final Label objcHeaderScannerTool;
private final Label appleSdk;
private final boolean strictObjcModuleMaps;
+ private final boolean disableObjcLibraryResources;
ObjcConfiguration(ObjcCommandLineOptions objcOptions, BuildConfiguration.Options options) {
this.iosSimulatorDevice =
@@ -111,6 +112,7 @@
this.objcHeaderScannerTool = objcOptions.objcHeaderScannerTool;
this.appleSdk = objcOptions.appleSdk;
this.strictObjcModuleMaps = objcOptions.strictObjcModuleMaps;
+ this.disableObjcLibraryResources = objcOptions.disableObjcLibraryResources;
}
/**
@@ -297,4 +299,9 @@
public boolean useStrictObjcModuleMaps() {
return strictObjcModuleMaps;
}
+
+ /** Returns true if Objective-C library resource attributes are disallowed. */
+ public boolean disableObjcLibraryResources() {
+ return disableObjcLibraryResources;
+ }
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcLibrary.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcLibrary.java
index 7a52350..07607b4 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcLibrary.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcLibrary.java
@@ -154,7 +154,28 @@
}
/** Throws errors or warnings for bad attribute state. */
- private static void validateAttributes(RuleContext ruleContext) {
+ private static void validateAttributes(RuleContext ruleContext) throws RuleErrorException {
+ if (ObjcRuleClasses.objcConfiguration(ruleContext).disableObjcLibraryResources()) {
+ ImmutableList<String> resourceAttributes =
+ ImmutableList.of(
+ "asset_catalogs",
+ "bundles",
+ "datamodels",
+ "resources",
+ "storyboards",
+ "strings",
+ "structured_resources",
+ "xibs");
+ for (String attribute : resourceAttributes) {
+ if (!ruleContext.getPrerequisites(attribute, Mode.TARGET).isEmpty()) {
+ ruleContext.throwWithAttributeError(
+ attribute,
+ "objc_library resource attributes are not allowed. Please use the 'data' "
+ + "attribute instead.");
+ }
+ }
+ }
+
for (String copt : ObjcCommon.getNonCrosstoolCopts(ruleContext)) {
if (copt.contains("-fmodules-cache-path")) {
ruleContext.ruleWarning(CompilationSupport.MODULES_CACHE_PATH_WARNING);
diff --git a/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcLibraryTest.java b/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcLibraryTest.java
index 2583655..403ffda 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcLibraryTest.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcLibraryTest.java
@@ -2046,4 +2046,81 @@
assertThat(Artifact.toRootRelativePaths(compileAction.getPossibleInputsForTesting()))
.contains("cc/txt_dep/hdr.h");
}
+
+ @Test
+ public void testIncompatibleResourceAttributeFlag_assetCatalogs() throws Exception {
+ useConfiguration("--incompatible_disable_objc_library_resources=true");
+
+ checkError(
+ "x",
+ "x",
+ "objc_library resource attributes are not allowed. Please use the 'data' attribute instead",
+ "objc_library(name = 'x', asset_catalogs = ['fg'])");
+ }
+
+ @Test
+ public void testIncompatibleResourceAttributeFlag_datamodels() throws Exception {
+ useConfiguration("--incompatible_disable_objc_library_resources=true");
+
+ checkError(
+ "x",
+ "x",
+ "objc_library resource attributes are not allowed. Please use the 'data' attribute instead",
+ "objc_library(name = 'x', datamodels = ['fg'])");
+ }
+
+ @Test
+ public void testIncompatibleResourceAttributeFlag_resources() throws Exception {
+ useConfiguration("--incompatible_disable_objc_library_resources=true");
+
+ checkError(
+ "x",
+ "x",
+ "objc_library resource attributes are not allowed. Please use the 'data' attribute instead",
+ "objc_library(name = 'x', resources = ['fg'])");
+ }
+
+ @Test
+ public void testIncompatibleResourceAttributeFlag_storyboards() throws Exception {
+ useConfiguration("--incompatible_disable_objc_library_resources=true");
+
+ checkError(
+ "x",
+ "x",
+ "objc_library resource attributes are not allowed. Please use the 'data' attribute instead",
+ "objc_library(name = 'x', storyboards = ['fg.storyboard'])");
+ }
+
+ @Test
+ public void testIncompatibleResourceAttributeFlag_strings() throws Exception {
+ useConfiguration("--incompatible_disable_objc_library_resources=true");
+
+ checkError(
+ "x",
+ "x",
+ "objc_library resource attributes are not allowed. Please use the 'data' attribute instead",
+ "objc_library(name = 'x', strings = ['fg.strings'])");
+ }
+
+ @Test
+ public void testIncompatibleResourceAttributeFlag_structuredResources() throws Exception {
+ useConfiguration("--incompatible_disable_objc_library_resources=true");
+
+ checkError(
+ "x",
+ "x",
+ "objc_library resource attributes are not allowed. Please use the 'data' attribute instead",
+ "objc_library(name = 'x', structured_resources = ['fg'])");
+ }
+
+ @Test
+ public void testIncompatibleResourceAttributeFlag_xibs() throws Exception {
+ useConfiguration("--incompatible_disable_objc_library_resources=true");
+
+ checkError(
+ "x",
+ "x",
+ "objc_library resource attributes are not allowed. Please use the 'data' attribute instead",
+ "objc_library(name = 'x', xibs = ['fg.xib'])");
+ }
}