diff options
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib')
45 files changed, 128 insertions, 1982 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java index 3788c3a909..20a072e544 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java @@ -162,6 +162,7 @@ import com.google.devtools.build.lib.rules.repository.WorkspaceBaseRule; import com.google.devtools.build.lib.rules.test.SkylarkTestingModule; import com.google.devtools.build.lib.rules.test.TestSuiteRule; import com.google.devtools.build.lib.util.ResourceFileLoader; + import java.io.IOException; /** A rule class provider implementing the rules Bazel knows. */ @@ -585,7 +586,6 @@ public class BazelRuleClassProvider { builder.addRuleDefinition(new ObjcRuleClasses.LinkingRule(objcProtoAspect)); builder.addRuleDefinition(new ObjcRuleClasses.MultiArchPlatformRule()); builder.addRuleDefinition(new ObjcRuleClasses.ResourcesRule()); - builder.addRuleDefinition(new ObjcRuleClasses.XcodegenRule()); builder.addRuleDefinition(new ObjcRuleClasses.AlwaysLinkRule()); builder.addRuleDefinition(new ObjcRuleClasses.SdkFrameworksDependerRule()); builder.addRuleDefinition(new ObjcRuleClasses.CompileDependencyRule()); diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/AppleWatch1Extension.java b/src/main/java/com/google/devtools/build/lib/rules/objc/AppleWatch1Extension.java index 622668122e..3c134e0475 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/AppleWatch1Extension.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/AppleWatch1Extension.java @@ -64,27 +64,22 @@ public class AppleWatch1Extension implements RuleConfiguredTargetFactory { + "(https://github.com/bazelbuild/rules_apple) to build Apple targets."); ObjcProvider.Builder extensionObjcProviderBuilder = new ObjcProvider.Builder(); - XcodeProvider.Builder applicationXcodeProviderBuilder = new XcodeProvider.Builder(); - XcodeProvider.Builder extensionXcodeProviderBuilder = new XcodeProvider.Builder(); NestedSetBuilder<Artifact> applicationFilesToBuild = NestedSetBuilder.stableOrder(); NestedSetBuilder<Artifact> extensionfilesToBuild = NestedSetBuilder.stableOrder(); // 1. Build watch application bundle. createWatchApplicationBundle( ruleContext, - applicationXcodeProviderBuilder, applicationFilesToBuild); // 2. Build watch extension bundle. - createWatchExtensionBundle(ruleContext, extensionXcodeProviderBuilder, - applicationXcodeProviderBuilder, extensionObjcProviderBuilder, extensionfilesToBuild); + createWatchExtensionBundle(ruleContext, extensionObjcProviderBuilder, extensionfilesToBuild); // 3. Extract the watch application bundle into the extension bundle. registerWatchApplicationUnBundlingAction(ruleContext); RuleConfiguredTargetBuilder targetBuilder = ObjcRuleClasses.ruleConfiguredTarget(ruleContext, extensionfilesToBuild.build()) - .addProvider(XcodeProvider.class, extensionXcodeProviderBuilder.build()) .addProvider( InstrumentedFilesProvider.class, InstrumentedFilesCollector.forward(ruleContext, "binary")); @@ -119,37 +114,30 @@ public class AppleWatch1Extension implements RuleConfiguredTargetFactory { * Creates a watch extension bundle. * * @param ruleContext rule context in which to create the bundle - * @param extensionXcodeProviderBuilder {@link XcodeProvider.Builder} for the extension - * @param applicationXcodeProviderBuilder {@link XcodeProvider.Builder} for the watch application * which is added as a dependency to the extension * @param objcProviderBuilder {@link ObjcProvider.Builder} for the extension * @param filesToBuild the list to contain the files to be built for this extension bundle */ private void createWatchExtensionBundle(RuleContext ruleContext, - XcodeProvider.Builder extensionXcodeProviderBuilder, - XcodeProvider.Builder applicationXcodeProviderBuilder, ObjcProvider.Builder objcProviderBuilder, NestedSetBuilder<Artifact> filesToBuild) throws InterruptedException { - new WatchExtensionSupport(ruleContext, - extensionDependencyAttributes, - ObjcRuleClasses.intermediateArtifacts(ruleContext), - watchExtensionBundleName(ruleContext), - watchExtensionIpaArtifact(ruleContext), - watchApplicationBundle(ruleContext), - applicationXcodeProviderBuilder.build(), - ConfigurationDistinguisher.WATCH_OS1_EXTENSION) - .createBundle(filesToBuild, objcProviderBuilder, extensionXcodeProviderBuilder); + new WatchExtensionSupport( + ruleContext, + extensionDependencyAttributes, + ObjcRuleClasses.intermediateArtifacts(ruleContext), + watchExtensionBundleName(ruleContext), + watchExtensionIpaArtifact(ruleContext), + watchApplicationBundle(ruleContext)) + .createBundle(filesToBuild, objcProviderBuilder); } /** * Creates a watch application bundle. * @param ruleContext rule context in which to create the bundle - * @param xcodeProviderBuilder {@link XcodeProvider.Builder} for the application * @param filesToBuild the list to contain the files to be built for this bundle */ private void createWatchApplicationBundle( RuleContext ruleContext, - XcodeProvider.Builder xcodeProviderBuilder, NestedSetBuilder<Artifact> filesToBuild) throws InterruptedException { new WatchApplicationSupport( @@ -160,10 +148,7 @@ public class AppleWatch1Extension implements RuleConfiguredTargetFactory { watchApplicationBundleName(ruleContext), watchApplicationIpaArtifact(ruleContext), watchApplicationBundleName(ruleContext)) - .createBundleAndXcodeproj( - xcodeProviderBuilder, - ImmutableList.<Artifact>of(), - filesToBuild); + .createBundle(ImmutableList.<Artifact>of(), filesToBuild); } /** diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/AppleWatch1ExtensionRule.java b/src/main/java/com/google/devtools/build/lib/rules/objc/AppleWatch1ExtensionRule.java index e7a359ed2b..a4cbcc328e 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/AppleWatch1ExtensionRule.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/AppleWatch1ExtensionRule.java @@ -97,7 +97,6 @@ public class AppleWatch1ExtensionRule implements RuleDefinition { .name("apple_watch1_extension") .factoryClass(AppleWatch1Extension.class) .ancestors(BaseRuleClasses.BaseRule.class, - ObjcRuleClasses.XcodegenRule.class, ObjcRuleClasses.WatchApplicationBundleRule.class, ObjcRuleClasses.WatchExtensionBundleRule.class) .build(); diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/AppleWatch2ExtensionRule.java b/src/main/java/com/google/devtools/build/lib/rules/objc/AppleWatch2ExtensionRule.java index 0bc8382e2c..7dd75085c9 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/AppleWatch2ExtensionRule.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/AppleWatch2ExtensionRule.java @@ -62,7 +62,6 @@ public class AppleWatch2ExtensionRule implements RuleDefinition { .factoryClass(AppleWatch2Extension.class) .ancestors( BaseRuleClasses.BaseRule.class, - ObjcRuleClasses.XcodegenRule.class, ObjcRuleClasses.WatchApplicationBundleRule.class, ObjcRuleClasses.WatchExtensionBundleRule.class) .build(); diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/AppleWatchExtensionBinary.java b/src/main/java/com/google/devtools/build/lib/rules/objc/AppleWatchExtensionBinary.java index 0914d95685..24fc54fc18 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/AppleWatchExtensionBinary.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/AppleWatchExtensionBinary.java @@ -27,7 +27,7 @@ import com.google.devtools.build.lib.rules.objc.CompilationSupport.ExtraLinkArgs public class AppleWatchExtensionBinary extends BinaryLinkingTargetFactory { public AppleWatchExtensionBinary() { - super(HasReleaseBundlingSupport.NO, XcodeProductType.LIBRARY_STATIC); + super(HasReleaseBundlingSupport.NO); } @Override diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/AppleWatchExtensionBinaryRule.java b/src/main/java/com/google/devtools/build/lib/rules/objc/AppleWatchExtensionBinaryRule.java index bf47c76e74..d6a5d30e4b 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/AppleWatchExtensionBinaryRule.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/AppleWatchExtensionBinaryRule.java @@ -44,8 +44,7 @@ public class AppleWatchExtensionBinaryRule implements RuleDefinition { return RuleDefinition.Metadata.builder() .name("apple_watch_extension_binary") .factoryClass(AppleWatchExtensionBinary.class) - .ancestors(BaseRuleClasses.BaseRule.class, ObjcRuleClasses.LinkingRule.class, - ObjcRuleClasses.XcodegenRule.class) + .ancestors(BaseRuleClasses.BaseRule.class, ObjcRuleClasses.LinkingRule.class) .build(); } } diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/BinaryLinkingTargetFactory.java b/src/main/java/com/google/devtools/build/lib/rules/objc/BinaryLinkingTargetFactory.java index 94e721ae54..decf574cbb 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/BinaryLinkingTargetFactory.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/BinaryLinkingTargetFactory.java @@ -59,12 +59,9 @@ abstract class BinaryLinkingTargetFactory implements RuleConfiguredTargetFactory } private final HasReleaseBundlingSupport hasReleaseBundlingSupport; - private final XcodeProductType productType; - protected BinaryLinkingTargetFactory( - HasReleaseBundlingSupport hasReleaseBundlingSupport, XcodeProductType productType) { + protected BinaryLinkingTargetFactory(HasReleaseBundlingSupport hasReleaseBundlingSupport) { this.hasReleaseBundlingSupport = hasReleaseBundlingSupport; - this.productType = productType; } /** @@ -100,16 +97,12 @@ abstract class BinaryLinkingTargetFactory implements RuleConfiguredTargetFactory .registerCompilationActions(); Optional<ObjcProvider> protosObjcProvider = protoSupport.getObjcProvider(); - Optional<XcodeProvider> protosXcodeProvider = protoSupport.getXcodeProvider(); ObjcCommon common = common(ruleContext, protosObjcProvider); ObjcProvider objcProvider = common.getObjcProvider(); assertLibraryOrSources(objcProvider, ruleContext); - XcodeProvider.Builder xcodeProviderBuilder = - new XcodeProvider.Builder().addPropagatedDependencies(protosXcodeProvider.asSet()); - IntermediateArtifacts intermediateArtifacts = ObjcRuleClasses.intermediateArtifacts(ruleContext); @@ -117,7 +110,7 @@ abstract class BinaryLinkingTargetFactory implements RuleConfiguredTargetFactory NestedSetBuilder.<Artifact>stableOrder() .add(intermediateArtifacts.strippedSingleArchitectureBinary()); - new ResourceSupport(ruleContext).validateAttributes().addXcodeSettings(xcodeProviderBuilder); + new ResourceSupport(ruleContext).validateAttributes(); ruleContext.assertNoErrors(); @@ -139,7 +132,6 @@ abstract class BinaryLinkingTargetFactory implements RuleConfiguredTargetFactory compilationSupport .validateAttributes() - .addXcodeSettings(xcodeProviderBuilder, common) .registerCompileAndArchiveActions(common) .registerFullyLinkAction( common.getObjcProvider(), @@ -168,7 +160,6 @@ abstract class BinaryLinkingTargetFactory implements RuleConfiguredTargetFactory appleConfiguration.getSingleArchPlatform()); releaseBundlingSupport .registerActions(DsymOutputType.APP) - .addXcodeSettings(xcodeProviderBuilder) .addFilesToBuild(filesToBuild, Optional.of(DsymOutputType.APP)) .validateResources() .validateAttributes(); @@ -188,26 +179,8 @@ abstract class BinaryLinkingTargetFactory implements RuleConfiguredTargetFactory throw new AssertionError(); } - XcodeSupport xcodeSupport = - new XcodeSupport(ruleContext) - // TODO(bazel-team): Use LIBRARY_STATIC as parameter instead of APPLICATION once - // objc_binary no longer creates an application bundle. - .addXcodeSettings(xcodeProviderBuilder, objcProvider, productType) - .addDependencies(xcodeProviderBuilder, new Attribute("bundles", Mode.TARGET)) - .addDependencies(xcodeProviderBuilder, new Attribute("deps", Mode.TARGET)) - .addNonPropagatedDependencies( - xcodeProviderBuilder, new Attribute("non_propagated_deps", Mode.TARGET)) - .addFilesToBuild(filesToBuild); - - if (productType != XcodeProductType.LIBRARY_STATIC) { - xcodeSupport.generateCompanionLibXcodeTarget(xcodeProviderBuilder); - } - XcodeProvider xcodeProvider = xcodeProviderBuilder.build(); - xcodeSupport.registerActions(xcodeProvider); - RuleConfiguredTargetBuilder targetBuilder = ObjcRuleClasses.ruleConfiguredTarget(ruleContext, filesToBuild.build()) - .addProvider(XcodeProvider.class, xcodeProvider) .addProvider(ObjcProvider.class, objcProvider) .addProvider( InstrumentedFilesProvider.class, diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/BundleSupport.java b/src/main/java/com/google/devtools/build/lib/rules/objc/BundleSupport.java index 9d0e3c27c4..1c7220b672 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/BundleSupport.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/BundleSupport.java @@ -37,7 +37,6 @@ import com.google.devtools.build.lib.rules.apple.AppleConfiguration; import com.google.devtools.build.lib.rules.apple.AppleToolchain; import com.google.devtools.build.lib.rules.apple.Platform; import com.google.devtools.build.lib.rules.apple.Platform.PlatformType; -import com.google.devtools.build.lib.rules.objc.XcodeProvider.Builder; import com.google.devtools.build.lib.vfs.FileSystemUtils; import com.google.devtools.build.lib.vfs.PathFragment; @@ -120,18 +119,6 @@ final class BundleSupport { } /** - * Adds any Xcode settings related to this bundle to the given provider builder. - * - * @return this bundle support - */ - BundleSupport addXcodeSettings(Builder xcodeProviderBuilder) { - if (bundling.getBundleInfoplist().isPresent()) { - xcodeProviderBuilder.setBundleInfoplist(bundling.getBundleInfoplist().get()); - } - return this; - } - - /** * Validates the platform for this build is either simulator or device, and does not * contain architectures for both platforms. * diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java b/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java index cac6791089..bcad1d6a71 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java @@ -20,7 +20,6 @@ import static com.google.devtools.build.lib.rules.objc.ObjcProvider.DYNAMIC_FRAM import static com.google.devtools.build.lib.rules.objc.ObjcProvider.FORCE_LOAD_LIBRARY; import static com.google.devtools.build.lib.rules.objc.ObjcProvider.FRAMEWORK_SEARCH_PATH_ONLY; import static com.google.devtools.build.lib.rules.objc.ObjcProvider.IMPORTED_LIBRARY; -import static com.google.devtools.build.lib.rules.objc.ObjcProvider.INCLUDE_SYSTEM; import static com.google.devtools.build.lib.rules.objc.ObjcProvider.LIBRARY; import static com.google.devtools.build.lib.rules.objc.ObjcProvider.SDK_DYLIB; import static com.google.devtools.build.lib.rules.objc.ObjcProvider.SDK_FRAMEWORK; @@ -181,14 +180,6 @@ public abstract class CompilationSupport { HEADERS)) .withSourceAttributes("srcs", "non_arc_srcs", "hdrs") .withDependencyAttributes("deps", "data", "binary", "xctest_app"); - - private static final Predicate<String> INCLUDE_DIR_OPTION_IN_COPTS = - new Predicate<String>() { - @Override - public boolean apply(String copt) { - return copt.startsWith("-I") && copt.length() > 2; - } - }; /** * Defines a library that contains the transitive closure of dependencies. @@ -735,52 +726,6 @@ public abstract class CompilationSupport { } /** - * Sets compilation-related Xcode project information on the given provider builder. - * - * @param common common information about this rule's attributes and its dependencies - * @return this compilation support - */ - CompilationSupport addXcodeSettings( - XcodeProvider.Builder xcodeProviderBuilder, ObjcCommon common) { - for (CompilationArtifacts artifacts : common.getCompilationArtifacts().asSet()) { - xcodeProviderBuilder.setCompilationArtifacts(artifacts); - } - - // The include directory options ("-I") are parsed out of copts. The include directories are - // added as non-propagated header search paths local to the associated Xcode target. - Iterable<String> copts = Iterables.concat(objcConfiguration.getCopts(), attributes.copts()); - Iterable<String> includeDirOptions = Iterables.filter(copts, INCLUDE_DIR_OPTION_IN_COPTS); - Iterable<String> coptsWithoutIncludeDirs = Iterables.filter( - copts, Predicates.not(INCLUDE_DIR_OPTION_IN_COPTS)); - ImmutableList.Builder<PathFragment> nonPropagatedHeaderSearchPaths = - new ImmutableList.Builder<>(); - for (String includeDirOption : includeDirOptions) { - nonPropagatedHeaderSearchPaths.add(PathFragment.create(includeDirOption.substring(2))); - } - - // We also need to add the -isystem directories from the CC header providers. ObjCommon - // adds these to the objcProvider, so let's just get them from there. - Iterable<PathFragment> includeSystemPaths = common.getObjcProvider().get(INCLUDE_SYSTEM); - - xcodeProviderBuilder - .addHeaders(attributes.hdrs()) - .addHeaders(attributes.textualHdrs()) - .addUserHeaderSearchPaths( - ObjcCommon.userHeaderSearchPaths(common.getObjcProvider(), buildConfiguration)) - .addHeaderSearchPaths( - "$(WORKSPACE_ROOT)", - attributes.headerSearchPaths(buildConfiguration.getGenfilesFragment())) - .addHeaderSearchPaths("$(WORKSPACE_ROOT)", includeSystemPaths) - .addHeaderSearchPaths("$(SDKROOT)/usr/include", attributes.sdkIncludes()) - .addNonPropagatedHeaderSearchPaths( - "$(WORKSPACE_ROOT)", nonPropagatedHeaderSearchPaths.build()) - .addCompilationModeCopts(objcConfiguration.getCoptsForCompilationMode()) - .addCopts(coptsWithoutIncludeDirs); - - return this; - } - - /** * Registers all actions necessary to compile this rule's sources and archive them. * * @param compilationArtifacts collection of artifacts required for the compilation diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/IntermediateArtifacts.java b/src/main/java/com/google/devtools/build/lib/rules/objc/IntermediateArtifacts.java index ba324e670d..f6d037b4cb 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/IntermediateArtifacts.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/IntermediateArtifacts.java @@ -16,7 +16,6 @@ package com.google.devtools.build.lib.rules.objc; import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.actions.Root; -import com.google.devtools.build.lib.analysis.RuleConfiguredTarget.Mode; import com.google.devtools.build.lib.analysis.RuleContext; import com.google.devtools.build.lib.analysis.config.BuildConfiguration; import com.google.devtools.build.lib.cmdline.Label; @@ -141,15 +140,6 @@ public final class IntermediateArtifacts { } /** - * A dummy .c file to be included in xcode projects. This is needed if the target does not have - * any source files but Xcode requires one. - */ - public Artifact dummySource() { - return scopedArtifact( - ruleContext.getPrerequisiteArtifact("$dummy_source", Mode.TARGET).getRootRelativePath()); - } - - /** * Returns a derived artifact in the genfiles directory obtained by appending some extension to * the end of the {@link PathFragment} corresponding to the owner {@link Label}. */ diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/IosApplication.java b/src/main/java/com/google/devtools/build/lib/rules/objc/IosApplication.java index b5ebb904f3..2d66821c95 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/IosApplication.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/IosApplication.java @@ -25,7 +25,6 @@ import com.google.devtools.build.lib.analysis.RuleContext; import com.google.devtools.build.lib.analysis.config.BuildOptions; import com.google.devtools.build.lib.packages.Attribute.SplitTransition; import com.google.devtools.build.lib.rules.apple.AppleConfiguration; -import com.google.devtools.build.lib.rules.apple.AppleConfiguration.ConfigurationDistinguisher; import com.google.devtools.build.lib.rules.apple.Platform; import com.google.devtools.build.lib.rules.apple.Platform.PlatformType; import com.google.devtools.build.lib.rules.objc.ObjcProvider.Flag; @@ -54,8 +53,7 @@ public class IosApplication extends ReleaseBundlingTargetFactory { new Attribute("extensions", Mode.TARGET)); public IosApplication() { - super(ReleaseBundlingSupport.APP_BUNDLE_DIR_FORMAT, XcodeProductType.APPLICATION, - DEPENDENCY_ATTRIBUTES, ConfigurationDistinguisher.IOS_APPLICATION); + super(ReleaseBundlingSupport.APP_BUNDLE_DIR_FORMAT, DEPENDENCY_ATTRIBUTES); } /** diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/IosApplicationRule.java b/src/main/java/com/google/devtools/build/lib/rules/objc/IosApplicationRule.java index ef98b48c6c..edc93674a6 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/IosApplicationRule.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/IosApplicationRule.java @@ -86,7 +86,6 @@ public class IosApplicationRule implements RuleDefinition { .ancestors( BaseRuleClasses.BaseRule.class, ObjcRuleClasses.ReleaseBundlingRule.class, - ObjcRuleClasses.XcodegenRule.class, ObjcRuleClasses.SimulatorRule.class, IpaRule.class) .build(); diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/IosExtension.java b/src/main/java/com/google/devtools/build/lib/rules/objc/IosExtension.java index 9f7d45b0c5..e7747bc258 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/IosExtension.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/IosExtension.java @@ -58,9 +58,9 @@ public class IosExtension extends ReleaseBundlingTargetFactory { ConfigurationDistinguisher.IOS_EXTENSION); public IosExtension() { - super(ReleaseBundlingSupport.EXTENSION_BUNDLE_DIR_FORMAT, XcodeProductType.EXTENSION, - ImmutableSet.of(new Attribute("binary", Mode.SPLIT)), - ConfigurationDistinguisher.IOS_EXTENSION); + super( + ReleaseBundlingSupport.EXTENSION_BUNDLE_DIR_FORMAT, + ImmutableSet.of(new Attribute("binary", Mode.SPLIT))); } @Override diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/IosExtensionBinary.java b/src/main/java/com/google/devtools/build/lib/rules/objc/IosExtensionBinary.java index 52e69a0b07..d598f6c2c2 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/IosExtensionBinary.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/IosExtensionBinary.java @@ -26,7 +26,7 @@ import com.google.devtools.build.lib.rules.objc.CompilationSupport.ExtraLinkArgs @Deprecated public class IosExtensionBinary extends BinaryLinkingTargetFactory { public IosExtensionBinary() { - super(HasReleaseBundlingSupport.NO, XcodeProductType.LIBRARY_STATIC); + super(HasReleaseBundlingSupport.NO); } @Override diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/IosExtensionBinaryRule.java b/src/main/java/com/google/devtools/build/lib/rules/objc/IosExtensionBinaryRule.java index 9cdb2a6479..226b98ff2f 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/IosExtensionBinaryRule.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/IosExtensionBinaryRule.java @@ -44,8 +44,7 @@ public class IosExtensionBinaryRule implements RuleDefinition { return RuleDefinition.Metadata.builder() .name("ios_extension_binary") .factoryClass(IosExtensionBinary.class) - .ancestors(BaseRuleClasses.BaseRule.class, ObjcRuleClasses.LinkingRule.class, - ObjcRuleClasses.XcodegenRule.class) + .ancestors(BaseRuleClasses.BaseRule.class, ObjcRuleClasses.LinkingRule.class) .build(); } } diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/IosExtensionRule.java b/src/main/java/com/google/devtools/build/lib/rules/objc/IosExtensionRule.java index d63f9f9994..62b6374d7e 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/IosExtensionRule.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/IosExtensionRule.java @@ -65,7 +65,6 @@ public class IosExtensionRule implements RuleDefinition { .ancestors( BaseRuleClasses.BaseRule.class, ObjcRuleClasses.ReleaseBundlingRule.class, - ObjcRuleClasses.XcodegenRule.class, IpaRule.class) .build(); } diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/IosTest.java b/src/main/java/com/google/devtools/build/lib/rules/objc/IosTest.java index 255ff0c0c7..5e3d3af5e9 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/IosTest.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/IosTest.java @@ -98,7 +98,6 @@ public final class IosTest implements RuleConfiguredTargetFactory { .registerGenerationActions() .registerCompilationActions(); Optional<ObjcProvider> protosObjcProvider = protoSupport.getObjcProvider(); - Optional<XcodeProvider> protosXcodeProvider = protoSupport.getXcodeProvider(); ObjcCommon common = common(ruleContext, protosObjcProvider); @@ -110,13 +109,9 @@ public final class IosTest implements RuleConfiguredTargetFactory { ruleContext.ruleError(NO_MULTI_CPUS_ERROR); } - XcodeProvider.Builder xcodeProviderBuilder = - new XcodeProvider.Builder().addPropagatedDependencies(protosXcodeProvider.asSet()); - NestedSetBuilder<Artifact> filesToBuild = NestedSetBuilder.stableOrder(); addResourceFilesToBuild(ruleContext, common.getObjcProvider(), filesToBuild); - XcodeProductType productType = getProductType(ruleContext); ExtraLinkArgs extraLinkArgs; Iterable<Artifact> extraLinkInputs; String bundleFormat; @@ -125,14 +120,6 @@ public final class IosTest implements RuleConfiguredTargetFactory { extraLinkInputs = ImmutableList.of(); bundleFormat = ReleaseBundlingSupport.APP_BUNDLE_DIR_FORMAT; } else { - xcodeProviderBuilder.setProductType(productType); - - XcodeProvider appIpaXcodeProvider = - ruleContext.getPrerequisite(XCTEST_APP_ATTR, Mode.TARGET, XcodeProvider.class); - if (appIpaXcodeProvider != null) { - xcodeProviderBuilder.setTestHost(appIpaXcodeProvider); - } - XcTestAppProvider testApp = xcTestAppProvider(ruleContext); Artifact bundleLoader = testApp.getBundleLoader(); @@ -183,7 +170,6 @@ public final class IosTest implements RuleConfiguredTargetFactory { .registerFullyLinkAction( common.getObjcProvider(), ruleContext.getImplicitOutputArtifact(CompilationSupport.FULLY_LINKED_LIB)) - .addXcodeSettings(xcodeProviderBuilder, common) .validateAttributes(); AppleConfiguration appleConfiguration = ruleContext.getFragment(AppleConfiguration.class); @@ -195,23 +181,12 @@ public final class IosTest implements RuleConfiguredTargetFactory { appleConfiguration.getMinimumOsForPlatformType(PlatformType.IOS), appleConfiguration.getMultiArchPlatform(PlatformType.IOS)) .registerActions(DsymOutputType.TEST) - .addXcodeSettings(xcodeProviderBuilder) .addFilesToBuild(filesToBuild, Optional.of(DsymOutputType.TEST)) .validateResources() .validateAttributes(); - new ResourceSupport(ruleContext).validateAttributes().addXcodeSettings(xcodeProviderBuilder); + new ResourceSupport(ruleContext).validateAttributes(); - new XcodeSupport(ruleContext) - .addXcodeSettings(xcodeProviderBuilder, common.getObjcProvider(), productType) - .addDependencies(xcodeProviderBuilder, new Attribute("bundles", Mode.TARGET)) - .addDependencies(xcodeProviderBuilder, new Attribute("deps", Mode.TARGET)) - .addNonPropagatedDependencies( - xcodeProviderBuilder, new Attribute("non_propagated_deps", Mode.TARGET)) - .addFilesToBuild(filesToBuild) - .registerActions(xcodeProviderBuilder.build()); - - XcodeProvider xcodeProvider = xcodeProviderBuilder.build(); NestedSet<Artifact> filesToBuildSet = filesToBuild.build(); Runfiles.Builder runfilesBuilder = @@ -249,7 +224,6 @@ public final class IosTest implements RuleConfiguredTargetFactory { return new RuleConfiguredTargetBuilder(ruleContext) .setFilesToBuild(filesToBuildBuilder.build()) - .addProvider(xcodeProvider) .addProvider(RunfilesProvider.simple(runfiles)) .addNativeDeclaredProvider(new ExecutionInfoProvider(execInfoMapBuilder.build())) .addNativeDeclaredProviders(testSupport.getExtraProviders()) @@ -258,14 +232,6 @@ public final class IosTest implements RuleConfiguredTargetFactory { .build(); } - private XcodeProductType getProductType(RuleContext ruleContext) { - if (isXcTest(ruleContext)) { - return XcodeProductType.UNIT_TEST; - } else { - return XcodeProductType.APPLICATION; - } - } - private void addResourceFilesToBuild( RuleContext ruleContext, ObjcProvider objcProvider, NestedSetBuilder<Artifact> filesToBuild) { IntermediateArtifacts intermediateArtifacts = diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/IosTestRule.java b/src/main/java/com/google/devtools/build/lib/rules/objc/IosTestRule.java index 9669710e41..f837b132ab 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/IosTestRule.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/IosTestRule.java @@ -173,7 +173,6 @@ public class IosTestRule implements RuleDefinition { BaseRuleClasses.TestBaseRule.class, ObjcRuleClasses.ReleaseBundlingRule.class, ObjcRuleClasses.LinkingRule.class, - ObjcRuleClasses.XcodegenRule.class, ObjcRuleClasses.SimulatorRule.class) .factoryClass(IosTest.class) .build(); diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcAspect.java b/src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcAspect.java index f44a4cb86a..bd3ecd4309 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcAspect.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcAspect.java @@ -17,7 +17,6 @@ package com.google.devtools.build.lib.rules.objc; import static com.google.devtools.build.lib.packages.Attribute.ConfigurationTransition.HOST; import static com.google.devtools.build.lib.packages.Attribute.attr; import static com.google.devtools.build.lib.packages.BuildType.LABEL; -import static com.google.devtools.build.lib.rules.objc.XcodeProductType.LIBRARY_STATIC; import static java.nio.charset.StandardCharsets.ISO_8859_1; import com.google.common.base.Joiner; @@ -253,7 +252,6 @@ public class J2ObjcAspect extends NativeAspectClass implements ConfiguredAspectF throws InterruptedException { ConfiguredAspect.Builder builder = new ConfiguredAspect.Builder(this, parameters, ruleContext); ObjcCommon common; - XcodeProvider xcodeProvider; if (!Iterables.isEmpty(j2ObjcSource.getObjcSrcs())) { common = @@ -264,14 +262,6 @@ public class J2ObjcAspect extends NativeAspectClass implements ConfiguredAspectF j2ObjcSource.getHeaderSearchPaths(), depAttributes); - xcodeProvider = - xcodeProvider( - ruleContext, - common, - j2ObjcSource.getObjcHdrs(), - j2ObjcSource.getHeaderSearchPaths(), - depAttributes); - try { CcToolchainProvider ccToolchain = CppHelper.getToolchain(ruleContext, ":j2objc_cc_toolchain"); @@ -307,20 +297,12 @@ public class J2ObjcAspect extends NativeAspectClass implements ConfiguredAspectF ImmutableList.<Artifact>of(), ImmutableList.<PathFragment>of(), depAttributes); - xcodeProvider = - xcodeProvider( - ruleContext, - common, - ImmutableList.<Artifact>of(), - ImmutableList.<PathFragment>of(), - depAttributes); } return builder .addProvider( exportedJ2ObjcMappingFileProvider(base, ruleContext, directJ2ObjcMappingFileProvider)) .addProvider(common.getObjcProvider()) - .addProvider(xcodeProvider) .build(); } @@ -832,36 +814,4 @@ public class J2ObjcAspect extends NativeAspectClass implements ConfiguredAspectF .setIntermediateArtifacts(intermediateArtifacts) .build(); } - - /** - * Sets up and returns an {@link XcodeProvider} object containing the J2ObjC-translated code. - * - */ - static XcodeProvider xcodeProvider(RuleContext ruleContext, ObjcCommon common, - Iterable<Artifact> transpiledHeaders, Iterable<PathFragment> headerSearchPaths, - Iterable<Attribute> dependentAttributes) { - XcodeProvider.Builder xcodeProviderBuilder = new XcodeProvider.Builder(); - XcodeSupport xcodeSupport = new XcodeSupport(ruleContext); - xcodeSupport.addXcodeSettings(xcodeProviderBuilder, common.getObjcProvider(), LIBRARY_STATIC); - - for (Attribute dependentAttribute : dependentAttributes) { - if (ruleContext.attributes().has(dependentAttribute.getName(), BuildType.LABEL_LIST) - || ruleContext.attributes().has(dependentAttribute.getName(), BuildType.LABEL)) { - xcodeSupport.addDependencies(xcodeProviderBuilder, dependentAttribute); - } - } - - if (!Iterables.isEmpty(transpiledHeaders)) { - xcodeProviderBuilder - .addUserHeaderSearchPaths(headerSearchPaths) - .addCopts(ruleContext.getFragment(ObjcConfiguration.class).getCopts()) - .addHeaders(transpiledHeaders); - } - - if (common.getCompilationArtifacts().isPresent()) { - xcodeProviderBuilder.setCompilationArtifacts(common.getCompilationArtifacts().get()); - } - - return xcodeProviderBuilder.build(); - } } diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcLibrary.java b/src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcLibrary.java index 37913f0e8a..612e400c60 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcLibrary.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcLibrary.java @@ -17,7 +17,6 @@ package com.google.devtools.build.lib.rules.objc; import static com.google.devtools.build.lib.collect.nestedset.Order.STABLE_ORDER; import static com.google.devtools.build.lib.rules.objc.ObjcProvider.JRE_LIBRARY; import static com.google.devtools.build.lib.rules.objc.ObjcProvider.LIBRARY; -import static com.google.devtools.build.lib.rules.objc.XcodeProductType.LIBRARY_STATIC; import com.google.common.base.Optional; import com.google.common.collect.ImmutableList; @@ -29,7 +28,6 @@ import com.google.devtools.build.lib.analysis.RuleContext; import com.google.devtools.build.lib.analysis.RunfilesProvider; import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; import com.google.devtools.build.lib.packages.BuildType; -import com.google.devtools.build.lib.packages.RuleClass.ConfiguredTargetFactory.RuleErrorException; import com.google.devtools.build.lib.rules.RuleConfiguredTargetFactory; import com.google.devtools.build.lib.syntax.Type; import com.google.devtools.build.lib.vfs.PathFragment; @@ -85,14 +83,7 @@ public class J2ObjcLibrary implements RuleConfiguredTargetFactory { objcProviderBuilder.addTransitiveAndPropagate(JRE_LIBRARY, prereq.get(LIBRARY)); } - XcodeProvider.Builder xcodeProviderBuilder = new XcodeProvider.Builder(); - XcodeSupport xcodeSupport = - new XcodeSupport(ruleContext) - .addJreDependencies(xcodeProviderBuilder) - .addDependencies(xcodeProviderBuilder, new Attribute("deps", Mode.TARGET)); - ObjcProvider objcProvider = objcProviderBuilder.build(); - xcodeSupport.addXcodeSettings(xcodeProviderBuilder, objcProvider, LIBRARY_STATIC); J2ObjcMappingFileProvider j2ObjcMappingFileProvider = J2ObjcMappingFileProvider.union( ruleContext.getPrerequisites("deps", Mode.TARGET, J2ObjcMappingFileProvider.class)); @@ -120,7 +111,6 @@ public class J2ObjcLibrary implements RuleConfiguredTargetFactory { .addProvider(J2ObjcEntryClassProvider.class, j2ObjcEntryClassProvider) .addProvider(J2ObjcMappingFileProvider.class, j2ObjcMappingFileProvider) .addProvider(ObjcProvider.class, objcProvider) - .addProvider(XcodeProvider.class, xcodeProviderBuilder.build()) .build(); } diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcBinary.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcBinary.java index 487970454d..03fdb97f3b 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcBinary.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcBinary.java @@ -26,10 +26,6 @@ public class ObjcBinary extends BinaryLinkingTargetFactory { super( // TODO(bazel-team): Remove the enum and delete all code depending on YES case once all // bundle users are migrated to ios_application. - HasReleaseBundlingSupport.YES, - - // TODO(bazel-team): Use LIBRARY_STATIC as parameter instead of APPLICATION once objc_binary - // no longer creates an application bundle - XcodeProductType.APPLICATION); + HasReleaseBundlingSupport.YES); } } diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcBinaryRule.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcBinaryRule.java index 30b7255ddb..55cde701d5 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcBinaryRule.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcBinaryRule.java @@ -73,7 +73,6 @@ public class ObjcBinaryRule implements RuleDefinition { .ancestors( BaseRuleClasses.BaseRule.class, ObjcRuleClasses.LinkingRule.class, - ObjcRuleClasses.XcodegenRule.class, ObjcRuleClasses.ReleaseBundlingRule.class, ObjcRuleClasses.SimulatorRule.class) .build(); 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 46b0a21af1..595efaea24 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 @@ -16,7 +16,6 @@ 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; import com.google.devtools.build.lib.actions.Artifact; @@ -32,7 +31,6 @@ import com.google.devtools.build.lib.rules.objc.ObjcCommon.ResourceAttributes; import com.google.devtools.build.lib.rules.objc.TargetDeviceFamily.InvalidFamilyNameException; import com.google.devtools.build.lib.rules.objc.TargetDeviceFamily.RepeatedFamilyNameException; import com.google.devtools.build.lib.syntax.Type; - import java.util.List; /** @@ -46,12 +44,9 @@ public class ObjcBundleLibrary implements RuleConfiguredTargetFactory { ObjcCommon common = common(ruleContext); Bundling bundling = bundling(ruleContext, common); - XcodeProvider.Builder xcodeProviderBuilder = new XcodeProvider.Builder(); NestedSetBuilder<Artifact> filesToBuild = NestedSetBuilder.stableOrder(); - new ResourceSupport(ruleContext) - .validateAttributes() - .addXcodeSettings(xcodeProviderBuilder); + new ResourceSupport(ruleContext).validateAttributes(); if (ruleContext.hasErrors()) { return null; @@ -61,31 +56,24 @@ public class ObjcBundleLibrary implements RuleConfiguredTargetFactory { // Platform is purposefully not validated on this BundleSupport. Multi-arch validation and // resource de-duplication should only take place at the level of the bundling rule. - new BundleSupport(ruleContext, + new BundleSupport( + ruleContext, appleConfiguration, appleConfiguration.getMultiArchPlatform(PlatformType.IOS), bundling, new ExtraActoolArgs()) .validateResources(common.getObjcProvider()) - .registerActions(common.getObjcProvider()) - .addXcodeSettings(xcodeProviderBuilder); + .registerActions(common.getObjcProvider()); if (ruleContext.hasErrors()) { return null; } - new XcodeSupport(ruleContext) - .addFilesToBuild(filesToBuild) - .addXcodeSettings(xcodeProviderBuilder, common.getObjcProvider(), BUNDLE) - .addDependencies(xcodeProviderBuilder, new Attribute("bundles", Mode.TARGET)) - .registerActions(xcodeProviderBuilder.build()); - ObjcProvider nestedBundleProvider = new ObjcProvider.Builder() .add(NESTED_BUNDLE, bundling) .build(); return ObjcRuleClasses.ruleConfiguredTarget(ruleContext, filesToBuild.build()) - .addProvider(XcodeProvider.class, xcodeProviderBuilder.build()) .addProvider(ObjcProvider.class, nestedBundleProvider) .build(); } diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcBundleLibraryRule.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcBundleLibraryRule.java index b488ad4420..45a066166f 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcBundleLibraryRule.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcBundleLibraryRule.java @@ -39,7 +39,7 @@ public class ObjcBundleLibraryRule implements RuleDefinition { .name("objc_bundle_library") .factoryClass(ObjcBundleLibrary.class) .ancestors(BaseRuleClasses.BaseRule.class, ObjcRuleClasses.ResourcesRule.class, - ObjcRuleClasses.BundlingRule.class, ObjcRuleClasses.XcodegenRule.class) + ObjcRuleClasses.BundlingRule.class) .build(); } } diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCommon.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCommon.java index 5b57a41498..1594ac7def 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCommon.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCommon.java @@ -15,7 +15,6 @@ package com.google.devtools.build.lib.rules.objc; import static com.google.devtools.build.lib.packages.BuildType.LABEL; -import static com.google.devtools.build.lib.rules.cpp.Link.LINK_LIBRARY_FILETYPES; import static com.google.devtools.build.lib.rules.objc.ObjcProvider.ASSET_CATALOG; import static com.google.devtools.build.lib.rules.objc.ObjcProvider.BUNDLE_FILE; import static com.google.devtools.build.lib.rules.objc.ObjcProvider.BUNDLE_IMPORT_DIR; @@ -26,7 +25,6 @@ import static com.google.devtools.build.lib.rules.objc.ObjcProvider.DEFINE; import static com.google.devtools.build.lib.rules.objc.ObjcProvider.DYNAMIC_FRAMEWORK_DIR; import static com.google.devtools.build.lib.rules.objc.ObjcProvider.DYNAMIC_FRAMEWORK_FILE; import static com.google.devtools.build.lib.rules.objc.ObjcProvider.FLAG; -import static com.google.devtools.build.lib.rules.objc.ObjcProvider.FORCE_LOAD_FOR_XCODEGEN; import static com.google.devtools.build.lib.rules.objc.ObjcProvider.FORCE_LOAD_LIBRARY; import static com.google.devtools.build.lib.rules.objc.ObjcProvider.Flag.USES_CPP; import static com.google.devtools.build.lib.rules.objc.ObjcProvider.GENERAL_RESOURCE_DIR; @@ -75,11 +73,11 @@ import com.google.devtools.build.lib.rules.cpp.CcLinkParams; import com.google.devtools.build.lib.rules.cpp.CcLinkParamsProvider; import com.google.devtools.build.lib.rules.cpp.CppCompilationContext; import com.google.devtools.build.lib.rules.cpp.CppModuleMap; -import com.google.devtools.build.lib.rules.cpp.LinkerInputs; import com.google.devtools.build.lib.syntax.Type; import com.google.devtools.build.lib.util.FileType; import com.google.devtools.build.lib.util.Preconditions; import com.google.devtools.build.lib.vfs.PathFragment; + import java.util.HashSet; import java.util.List; import java.util.Set; @@ -457,15 +455,6 @@ public final class ObjcCommon { .addAll(SDK_FRAMEWORK, frameworkLinkOpts.build()) .addAll(LINKOPT, nonFrameworkLinkOpts.build()) .addTransitiveAndPropagate(CC_LIBRARY, params.getLibraries()); - - for (LinkerInputs.LibraryToLink library : params.getLibraries()) { - Artifact artifact = library.getArtifact(); - if (LINK_LIBRARY_FILETYPES.matches(artifact.getFilename())) { - objcProvider.add( - FORCE_LOAD_FOR_XCODEGEN, - "$(WORKSPACE_ROOT)/" + artifact.getExecPath().getSafePathString()); - } - } } if (compilationAttributes.isPresent()) { @@ -550,18 +539,10 @@ public final class ObjcCommon { for (CompilationArtifacts artifacts : compilationArtifacts.asSet()) { for (Artifact archive : artifacts.getArchive().asSet()) { objcProvider.add(FORCE_LOAD_LIBRARY, archive); - objcProvider.add( - FORCE_LOAD_FOR_XCODEGEN, - String.format( - "$(BUILT_PRODUCTS_DIR)/lib%s.a", - XcodeProvider.xcodeTargetName(context.getLabel()))); } } for (Artifact archive : extraImportLibraries) { objcProvider.add(FORCE_LOAD_LIBRARY, archive); - objcProvider.add( - FORCE_LOAD_FOR_XCODEGEN, - "$(WORKSPACE_ROOT)/" + archive.getExecPath().getSafePathString()); } } diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcImport.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcImport.java index f6045bf7e5..08d2b26cef 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcImport.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcImport.java @@ -14,8 +14,6 @@ package com.google.devtools.build.lib.rules.objc; -import static com.google.devtools.build.lib.rules.objc.XcodeProductType.LIBRARY_STATIC; - import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.analysis.ConfiguredTarget; import com.google.devtools.build.lib.analysis.RuleConfiguredTarget.Mode; @@ -47,7 +45,6 @@ public class ObjcImport implements RuleConfiguredTargetFactory { ruleContext.getPrerequisites("bundles", Mode.TARGET, ObjcProvider.class)) .build(); - XcodeProvider.Builder xcodeProviderBuilder = new XcodeProvider.Builder(); NestedSetBuilder<Artifact> filesToBuild = NestedSetBuilder.stableOrder(); CompilationAttributes compilationAttributes = @@ -58,26 +55,15 @@ public class ObjcImport implements RuleConfiguredTargetFactory { Iterable<Artifact> publicHeaders = compilationAttributes.hdrs(); CppModuleMap moduleMap = intermediateArtifacts.moduleMap(); - CompilationSupport compilationSupport = - new CompilationSupport.Builder().setRuleContext(ruleContext).build(); - - compilationSupport + new CompilationSupport.Builder() + .setRuleContext(ruleContext) + .build() .registerGenerateModuleMapAction(moduleMap, publicHeaders) - .addXcodeSettings(xcodeProviderBuilder, common) .validateAttributes(); - new ResourceSupport(ruleContext) - .validateAttributes() - .addXcodeSettings(xcodeProviderBuilder); - - new XcodeSupport(ruleContext) - .addXcodeSettings(xcodeProviderBuilder, common.getObjcProvider(), LIBRARY_STATIC) - .addDependencies(xcodeProviderBuilder, new Attribute("bundles", Mode.TARGET)) - .registerActions(xcodeProviderBuilder.build()) - .addFilesToBuild(filesToBuild); + new ResourceSupport(ruleContext).validateAttributes(); return ObjcRuleClasses.ruleConfiguredTarget(ruleContext, filesToBuild.build()) - .addProvider(XcodeProvider.class, xcodeProviderBuilder.build()) .addProvider(ObjcProvider.class, common.getObjcProvider()) .build(); } diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcImportRule.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcImportRule.java index 1e6b118542..da31ceecff 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcImportRule.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcImportRule.java @@ -50,8 +50,7 @@ public class ObjcImportRule implements RuleDefinition { return RuleDefinition.Metadata.builder() .name("objc_import") .factoryClass(ObjcImport.class) - .ancestors(BaseRuleClasses.BaseRule.class, ObjcRuleClasses.AlwaysLinkRule.class, - ObjcRuleClasses.XcodegenRule.class) + .ancestors(BaseRuleClasses.BaseRule.class, ObjcRuleClasses.AlwaysLinkRule.class) .build(); } } 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 be85472195..6ab4f59b16 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 @@ -14,8 +14,6 @@ package com.google.devtools.build.lib.rules.objc; -import static com.google.devtools.build.lib.rules.objc.XcodeProductType.LIBRARY_STATIC; - import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.analysis.ConfiguredTarget; import com.google.devtools.build.lib.analysis.RuleConfiguredTarget.Mode; @@ -64,7 +62,6 @@ public class ObjcLibrary implements RuleConfiguredTargetFactory { ObjcCommon common = common(ruleContext); - XcodeProvider.Builder xcodeProviderBuilder = new XcodeProvider.Builder(); NestedSetBuilder<Artifact> filesToBuild = NestedSetBuilder.<Artifact>stableOrder() .addAll(common.getCompiledArchive().asSet()); @@ -81,21 +78,9 @@ public class ObjcLibrary implements RuleConfiguredTargetFactory { .registerFullyLinkAction( common.getObjcProvider(), ruleContext.getImplicitOutputArtifact(CompilationSupport.FULLY_LINKED_LIB)) - .addXcodeSettings(xcodeProviderBuilder, common) .validateAttributes(); - - new ResourceSupport(ruleContext) - .validateAttributes() - .addXcodeSettings(xcodeProviderBuilder); - - new XcodeSupport(ruleContext) - .addFilesToBuild(filesToBuild) - .addXcodeSettings(xcodeProviderBuilder, common.getObjcProvider(), LIBRARY_STATIC) - .addDependencies(xcodeProviderBuilder, new Attribute("bundles", Mode.TARGET)) - .addDependencies(xcodeProviderBuilder, new Attribute("deps", Mode.TARGET)) - .addNonPropagatedDependencies( - xcodeProviderBuilder, new Attribute("non_propagated_deps", Mode.TARGET)) - .registerActions(xcodeProviderBuilder.build()); + + new ResourceSupport(ruleContext).validateAttributes(); J2ObjcMappingFileProvider j2ObjcMappingFileProvider = J2ObjcMappingFileProvider.union( ruleContext.getPrerequisites("deps", Mode.TARGET, J2ObjcMappingFileProvider.class)); @@ -104,7 +89,6 @@ public class ObjcLibrary implements RuleConfiguredTargetFactory { J2ObjcEntryClassProvider.class)).build(); return ObjcRuleClasses.ruleConfiguredTarget(ruleContext, filesToBuild.build()) - .addProvider(XcodeProvider.class, xcodeProviderBuilder.build()) .addProvider(ObjcProvider.class, common.getObjcProvider()) .addProvider(J2ObjcEntryClassProvider.class, j2ObjcEntryClassProvider) .addProvider(J2ObjcMappingFileProvider.class, j2ObjcMappingFileProvider) diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcLibraryRule.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcLibraryRule.java index 9e50153195..249f27ac7b 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcLibraryRule.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcLibraryRule.java @@ -51,7 +51,7 @@ public class ObjcLibraryRule implements RuleDefinition { .name("objc_library") .factoryClass(ObjcLibrary.class) .ancestors(BaseRuleClasses.BaseRule.class, ObjcRuleClasses.CompilingRule.class, - ObjcRuleClasses.AlwaysLinkRule.class, ObjcRuleClasses.XcodegenRule.class) + ObjcRuleClasses.AlwaysLinkRule.class) .build(); } } diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProtoLibrary.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProtoLibrary.java index 100d918ddf..cb056b9356 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProtoLibrary.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProtoLibrary.java @@ -15,7 +15,6 @@ package com.google.devtools.build.lib.rules.objc; -import com.google.common.base.Optional; import com.google.common.collect.Iterables; import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.analysis.ConfiguredTarget; @@ -23,7 +22,6 @@ import com.google.devtools.build.lib.analysis.RuleConfiguredTarget.Mode; import com.google.devtools.build.lib.analysis.RuleContext; import com.google.devtools.build.lib.collect.nestedset.NestedSet; import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; -import com.google.devtools.build.lib.packages.RuleClass.ConfiguredTargetFactory.RuleErrorException; import com.google.devtools.build.lib.rules.RuleConfiguredTargetFactory; import com.google.devtools.build.lib.rules.proto.ProtoSourcesProvider; @@ -68,15 +66,8 @@ public class ObjcProtoLibrary implements RuleConfiguredTargetFactory { .registerGenerationActions() .addFilesToBuild(filesToBuild); - Optional<XcodeProvider> xcodeProvider = protoSupport.getXcodeProvider(); - - new XcodeSupport(ruleContext) - .registerActions(xcodeProvider.get()) - .addFilesToBuild(filesToBuild); - return ObjcRuleClasses.ruleConfiguredTarget(ruleContext, filesToBuild.build()) .addProvider(ObjcProvider.class, protoSupport.getObjcProvider().get()) - .addProvider(XcodeProvider.class, xcodeProvider.get()) .build(); } @@ -117,13 +108,8 @@ public class ObjcProtoLibrary implements RuleConfiguredTargetFactory { .registerCompilationActions() .addFilesToBuild(filesToBuild); - XcodeProvider xcodeProvider = protoSupport.getXcodeProvider(); - - new XcodeSupport(ruleContext).registerActions(xcodeProvider).addFilesToBuild(filesToBuild); - return ObjcRuleClasses.ruleConfiguredTarget(ruleContext, filesToBuild.build()) .addProvider(ObjcProvider.class, protoSupport.getObjcProvider()) - .addProvider(XcodeProvider.class, xcodeProvider) .build(); } } diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProvider.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProvider.java index 85cd91bd4e..458ad11b2b 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProvider.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProvider.java @@ -132,17 +132,6 @@ public final class ObjcProvider extends SkylarkClassObject implements Transitive new Key<>(LINK_ORDER, "force_load_library", Artifact.class); /** - * Libraries to pass with -force_load flags when setting the linkopts in Xcodegen. This is needed - * in addition to {@link #FORCE_LOAD_LIBRARY} because that one, contains a mixture of import - * archives (which are not built by Xcode) and built-from-source library archives (which are built - * by Xcode). Archives that are built by Xcode are placed directly under - * {@code BUILT_PRODUCTS_DIR} while those not built by Xcode appear somewhere in the Bazel - * workspace under {@code WORKSPACE_ROOT}. - */ - public static final Key<String> FORCE_LOAD_FOR_XCODEGEN = - new Key<>(LINK_ORDER, "force_load_for_xcodegen", String.class); - - /** * Contains all header files. These may be either public or private headers. */ public static final Key<Artifact> HEADER = new Key<>(STABLE_ORDER, "header", Artifact.class); @@ -463,8 +452,6 @@ public final class ObjcProvider extends SkylarkClassObject implements Transitive static final ImmutableList<Key<?>> KEYS_NOT_IN_SKYLARK = ImmutableList.<Key<?>>of( // LibraryToLink not exposed to skylark. CC_LIBRARY, - // Xcodegen is deprecated. - FORCE_LOAD_FOR_XCODEGEN, // Flag enum is not exposed to skylark. FLAG, // Bundle not exposed to skylark. 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 14fdc4aa38..d5c02b09d3 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 @@ -531,28 +531,6 @@ public class ObjcRuleClasses { } /** - * Common attributes for {@code objc_*} rules that export an xcode project. - */ - public static class XcodegenRule implements RuleDefinition { - @Override - public RuleClass build(Builder builder, RuleDefinitionEnvironment env) { - return builder - .add(attr("$xcodegen", LABEL).cfg(HOST).exec() - .value(env.getToolsLabel("//tools/objc:xcodegen"))) - .add(attr("$dummy_source", LABEL) - .value(env.getToolsLabel("//tools/objc:objc_dummy.mm"))) - .build(); - } - @Override - public Metadata getMetadata() { - return RuleDefinition.Metadata.builder() - .name("$objc_xcodegen_rule") - .type(RuleClassType.ABSTRACT) - .build(); - } - } - - /** * Common attributes for {@code objc_*} rules that depend on a crosstool. */ public static class CrosstoolRule implements RuleDefinition { diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcXcodeproj.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcXcodeproj.java deleted file mode 100644 index 4679e0e61b..0000000000 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcXcodeproj.java +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright 2015 The Bazel Authors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package com.google.devtools.build.lib.rules.objc; - -import com.google.devtools.build.lib.actions.Artifact; -import com.google.devtools.build.lib.analysis.ConfiguredTarget; -import com.google.devtools.build.lib.analysis.RuleConfiguredTarget.Mode; -import com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder; -import com.google.devtools.build.lib.analysis.RuleContext; -import com.google.devtools.build.lib.analysis.RunfilesProvider; -import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; -import com.google.devtools.build.lib.packages.RuleClass.ConfiguredTargetFactory.RuleErrorException; -import com.google.devtools.build.lib.rules.RuleConfiguredTargetFactory; - -/** - * Implementation for {@code objc_xcodeproj}. - */ -public class ObjcXcodeproj implements RuleConfiguredTargetFactory { - - @Override - public ConfiguredTarget create(RuleContext ruleContext) - throws InterruptedException, RuleErrorException { - ruleContext.ruleWarning("This rule is deprecated, and is not supported by Skylark rules. " - + "Please use Tulsi (https://tulsi.bazel.build/) to manage Xcode projects."); - - NestedSetBuilder<Artifact> filesToBuild = NestedSetBuilder.stableOrder(); - new XcodeSupport(ruleContext) - .addFilesToBuild(filesToBuild) - .registerActions(ruleContext.getPrerequisites("deps", Mode.TARGET, XcodeProvider.class)); - - return new RuleConfiguredTargetBuilder(ruleContext) - .setFilesToBuild(filesToBuild.build()) - .addProvider(RunfilesProvider.class, RunfilesProvider.EMPTY) - .build(); - } -} diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ProtobufSupport.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ProtobufSupport.java index 6b5c85c25d..f0e835747f 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/ProtobufSupport.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ProtobufSupport.java @@ -14,8 +14,6 @@ package com.google.devtools.build.lib.rules.objc; -import static com.google.devtools.build.lib.rules.objc.XcodeProductType.LIBRARY_STATIC; - import com.google.common.base.Function; import com.google.common.base.Joiner; import com.google.common.base.Optional; @@ -33,8 +31,6 @@ import com.google.devtools.build.lib.analysis.actions.CustomCommandLine; import com.google.devtools.build.lib.analysis.actions.FileWriteAction; import com.google.devtools.build.lib.analysis.actions.SpawnAction; import com.google.devtools.build.lib.analysis.config.BuildConfiguration; -import com.google.devtools.build.lib.cmdline.Label; -import com.google.devtools.build.lib.cmdline.LabelSyntaxException; import com.google.devtools.build.lib.collect.nestedset.NestedSet; import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; import com.google.devtools.build.lib.packages.RuleClass.ConfiguredTargetFactory.RuleErrorException; @@ -297,44 +293,6 @@ final class ProtobufSupport { return Optional.of(commonBuilder.build().getObjcProvider()); } - /** - * Returns the XcodeProvider for this target or Optional.absent() if there were no protos to - * generate. - */ - public Optional<XcodeProvider> getXcodeProvider() throws RuleErrorException { - if (inputsToOutputsMap.isEmpty()) { - return Optional.absent(); - } - - XcodeProvider.Builder xcodeProviderBuilder = new XcodeProvider.Builder(); - new XcodeSupport(ruleContext, intermediateArtifacts, getXcodeLabel(getBundledProtosSuffix())) - .addXcodeSettings(xcodeProviderBuilder, getObjcProvider().get(), LIBRARY_STATIC); - - int actionId = 0; - for (ImmutableSet<Artifact> inputProtos : inputsToOutputsMap.keySet()) { - ImmutableSet<Artifact> outputProtos = inputsToOutputsMap.get(inputProtos); - IntermediateArtifacts bundleIntermediateArtifacts = getUniqueIntermediateArtifacts(actionId); - - CompilationArtifacts compilationArtifacts = - getCompilationArtifacts(bundleIntermediateArtifacts, inputProtos, outputProtos); - - ObjcCommon common = getCommon(bundleIntermediateArtifacts, compilationArtifacts); - - XcodeProvider bundleProvider = - getBundleXcodeProvider( - common, bundleIntermediateArtifacts, getUniqueBundledProtosSuffix(actionId)); - if (isLinkingTarget()) { - xcodeProviderBuilder.addPropagatedDependencies(ImmutableSet.of(bundleProvider)); - } else { - xcodeProviderBuilder.addPropagatedDependenciesWithStrictDependencyHeaders( - ImmutableSet.of(bundleProvider)); - } - actionId++; - } - - return Optional.of(xcodeProviderBuilder.build()); - } - private NestedSet<Artifact> getProtobufHeaders() { NestedSetBuilder<Artifact> protobufHeaders = NestedSetBuilder.stableOrder(); for (ObjcProtoProvider objcProtoProvider : objcProtoProviders) { @@ -403,32 +361,6 @@ final class ProtobufSupport { return inputsToOutputsMapBuilder.build(); } - private XcodeProvider getBundleXcodeProvider( - ObjcCommon common, IntermediateArtifacts intermediateArtifacts, String labelSuffix) - throws RuleErrorException { - Iterable<PathFragment> userHeaderSearchPaths = - ImmutableList.of(getWorkspaceRelativeOutputDir()); - - XcodeProvider.Builder xcodeProviderBuilder = - new XcodeProvider.Builder() - .addUserHeaderSearchPaths(userHeaderSearchPaths) - .setCompilationArtifacts(common.getCompilationArtifacts().get()); - - XcodeSupport xcodeSupport = - new XcodeSupport(ruleContext, intermediateArtifacts, getXcodeLabel(labelSuffix)) - .addXcodeSettings(xcodeProviderBuilder, common.getObjcProvider(), LIBRARY_STATIC); - if (isLinkingTarget()) { - xcodeProviderBuilder - .addHeaders(getProtobufHeaders()) - .addUserHeaderSearchPaths(getProtobufHeaderSearchPaths()); - } else { - xcodeSupport.addDependencies( - xcodeProviderBuilder, new Attribute(ObjcRuleClasses.PROTO_LIB_ATTR, Mode.TARGET)); - } - - return xcodeProviderBuilder.build(); - } - private String getBundledProtosSuffix() { return "_" + BUNDLED_PROTOS_IDENTIFIER; } @@ -441,17 +373,6 @@ final class ProtobufSupport { return getBundledProtosSuffix() + "_" + actionId; } - private Label getXcodeLabel(String suffix) throws RuleErrorException { - Label xcodeLabel = null; - try { - xcodeLabel = - ruleContext.getLabel().getLocalTargetLabel(ruleContext.getLabel().getName() + suffix); - } catch (LabelSyntaxException e) { - ruleContext.throwWithRuleError(e.getLocalizedMessage()); - } - return xcodeLabel; - } - private IntermediateArtifacts getUniqueIntermediateArtifacts(int actionId) { return new IntermediateArtifacts( ruleContext, diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ProtocolBuffers2Support.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ProtocolBuffers2Support.java index 5b4300b50d..610f27776a 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/ProtocolBuffers2Support.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ProtocolBuffers2Support.java @@ -14,8 +14,6 @@ package com.google.devtools.build.lib.rules.objc; -import static com.google.devtools.build.lib.rules.objc.XcodeProductType.LIBRARY_STATIC; - import com.google.common.base.Function; import com.google.common.base.Optional; import com.google.common.collect.ImmutableList; @@ -119,21 +117,6 @@ final class ProtocolBuffers2Support { return getCommon().getObjcProvider(); } - /** Returns the XcodeProvider for this target. */ - public XcodeProvider getXcodeProvider() { - XcodeProvider.Builder xcodeProviderBuilder = - new XcodeProvider.Builder() - .addUserHeaderSearchPaths(getIncludes()) - .setCompilationArtifacts(getCompilationArtifacts()); - - new XcodeSupport(ruleContext) - .addXcodeSettings(xcodeProviderBuilder, getCommon().getObjcProvider(), LIBRARY_STATIC) - .addDependencies( - xcodeProviderBuilder, new Attribute(ObjcRuleClasses.PROTO_LIB_ATTR, Mode.TARGET)); - - return xcodeProviderBuilder.build(); - } - private String getHeaderExtension() { return ".pb" + (attributes.usesObjcHeaderNames() ? "objc.h" : ".h"); } diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/README.md b/src/main/java/com/google/devtools/build/lib/rules/objc/README.md new file mode 100644 index 0000000000..3f047918ae --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/README.md @@ -0,0 +1,84 @@ +# The Apple Rule Implementations: +The packages `devtools/build/lib/rules/objc` and +`devtools/build/lib/rules/apple` implement the objc and ios Bazel rules. + +## Interfacing from Skylark + +Information exchange between skylark rules and native objc_* or ios_* rules +occurs by three mechanisms: + +1) **`AppleToolchain:`** + +`AppleToolchain.java` houses constants and static methods for use in rule +implementations. It is accessed in skylark through the global `apple_common` +namespace: + +``` +def __impl(ctx): + platform_dir = apple_common.apple_toolchain().platform_dir('iphoneos') + sdk_dir = apple_common.apple_toolchain().sdk_dir() +``` + +2) **`AppleConfiguration` and `ObjcConfiguration`**: + +In Bazel, configuration fragments are used as containers for invocation-specific +build information (that is, information that cannot always be derived strictly +from BUILD files). The contents of these configurations can be inspected by +looking at `rules/objc/ObjcConfiguration.java` and +`rules/apple/AppleConfiguration.java`. To access a configuration fragment from +skylark, the fragment must be declared in the rule definition: + +``` +def __impl(ctx): + cpu = ctx.fragments.apple.ios_cpu() + env = ctx.fragments.apple.target_apple_env(platform) +my_rule = rule( + implementation = __impl + fragments = ['apple'] +) +``` + +3) **`ObjcProvider`**: + +The ObjcProvider maps "keys" to NestedSet instances, where "keys" are singleton +objects defined in ObjcProvider that identify a category of transitive +information to be communicated between targets in a dependency chain. + +Native objc/ios rules export ObjcProvider instances, which are made available +to skylark dependants: + +``` +def __impl(ctx): + dep = ctx.attr.deps[0] + objc_provider = dep.objc +``` + +The provider can be queried by accessing fields that correspond to ObjcProvider +keys. + +``` + libraries = objc_provider.library # A SkylarkNestedSet of Artifacts +``` + +A skylark rule that is intended to be a dependency of native objc rules should +export an ObjcProvider itself. An ObjcProvider is constructed using a +constructor exposed on the apple_common namespace. + +``` +def __impl(ctx): + define = 'some_define' + objc_provider = apple_common.new_objc_provider(define=define) + return struct(objc = objc_provider) +``` + +Arguments to `new_objc_provider` should correspond to ObjcProvider keys, and +values should be skylark sets that should be added to the provider. Other +instances of ObjcProvider can also be used in provider construction. + +``` +def __impl(ctx): + dep = ctx.attr.deps[0] + define = 'some_define' + objc_provider = apple_common.new_objc_provider(providers=[dep.objc], define=define) + return struct(objc = objc_provider) +``` 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 52e117246f..b5d7dacd89 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 @@ -20,17 +20,14 @@ import static com.google.devtools.build.lib.rules.objc.ObjcProvider.Flag.USES_SW 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.DEBUG_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.dd.plist.NSArray; import com.dd.plist.NSDictionary; import com.dd.plist.NSObject; import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Joiner; import com.google.common.base.Optional; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.analysis.BuildInfo; @@ -63,7 +60,6 @@ import com.google.devtools.build.lib.rules.apple.Platform.PlatformType; import com.google.devtools.build.lib.rules.objc.BundleSupport.ExtraActoolArgs; import com.google.devtools.build.lib.rules.objc.Bundling.Builder; import com.google.devtools.build.lib.shell.ShellUtils; -import com.google.devtools.build.xcode.xcodegen.proto.XcodeGenProtos.XcodeprojBuildSetting; import java.util.List; import java.util.Map.Entry; import javax.annotation.Nullable; @@ -612,20 +608,6 @@ public final class ReleaseBundlingSupport { } /** - * Adds bundle- and application-related settings to the given Xcode provider builder. - * - * @return this application support - */ - ReleaseBundlingSupport addXcodeSettings(XcodeProvider.Builder xcodeProviderBuilder) { - bundleSupport.addXcodeSettings(xcodeProviderBuilder); - // Add application-related Xcode build settings to the main target only. The companion library - // target does not need them. - xcodeProviderBuilder.addMainTargetXcodeprojBuildSettings(buildSettings()); - - return this; - } - - /** * Adds any files to the given nested set builder that should be built if this application is the * top level target in a blaze invocation. * @@ -845,47 +827,6 @@ public final class ReleaseBundlingSupport { return linkedBinariesBuilder.build(); } - /** Returns this target's Xcode build settings. */ - private Iterable<XcodeprojBuildSetting> buildSettings() { - ImmutableList.Builder<XcodeprojBuildSetting> buildSettings = new ImmutableList.Builder<>(); - if (releaseBundling.getAppIcon() != null) { - buildSettings.add(XcodeprojBuildSetting.newBuilder() - .setName("ASSETCATALOG_COMPILER_APPICON_NAME") - .setValue(releaseBundling.getAppIcon()) - .build()); - } - if (releaseBundling.getLaunchImage() != null) { - buildSettings.add(XcodeprojBuildSetting.newBuilder() - .setName("ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME") - .setValue(releaseBundling.getLaunchImage()) - .build()); - } - - // Convert names to a sequence containing "1" and/or "2" for iPhone and iPad, respectively. - ImmutableSet<TargetDeviceFamily> families; - if (bundleSupport.isBuildingForWatch()) { - families = ImmutableSet.of(TargetDeviceFamily.WATCH); - } else { - families = bundleSupport.targetDeviceFamilies(); - } - Iterable<Integer> familyIndexes = - families.isEmpty() ? ImmutableList.<Integer>of() : UI_DEVICE_FAMILY_VALUES.get(families); - buildSettings.add(XcodeprojBuildSetting.newBuilder() - .setName("TARGETED_DEVICE_FAMILY") - .setValue(Joiner.on(',').join(familyIndexes)) - .build()); - - Artifact entitlements = releaseBundling.getEntitlements(); - if (entitlements != null) { - buildSettings.add(XcodeprojBuildSetting.newBuilder() - .setName("CODE_SIGN_ENTITLEMENTS") - .setValue("$(WORKSPACE_ROOT)/" + entitlements.getExecPathString()) - .build()); - } - - return buildSettings.build(); - } - private void registerBundleMergeActions() { Artifact bundleMergeControlArtifact = ObjcRuleClasses.artifactByAppendingToBaseName(ruleContext, artifactName(".ipa-control")); diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ReleaseBundlingTargetFactory.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ReleaseBundlingTargetFactory.java index 39b5992f45..6a50889637 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/ReleaseBundlingTargetFactory.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ReleaseBundlingTargetFactory.java @@ -21,10 +21,8 @@ import com.google.devtools.build.lib.analysis.ConfiguredTarget; import com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder; import com.google.devtools.build.lib.analysis.RuleContext; import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; -import com.google.devtools.build.lib.packages.RuleClass.ConfiguredTargetFactory.RuleErrorException; import com.google.devtools.build.lib.rules.RuleConfiguredTargetFactory; import com.google.devtools.build.lib.rules.apple.AppleConfiguration; -import com.google.devtools.build.lib.rules.apple.AppleConfiguration.ConfigurationDistinguisher; import com.google.devtools.build.lib.rules.apple.DottedVersion; import com.google.devtools.build.lib.rules.apple.Platform.PlatformType; import com.google.devtools.build.lib.rules.objc.ReleaseBundlingSupport.LinkedBinary; @@ -42,28 +40,18 @@ import javax.annotation.Nullable; public abstract class ReleaseBundlingTargetFactory implements RuleConfiguredTargetFactory { private final String bundleDirFormat; - private final XcodeProductType xcodeProductType; private final ImmutableSet<Attribute> dependencyAttributes; - private final ConfigurationDistinguisher configurationDistinguisher; /** * @param bundleDirFormat format string representing the bundle's directory with a single * placeholder for the target name (e.g. {@code "Payload/%s.app"}) * @param dependencyAttributes all attributes that contain dependencies of this rule. Any - * dependency so listed must expose {@link XcodeProvider} and {@link ObjcProvider}. - * @param configurationDistinguisher distinguisher used for cases where inputs from dependencies - * of this bundle may need distinguishing because they come from configurations that are only - * different by this value + * dependency so listed must expose {@link ObjcProvider}. */ public ReleaseBundlingTargetFactory( - String bundleDirFormat, - XcodeProductType xcodeProductType, - ImmutableSet<Attribute> dependencyAttributes, - ConfigurationDistinguisher configurationDistinguisher) { + String bundleDirFormat, ImmutableSet<Attribute> dependencyAttributes) { this.bundleDirFormat = bundleDirFormat; - this.xcodeProductType = xcodeProductType; this.dependencyAttributes = dependencyAttributes; - this.configurationDistinguisher = configurationDistinguisher; } @Override @@ -76,7 +64,6 @@ public abstract class ReleaseBundlingTargetFactory implements RuleConfiguredTarg validateAttributes(ruleContext); ObjcCommon common = common(ruleContext); - XcodeProvider.Builder xcodeProviderBuilder = new XcodeProvider.Builder(); NestedSetBuilder<Artifact> filesToBuild = NestedSetBuilder.stableOrder(); AppleConfiguration appleConfiguration = ruleContext.getFragment(AppleConfiguration.class); @@ -86,28 +73,13 @@ public abstract class ReleaseBundlingTargetFactory implements RuleConfiguredTarg appleConfiguration.getMultiArchPlatform(PlatformType.IOS)); releaseBundlingSupport .registerActions(DsymOutputType.APP) - .addXcodeSettings(xcodeProviderBuilder) .addFilesToBuild(filesToBuild, Optional.of(DsymOutputType.APP)) .validateResources() .validateAttributes(); - XcodeSupport xcodeSupport = new XcodeSupport(ruleContext) - .addFilesToBuild(filesToBuild) - .addXcodeSettings(xcodeProviderBuilder, common.getObjcProvider(), xcodeProductType, - ruleContext.getFragment(AppleConfiguration.class).getDependencySingleArchitecture(), - configurationDistinguisher) - .addDummySource(xcodeProviderBuilder); - - for (Attribute attribute : dependencyAttributes) { - xcodeSupport.addDependencies(xcodeProviderBuilder, attribute); - } - - xcodeSupport.registerActions(xcodeProviderBuilder.build()); - RuleConfiguredTargetBuilder targetBuilder = ObjcRuleClasses.ruleConfiguredTarget(ruleContext, filesToBuild.build()) .addProvider(XcTestAppProvider.class, releaseBundlingSupport.xcTestAppProvider()) - .addProvider(XcodeProvider.class, xcodeProviderBuilder.build()) .addProvider( InstrumentedFilesProvider.class, InstrumentedFilesCollector.forward(ruleContext, "binary")); diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ResourceSupport.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ResourceSupport.java index 3b067f8cfc..1cb626edb7 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/ResourceSupport.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ResourceSupport.java @@ -39,16 +39,6 @@ final class ResourceSupport { } /** - * Adds common xcode settings to the given provider builder. - * - * @return this resource support - */ - ResourceSupport addXcodeSettings(XcodeProvider.Builder xcodeProviderBuilder) { - xcodeProviderBuilder.addInputsToXcodegen(Xcdatamodel.inputsToXcodegen(attributes.datamodels())); - return this; - } - - /** * Validates resource attributes on this rule. * * @return this resource support diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/WatchApplicationSupport.java b/src/main/java/com/google/devtools/build/lib/rules/objc/WatchApplicationSupport.java index 6b7db2dc70..fdc8796565 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/WatchApplicationSupport.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/WatchApplicationSupport.java @@ -43,18 +43,14 @@ import com.google.common.collect.ImmutableSet; import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.analysis.RuleConfiguredTarget.Mode; import com.google.devtools.build.lib.analysis.RuleContext; -import com.google.devtools.build.lib.cmdline.Label; -import com.google.devtools.build.lib.cmdline.LabelSyntaxException; import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; import com.google.devtools.build.lib.rules.apple.AppleConfiguration; -import com.google.devtools.build.lib.rules.apple.AppleConfiguration.ConfigurationDistinguisher; import com.google.devtools.build.lib.rules.apple.DottedVersion; import com.google.devtools.build.lib.rules.apple.Platform; import com.google.devtools.build.lib.rules.apple.Platform.PlatformType; import com.google.devtools.build.lib.rules.objc.ReleaseBundlingSupport.LinkedBinary; import com.google.devtools.build.lib.rules.objc.WatchUtils.WatchOSVersion; import com.google.devtools.build.lib.syntax.Type; -import com.google.devtools.build.xcode.xcodegen.proto.XcodeGenProtos.XcodeprojBuildSetting; import javax.annotation.Nullable; /** @@ -121,56 +117,6 @@ final class WatchApplicationSupport { ObjcProvider objcProvider = objcProvider(innerBundleZips); - createBundle( - Optional.<XcodeProvider.Builder>absent(), - objcProvider, - filesToBuild); - } - - /** - * Registers actions to create a watch application bundle and xcode project. - * - * @param xcodeProviderBuilder provider builder which xcode project generation information is - * added to (for later consumption by depending rules) - * @param innerBundleZips any zip files to be unzipped and merged into the application bundle - * @param filesToBuild files to build for the rule; the watchOS application .ipa is added to this - * set - */ - void createBundleAndXcodeproj( - XcodeProvider.Builder xcodeProviderBuilder, - Iterable<Artifact> innerBundleZips, - NestedSetBuilder<Artifact> filesToBuild) - throws InterruptedException { - ObjcProvider objcProvider = objcProvider(innerBundleZips); - - createBundle( - Optional.of(xcodeProviderBuilder), objcProvider, filesToBuild); - - // Add common watch settings. - WatchUtils.addXcodeSettings(ruleContext, xcodeProviderBuilder); - - // Add watch application specific xcode settings. - addXcodeSettings(xcodeProviderBuilder); - - XcodeSupport xcodeSupport = - new XcodeSupport(ruleContext, intermediateArtifacts, labelForWatchApplication()) - .addXcodeSettings( - xcodeProviderBuilder, - objcProvider, - watchOSVersion.getApplicationXcodeProductType(), - ruleContext.getFragment(AppleConfiguration.class).getIosCpu(), - ConfigurationDistinguisher.WATCH_OS1_EXTENSION); - - for (Attribute attribute : dependencyAttributes) { - xcodeSupport.addDependencies(xcodeProviderBuilder, attribute); - } - } - - private void createBundle( - Optional<XcodeProvider.Builder> xcodeProviderBuilder, - ObjcProvider depsObjcProvider, - NestedSetBuilder<Artifact> filesToBuild) - throws InterruptedException { registerActions(); ReleaseBundling.Builder releaseBundling = new ReleaseBundling.Builder() @@ -203,7 +149,7 @@ final class WatchApplicationSupport { ReleaseBundlingSupport releaseBundlingSupport = new ReleaseBundlingSupport( ruleContext, - depsObjcProvider, + objcProvider, LinkedBinary.DEPENDENCIES_ONLY, watchOSVersion.getApplicationBundleDirFormat(), bundleName, @@ -212,10 +158,6 @@ final class WatchApplicationSupport { appleConfiguration.getMultiArchPlatform(appPlatformType)) .registerActions(DsymOutputType.APP); - if (xcodeProviderBuilder.isPresent()) { - releaseBundlingSupport.addXcodeSettings(xcodeProviderBuilder.get()); - } - releaseBundlingSupport .addFilesToBuild(filesToBuild, Optional.<DsymOutputType>absent()) .validateResources() @@ -242,19 +184,6 @@ final class WatchApplicationSupport { } /** - * Adds watch application specific xcode settings - TARGETED_DEVICE_FAMILY is set to "1, 4" - * for enabling building for simulator. - */ - private void addXcodeSettings(XcodeProvider.Builder xcodeProviderBuilder) { - xcodeProviderBuilder.addMainTargetXcodeprojBuildSettings(ImmutableList.of( - XcodeprojBuildSetting.newBuilder() - .setName("TARGETED_DEVICE_FAMILY[sdk=iphonesimulator*]") - .setValue(Joiner.on(',').join(TargetDeviceFamily.UI_DEVICE_FAMILY_VALUES.get( - families()))) - .build())); - } - - /** * Registers actions to copy WatchKit stub binary at * $(SDK_ROOT)/Library/Application Support/WatchKit/WK as bundle binary and as stub resource. * @@ -347,16 +276,6 @@ final class WatchApplicationSupport { return objcProviderBuilder.build(); } - private Label labelForWatchApplication() - throws InterruptedException { - try { - return Label.create(ruleContext.getLabel().getPackageName(), bundleName); - } catch (LabelSyntaxException labelSyntaxException) { - throw new InterruptedException("Exception while creating target label for watch " - + "appplication " + labelSyntaxException); - } - } - /** * Returns a zip {@link Artifact} containing stub binary and stub resource that are to be added * to the bundle. diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/WatchExtensionSupport.java b/src/main/java/com/google/devtools/build/lib/rules/objc/WatchExtensionSupport.java index afc177a797..ba2634a792 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/WatchExtensionSupport.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/WatchExtensionSupport.java @@ -43,12 +43,10 @@ import com.google.devtools.build.lib.analysis.RuleContext; import com.google.devtools.build.lib.analysis.actions.FileWriteAction; import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; import com.google.devtools.build.lib.rules.apple.AppleConfiguration; -import com.google.devtools.build.lib.rules.apple.AppleConfiguration.ConfigurationDistinguisher; import com.google.devtools.build.lib.rules.apple.Platform.PlatformType; import com.google.devtools.build.lib.rules.objc.ReleaseBundlingSupport.LinkedBinary; import com.google.devtools.build.lib.rules.objc.TargetDeviceFamily.InvalidFamilyNameException; import com.google.devtools.build.lib.rules.objc.TargetDeviceFamily.RepeatedFamilyNameException; -import com.google.devtools.build.lib.rules.objc.WatchUtils.WatchOSVersion; import com.google.devtools.build.lib.syntax.Type; import java.util.List; import javax.annotation.Nullable; @@ -71,8 +69,6 @@ public class WatchExtensionSupport { private final Artifact ipaArtifact; private final Artifact watchApplicationBundle; private final Attributes attributes; - private final XcodeProvider watchApplicationXcodeProvider; - private final ConfigurationDistinguisher configurationDistinguisher; WatchExtensionSupport( RuleContext ruleContext, @@ -80,28 +76,22 @@ public class WatchExtensionSupport { IntermediateArtifacts intermediateArtifacts, String bundleName, Artifact ipaArtifact, - @Nullable Artifact watchApplicationBundle, - @Nullable XcodeProvider watchApplicationXcodeProvider, - ConfigurationDistinguisher configurationDistinguisher) { + @Nullable Artifact watchApplicationBundle) { this.ruleContext = ruleContext; this.dependencyAttributes = dependencyAttributes; this.intermediateArtifacts = intermediateArtifacts; this.bundleName = bundleName; this.ipaArtifact = ipaArtifact; this.attributes = new Attributes(ruleContext); - this.watchApplicationXcodeProvider = checkNotNull(watchApplicationXcodeProvider); this.watchApplicationBundle = checkNotNull(watchApplicationBundle); - this.configurationDistinguisher = configurationDistinguisher; } - void createBundle(NestedSetBuilder<Artifact> filesToBuild, - ObjcProvider.Builder exposedObjcProviderBuilder, XcodeProvider.Builder xcodeProviderBuilder) - throws InterruptedException { + void createBundle( + NestedSetBuilder<Artifact> filesToBuild, ObjcProvider.Builder exposedObjcProviderBuilder) + throws InterruptedException { ObjcProvider releaseBundlingObjcProvider = releaseBundlingObjcProvider(); - WatchUtils.addXcodeSettings(ruleContext, xcodeProviderBuilder); - registerWatchExtensionAutomaticPlistAction(); ImmutableSet<TargetDeviceFamily> families = attributes.families(); @@ -142,36 +132,12 @@ public class WatchExtensionSupport { appleConfiguration.getMultiArchPlatform(PlatformType.IOS)); releaseBundlingSupport.registerActions(DsymOutputType.APP); - releaseBundlingSupport.addXcodeSettings(xcodeProviderBuilder); releaseBundlingSupport .addFilesToBuild(filesToBuild, Optional.of(DsymOutputType.APP)) .validateResources() .validateAttributes() .addExportedDebugArtifacts(exposedObjcProviderBuilder, DsymOutputType.APP); - - XcodeSupport xcodeSupport = - new XcodeSupport(ruleContext) - .addFilesToBuild(filesToBuild) - .addXcodeSettings( - xcodeProviderBuilder, - releaseBundlingObjcProvider, - WatchOSVersion.OS1.getExtensionXcodeProductType(), - ruleContext - .getFragment(AppleConfiguration.class) - .getDependencySingleArchitecture(), - configurationDistinguisher) - .addDummySource(xcodeProviderBuilder); - - for (Attribute attribute : dependencyAttributes) { - xcodeSupport.addDependencies(xcodeProviderBuilder, attribute); - } - - // Generate xcodeproj for watch OS 1 extension as the main target with watch application - // target as the dependency. - xcodeProviderBuilder.addPropagatedDependencies( - ImmutableList.of(watchApplicationXcodeProvider)); - xcodeSupport.registerActions(xcodeProviderBuilder.build()); } /** diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/WatchUtils.java b/src/main/java/com/google/devtools/build/lib/rules/objc/WatchUtils.java index 08d99e49b8..2805fb7c9d 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/WatchUtils.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/WatchUtils.java @@ -25,7 +25,6 @@ import com.google.devtools.build.lib.analysis.RuleContext; import com.google.devtools.build.lib.rules.apple.AppleConfiguration; import com.google.devtools.build.lib.rules.apple.DottedVersion; import com.google.devtools.build.lib.rules.apple.Platform.PlatformType; -import com.google.devtools.build.xcode.xcodegen.proto.XcodeGenProtos.XcodeprojBuildSetting; /** * Contains support methods for common processing and generating of watch extension and application @@ -48,45 +47,21 @@ final class WatchUtils { */ enum WatchOSVersion { OS1( - XcodeProductType.WATCH_OS1_APPLICATION, - XcodeProductType.WATCH_OS1_EXTENSION, ReleaseBundlingSupport.APP_BUNDLE_DIR_FORMAT, "WatchKitSupport"), OS2( - XcodeProductType.WATCH_OS2_APPLICATION, - XcodeProductType.WATCH_OS2_EXTENSION, WATCH2_APP_BUNDLE_DIR_FORMAT, "WatchKitSupport2"); - private final XcodeProductType applicationXcodeProductType; - private final XcodeProductType extensionXcodeProductType; private final String applicationBundleDirFormat; private final String watchKitSupportDirName; WatchOSVersion( - XcodeProductType applicationXcodeProductType, - XcodeProductType extensionXcodeProductType, String applicationBundleDirFormat, String watchKitSupportDirName) { - this.applicationXcodeProductType = applicationXcodeProductType; - this.extensionXcodeProductType = extensionXcodeProductType; this.applicationBundleDirFormat = applicationBundleDirFormat; this.watchKitSupportDirName = watchKitSupportDirName; } - - /** - * Returns the {@link XcodeProductType} to be used for the watch application's Xcode target. - */ - XcodeProductType getApplicationXcodeProductType() { - return applicationXcodeProductType; - } - - /** - * Returns the {@link XcodeProductType} to be used for the watch extension's Xcode target. - */ - XcodeProductType getExtensionXcodeProductType() { - return extensionXcodeProductType; - } /** Returns the bundle directory format of the watch application relative to its container. */ String getApplicationBundleDirFormat() { @@ -111,15 +86,6 @@ final class WatchUtils { static final DottedVersion MINIMUM_OS_VERSION = DottedVersion.fromString("8.2"); /** - * Adds common xcode build settings required for watch bundles to the given xcode provider - * builder. - */ - static void addXcodeSettings(RuleContext ruleContext, - XcodeProvider.Builder xcodeProviderBuilder) { - xcodeProviderBuilder.addMainTargetXcodeprojBuildSettings(xcodeSettings(ruleContext)); - } - - /** * Watch Extension are not accepted by Apple below iOS version 8.2. While applications built with * a minimum iOS version of less than 8.2 may contain watch extension in their bundle, the * extension itself needs to be built with 8.2 or higher. This logic overrides (if necessary) @@ -130,10 +96,6 @@ final class WatchUtils { return Ordering.natural().max(fromFlag, MINIMUM_OS_VERSION); } - static boolean isBuildingForWatchOS1Version(WatchOSVersion watchOSVersion) { - return watchOSVersion == WatchOSVersion.OS1; - } - /** * Adds WatchKitSupport stub to the final ipa and exposes it to given @{link ObjcProvider.Builder} * based on watch OS version. @@ -184,21 +146,4 @@ final class WatchUtils { return ruleContext.getRelatedArtifact( ruleContext.getUniqueDirectory("_watch"), "/WatchKitSupport.zip"); } - - private static Iterable<XcodeprojBuildSetting> xcodeSettings(RuleContext ruleContext) { - ImmutableList.Builder<XcodeprojBuildSetting> xcodeSettings = new ImmutableList.Builder<>(); - xcodeSettings.add( - XcodeprojBuildSetting.newBuilder() - .setName("RESOURCES_TARGETED_DEVICE_FAMILY") - .setValue(TargetDeviceFamily.WATCH.getNameInRule()) - .build()); - xcodeSettings.add( - XcodeprojBuildSetting.newBuilder() - .setName("IPHONEOS_DEPLOYMENT_TARGET") - .setValue(determineMinimumIosVersion( - ruleContext.getFragment(AppleConfiguration.class) - .getMinimumOsForPlatformType(PlatformType.IOS)).toString()) - .build()); - return xcodeSettings.build(); - } } diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/XcodeProductType.java b/src/main/java/com/google/devtools/build/lib/rules/objc/XcodeProductType.java deleted file mode 100644 index bc4bb96722..0000000000 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/XcodeProductType.java +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright 2014 The Bazel Authors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package com.google.devtools.build.lib.rules.objc; - -/** - * Possible values that {@code objc_*} rules care about for what Xcode project files refer to as - * "product type." - */ -enum XcodeProductType { - LIBRARY_STATIC("com.apple.product-type.library.static"), - BUNDLE("com.apple.product-type.bundle"), - APPLICATION("com.apple.product-type.application"), - UNIT_TEST("com.apple.product-type.bundle.unit-test"), - EXTENSION("com.apple.product-type.app-extension"), - FRAMEWORK("com.apple.product-type.framework"), - WATCH_OS1_APPLICATION("com.apple.product-type.application.watchapp"), - WATCH_OS2_APPLICATION("com.apple.product-type.application.watchapp2"), - WATCH_OS1_EXTENSION("com.apple.product-type.watchkit-extension"), - WATCH_OS2_EXTENSION("com.apple.product-type.watchkit2-extension"); - - private final String identifier; - - XcodeProductType(String identifier) { - this.identifier = identifier; - } - - /** - * Returns the string used to identify this product type in the {@code productType} field of - * {@code PBXNativeTarget} objects in Xcode project files. - */ - public String getIdentifier() { - return identifier; - } -} diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/XcodeProvider.java b/src/main/java/com/google/devtools/build/lib/rules/objc/XcodeProvider.java deleted file mode 100644 index 45366a60ba..0000000000 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/XcodeProvider.java +++ /dev/null @@ -1,811 +0,0 @@ -// Copyright 2014 The Bazel Authors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package com.google.devtools.build.lib.rules.objc; - -import static com.google.devtools.build.lib.rules.objc.LegacyCompilationSupport.AUTOMATIC_SDK_FRAMEWORKS; -import static com.google.devtools.build.lib.rules.objc.ObjcProvider.BUNDLE_IMPORT_DIR; -import static com.google.devtools.build.lib.rules.objc.ObjcProvider.CC_LIBRARY; -import static com.google.devtools.build.lib.rules.objc.ObjcProvider.DEFINE; -import static com.google.devtools.build.lib.rules.objc.ObjcProvider.FORCE_LOAD_FOR_XCODEGEN; -import static com.google.devtools.build.lib.rules.objc.ObjcProvider.FRAMEWORK_SEARCH_PATH_ONLY; -import static com.google.devtools.build.lib.rules.objc.ObjcProvider.GENERAL_RESOURCE_DIR; -import static com.google.devtools.build.lib.rules.objc.ObjcProvider.GENERAL_RESOURCE_FILE; -import static com.google.devtools.build.lib.rules.objc.ObjcProvider.IMPORTED_LIBRARY; -import static com.google.devtools.build.lib.rules.objc.ObjcProvider.SDK_DYLIB; -import static com.google.devtools.build.lib.rules.objc.ObjcProvider.SDK_FRAMEWORK; -import static com.google.devtools.build.lib.rules.objc.ObjcProvider.STATIC_FRAMEWORK_DIR; -import static com.google.devtools.build.lib.rules.objc.ObjcProvider.WEAK_SDK_FRAMEWORK; -import static com.google.devtools.build.lib.rules.objc.ObjcProvider.XCASSETS_DIR; -import static com.google.devtools.build.lib.rules.objc.ObjcProvider.XCDATAMODEL; -import static com.google.devtools.build.lib.rules.objc.XcodeProductType.LIBRARY_STATIC; -import static com.google.devtools.build.lib.rules.objc.XcodeProductType.WATCH_OS1_APPLICATION; - -import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Function; -import com.google.common.base.Joiner; -import com.google.common.base.Optional; -import com.google.common.base.Splitter; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; -import com.google.devtools.build.lib.actions.Artifact; -import com.google.devtools.build.lib.analysis.TransitiveInfoProvider; -import com.google.devtools.build.lib.cmdline.Label; -import com.google.devtools.build.lib.collect.nestedset.NestedSet; -import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; -import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; -import com.google.devtools.build.lib.rules.apple.AppleConfiguration.ConfigurationDistinguisher; -import com.google.devtools.build.lib.rules.apple.AppleToolchain; -import com.google.devtools.build.lib.rules.cpp.LinkerInputs; -import com.google.devtools.build.lib.rules.objc.ObjcProvider.Flag; -import com.google.devtools.build.lib.util.Preconditions; -import com.google.devtools.build.lib.vfs.PathFragment; -import com.google.devtools.build.xcode.xcodegen.proto.XcodeGenProtos.DependencyControl; -import com.google.devtools.build.xcode.xcodegen.proto.XcodeGenProtos.TargetControl; -import com.google.devtools.build.xcode.xcodegen.proto.XcodeGenProtos.XcodeprojBuildSetting; -import java.util.Arrays; -import java.util.EnumSet; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -/** - * Provider which provides transitive dependency information that is specific to Xcodegen. In - * particular, it provides a sequence of targets which can be used to create a self-contained - * {@code .xcodeproj} file. - */ -@Immutable -public final class XcodeProvider implements TransitiveInfoProvider { - private static final String COMPANION_LIB_TARGET_LABEL_SUFFIX = "_static_lib"; - - /** - * A builder for instances of {@link XcodeProvider}. - */ - public static final class Builder { - private Label label; - // Propagated dependencies and search paths are seen by all transitive dependents of this - // target. Non propagated dependencies are only seen by this target; none of the direct and - // transitive dependents of this target will see this provider. Strictly propagated dependencies - // are only seen by this target and only direct dependents; transitive dependents won't see this - // provider. - private final NestedSetBuilder<String> propagatedUserHeaderSearchPaths = - NestedSetBuilder.linkOrder(); - private final NestedSetBuilder<String> nonPropagatedUserHeaderSearchPaths = - NestedSetBuilder.linkOrder(); - private final NestedSetBuilder<String> strictlyPropagatedUserHeaderSearchPaths = - NestedSetBuilder.linkOrder(); - private final NestedSetBuilder<String> propagatedHeaderSearchPaths = - NestedSetBuilder.linkOrder(); - private final NestedSetBuilder<String> nonPropagatedHeaderSearchPaths = - NestedSetBuilder.linkOrder(); - private final NestedSetBuilder<String> strictlyPropagatedHeaderSearchPaths = - NestedSetBuilder.linkOrder(); - // Dependencies must be in link order because XCode observes the dependency ordering for - // binary linking. - private final NestedSetBuilder<XcodeProvider> propagatedDependencies = - NestedSetBuilder.linkOrder(); - private final NestedSetBuilder<XcodeProvider> nonPropagatedDependencies = - NestedSetBuilder.linkOrder(); - private final NestedSetBuilder<XcodeProvider> strictlyPropagatedDependencies = - NestedSetBuilder.linkOrder(); - private Optional<Artifact> bundleInfoplist = Optional.absent(); - private final NestedSetBuilder<XcodeProvider> jreDependencies = NestedSetBuilder.linkOrder(); - private final ImmutableList.Builder<XcodeprojBuildSetting> xcodeprojBuildSettings = - new ImmutableList.Builder<>(); - private final ImmutableList.Builder<XcodeprojBuildSetting> - companionTargetXcodeprojBuildSettings = new ImmutableList.Builder<>(); - private final ImmutableList.Builder<String> copts = new ImmutableList.Builder<>(); - private final ImmutableList.Builder<String> compilationModeCopts = - new ImmutableList.Builder<>(); - private XcodeProductType productType; - private final ImmutableList.Builder<Artifact> headers = new ImmutableList.Builder<>(); - private Optional<CompilationArtifacts> compilationArtifacts = Optional.absent(); - private ObjcProvider objcProvider; - private Optional<XcodeProvider> testHost = Optional.absent(); - private final NestedSetBuilder<Artifact> inputsToXcodegen = NestedSetBuilder.stableOrder(); - private final NestedSetBuilder<Artifact> additionalSources = NestedSetBuilder.stableOrder(); - private final ImmutableList.Builder<XcodeProvider> extensions = new ImmutableList.Builder<>(); - private String architecture; - private boolean generateCompanionLibTarget = false; - private ConfigurationDistinguisher configurationDistinguisher; - - /** - * Sets the label of the build target which corresponds to this Xcode target. - */ - public Builder setLabel(Label label) { - this.label = label; - return this; - } - - /** - * Adds user header search paths for this target. - */ - public Builder addUserHeaderSearchPaths(Iterable<PathFragment> userHeaderSearchPaths) { - this.propagatedUserHeaderSearchPaths - .addAll(rootEach("$(WORKSPACE_ROOT)", userHeaderSearchPaths)); - return this; - } - - /** - * Adds header search paths for this target. Each path is interpreted relative to the given - * root, such as {@code "$(WORKSPACE_ROOT)"}. - */ - public Builder addHeaderSearchPaths(String root, Iterable<PathFragment> paths) { - this.propagatedHeaderSearchPaths.addAll(rootEach(root, paths)); - return this; - } - - /** - * Adds non-propagated header search paths for this target. Each relative path is interpreted - * relative to the given root, such as {@code "$(WORKSPACE_ROOT)"}. - */ - public Builder addNonPropagatedHeaderSearchPaths(String root, Iterable<PathFragment> paths) { - this.nonPropagatedHeaderSearchPaths.addAll(rootEach(root, paths)); - return this; - } - - /** - * Sets the Info.plist for the bundle represented by this provider. - */ - public Builder setBundleInfoplist(Artifact bundleInfoplist) { - this.bundleInfoplist = Optional.of(bundleInfoplist); - return this; - } - - /** - * Adds items in the {@link NestedSet}s of the given target to the corresponding sets in this - * builder. This is useful if the given target is a dependency or like a dependency - * (e.g. a test host). The given provider is not registered as a dependency with this provider. - */ - private void addTransitiveSets(XcodeProvider dependencyish) { - additionalSources.addTransitive(dependencyish.additionalSources); - inputsToXcodegen.addTransitive(dependencyish.inputsToXcodegen); - propagatedUserHeaderSearchPaths.addTransitive(dependencyish.propagatedUserHeaderSearchPaths); - propagatedHeaderSearchPaths.addTransitive(dependencyish.propagatedHeaderSearchPaths); - } - - /** - * Adds {@link XcodeProvider}s corresponding to direct dependencies of this target which should - * be added in the {@code .xcodeproj} file and propagated up the dependency chain. - */ - public Builder addPropagatedDependencies(Iterable<XcodeProvider> dependencies) { - return addDependencies(dependencies, /*doPropagate=*/true); - } - - /** - * Adds {@link XcodeProvider}s corresponding to direct dependencies of this target which should - * be added in the {@code .xcodeproj} file and only propagate the header search paths to direct - * dependents of this target. Propagated dependencies of this target are still propagated as the - * code still needs to be linked, and only limits the propagation of this target's header search - * paths. - */ - public Builder addPropagatedDependenciesWithStrictDependencyHeaders( - Iterable<XcodeProvider> dependencies) { - for (XcodeProvider dependency : dependencies) { - this.strictlyPropagatedDependencies.add(dependency); - this.propagatedDependencies.addTransitive(dependency.propagatedDependencies); - this.nonPropagatedDependencies.addTransitive(dependency.strictlyPropagatedDependencies); - this.strictlyPropagatedUserHeaderSearchPaths.addTransitive( - dependency.propagatedUserHeaderSearchPaths); - this.strictlyPropagatedHeaderSearchPaths.addTransitive( - dependency.propagatedHeaderSearchPaths); - } - return this; - } - - /** - * Adds {@link XcodeProvider}s corresponding to direct dependencies of this target which should - * be added in the {@code .xcodeproj} file and not propagated up the dependency chain. - */ - public Builder addNonPropagatedDependencies(Iterable<XcodeProvider> dependencies) { - return addDependencies(dependencies, /*doPropagate=*/false); - } - - /** - * Adds {@link XcodeProvider}s corresponding to direct J2ObjC JRE dependencies of this target - * which should be added in the {@code .xcodeproj} file and propagated up the dependency chain. - */ - public Builder addJreDependencies(Iterable<XcodeProvider> dependencies) { - for (XcodeProvider dependency : dependencies) { - this.jreDependencies.add(dependency); - this.jreDependencies.addTransitive(dependency.propagatedDependencies); - } - return addDependencies(dependencies, /*doPropagate=*/true); - } - - private Builder addDependencies(Iterable<XcodeProvider> dependencies, boolean doPropagate) { - for (XcodeProvider dependency : dependencies) { - // TODO(bazel-team): This is messy. Maybe we should make XcodeProvider be able to specify - // how to depend on it rather than require this method to choose based on the dependency's - // type. - if (dependency.productType == XcodeProductType.EXTENSION - || dependency.productType == XcodeProductType.WATCH_OS1_EXTENSION) { - this.extensions.add(dependency); - this.inputsToXcodegen.addTransitive(dependency.inputsToXcodegen); - this.additionalSources.addTransitive(dependency.additionalSources); - } else { - if (doPropagate) { - this.propagatedDependencies.add(dependency); - this.propagatedDependencies.addTransitive(dependency.propagatedDependencies); - this.jreDependencies.addTransitive(dependency.jreDependencies); - this.addTransitiveSets(dependency); - } else { - this.nonPropagatedDependencies.add(dependency); - this.nonPropagatedDependencies.addTransitive(dependency.propagatedDependencies); - this.nonPropagatedUserHeaderSearchPaths - .addTransitive(dependency.propagatedUserHeaderSearchPaths); - this.nonPropagatedHeaderSearchPaths - .addTransitive(dependency.propagatedHeaderSearchPaths); - this.inputsToXcodegen.addTransitive(dependency.inputsToXcodegen); - } - this.nonPropagatedUserHeaderSearchPaths.addTransitive( - dependency.strictlyPropagatedUserHeaderSearchPaths); - this.nonPropagatedHeaderSearchPaths.addTransitive( - dependency.strictlyPropagatedHeaderSearchPaths); - } - } - return this; - } - - /** - * Adds additional build settings of this target and its companion library target, if it exists. - */ - public Builder addXcodeprojBuildSettings( - Iterable<XcodeprojBuildSetting> xcodeprojBuildSettings) { - this.xcodeprojBuildSettings.addAll(xcodeprojBuildSettings); - this.companionTargetXcodeprojBuildSettings.addAll(xcodeprojBuildSettings); - return this; - } - - /** - * Adds additional build settings of this target without adding them to the companion lib - * target, if it exists. - */ - public Builder addMainTargetXcodeprojBuildSettings( - Iterable<XcodeprojBuildSetting> xcodeprojBuildSettings) { - this.xcodeprojBuildSettings.addAll(xcodeprojBuildSettings); - return this; - } - /** - * Sets the copts to use when compiling the Xcode target. - */ - public Builder addCopts(Iterable<String> copts) { - this.copts.addAll(copts); - return this; - } - - /** - * Sets the copts derived from compilation mode to use when compiling the Xcode target. These - * will be included before the DEFINE options. - */ - public Builder addCompilationModeCopts(Iterable<String> copts) { - this.compilationModeCopts.addAll(copts); - return this; - } - - /** - * Sets the product type for the PBXTarget in the .xcodeproj file. - */ - public Builder setProductType(XcodeProductType productType) { - this.productType = productType; - return this; - } - - /** - * Adds to the header files of this target. It needs not to include the header files of - * dependencies. - */ - public Builder addHeaders(Iterable<Artifact> headers) { - this.headers.addAll(headers); - return this; - } - - /** - * The compilation artifacts for this target. - */ - public Builder setCompilationArtifacts(CompilationArtifacts compilationArtifacts) { - this.compilationArtifacts = Optional.of(compilationArtifacts); - return this; - } - - /** - * Any additional sources not included in {@link #setCompilationArtifacts}. - */ - public Builder addAdditionalSources(Artifact... artifacts) { - this.additionalSources.addAll(Arrays.asList(artifacts)); - return this; - } - - /** - * Sets the {@link ObjcProvider} corresponding to this target. - */ - public Builder setObjcProvider(ObjcProvider objcProvider) { - this.objcProvider = objcProvider; - return this; - } - - /** - * Sets the test host. This is used for xctest targets. - */ - public Builder setTestHost(XcodeProvider testHost) { - Preconditions.checkState(!this.testHost.isPresent()); - this.testHost = Optional.of(testHost); - this.addTransitiveSets(testHost); - return this; - } - - /** - * Adds inputs that are passed to Xcodegen when generating the project file. - */ - public Builder addInputsToXcodegen(Iterable<Artifact> inputsToXcodegen) { - this.inputsToXcodegen.addAll(inputsToXcodegen); - return this; - } - - /** - * Sets the CPU architecture this xcode target was constructed for, derived from - * {@link ObjcConfiguration#getIosCpu()}. - */ - public Builder setArchitecture(String architecture) { - this.architecture = architecture; - return this; - } - - /** - * Generates an extra LIBRARY_STATIC Xcode target with the same compilation artifacts. Dependent - * Xcode targets will pick this companion library target as its dependency, rather than the - * main Xcode target of this provider. - */ - // TODO(bazel-team): Remove this when the binary rule types and bundling rule types are merged. - public Builder generateCompanionLibTarget() { - this.generateCompanionLibTarget = true; - return this; - } - - /** - * Sets the distinguisher that will cause this xcode provider to discard any dependencies from - * sources that are tagged with a different distinguisher. - */ - public Builder setConfigurationDistinguisher(ConfigurationDistinguisher distinguisher) { - this.configurationDistinguisher = distinguisher; - return this; - } - - public XcodeProvider build() { - Preconditions.checkState( - !testHost.isPresent() || (productType == XcodeProductType.UNIT_TEST), - "%s product types cannot have a test host (test host: %s).", productType, testHost); - return new XcodeProvider(this); - } - } - - /** - * A collection of top-level targets that can be used to create a complete project. - */ - public static final class Project { - private final NestedSet<Artifact> inputsToXcodegen; - private final NestedSet<Artifact> additionalSources; - private final ImmutableList<XcodeProvider> topLevelTargets; - - private Project( - NestedSet<Artifact> inputsToXcodegen, NestedSet<Artifact> additionalSources, - ImmutableList<XcodeProvider> topLevelTargets) { - this.inputsToXcodegen = inputsToXcodegen; - this.additionalSources = additionalSources; - this.topLevelTargets = topLevelTargets; - } - - public static Project fromTopLevelTarget(XcodeProvider topLevelTarget) { - return fromTopLevelTargets(ImmutableList.of(topLevelTarget)); - } - - public static Project fromTopLevelTargets(Iterable<XcodeProvider> topLevelTargets) { - NestedSetBuilder<Artifact> inputsToXcodegen = NestedSetBuilder.stableOrder(); - NestedSetBuilder<Artifact> additionalSources = NestedSetBuilder.stableOrder(); - for (XcodeProvider target : topLevelTargets) { - inputsToXcodegen.addTransitive(target.inputsToXcodegen); - additionalSources.addTransitive(target.additionalSources); - } - return new Project(inputsToXcodegen.build(), additionalSources.build(), - ImmutableList.copyOf(topLevelTargets)); - } - - /** - * Returns artifacts that are passed to the Xcodegen action when generating a project file that - * contains all of the given targets. - */ - public NestedSet<Artifact> getInputsToXcodegen() { - return inputsToXcodegen; - } - - /** - * Returns artifacts that are additional sources for the Xcodegen action. - */ - public NestedSet<Artifact> getAdditionalSources() { - return additionalSources; - } - - /** - * Returns all the target controls that must be added to the xcodegen control. No other target - * controls are needed to generate a functional project file. This method creates a new list - * whenever it is called. - */ - public ImmutableList<TargetControl> targets() { - // Collect all the dependencies of all the providers, filtering out duplicates. - Set<XcodeProvider> providerSet = new LinkedHashSet<>(); - for (XcodeProvider target : topLevelTargets) { - target.collectProviders(providerSet); - } - - ImmutableList.Builder<TargetControl> controls = new ImmutableList.Builder<>(); - Map<Label, XcodeProvider> labelToProvider = new HashMap<>(); - for (XcodeProvider provider : providerSet) { - XcodeProvider oldProvider = labelToProvider.put(provider.label, provider); - if (oldProvider != null) { - if (!oldProvider.architecture.equals(provider.architecture) - || oldProvider.configurationDistinguisher != provider.configurationDistinguisher) { - // Do not include duplicate dependencies whose architecture or configuration - // distinguisher does not match this project's. This check avoids having multiple - // conflicting Xcode targets for the same BUILD target that are only distinguished by - // these fields (which Xcode does not care about). - continue; - } - - throw new IllegalStateException("Depending on multiple versions of the same xcode target " - + "is not allowed but occurred for: " + provider.label); - } - controls.addAll(provider.targetControls()); - } - return controls.build(); - } - } - - private final Label label; - private final NestedSet<String> propagatedUserHeaderSearchPaths; - private final NestedSet<String> nonPropagatedUserHeaderSearchPaths; - private final NestedSet<String> strictlyPropagatedUserHeaderSearchPaths; - private final NestedSet<String> propagatedHeaderSearchPaths; - private final NestedSet<String> nonPropagatedHeaderSearchPaths; - private final NestedSet<String> strictlyPropagatedHeaderSearchPaths; - private final Optional<Artifact> bundleInfoplist; - private final NestedSet<XcodeProvider> propagatedDependencies; - private final NestedSet<XcodeProvider> nonPropagatedDependencies; - private final NestedSet<XcodeProvider> strictlyPropagatedDependencies; - private final NestedSet<XcodeProvider> jreDependencies; - private final ImmutableList<XcodeprojBuildSetting> xcodeprojBuildSettings; - private final ImmutableList<XcodeprojBuildSetting> companionTargetXcodeprojBuildSettings; - private final ImmutableList<String> copts; - private final ImmutableList<String> compilationModeCopts; - private final XcodeProductType productType; - private final ImmutableList<Artifact> headers; - private final Optional<CompilationArtifacts> compilationArtifacts; - private final ObjcProvider objcProvider; - private final Optional<XcodeProvider> testHost; - private final NestedSet<Artifact> inputsToXcodegen; - private final NestedSet<Artifact> additionalSources; - private final ImmutableList<XcodeProvider> extensions; - private final String architecture; - private final boolean generateCompanionLibTarget; - private final ConfigurationDistinguisher configurationDistinguisher; - - private XcodeProvider(Builder builder) { - this.label = Preconditions.checkNotNull(builder.label); - this.propagatedUserHeaderSearchPaths = builder.propagatedUserHeaderSearchPaths.build(); - this.nonPropagatedUserHeaderSearchPaths = builder.nonPropagatedUserHeaderSearchPaths.build(); - this.strictlyPropagatedUserHeaderSearchPaths = - builder.strictlyPropagatedUserHeaderSearchPaths.build(); - this.propagatedHeaderSearchPaths = builder.propagatedHeaderSearchPaths.build(); - this.nonPropagatedHeaderSearchPaths = builder.nonPropagatedHeaderSearchPaths.build(); - this.strictlyPropagatedHeaderSearchPaths = builder.strictlyPropagatedHeaderSearchPaths.build(); - this.bundleInfoplist = builder.bundleInfoplist; - this.propagatedDependencies = builder.propagatedDependencies.build(); - this.nonPropagatedDependencies = builder.nonPropagatedDependencies.build(); - this.strictlyPropagatedDependencies = builder.strictlyPropagatedDependencies.build(); - this.jreDependencies = builder.jreDependencies.build(); - this.xcodeprojBuildSettings = builder.xcodeprojBuildSettings.build(); - this.companionTargetXcodeprojBuildSettings = - builder.companionTargetXcodeprojBuildSettings.build(); - this.copts = builder.copts.build(); - this.compilationModeCopts = builder.compilationModeCopts.build(); - this.productType = Preconditions.checkNotNull(builder.productType); - this.headers = builder.headers.build(); - this.compilationArtifacts = builder.compilationArtifacts; - this.objcProvider = Preconditions.checkNotNull(builder.objcProvider); - this.testHost = Preconditions.checkNotNull(builder.testHost); - this.inputsToXcodegen = builder.inputsToXcodegen.build(); - this.additionalSources = builder.additionalSources.build(); - this.extensions = builder.extensions.build(); - this.architecture = Preconditions.checkNotNull(builder.architecture); - this.generateCompanionLibTarget = builder.generateCompanionLibTarget; - this.configurationDistinguisher = - Preconditions.checkNotNull(builder.configurationDistinguisher); - } - - private void collectProviders(Set<XcodeProvider> allProviders) { - if (allProviders.add(this)) { - Iterable<XcodeProvider> allDependencies = - Iterables.concat( - propagatedDependencies, nonPropagatedDependencies, strictlyPropagatedDependencies); - for (XcodeProvider dependency : allDependencies) { - dependency.collectProviders(allProviders); - } - for (XcodeProvider justTestHost : testHost.asSet()) { - justTestHost.collectProviders(allProviders); - } - for (XcodeProvider extension : extensions) { - extension.collectProviders(allProviders); - } - } - } - - @VisibleForTesting - static final EnumSet<XcodeProductType> CAN_LINK_PRODUCT_TYPES = - EnumSet.of( - XcodeProductType.APPLICATION, - XcodeProductType.BUNDLE, - XcodeProductType.UNIT_TEST, - XcodeProductType.EXTENSION, - XcodeProductType.FRAMEWORK, - XcodeProductType.WATCH_OS1_EXTENSION, - XcodeProductType.WATCH_OS1_APPLICATION); - - /** - * Returns the name of the Xcode target that corresponds to a build target with the given name. - * This changes the label to make it a legal Xcode target name (which means removing slashes and - * the colon). It also makes the label more readable in the Xcode UI by putting the target name - * first and the package elements in reverse. This means the "important" part is visible even if - * the project navigator is too narrow to show the entire name. - */ - static String xcodeTargetName(Label label) { - return xcodeTargetName(label, /*labelSuffix=*/""); - } - - /** - * Returns the name of the companion Xcode library target that corresponds to a build target with - * the given name. See {@link XcodeSupport#generateCompanionLibXcodeTarget} for the rationale of - * the companion library target and {@link #xcodeTargetName(Label)} for naming details. - */ - static String xcodeCompanionLibTargetName(Label label) { - return xcodeTargetName(label, COMPANION_LIB_TARGET_LABEL_SUFFIX); - } - - private static String xcodeTargetName(Label label, String labelSuffix) { - String pathFromWorkspaceRoot = label + labelSuffix; - if (label.getPackageIdentifier().getRepository().isMain()) { - pathFromWorkspaceRoot = pathFromWorkspaceRoot.replace("//", "") - .replace(':', '/'); - } else { - pathFromWorkspaceRoot = pathFromWorkspaceRoot.replace("//", "_") - .replace(':', '/').replace("@", "external_"); - } - List<String> components = Splitter.on('/').splitToList(pathFromWorkspaceRoot); - return Joiner.on('_').join(Lists.reverse(components)); - } - - /** - * Returns the name of the xcode target in this provider to be referenced as a dep for dependents. - */ - private String dependencyXcodeTargetName() { - return generateCompanionLibTarget ? xcodeCompanionLibTargetName(label) : xcodeTargetName(label); - } - - private Iterable<TargetControl> targetControls() { - TargetControl mainTargetControl = targetControl(); - if (generateCompanionLibTarget) { - return ImmutableList.of(mainTargetControl, companionLibTargetControl(mainTargetControl)); - } else { - return ImmutableList.of(mainTargetControl); - } - } - - private TargetControl targetControl() { - String buildFilePath = label.getPackageFragment().getSafePathString() + "/BUILD"; - NestedSet<String> userHeaderSearchPaths = - NestedSetBuilder.<String>linkOrder() - .addTransitive(propagatedUserHeaderSearchPaths) - .addTransitive(nonPropagatedUserHeaderSearchPaths) - .addTransitive(strictlyPropagatedUserHeaderSearchPaths) - .build(); - NestedSet<String> headerSearchPaths = - NestedSetBuilder.<String>linkOrder() - .addTransitive(propagatedHeaderSearchPaths) - .addTransitive(nonPropagatedHeaderSearchPaths) - .addTransitive(strictlyPropagatedHeaderSearchPaths) - .build(); - - // Automatic SDK frameworks are no longer propagated through ObjcProvider; they are now added - // during the link action. To preserve the existing Xcode project generation, we need to add - // them to the Xcode target below, unless it is a watchOS 1 application. - Set<SdkFramework> automaticSdkFrameworks = - (productType != WATCH_OS1_APPLICATION) - ? ImmutableSet.copyOf(AUTOMATIC_SDK_FRAMEWORKS) - : ImmutableSet.<SdkFramework>of(); - - // TODO(bazel-team): Add provisioning profile information when Xcodegen supports it. - TargetControl.Builder targetControl = - TargetControl.newBuilder() - .setName(label.getName()) - .setLabel(xcodeTargetName(label)) - .setProductType(productType.getIdentifier()) - .addSupportFile(buildFilePath) - .addAllImportedLibrary(Artifact.toExecPaths(objcProvider.get(IMPORTED_LIBRARY))) - .addAllImportedLibrary(Artifact.toExecPaths(ccLibraries(objcProvider))) - .addAllUserHeaderSearchPath(userHeaderSearchPaths) - .addAllHeaderSearchPath(headerSearchPaths) - .addAllSupportFile(Artifact.toExecPaths(headers)) - .addAllCopt(compilationModeCopts) - .addAllCopt(CompilationSupport.DEFAULT_COMPILER_FLAGS) - .addAllCopt(Interspersing.prependEach("-D", objcProvider.get(DEFINE))) - .addAllCopt(copts) - .addAllLinkopt( - Interspersing.beforeEach("-force_load", objcProvider.get(FORCE_LOAD_FOR_XCODEGEN))) - .addAllLinkopt(CompilationSupport.DEFAULT_LINKER_FLAGS) - .addAllLinkopt( - Interspersing.beforeEach( - "-weak_framework", SdkFramework.names(objcProvider.get(WEAK_SDK_FRAMEWORK)))) - .addAllBuildSetting(xcodeprojBuildSettings) - .addAllBuildSetting(AppleToolchain.defaultWarningsForXcode()) - .addAllSdkFramework(SdkFramework.names(automaticSdkFrameworks)) - .addAllSdkFramework(SdkFramework.names(objcProvider.get(SDK_FRAMEWORK))) - .addAllFramework(PathFragment.safePathStrings(objcProvider.get(STATIC_FRAMEWORK_DIR))) - .addAllFrameworkSearchPathOnly( - PathFragment.safePathStrings(objcProvider.get(FRAMEWORK_SEARCH_PATH_ONLY))) - .addAllXcassetsDir(PathFragment.safePathStrings(objcProvider.get(XCASSETS_DIR))) - .addAllXcdatamodel( - PathFragment.safePathStrings( - Xcdatamodels.datamodelDirs(objcProvider.get(XCDATAMODEL)))) - .addAllBundleImport(PathFragment.safePathStrings(objcProvider.get(BUNDLE_IMPORT_DIR))) - .addAllSdkDylib(objcProvider.get(SDK_DYLIB)) - .addAllGeneralResourceFile( - Artifact.toExecPaths(objcProvider.get(GENERAL_RESOURCE_FILE))) - .addAllGeneralResourceFile( - PathFragment.safePathStrings(objcProvider.get(GENERAL_RESOURCE_DIR))); - - if (CAN_LINK_PRODUCT_TYPES.contains(productType)) { - // For builds with --ios_multi_cpus set, we may have several copies of some XCodeProviders - // in the dependencies (one per cpu architecture). We deduplicate the corresponding - // xcode target names with a LinkedHashSet before adding to the TargetControl. - Set<String> jreTargetNames = new HashSet<>(); - for (XcodeProvider jreDependency : jreDependencies) { - jreTargetNames.add(jreDependency.dependencyXcodeTargetName()); - } - Set<DependencyControl> dependencySet = new LinkedHashSet<>(); - Set<DependencyControl> jreDependencySet = new LinkedHashSet<>(); - for (XcodeProvider dependency : propagatedDependencies) { - // Only add a library target to a binary's dependencies if it has source files to compile - // and it is not from the "non_propagated_deps" attribute. Xcode cannot build targets - // without a source file in the PBXSourceFilesBuildPhase, so if such a target is present in - // the control file, it is only to get Xcodegen to put headers and resources not used by the - // final binary in the Project Navigator. - // - // The exceptions to this rule are objc_bundle_library and ios_extension targets. Bundles - // are generally used for resources and can lack a PBXSourceFilesBuildPhase in the project - // file and still be considered valid by Xcode. - // - // ios_extension targets are an exception because they have no CompilationArtifact object - // but do have a dummy source file to make Xcode happy. - boolean hasSources = dependency.compilationArtifacts.isPresent() - && dependency.compilationArtifacts.get().getArchive().isPresent(); - if (hasSources - || (dependency.productType == XcodeProductType.BUNDLE - || (dependency.productType == XcodeProductType.WATCH_OS1_APPLICATION))) { - String dependencyXcodeTargetName = dependency.dependencyXcodeTargetName(); - Set<DependencyControl> set = jreTargetNames.contains(dependencyXcodeTargetName) - ? jreDependencySet : dependencySet; - set.add(DependencyControl.newBuilder() - .setTargetLabel(dependencyXcodeTargetName) - .build()); - } - } - - for (DependencyControl dependencyControl : dependencySet) { - targetControl.addDependency(dependencyControl); - } - // Make sure that JRE dependencies are ordered after other propagated dependencies. - for (DependencyControl dependencyControl : jreDependencySet) { - targetControl.addDependency(dependencyControl); - } - } - for (XcodeProvider justTestHost : testHost.asSet()) { - targetControl.addDependency(DependencyControl.newBuilder() - .setTargetLabel(xcodeTargetName(justTestHost.label)) - .setTestHost(true) - .build()); - } - for (XcodeProvider extension : extensions) { - targetControl.addDependency(DependencyControl.newBuilder() - .setTargetLabel(xcodeTargetName(extension.label)) - .build()); - } - - if (bundleInfoplist.isPresent()) { - targetControl.setInfoplist(bundleInfoplist.get().getExecPathString()); - } - for (CompilationArtifacts artifacts : compilationArtifacts.asSet()) { - targetControl - .addAllSourceFile(Artifact.toExecPaths(artifacts.getSrcs())) - .addAllSupportFile(Artifact.toExecPaths(artifacts.getAdditionalHdrs())) - .addAllSupportFile(Artifact.toExecPaths(artifacts.getPrivateHdrs())) - .addAllNonArcSourceFile(Artifact.toExecPaths(artifacts.getNonArcSrcs())); - - for (Artifact pchFile : artifacts.getPchFile().asSet()) { - targetControl - .setPchPath(pchFile.getExecPathString()) - .addSupportFile(pchFile.getExecPathString()); - } - } - - for (Artifact artifact : additionalSources) { - targetControl.addSourceFile(artifact.getExecPathString()); - } - - if (objcProvider.is(Flag.USES_CPP)) { - targetControl.addSdkDylib("libc++"); - } - - return targetControl.build(); - } - - private TargetControl companionLibTargetControl(TargetControl mainTargetControl) { - return TargetControl.newBuilder() - .mergeFrom(mainTargetControl) - .setName(label.getName() + COMPANION_LIB_TARGET_LABEL_SUFFIX) - .setLabel(xcodeCompanionLibTargetName(label)) - .setProductType(LIBRARY_STATIC.getIdentifier()) - .clearInfoplist() - .clearDependency() - .clearBuildSetting() - .addAllBuildSetting(companionTargetXcodeprojBuildSettings) - .addAllBuildSetting(AppleToolchain.defaultWarningsForXcode()) - .build(); - } - - /** - * Prepends the given path to each path in {@code paths}. Empty paths are - * transformed to the value of {@code variable} rather than {@code variable + "/."}. Absolute - * paths are returned without modifications. - */ - @VisibleForTesting - static Iterable<String> rootEach(final String prefix, Iterable<PathFragment> paths) { - Preconditions.checkArgument(prefix.startsWith("$"), - "prefix should start with a build setting variable like '$(NAME)': %s", prefix); - Preconditions.checkArgument(!prefix.endsWith("/"), - "prefix should not end with '/': %s", prefix); - return Iterables.transform(paths, new Function<PathFragment, String>() { - @Override - public String apply(PathFragment input) { - if (input.getSafePathString().equals(".")) { - return prefix; - } else if (input.isAbsolute()) { - return input.getSafePathString(); - } else { - return prefix + "/" + input.getSafePathString(); - } - } - }); - } - - private ImmutableList<Artifact> ccLibraries(ObjcProvider objcProvider) { - ImmutableList.Builder<Artifact> ccLibraryBuilder = ImmutableList.builder(); - for (LinkerInputs.LibraryToLink libraryToLink : objcProvider.get(CC_LIBRARY)) { - ccLibraryBuilder.add(libraryToLink.getArtifact()); - } - return ccLibraryBuilder.build(); - } -} diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/XcodeSupport.java b/src/main/java/com/google/devtools/build/lib/rules/objc/XcodeSupport.java deleted file mode 100644 index 379509f08c..0000000000 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/XcodeSupport.java +++ /dev/null @@ -1,331 +0,0 @@ -// Copyright 2015 The Bazel Authors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package com.google.devtools.build.lib.rules.objc; - -import static com.google.devtools.build.lib.packages.ImplicitOutputsFunction.fromTemplates; - -import com.google.common.annotations.VisibleForTesting; -import com.google.common.collect.ImmutableList; -import com.google.common.io.ByteSource; -import com.google.devtools.build.lib.actions.Artifact; -import com.google.devtools.build.lib.analysis.RuleConfiguredTarget.Mode; -import com.google.devtools.build.lib.analysis.RuleContext; -import com.google.devtools.build.lib.analysis.actions.BinaryFileWriteAction; -import com.google.devtools.build.lib.analysis.actions.SpawnAction; -import com.google.devtools.build.lib.analysis.actions.SymlinkAction; -import com.google.devtools.build.lib.cmdline.Label; -import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; -import com.google.devtools.build.lib.packages.ImplicitOutputsFunction.SafeImplicitOutputsFunction; -import com.google.devtools.build.lib.rules.apple.AppleConfiguration; -import com.google.devtools.build.lib.rules.apple.AppleConfiguration.ConfigurationDistinguisher; -import com.google.devtools.build.lib.rules.apple.Platform.PlatformType; -import com.google.devtools.build.lib.rules.objc.XcodeProvider.Builder; -import com.google.devtools.build.lib.rules.objc.XcodeProvider.Project; -import com.google.devtools.build.xcode.xcodegen.proto.XcodeGenProtos; -import com.google.devtools.build.xcode.xcodegen.proto.XcodeGenProtos.XcodeprojBuildSetting; -import java.io.InputStream; -import java.util.List; - -/** - * Support for Objc rule types that export an Xcode provider or generate xcode project files. - * - * <p>Methods on this class can be called in any order without impacting the result. - * - * <p>These objects should not outlast the analysis phase. Do not pass them to {@link Action} - * objects or other persistent objects. There are internal tests to ensure that XcodeSupport objects - * are not persisted that check the name of this class, so update those tests if you change this - * class's name. - */ -public final class XcodeSupport { - - /** Template for a target's xcode project. */ - private static final SafeImplicitOutputsFunction PBXPROJ = - fromTemplates("%{name}.xcodeproj/project.pbxproj"); - - private final RuleContext ruleContext; - private final IntermediateArtifacts intermediateArtifacts; - private final Label xcodeTargetLabel; - - /** - * Creates a new xcode support for the given context. - */ - XcodeSupport(RuleContext ruleContext) { - this(ruleContext, ObjcRuleClasses.intermediateArtifacts(ruleContext), ruleContext.getLabel()); - } - - /** - * Creates a new xcode support for the given context and {@link IntermediateArtifacts} with given - * target label. - */ - public XcodeSupport( - RuleContext ruleContext, IntermediateArtifacts intermediateArtifacts, - Label xcodeTargetLabel) { - this.ruleContext = ruleContext; - this.intermediateArtifacts = intermediateArtifacts; - this.xcodeTargetLabel = xcodeTargetLabel; - } - - /** - * Adds xcode project files to the given builder. - * - * @return this xcode support - * @throws InterruptedException - */ - XcodeSupport addFilesToBuild(NestedSetBuilder<Artifact> filesToBuild) - throws InterruptedException { - if (ObjcRuleClasses.objcConfiguration(ruleContext).generateXcodeProject()) { - filesToBuild.add(ruleContext.getImplicitOutputArtifact(PBXPROJ)); - } - - return this; - } - - /** - * Adds a dummy source file to the Xcode target. This is needed if the target does not have any - * source files but Xcode requires one. - * - * @return this xcode support - */ - XcodeSupport addDummySource(XcodeProvider.Builder xcodeProviderBuilder) { - ruleContext.registerAction(new SymlinkAction( - ruleContext.getActionOwner(), - ruleContext.getPrerequisiteArtifact("$dummy_source", Mode.TARGET), - intermediateArtifacts.dummySource(), - "Symlinking dummy artifact")); - - xcodeProviderBuilder.addAdditionalSources(intermediateArtifacts.dummySource()); - return this; - } - - /** - * Registers actions that generate the rule's Xcode project. - * - * @param xcodeProvider information about this rule's xcode settings and that of its dependencies - * @return this xcode support - * @throws InterruptedException - */ - XcodeSupport registerActions(XcodeProvider xcodeProvider) throws InterruptedException { - registerXcodegenActions(XcodeProvider.Project.fromTopLevelTarget(xcodeProvider)); - return this; - } - - /** - * Registers actions that generate the rule's Xcode project. - * - * @param xcodeProviders information about several rules' xcode settings - * @return this xcode support - * @throws InterruptedException - */ - XcodeSupport registerActions(Iterable<XcodeProvider> xcodeProviders) throws InterruptedException { - registerXcodegenActions(Project.fromTopLevelTargets(xcodeProviders)); - return this; - } - - /** - * Adds common xcode settings to the given provider builder. - * - * @param objcProvider provider containing all dependencies' information as well as some of this - * rule's - * @param productType type of this rule's Xcode target - * - * @return this xcode support - */ - XcodeSupport addXcodeSettings(XcodeProvider.Builder xcodeProviderBuilder, - ObjcProvider objcProvider, XcodeProductType productType) { - AppleConfiguration appleConfiguration = ruleContext.getFragment(AppleConfiguration.class); - return addXcodeSettings(xcodeProviderBuilder, objcProvider, productType, - appleConfiguration.getIosCpu(), appleConfiguration.getConfigurationDistinguisher()); - } - - /** - * Adds common xcode settings to the given provider builder, explicitly specifying architecture - * to use. - * - * @param objcProvider provider containing all dependencies' information as well as some of this - * rule's - * @param productType type of this rule's Xcode target - * @param architecture architecture to filter all dependencies with (only matching ones will be - * included in the final targets generated) - * @param configurationDistinguisher distinguisher that will cause this target's xcode provider to - * discard any dependencies from sources that are tagged with a different distinguisher - * @return this xcode support - */ - XcodeSupport addXcodeSettings(Builder xcodeProviderBuilder, - ObjcProvider objcProvider, XcodeProductType productType, String architecture, - ConfigurationDistinguisher configurationDistinguisher) { - xcodeProviderBuilder - .setLabel(xcodeTargetLabel) - .setArchitecture(architecture) - .setConfigurationDistinguisher(configurationDistinguisher) - .setObjcProvider(objcProvider) - .setProductType(productType) - .addXcodeprojBuildSettings(XcodeSupport.defaultXcodeSettings()); - return this; - } - - /** - * Adds dependencies to the given provider builder from the given attribute. - * - * @return this xcode support - */ - XcodeSupport addDependencies(Builder xcodeProviderBuilder, Attribute attribute) { - xcodeProviderBuilder.addPropagatedDependencies( - ruleContext.getPrerequisites( - attribute.getName(), attribute.getAccessMode(), XcodeProvider.class)); - return this; - } - - /** - * Adds non-propagated dependencies to the given provider builder from the given attribute. - * - * <p>A non-propagated dependency will not be linked into the final app bundle and can only serve - * as a compile-only dependency for its direct dependent. - * - * @return this xcode support - */ - XcodeSupport addNonPropagatedDependencies(Builder xcodeProviderBuilder, Attribute attribute) { - xcodeProviderBuilder.addNonPropagatedDependencies( - ruleContext.getPrerequisites( - attribute.getName(), attribute.getAccessMode(), XcodeProvider.class)); - return this; - } - - /** - * Adds J2ObjC JRE dependencies to the given provider builder from the given attribute. - * - * @return this xcode support - */ - XcodeSupport addJreDependencies(Builder xcodeProviderBuilder) { - xcodeProviderBuilder.addJreDependencies( - ruleContext.getPrerequisites("jre_deps", Mode.TARGET, XcodeProvider.class)); - return this; - } - - /** - * Generates an extra {@link XcodeProductType#LIBRARY_STATIC} Xcode target with the same - * compilation artifacts as the main Xcode target associated with this Xcode support. The extra - * Xcode library target, instead of the main Xcode target, will act as a dependency for all - * dependent Xcode targets. - * - * <p>This is needed to build the Xcode binary target generated by ios_application in XCode. - * Currently there is an Xcode target dependency between the binary target from ios_application - * and the binary target from objc_binary. But Xcode does not link in compiled artifacts from - * binary dependencies, so any sources specified on objc_binary rules will not be compiled and - * linked into the app bundle in dependent binary targets associated with ios_application in - * XCode. - */ - // TODO(bazel-team): Remove this when the binary rule types and bundling rule types are merged. - XcodeSupport generateCompanionLibXcodeTarget(Builder xcodeProviderBuilder) { - xcodeProviderBuilder.generateCompanionLibTarget(); - return this; - } - - private void registerXcodegenActions(XcodeProvider.Project project) throws InterruptedException { - Artifact controlFile = intermediateArtifacts.pbxprojControlArtifact(); - - ruleContext.registerAction(new BinaryFileWriteAction( - ruleContext.getActionOwner(), - controlFile, - xcodegenControlFileBytes(project), - /*makeExecutable=*/false)); - - ruleContext.registerAction(new SpawnAction.Builder() - .setMnemonic("GenerateXcodeproj") - .setExecutable(ruleContext.getExecutablePrerequisite("$xcodegen", Mode.HOST)) - .addArgument("--control") - .addInputArgument(controlFile) - .addOutput(ruleContext.getImplicitOutputArtifact(XcodeSupport.PBXPROJ)) - .addTransitiveInputs(project.getInputsToXcodegen()) - .addTransitiveInputs(project.getAdditionalSources()) - .build(ruleContext)); - } - - /** - * Static class to avoid keeping references to configurations and this XcodeSupport object during - * execution. - */ - private static class XcodegenControlFileBytes extends ByteSource { - private final XcodeProvider.Project project; - private final Artifact pbxproj; - private final String workspaceRoot; - private final List<String> appleCpus; - private final String minimumOs; - private final boolean generateDebugSymbols; - - XcodegenControlFileBytes( - ObjcConfiguration objcConfiguration, - AppleConfiguration appleConfiguration, - Project project, - Artifact pbxproj) { - this.project = project; - this.pbxproj = pbxproj; - this.workspaceRoot = objcConfiguration.getXcodeWorkspaceRoot(); - this.appleCpus = appleConfiguration.getMultiArchitectures( - appleConfiguration.getSingleArchPlatform().getType()); - this.minimumOs = appleConfiguration.getMinimumOsForPlatformType(PlatformType.IOS).toString(); - this.generateDebugSymbols = objcConfiguration.generateDsym(); - } - - @Override - public InputStream openStream() { - XcodeGenProtos.Control.Builder builder = XcodeGenProtos.Control.newBuilder(); - if (workspaceRoot != null) { - builder.setWorkspaceRoot(workspaceRoot); - } - - builder.addAllCpuArchitecture(appleCpus); - - return builder - .setPbxproj(pbxproj.getExecPathString()) - .addAllTarget(project.targets()) - .addBuildSetting( - XcodeGenProtos.XcodeprojBuildSetting.newBuilder() - .setName("IPHONEOS_DEPLOYMENT_TARGET") - .setValue(minimumOs) - .build()) - .addBuildSetting( - XcodeGenProtos.XcodeprojBuildSetting.newBuilder() - .setName("DEBUG_INFORMATION_FORMAT") - .setValue(generateDebugSymbols ? "dwarf-with-dsym" : "dwarf") - .build()) - .build() - .toByteString() - .newInput(); - } - } - - private ByteSource xcodegenControlFileBytes(XcodeProvider.Project project) - throws InterruptedException { - return new XcodegenControlFileBytes( - ObjcRuleClasses.objcConfiguration(ruleContext), - ruleContext.getFragment(AppleConfiguration.class), - project, - ruleContext.getImplicitOutputArtifact(XcodeSupport.PBXPROJ)); - } - - /** - * Returns a list of default XCode build settings for Bazel-generated XCode projects. - */ - @VisibleForTesting - static Iterable<XcodeprojBuildSetting> defaultXcodeSettings() { - // Do not use XCode headermap because Bazel-generated header search paths are sufficient for - // resolving header imports. - return ImmutableList.of( - XcodeprojBuildSetting.newBuilder() - .setName("USE_HEADERMAP") - .setValue("NO") - .build()); - } -} |