aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Dave MacLachlan <dmaclach@google.com>2016-03-25 22:00:14 +0000
committerGravatar Kristina Chodorow <kchodorow@google.com>2016-03-28 18:05:29 +0000
commite9565a39d290b27ee89992270ea613af7844adb3 (patch)
treebd1268dadfdf154ea89bf2294c83c0d0b7466a09
parent4a317f484b83e2eb265b71b15b4a181a2eba27a9 (diff)
Move several naked strings over to constants as general code cleanup.
RELNOTES: -- MOS_MIGRATED_REVID=118242131
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/objc/Bundling.java9
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/objc/ObjcBundleLibrary.java5
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/objc/ObjcRuleClasses.java30
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/objc/ReleaseBundling.java39
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/objc/ReleaseBundlingSupport.java9
5 files changed, 58 insertions, 34 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/Bundling.java b/src/main/java/com/google/devtools/build/lib/rules/objc/Bundling.java
index c9b83efdae..90864205a0 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/Bundling.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/Bundling.java
@@ -25,7 +25,8 @@ import static com.google.devtools.build.lib.rules.objc.ObjcProvider.STORYBOARD;
import static com.google.devtools.build.lib.rules.objc.ObjcProvider.STRINGS;
import static com.google.devtools.build.lib.rules.objc.ObjcProvider.XCDATAMODEL;
import static com.google.devtools.build.lib.rules.objc.ObjcProvider.XIB;
-import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.BundlingRule;
+import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.BundlingRule.FAMILIES_ATTR;
+import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.BundlingRule.INFOPLIST_ATTR;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
@@ -131,7 +132,7 @@ final class Bundling {
*/
public Builder addInfoplistInputFromRule(RuleContext ruleContext) {
Artifact infoplist =
- ruleContext.getPrerequisiteArtifact(BundlingRule.INFOPLIST_ATTR, Mode.TARGET);
+ ruleContext.getPrerequisiteArtifact(INFOPLIST_ATTR, Mode.TARGET);
if (infoplist != null) {
infoplistInputs.add(infoplist);
}
@@ -281,7 +282,7 @@ final class Bundling {
public Bundling build() {
Preconditions.checkNotNull(intermediateArtifacts, "intermediateArtifacts");
- Preconditions.checkNotNull(families, "families");
+ Preconditions.checkNotNull(families, FAMILIES_ATTR);
NestedSet<Artifact> bundleInfoplistInputs = bundleInfoplistInputs();
Optional<Artifact> bundleInfoplist = bundleInfoplist(bundleInfoplistInputs);
Optional<Artifact> actoolzipOutput = actoolzipOutput();
@@ -542,7 +543,7 @@ final class Bundling {
/**
* Returns the list of {@link TargetDeviceFamily} values this bundle is targeting.
- * If empty, the default values specified by "families" attribute will be used.
+ * If empty, the default values specified by {@link FAMILIES_ATTR} will be used.
*/
public ImmutableSet<TargetDeviceFamily> getTargetDeviceFamilies() {
return families;
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcBundleLibrary.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcBundleLibrary.java
index 6fa174900d..2fb999eaff 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcBundleLibrary.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcBundleLibrary.java
@@ -15,6 +15,7 @@
package com.google.devtools.build.lib.rules.objc;
import static com.google.devtools.build.lib.rules.objc.ObjcProvider.NESTED_BUNDLE;
+import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.BundlingRule.FAMILIES_ATTR;
import static com.google.devtools.build.lib.rules.objc.XcodeProductType.BUNDLE;
import com.google.common.collect.ImmutableSet;
@@ -85,7 +86,7 @@ public class ObjcBundleLibrary implements RuleConfiguredTargetFactory {
AppleConfiguration appleConfiguration = ruleContext.getFragment(AppleConfiguration.class);
ImmutableSet<TargetDeviceFamily> families = null;
- List<String> rawFamilies = ruleContext.attributes().get("families", Type.STRING_LIST);
+ List<String> rawFamilies = ruleContext.attributes().get(FAMILIES_ATTR, Type.STRING_LIST);
try {
families = ImmutableSet.copyOf(TargetDeviceFamily.fromNamesInRule(rawFamilies));
} catch (InvalidFamilyNameException | RepeatedFamilyNameException e) {
@@ -93,7 +94,7 @@ public class ObjcBundleLibrary implements RuleConfiguredTargetFactory {
}
if (families.isEmpty()) {
- ruleContext.attributeError("families", ReleaseBundling.INVALID_FAMILIES_ERROR);
+ ruleContext.attributeError(FAMILIES_ATTR, ReleaseBundling.INVALID_FAMILIES_ERROR);
}
return new Bundling.Builder()
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcRuleClasses.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcRuleClasses.java
index ea537161b2..04505b885b 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcRuleClasses.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcRuleClasses.java
@@ -728,6 +728,7 @@ public class ObjcRuleClasses {
*/
public static class BundlingRule implements RuleDefinition {
static final String INFOPLIST_ATTR = "infoplist";
+ static final String FAMILIES_ATTR = "families";
@Override
public RuleClass build(Builder builder, RuleDefinitionEnvironment env) {
@@ -772,7 +773,7 @@ public class ObjcRuleClasses {
empty.</p>
<!-- #END_BLAZE_RULE.ATTRIBUTE -->*/
.add(
- attr("families", STRING_LIST)
+ attr(FAMILIES_ATTR, STRING_LIST)
.value(ImmutableList.of(TargetDeviceFamily.IPHONE.getNameInRule())))
.add(
attr("$momcwrapper", LABEL)
@@ -806,6 +807,15 @@ public class ObjcRuleClasses {
* application or extension).
*/
public static class ReleaseBundlingRule implements RuleDefinition {
+ static final String APP_ICON_ATTR = "app_icon";
+ static final String BUNDLE_ID_ATTR = "bundle_id";
+ static final String DEFAULT_PROVISIONING_PROFILE_ATTR = ":default_provisioning_profile";
+ static final String ENTITLEMENTS_ATTR = "entitlements";
+ static final String EXTRA_ENTITLEMENTS_ATTR = ":extra_entitlements";
+ static final String LAUNCH_IMAGE_ATTR = "launch_image";
+ static final String LAUNCH_STORYBOARD_ATTR = "launch_storyboard";
+ static final String PROVISIONING_PROFILE_ATTR = "provisioning_profile";
+
@Override
public RuleClass build(Builder builder, RuleDefinitionEnvironment env) {
return builder
@@ -821,9 +831,9 @@ public class ObjcRuleClasses {
<a href="https://developer.apple.com/library/ios/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html">their definitions in Apple's documentation</a>:
$(AppIdentifierPrefix) and $(CFBundleIdentifier).
<!-- #END_BLAZE_RULE.ATTRIBUTE -->*/
- .add(attr("entitlements", LABEL).legacyAllowAnyFileType())
+ .add(attr(ENTITLEMENTS_ATTR, LABEL).legacyAllowAnyFileType())
.add(
- attr(":extra_entitlements", LABEL)
+ attr(EXTRA_ENTITLEMENTS_ATTR, LABEL)
.singleArtifact()
.value(
new LateBoundLabel<BuildConfiguration>(ObjcConfiguration.class) {
@@ -842,12 +852,12 @@ public class ObjcRuleClasses {
This is only used for non-simulator builds.
<!-- #END_BLAZE_RULE.ATTRIBUTE -->*/
.add(
- attr("provisioning_profile", LABEL)
+ attr(PROVISIONING_PROFILE_ATTR, LABEL)
.singleArtifact()
.allowedFileTypes(FileType.of(".mobileprovision")))
// Will be used if provisioning_profile is null.
.add(
- attr(":default_provisioning_profile", LABEL)
+ attr(DEFAULT_PROVISIONING_PROFILE_ATTR, LABEL)
.singleArtifact()
.allowedFileTypes(FileType.of(".mobileprovision"))
.value(
@@ -860,7 +870,7 @@ public class ObjcRuleClasses {
if (appleConfiguration.getBundlingPlatform() != Platform.IOS_DEVICE) {
return null;
}
- if (rule.isAttributeValueExplicitlySpecified("provisioning_profile")) {
+ if (rule.isAttributeValueExplicitlySpecified(PROVISIONING_PROFILE_ATTR)) {
return null;
}
return appleConfiguration.getDefaultProvisioningProfileLabel();
@@ -876,7 +886,7 @@ public class ObjcRuleClasses {
If the application icon is not in an asset catalog, do not use this
attribute. Instead, add a CFBundleIcons entry to the Info.plist file.
<!-- #END_BLAZE_RULE.ATTRIBUTE -->*/
- .add(attr("app_icon", STRING))
+ .add(attr(APP_ICON_ATTR, STRING))
/* <!-- #BLAZE_RULE($objc_release_bundling_rule).ATTRIBUTE(launch_image) -->
The name of the launch image.
@@ -889,7 +899,7 @@ public class ObjcRuleClasses {
bundle.
<p>
<!-- #END_BLAZE_RULE.ATTRIBUTE -->*/
- .add(attr("launch_image", STRING))
+ .add(attr(LAUNCH_IMAGE_ATTR, STRING))
/* <!-- #BLAZE_RULE($objc_release_bundling_rule).ATTRIBUTE(launch_storyboard) -->
The location of the launch storyboard (.xib or .storyboard).
@@ -906,7 +916,7 @@ public class ObjcRuleClasses {
<p>
<!-- #END_BLAZE_RULE.ATTRIBUTE -->*/
.add(
- attr("launch_storyboard", LABEL)
+ attr(LAUNCH_STORYBOARD_ATTR, LABEL)
.direct_compile_time_input()
.allowedFileTypes(FileTypeSet.of(XIB_TYPE, STORYBOARD_TYPE)))
/* <!-- #BLAZE_RULE($objc_release_bundling_rule).ATTRIBUTE(bundle_id) -->
@@ -917,7 +927,7 @@ public class ObjcRuleClasses {
will be used.
<!-- #END_BLAZE_RULE.ATTRIBUTE -->*/
.add(
- attr("bundle_id", STRING)
+ attr(BUNDLE_ID_ATTR, STRING)
.value(
new Attribute.ComputedDefault() {
@Override
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ReleaseBundling.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ReleaseBundling.java
index a78f0077d1..ebc2e2ec15 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/ReleaseBundling.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ReleaseBundling.java
@@ -14,6 +14,14 @@
package com.google.devtools.build.lib.rules.objc;
+import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.BundlingRule.FAMILIES_ATTR;
+import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.ReleaseBundlingRule.APP_ICON_ATTR;
+import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.ReleaseBundlingRule.BUNDLE_ID_ATTR;
+import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.ReleaseBundlingRule.DEFAULT_PROVISIONING_PROFILE_ATTR;
+import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.ReleaseBundlingRule.LAUNCH_IMAGE_ATTR;
+import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.ReleaseBundlingRule.LAUNCH_STORYBOARD_ATTR;
+import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.ReleaseBundlingRule.PROVISIONING_PROFILE_ATTR;
+
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableSet;
@@ -131,7 +139,7 @@ final class ReleaseBundling {
public ReleaseBundling build() {
Preconditions.checkNotNull(intermediateArtifacts, "intermediateArtifacts");
- Preconditions.checkNotNull(families, "families");
+ Preconditions.checkNotNull(families, FAMILIES_ATTR);
return new ReleaseBundling(
ipaArtifact,
bundleId,
@@ -157,29 +165,29 @@ final class ReleaseBundling {
public static ReleaseBundling releaseBundling(RuleContext ruleContext)
throws InterruptedException {
Preconditions.checkState(!Strings.isNullOrEmpty(
- ruleContext.attributes().get("bundle_id", Type.STRING)),
+ ruleContext.attributes().get(BUNDLE_ID_ATTR, Type.STRING)),
"requires a bundle_id value");
String primaryBundleId = null;
String fallbackBundleId = null;
Artifact provisioningProfile;
- if (ruleContext.attributes().isAttributeValueExplicitlySpecified("bundle_id")) {
- primaryBundleId = ruleContext.attributes().get("bundle_id", Type.STRING);
+ if (ruleContext.attributes().isAttributeValueExplicitlySpecified(BUNDLE_ID_ATTR)) {
+ primaryBundleId = ruleContext.attributes().get(BUNDLE_ID_ATTR, Type.STRING);
} else {
- fallbackBundleId = ruleContext.attributes().get("bundle_id", Type.STRING);
+ fallbackBundleId = ruleContext.attributes().get(BUNDLE_ID_ATTR, Type.STRING);
}
Artifact explicitProvisioningProfile =
- ruleContext.getPrerequisiteArtifact("provisioning_profile", Mode.TARGET);
+ ruleContext.getPrerequisiteArtifact(PROVISIONING_PROFILE_ATTR, Mode.TARGET);
if (explicitProvisioningProfile != null) {
provisioningProfile = explicitProvisioningProfile;
} else {
- provisioningProfile = ruleContext.getPrerequisiteArtifact(":default_provisioning_profile",
+ provisioningProfile = ruleContext.getPrerequisiteArtifact(DEFAULT_PROVISIONING_PROFILE_ATTR,
Mode.TARGET);
}
ImmutableSet<TargetDeviceFamily> families = null;
- List<String> rawFamilies = ruleContext.attributes().get("families", Type.STRING_LIST);
+ List<String> rawFamilies = ruleContext.attributes().get(FAMILIES_ATTR, Type.STRING_LIST);
try {
families = ImmutableSet.copyOf(TargetDeviceFamily.fromNamesInRule(rawFamilies));
} catch (InvalidFamilyNameException | RepeatedFamilyNameException e) {
@@ -187,20 +195,21 @@ final class ReleaseBundling {
}
if (families.isEmpty()) {
- ruleContext.attributeError("families", INVALID_FAMILIES_ERROR);
+ ruleContext.attributeError(FAMILIES_ATTR, INVALID_FAMILIES_ERROR);
}
return new ReleaseBundling.Builder()
.setIpaArtifact(ruleContext.getImplicitOutputArtifact(ReleaseBundlingSupport.IPA))
- .setBundleId(ruleContext.attributes().get("bundle_id", Type.STRING))
+ .setBundleId(ruleContext.attributes().get(BUNDLE_ID_ATTR, Type.STRING))
.setPrimaryBundleId(primaryBundleId)
.setFallbackBundleId(fallbackBundleId)
- .setAppIcon(Strings.emptyToNull(ruleContext.attributes().get("app_icon", Type.STRING)))
+ .setAppIcon(Strings.emptyToNull(ruleContext.attributes().get(APP_ICON_ATTR, Type.STRING)))
.setLaunchImage(Strings.emptyToNull(
- ruleContext.attributes().get("launch_image", Type.STRING)))
- .setLaunchStoryboard(ruleContext.getPrerequisiteArtifact("launch_storyboard", Mode.TARGET))
+ ruleContext.attributes().get(LAUNCH_IMAGE_ATTR, Type.STRING)))
+ .setLaunchStoryboard(
+ ruleContext.getPrerequisiteArtifact(LAUNCH_STORYBOARD_ATTR, Mode.TARGET))
.setProvisioningProfile(provisioningProfile)
- .setProvisioningProfileAttributeName("provisioning_profile")
+ .setProvisioningProfileAttributeName(PROVISIONING_PROFILE_ATTR)
.setTargetDeviceFamilies(families)
.setIntermediateArtifacts(ObjcRuleClasses.intermediateArtifacts(ruleContext))
.build();
@@ -322,7 +331,7 @@ final class ReleaseBundling {
/**
* Returns the list of {@link TargetDeviceFamily} values this bundle is targeting.
- * If empty, the default values specified by "families" attribute will be used.
+ * If empty, the default values specified by {@link FAMILIES_ATTR} will be used.
*/
public ImmutableSet<TargetDeviceFamily> getTargetDeviceFamilies() {
return families;
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ReleaseBundlingSupport.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ReleaseBundlingSupport.java
index 4f922f728d..05e3adc593 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/ReleaseBundlingSupport.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ReleaseBundlingSupport.java
@@ -17,6 +17,9 @@ package com.google.devtools.build.lib.rules.objc;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.devtools.build.lib.packages.ImplicitOutputsFunction.fromTemplates;
import static com.google.devtools.build.lib.rules.objc.ObjcProvider.Flag.USES_SWIFT;
+import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.ReleaseBundlingRule.APP_ICON_ATTR;
+import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.ReleaseBundlingRule.ENTITLEMENTS_ATTR;
+import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.ReleaseBundlingRule.EXTRA_ENTITLEMENTS_ATTR;
import static com.google.devtools.build.lib.rules.objc.TargetDeviceFamily.UI_DEVICE_FAMILY_VALUES;
import com.google.common.annotations.VisibleForTesting;
@@ -238,7 +241,7 @@ public final class ReleaseBundlingSupport {
// and we MUST raise our own error somehow...
if (!objcProvider.hasAssetCatalogs()) {
if (releaseBundling.getAppIcon() != null) {
- ruleContext.attributeError("app_icon",
+ ruleContext.attributeError(APP_ICON_ATTR,
String.format(NO_ASSET_CATALOG_ERROR_FORMAT, releaseBundling.getAppIcon()));
}
if (releaseBundling.getLaunchImage() != null) {
@@ -1046,12 +1049,12 @@ public final class ReleaseBundlingSupport {
@Nullable
Artifact entitlements() {
- return ruleContext.getPrerequisiteArtifact("entitlements", Mode.TARGET);
+ return ruleContext.getPrerequisiteArtifact(ENTITLEMENTS_ATTR, Mode.TARGET);
}
@Nullable
Artifact extraEntitlements() {
- return ruleContext.getPrerequisiteArtifact(":extra_entitlements", Mode.TARGET);
+ return ruleContext.getPrerequisiteArtifact(EXTRA_ENTITLEMENTS_ATTR, Mode.TARGET);
}
NestedSet<? extends Artifact> dependentLinkedBinaries() {