Skip to content

Commit

Permalink
Support multiarchitecture objc libraries for both simulator and devic…
Browse files Browse the repository at this point in the history
…e architectures in a single build, refining the multiarchitecture device restriction only to rules which require bundling.

--
MOS_MIGRATED_REVID=103016981
  • Loading branch information
c-parsons authored and jhfield committed Sep 15, 2015
1 parent 1906b26 commit 5dd6819
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public BundleSupport(RuleContext ruleContext,
this.bundling = bundling;
this.attributes = new Attributes(ruleContext);
}

/**
* Registers actions required for constructing this bundle, namely merging all involved {@code
* Info.plist} files and generating asset catalogues.
Expand Down Expand Up @@ -126,13 +126,22 @@ BundleSupport addXcodeSettings(Builder xcodeProviderBuilder) {
return this;
}

/**
* Validates that resources defined in this rule and its dependencies and written to this bundle
* are legal (for example that they are not mapped to the same bundle location).
*
* @return this bundle support
*/
BundleSupport validateResources(ObjcProvider objcProvider) {
private void validatePlatform() {
ObjcConfiguration objcConfiguration = ObjcRuleClasses.objcConfiguration(ruleContext);
Platform platform = null;
for (String architecture : objcConfiguration.getIosMultiCpus()) {
if (platform == null) {
platform = Platform.forArch(architecture);
} else if (platform != Platform.forArch(architecture)) {
ruleContext.ruleError(
String.format("In builds which require bundling, --ios_multi_cpus does not currently "
+ "allow values for both simulator and device builds. Flag was %s",
objcConfiguration.getIosMultiCpus()));
}
}
}

private void validateResources(ObjcProvider objcProvider) {
Map<String, Artifact> bundlePathToFile = new HashMap<>();
NestedSet<Artifact> artifacts = objcProvider.get(STRINGS);

Expand Down Expand Up @@ -177,6 +186,22 @@ BundleSupport validateResources(ObjcProvider objcProvider) {

// TODO(bazel-team): Do the same validation for storyboards and datamodels which could also be
// generated by genrules or doubly defined.
}

/**
* Validates bundle support.
* <ul>
* <li>Validates that resources defined in this rule and its dependencies and written to this
* bundle are legal (for example that they are not mapped to the same bundle location)
* <li>Validates the platform for this build is either simulator or device, and does not
* contain architectures for both platforms
* </ul>
*
* @return this bundle support
*/
BundleSupport validate(ObjcProvider objcProvider) {
validatePlatform();
validateResources(objcProvider);

return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import com.google.devtools.build.lib.rules.RuleConfiguredTargetFactory;
import com.google.devtools.build.lib.rules.objc.ObjcCommon.ResourceAttributes;


/**
* Implementation for {@code objc_bundle_library}.
*/
Expand All @@ -49,7 +48,7 @@ public ConfiguredTarget create(RuleContext ruleContext) throws InterruptedExcept

new BundleSupport(ruleContext, bundling)
.registerActions(common.getObjcProvider())
.validateResources(common.getObjcProvider())
.validate(common.getObjcProvider())
.addXcodeSettings(xcodeProviderBuilder);

if (ruleContext.hasErrors()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@
import com.google.common.collect.ImmutableMap;
import com.google.devtools.build.lib.analysis.BlazeDirectories;
import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
import com.google.devtools.build.lib.analysis.config.BuildOptions;
import com.google.devtools.build.lib.analysis.config.CompilationMode;
import com.google.devtools.build.lib.events.Event;
import com.google.devtools.build.lib.events.EventHandler;
import com.google.devtools.build.lib.rules.objc.ReleaseBundlingSupport.SplitArchTransition.ConfigurationDistinguisher;
import com.google.devtools.build.lib.syntax.Label;
import com.google.devtools.build.lib.vfs.Path;
Expand Down Expand Up @@ -290,21 +287,6 @@ public String getOutputDirectoryName() {
return Joiner.on('-').join(components);
}

@Override
public void reportInvalidOptions(EventHandler reporter, BuildOptions buildOptions) {
// TODO(bazel-team): Remove this constraint once getBundlingPlatform can return multiple values.
Platform platform = null;
for (String architecture : iosMultiCpus) {
if (platform == null) {
platform = Platform.forArch(architecture);
} else if (platform != Platform.forArch(architecture)) {
reporter.handle(Event.error(
String.format("--ios_multi_cpus does not currently allow values for both simulator and "
+ "device builds but was %s", iosMultiCpus)));
}
}
}

/**
* @return whether to add include path entries for every proto file's containing directory.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ ReleaseBundlingSupport validateAttributes() {
* @return this release bundling support
*/
ReleaseBundlingSupport validateResources() {
bundleSupport.validateResources(objcProvider);
bundleSupport.validate(objcProvider);
return this;
}

Expand Down

0 comments on commit 5dd6819

Please sign in to comment.