Search in sources :

Example 6 with AppleConfiguration

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

the class ReleaseBundlingSupport method registerPostProcessAndSigningActions.

/**
   * Registers all actions necessary to create a processed and signed IPA from the initial merged
   * IPA.
   *
   * <p>Includes user-provided actions to process IPA contents (via {@code ipa_post_processor}),
   * and signing actions if the IPA is being built for device architectures. If signing is necessary
   * also includes entitlements generation and processing actions.
   *
   * <p>Note that multiple "actions" on the IPA contents may be run in a single blaze action to
   * avoid excessive zipping/unzipping of IPA contents.
   */
private void registerPostProcessAndSigningActions() {
    Artifact processedIpa = releaseBundling.getIpaArtifact();
    Artifact unprocessedIpa = intermediateArtifacts.unprocessedIpa();
    NestedSetBuilder<Artifact> inputs = NestedSetBuilder.<Artifact>stableOrder().add(unprocessedIpa);
    String actionCommandLine = "set -e && " + "t=$(mktemp -d \"${TMPDIR:-/tmp}/signing_intermediate.XXXXXX\") && " + "trap \"rm -rf ${t}\" EXIT && " + // Get an absolute path since we need to cd into the temp directory for zip.
    "signed_ipa=${PWD}/" + processedIpa.getShellEscapedExecPathString() + " && " + "/usr/bin/unzip -qq " + unprocessedIpa.getShellEscapedExecPathString() + " -d ${t} && ";
    FilesToRunProvider processor = attributes.ipaPostProcessor();
    if (processor != null) {
        actionCommandLine += processor.getExecutable().getShellEscapedExecPathString() + " ${t} && ";
    }
    if (platform.isDevice()) {
        actionCommandLine += deviceSigningCommandLine();
        registerEntitlementsActions();
        inputs.add(releaseBundling.getProvisioningProfile()).add(intermediateArtifacts.entitlements());
    } else {
        actionCommandLine += simulatorSigningCommandLine();
    }
    actionCommandLine += "cd ${t} && /usr/bin/zip -q -r \"${signed_ipa}\" .";
    AppleConfiguration appleConfiguration = ruleContext.getFragment(AppleConfiguration.class);
    SpawnAction.Builder processAction = ObjcRuleClasses.spawnBashOnDarwinActionBuilder(actionCommandLine).setEnvironment(ObjcRuleClasses.appleToolchainEnvironment(appleConfiguration, platform)).setMnemonic("ObjcProcessIpa").setProgressMessage("Processing iOS IPA: " + ruleContext.getLabel()).disableSandboxing().addTransitiveInputs(inputs.build()).addOutput(processedIpa);
    if (processor != null) {
        processAction.addTool(processor);
    }
    ruleContext.registerAction(processAction.build(ruleContext));
}
Also used : FilesToRunProvider(com.google.devtools.build.lib.analysis.FilesToRunProvider) SpawnAction(com.google.devtools.build.lib.analysis.actions.SpawnAction) AppleConfiguration(com.google.devtools.build.lib.rules.apple.AppleConfiguration) Artifact(com.google.devtools.build.lib.actions.Artifact)

Example 7 with AppleConfiguration

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

the class ReleaseBundlingSupport method bundling.

private Bundling bundling(RuleContext ruleContext, ObjcProvider objcProvider, String bundleDirFormat, String bundleName, DottedVersion minimumOsVersion) {
    ImmutableList<BundleableFile> extraBundleFiles;
    AppleConfiguration appleConfiguration = ruleContext.getFragment(AppleConfiguration.class);
    if (platform.isDevice()) {
        extraBundleFiles = ImmutableList.of(new BundleableFile(releaseBundling.getProvisioningProfile(), PROVISIONING_PROFILE_BUNDLE_FILE));
    } else {
        extraBundleFiles = ImmutableList.of();
    }
    Bundling.Builder bundling = new Builder().setName(bundleName).setExecutableName(bundleName).setArchitecture(appleConfiguration.getDependencySingleArchitecture()).setBundleDirFormat(bundleDirFormat).addExtraBundleFiles(extraBundleFiles).setObjcProvider(objcProvider).setIntermediateArtifacts(intermediateArtifacts).setPrimaryBundleId(releaseBundling.getPrimaryBundleId()).setFallbackBundleId(releaseBundling.getFallbackBundleId()).setMinimumOsVersion(minimumOsVersion).setArtifactPrefix(releaseBundling.getArtifactPrefix()).setTargetDeviceFamilies(releaseBundling.getTargetDeviceFamilies());
    // Add plists from rule first.
    if (releaseBundling.getInfoPlistsFromRule() != null) {
        bundling.addInfoplistInputs(releaseBundling.getInfoPlistsFromRule());
    } else {
        bundling.addInfoplistInputFromRule(ruleContext);
    }
    // Add generated plists next so that generated values can override the default values in the
    // plists from rule.
    bundling.setAutomaticEntriesInfoplistInput(getGeneratedAutomaticPlist()).addInfoplistInput(getGeneratedVersionPlist()).addInfoplistInput(getGeneratedEnvironmentPlist()).addInfoplistInputs(releaseBundling.getInfoplistInputs());
    if (releaseBundling.getLaunchStoryboard() != null) {
        bundling.addInfoplistInput(getLaunchStoryboardPlist());
    }
    return bundling.build();
}
Also used : NestedSetBuilder(com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder) Builder(com.google.devtools.build.lib.rules.objc.Bundling.Builder) Builder(com.google.devtools.build.lib.rules.objc.Bundling.Builder) AppleConfiguration(com.google.devtools.build.lib.rules.apple.AppleConfiguration)

Example 8 with AppleConfiguration

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

the class TestSupport method getExtraProviders.

/**
   * Returns any additional providers that need to be exported to the rule context to the passed
   * builder.
   */
public Iterable<SkylarkClassObject> getExtraProviders() {
    IosDeviceProvider deviceProvider = (IosDeviceProvider) ruleContext.getPrerequisite(IosTest.TARGET_DEVICE, Mode.TARGET, IosDeviceProvider.SKYLARK_CONSTRUCTOR.getKey());
    DottedVersion xcodeVersion = deviceProvider.getXcodeVersion();
    AppleConfiguration configuration = ruleContext.getFragment(AppleConfiguration.class);
    ImmutableMap.Builder<String, String> envBuilder = ImmutableMap.builder();
    if (xcodeVersion != null) {
        envBuilder.putAll(configuration.getXcodeVersionEnv(xcodeVersion));
    }
    if (ruleContext.getConfiguration().isCodeCoverageEnabled()) {
        envBuilder.put("COVERAGE_GCOV_PATH", ruleContext.getHostPrerequisiteArtifact(IosTest.OBJC_GCOV_ATTR).getExecPathString());
        envBuilder.put("APPLE_COVERAGE", "1");
    }
    return ImmutableList.<SkylarkClassObject>of(new TestEnvironmentProvider(envBuilder.build()));
}
Also used : DottedVersion(com.google.devtools.build.lib.rules.apple.DottedVersion) SkylarkClassObject(com.google.devtools.build.lib.packages.SkylarkClassObject) TestEnvironmentProvider(com.google.devtools.build.lib.rules.test.TestEnvironmentProvider) AppleConfiguration(com.google.devtools.build.lib.rules.apple.AppleConfiguration) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 9 with AppleConfiguration

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

the class WatchApplicationSupport method registerActions.

/**
   * Registers actions to copy WatchKit stub binary at
   * $(SDK_ROOT)/Library/Application Support/WatchKit/WK as bundle binary and as stub resource.
   *
   * For example, for a bundle named "Foo.app", the contents will be,
   *    - Foo.app/Foo (WK stub as binary)
   *    - Foo.app/_WatchKitStub/WK  (WK stub as resource)
   */
private void registerActions() {
    Artifact watchKitStubZip = watchKitStubZip();
    String workingDirectory = watchKitStubZip.getExecPathString().substring(0, watchKitStubZip.getExecPathString().lastIndexOf('/'));
    String watchKitStubBinaryPath = workingDirectory + "/" + bundleName;
    String watchKitStubResourcePath = workingDirectory + "/_WatchKitStub";
    ImmutableList<String> command = ImmutableList.of(// 1. Copy WK stub as binary
    String.format("cp -f %s %s", WatchUtils.WATCH_KIT_STUB_PATH, watchKitStubBinaryPath), "&&", // 2. Copy WK stub as bundle resource.
    "mkdir -p " + watchKitStubResourcePath, "&&", String.format("cp -f %s %s", WatchUtils.WATCH_KIT_STUB_PATH, watchKitStubResourcePath), // 3. Zip them.
    "&&", "cd " + workingDirectory, "&&", String.format("/usr/bin/zip -q -r -0 %s %s", watchKitStubZip.getFilename(), Joiner.on(" ").join(ImmutableList.of("_WatchKitStub", bundleName))));
    AppleConfiguration appleConfiguration = ruleContext.getFragment(AppleConfiguration.class);
    ruleContext.registerAction(ObjcRuleClasses.spawnAppleEnvActionBuilder(appleConfiguration, appleConfiguration.getMultiArchPlatform(PlatformType.WATCHOS)).setProgressMessage("Copying WatchKit binary and stub resource: " + ruleContext.getLabel()).setShellCommand(ImmutableList.of("/bin/bash", "-c", Joiner.on(" ").join(command))).addOutput(watchKitStubZip).build(ruleContext));
}
Also used : AppleConfiguration(com.google.devtools.build.lib.rules.apple.AppleConfiguration) Artifact(com.google.devtools.build.lib.actions.Artifact)

Example 10 with AppleConfiguration

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

the class ObjcBundleLibrary method bundling.

private Bundling bundling(RuleContext ruleContext, ObjcCommon common) {
    IntermediateArtifacts intermediateArtifacts = ObjcRuleClasses.intermediateArtifacts(ruleContext);
    AppleConfiguration appleConfiguration = ruleContext.getFragment(AppleConfiguration.class);
    ImmutableSet<TargetDeviceFamily> families = null;
    List<String> rawFamilies = ruleContext.attributes().get(FAMILIES_ATTR, Type.STRING_LIST);
    try {
        families = ImmutableSet.copyOf(TargetDeviceFamily.fromNamesInRule(rawFamilies));
    } catch (InvalidFamilyNameException | RepeatedFamilyNameException e) {
        families = ImmutableSet.of();
    }
    if (families.isEmpty()) {
        ruleContext.attributeError(FAMILIES_ATTR, ReleaseBundling.INVALID_FAMILIES_ERROR);
    }
    return new Bundling.Builder().setName(ruleContext.getLabel().getName()).setArchitecture(appleConfiguration.getIosCpu()).setBundleDirFormat("%s.bundle").setObjcProvider(common.getObjcProvider()).addInfoplistInputFromRule(ruleContext).setIntermediateArtifacts(intermediateArtifacts).setMinimumOsVersion(appleConfiguration.getMinimumOsForPlatformType(PlatformType.IOS)).setTargetDeviceFamilies(families).build();
}
Also used : InvalidFamilyNameException(com.google.devtools.build.lib.rules.objc.TargetDeviceFamily.InvalidFamilyNameException) AppleConfiguration(com.google.devtools.build.lib.rules.apple.AppleConfiguration) RepeatedFamilyNameException(com.google.devtools.build.lib.rules.objc.TargetDeviceFamily.RepeatedFamilyNameException)

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