Search in sources :

Example 16 with AppleConfiguration

use of com.google.devtools.build.lib.rules.apple.AppleConfiguration in project bazel by bazelbuild.

the class AppleWatch2Extension method validateAttributesAndConfiguration.

private void validateAttributesAndConfiguration(RuleContext ruleContext) throws RuleErrorException {
    boolean hasError = false;
    Multiset<Artifact> appResources = HashMultiset.create();
    appResources.addAll(ruleContext.getPrerequisiteArtifacts("app_resources", Mode.TARGET).list());
    appResources.addAll(ruleContext.getPrerequisiteArtifacts("app_strings", Mode.TARGET).list());
    for (Multiset.Entry<Artifact> entry : appResources.entrySet()) {
        if (entry.getCount() > 1) {
            ruleContext.ruleError("The same file was included multiple times in this rule: " + entry.getElement().getRootRelativePathString());
            hasError = true;
        }
    }
    Multiset<Artifact> extResources = HashMultiset.create();
    extResources.addAll(ruleContext.getPrerequisiteArtifacts("ext_resources", Mode.TARGET).list());
    extResources.addAll(ruleContext.getPrerequisiteArtifacts("ext_strings", Mode.TARGET).list());
    for (Multiset.Entry<Artifact> entry : extResources.entrySet()) {
        if (entry.getCount() > 1) {
            ruleContext.ruleError("The same file was included multiple times in this rule: " + entry.getElement().getRootRelativePathString());
            hasError = true;
        }
    }
    AppleConfiguration appleConfiguration = ruleContext.getFragment(AppleConfiguration.class);
    Platform watchPlatform = appleConfiguration.getMultiArchPlatform(PlatformType.WATCHOS);
    Platform iosPlatform = appleConfiguration.getMultiArchPlatform(PlatformType.IOS);
    if (watchPlatform.isDevice() != iosPlatform.isDevice()) {
        hasError = true;
        if (watchPlatform.isDevice()) {
            ruleContext.ruleError(String.format("Building a watch extension for watch device architectures [%s] " + "requires a device ios architecture. Found [%s] instead.", Joiner.on(",").join(appleConfiguration.getMultiArchitectures(PlatformType.WATCHOS)), Joiner.on(",").join(appleConfiguration.getMultiArchitectures(PlatformType.IOS))));
        } else {
            ruleContext.ruleError(String.format("Building a watch extension for ios device architectures [%s] " + "requires a device watch architecture. Found [%s] instead.", Joiner.on(",").join(appleConfiguration.getMultiArchitectures(PlatformType.IOS)), Joiner.on(",").join(appleConfiguration.getMultiArchitectures(PlatformType.WATCHOS))));
        }
        ruleContext.ruleError("For building watch extension, there may only be a watch device " + "architecture if and only if there is an ios device architecture");
    }
    if (hasError) {
        throw new RuleErrorException();
    }
}
Also used : Platform(com.google.devtools.build.lib.rules.apple.Platform) Multiset(com.google.common.collect.Multiset) HashMultiset(com.google.common.collect.HashMultiset) AppleConfiguration(com.google.devtools.build.lib.rules.apple.AppleConfiguration) Artifact(com.google.devtools.build.lib.actions.Artifact)

Example 17 with AppleConfiguration

use of com.google.devtools.build.lib.rules.apple.AppleConfiguration in project bazel by bazelbuild.

the class BinaryLinkingTargetFactory method create.

@Override
public final ConfiguredTarget create(RuleContext ruleContext) throws InterruptedException, RuleErrorException {
    ProtobufSupport protoSupport = new ProtobufSupport(ruleContext).registerGenerationActions().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);
    NestedSetBuilder<Artifact> filesToBuild = NestedSetBuilder.<Artifact>stableOrder().add(intermediateArtifacts.strippedSingleArchitectureBinary());
    new ResourceSupport(ruleContext).validateAttributes().addXcodeSettings(xcodeProviderBuilder);
    ruleContext.assertNoErrors();
    J2ObjcMappingFileProvider j2ObjcMappingFileProvider = J2ObjcMappingFileProvider.union(ruleContext.getPrerequisites("deps", Mode.TARGET, J2ObjcMappingFileProvider.class));
    J2ObjcEntryClassProvider j2ObjcEntryClassProvider = new J2ObjcEntryClassProvider.Builder().addTransitive(ruleContext.getPrerequisites("deps", Mode.TARGET, J2ObjcEntryClassProvider.class)).build();
    CompilationSupport compilationSupport = CompilationSupport.create(ruleContext).validateAttributes().addXcodeSettings(xcodeProviderBuilder, common).registerCompileAndArchiveActions(common).registerFullyLinkAction(common.getObjcProvider(), ruleContext.getImplicitOutputArtifact(CompilationSupport.FULLY_LINKED_LIB)).registerLinkActions(objcProvider, j2ObjcMappingFileProvider, j2ObjcEntryClassProvider, getExtraLinkArgs(ruleContext), ImmutableList.<Artifact>of(), DsymOutputType.APP);
    Optional<XcTestAppProvider> xcTestAppProvider;
    Optional<RunfilesSupport> maybeRunfilesSupport = Optional.absent();
    switch(hasReleaseBundlingSupport) {
        case YES:
            AppleConfiguration appleConfiguration = ruleContext.getFragment(AppleConfiguration.class);
            // TODO(bazel-team): Remove once all bundle users are migrated to ios_application.
            ReleaseBundlingSupport releaseBundlingSupport = new ReleaseBundlingSupport(ruleContext, objcProvider, LinkedBinary.LOCAL_AND_DEPENDENCIES, ReleaseBundlingSupport.APP_BUNDLE_DIR_FORMAT, appleConfiguration.getMinimumOsForPlatformType(PlatformType.IOS), appleConfiguration.getSingleArchPlatform());
            releaseBundlingSupport.registerActions(DsymOutputType.APP).addXcodeSettings(xcodeProviderBuilder).addFilesToBuild(filesToBuild, Optional.of(DsymOutputType.APP)).validateResources().validateAttributes();
            xcTestAppProvider = Optional.of(releaseBundlingSupport.xcTestAppProvider());
            if (appleConfiguration.getMultiArchPlatform(PlatformType.IOS) == Platform.IOS_SIMULATOR) {
                Artifact runnerScript = intermediateArtifacts.runnerScript();
                Artifact ipaFile = ruleContext.getImplicitOutputArtifact(ReleaseBundlingSupport.IPA);
                releaseBundlingSupport.registerGenerateRunnerScriptAction(runnerScript, ipaFile);
                maybeRunfilesSupport = Optional.of(releaseBundlingSupport.runfilesSupport(runnerScript));
            }
            break;
        case NO:
            xcTestAppProvider = Optional.absent();
            break;
        default:
            throw new AssertionError();
    }
    XcodeSupport xcodeSupport = new XcodeSupport(ruleContext).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, compilationSupport.getInstrumentedFilesProvider(common));
    if (xcTestAppProvider.isPresent()) {
        // TODO(bazel-team): Stop exporting an XcTestAppProvider once objc_binary no longer creates an
        // application bundle.
        targetBuilder.addProvider(XcTestAppProvider.class, xcTestAppProvider.get());
    }
    if (maybeRunfilesSupport.isPresent()) {
        RunfilesSupport runfilesSupport = maybeRunfilesSupport.get();
        targetBuilder.setRunfilesSupport(runfilesSupport, runfilesSupport.getExecutable());
    }
    configureTarget(targetBuilder, ruleContext);
    return targetBuilder.build();
}
Also used : NestedSetBuilder(com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder) RuleConfiguredTargetBuilder(com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder) AppleConfiguration(com.google.devtools.build.lib.rules.apple.AppleConfiguration) RunfilesSupport(com.google.devtools.build.lib.analysis.RunfilesSupport) Artifact(com.google.devtools.build.lib.actions.Artifact) RuleConfiguredTargetBuilder(com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder)

Example 18 with AppleConfiguration

use of com.google.devtools.build.lib.rules.apple.AppleConfiguration in project bazel by bazelbuild.

the class AppleStaticLibrary method create.

@Override
public final ConfiguredTarget create(RuleContext ruleContext) throws InterruptedException, RuleErrorException {
    PlatformType platformType = MultiArchSplitTransitionProvider.getPlatformType(ruleContext);
    ImmutableListMultimap<BuildConfiguration, TransitiveInfoCollection> configToDepsCollectionMap = ruleContext.getPrerequisitesByConfiguration("deps", Mode.SPLIT);
    ImmutableListMultimap<BuildConfiguration, ObjcProvider> configToObjcAvoidDepsMap = ruleContext.getPrerequisitesByConfiguration(AppleStaticLibraryRule.AVOID_DEPS_ATTR_NAME, Mode.SPLIT, ObjcProvider.class);
    ImmutableListMultimap<BuildConfiguration, CcLinkParamsProvider> configToCcAvoidDepsMap = ruleContext.getPrerequisitesByConfiguration(AppleStaticLibraryRule.AVOID_DEPS_ATTR_NAME, Mode.SPLIT, CcLinkParamsProvider.class);
    Set<BuildConfiguration> childConfigurations = getChildConfigurations(ruleContext);
    IntermediateArtifacts ruleIntermediateArtifacts = ObjcRuleClasses.intermediateArtifacts(ruleContext);
    NestedSetBuilder<Artifact> librariesToLipo = NestedSetBuilder.<Artifact>stableOrder();
    NestedSetBuilder<Artifact> filesToBuild = NestedSetBuilder.<Artifact>stableOrder().add(ruleIntermediateArtifacts.combinedArchitectureArchive());
    ObjcProvider.Builder objcProviderBuilder = new ObjcProvider.Builder();
    for (BuildConfiguration childConfig : childConfigurations) {
        ProtobufSupport protoSupport = new ProtobufSupport(ruleContext, childConfig).registerGenerationActions().registerCompilationActions();
        Optional<ObjcProvider> protosObjcProvider = protoSupport.getObjcProvider();
        IntermediateArtifacts intermediateArtifacts = ObjcRuleClasses.intermediateArtifacts(ruleContext, childConfig);
        ObjcCommon common = common(ruleContext, childConfig, intermediateArtifacts, nullToEmptyList(configToDepsCollectionMap.get(childConfig)), protosObjcProvider);
        ObjcProvider objcProvider = common.getObjcProvider().subtractSubtrees(configToObjcAvoidDepsMap.get(childConfig), configToCcAvoidDepsMap.get(childConfig));
        librariesToLipo.add(intermediateArtifacts.strippedSingleArchitectureLibrary());
        CompilationSupport.createForConfig(ruleContext, childConfig).registerCompileAndArchiveActions(common).registerFullyLinkAction(objcProvider, intermediateArtifacts.strippedSingleArchitectureLibrary()).validateAttributes();
        ruleContext.assertNoErrors();
        addTransitivePropagatedKeys(objcProviderBuilder, objcProvider);
    }
    AppleConfiguration appleConfiguration = ruleContext.getFragment(AppleConfiguration.class);
    new LipoSupport(ruleContext).registerCombineArchitecturesAction(librariesToLipo.build(), ruleIntermediateArtifacts.combinedArchitectureArchive(), appleConfiguration.getMultiArchPlatform(platformType));
    RuleConfiguredTargetBuilder targetBuilder = ObjcRuleClasses.ruleConfiguredTarget(ruleContext, filesToBuild.build());
    objcProviderBuilder.add(MULTI_ARCH_LINKED_ARCHIVES, ruleIntermediateArtifacts.combinedArchitectureArchive());
    targetBuilder.addProvider(ObjcProvider.class, objcProviderBuilder.build());
    return targetBuilder.build();
}
Also used : CcLinkParamsProvider(com.google.devtools.build.lib.rules.cpp.CcLinkParamsProvider) NestedSetBuilder(com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder) RuleConfiguredTargetBuilder(com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder) AppleConfiguration(com.google.devtools.build.lib.rules.apple.AppleConfiguration) Artifact(com.google.devtools.build.lib.actions.Artifact) BuildConfiguration(com.google.devtools.build.lib.analysis.config.BuildConfiguration) RuleConfiguredTargetBuilder(com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder) TransitiveInfoCollection(com.google.devtools.build.lib.analysis.TransitiveInfoCollection) PlatformType(com.google.devtools.build.lib.rules.apple.Platform.PlatformType)

Example 19 with AppleConfiguration

use of com.google.devtools.build.lib.rules.apple.AppleConfiguration in project bazel by bazelbuild.

the class ObjcBundleLibrary method create.

@Override
public ConfiguredTarget create(RuleContext ruleContext) throws InterruptedException, RuleErrorException {
    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);
    if (ruleContext.hasErrors()) {
        return null;
    }
    AppleConfiguration appleConfiguration = ruleContext.getFragment(AppleConfiguration.class);
    // 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, appleConfiguration, appleConfiguration.getMultiArchPlatform(PlatformType.IOS), bundling, new ExtraActoolArgs()).validateResources(common.getObjcProvider()).registerActions(common.getObjcProvider()).addXcodeSettings(xcodeProviderBuilder);
    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();
}
Also used : NestedSetBuilder(com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder) AppleConfiguration(com.google.devtools.build.lib.rules.apple.AppleConfiguration) Artifact(com.google.devtools.build.lib.actions.Artifact) ExtraActoolArgs(com.google.devtools.build.lib.rules.objc.BundleSupport.ExtraActoolArgs)

Example 20 with AppleConfiguration

use of com.google.devtools.build.lib.rules.apple.AppleConfiguration in project bazel by bazelbuild.

the class ReleaseBundlingSupport method registerEnvironmentPlistAction.

private void registerEnvironmentPlistAction() {
    AppleConfiguration configuration = ruleContext.getFragment(AppleConfiguration.class);
    // Generates a .plist that contains environment values (such as the SDK used to build, the Xcode
    // version, etc), which are parsed from various .plist files of the OS, namely Xcodes' and
    // Platforms' plists.
    // The resulting file is meant to be merged with the final bundle.
    String platformWithVersion = String.format("%s%s", platform.getLowerCaseNameInPlist(), configuration.getSdkVersionForPlatform(platform));
    ruleContext.registerAction(ObjcRuleClasses.spawnAppleEnvActionBuilder(configuration, platform).setMnemonic("EnvironmentPlist").setExecutable(attributes.environmentPlist()).addArguments("--platform", platformWithVersion).addArguments("--output", getGeneratedEnvironmentPlist().getExecPathString()).addOutput(getGeneratedEnvironmentPlist()).build(ruleContext));
}
Also used : AppleConfiguration(com.google.devtools.build.lib.rules.apple.AppleConfiguration)

Aggregations

AppleConfiguration (com.google.devtools.build.lib.rules.apple.AppleConfiguration)25 Artifact (com.google.devtools.build.lib.actions.Artifact)12 NestedSetBuilder (com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder)10 RuleConfiguredTargetBuilder (com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder)6 Platform (com.google.devtools.build.lib.rules.apple.Platform)4 CustomCommandLine (com.google.devtools.build.lib.analysis.actions.CustomCommandLine)3 DottedVersion (com.google.devtools.build.lib.rules.apple.DottedVersion)3 PlatformType (com.google.devtools.build.lib.rules.apple.Platform.PlatformType)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 RunfilesSupport (com.google.devtools.build.lib.analysis.RunfilesSupport)2 TransitiveInfoCollection (com.google.devtools.build.lib.analysis.TransitiveInfoCollection)2 BuildConfiguration (com.google.devtools.build.lib.analysis.config.BuildConfiguration)2 NSArray (com.dd.plist.NSArray)1 NSDictionary (com.dd.plist.NSDictionary)1 HashMultiset (com.google.common.collect.HashMultiset)1 Multiset (com.google.common.collect.Multiset)1 TreeFileArtifact (com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact)1 FilesToRunProvider (com.google.devtools.build.lib.analysis.FilesToRunProvider)1 Runfiles (com.google.devtools.build.lib.analysis.Runfiles)1 RunfilesProvider (com.google.devtools.build.lib.analysis.RunfilesProvider)1