Search in sources :

Example 86 with ImmutableList

use of com.google.common.collect.ImmutableList in project buck by facebook.

the class MultiarchFile method getBuildSteps.

@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
    buildableContext.recordArtifact(output);
    ImmutableList.Builder<Step> steps = ImmutableList.builder();
    steps.add(new MkdirStep(getProjectFilesystem(), output.getParent()));
    lipoBinaries(context, steps);
    copyLinkMaps(buildableContext, steps);
    return steps.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) MkdirStep(com.facebook.buck.step.fs.MkdirStep) Step(com.facebook.buck.step.Step) CopyStep(com.facebook.buck.step.fs.CopyStep) MkdirStep(com.facebook.buck.step.fs.MkdirStep) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) DefaultShellStep(com.facebook.buck.shell.DefaultShellStep)

Example 87 with ImmutableList

use of com.google.common.collect.ImmutableList in project buck by facebook.

the class MultiarchFileInfos method generateThinFlavors.

/**
   * Expand flavors representing a fat binary into its thin binary equivalents.
   *
   * Useful when dealing with functions unaware of fat binaries.
   *
   * This does not actually check that the particular flavor set is valid.
   */
public static ImmutableList<ImmutableSortedSet<Flavor>> generateThinFlavors(Set<Flavor> platformFlavors, SortedSet<Flavor> flavors) {
    Set<Flavor> platformFreeFlavors = Sets.difference(flavors, platformFlavors);
    ImmutableList.Builder<ImmutableSortedSet<Flavor>> thinTargetsBuilder = ImmutableList.builder();
    for (Flavor flavor : flavors) {
        if (platformFlavors.contains(flavor)) {
            thinTargetsBuilder.add(ImmutableSortedSet.<Flavor>naturalOrder().addAll(platformFreeFlavors).add(flavor).build());
        }
    }
    return thinTargetsBuilder.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) Flavor(com.facebook.buck.model.Flavor)

Example 88 with ImmutableList

use of com.google.common.collect.ImmutableList in project buck by facebook.

the class ProvisioningProfileCopyStep method execute.

@Override
public StepExecutionResult execute(ExecutionContext context) throws InterruptedException {
    final String bundleID;
    try {
        bundleID = AppleInfoPlistParsing.getBundleIdFromPlistStream(filesystem.getInputStreamForRelativePath(infoPlist)).get();
    } catch (IOException e) {
        throw new HumanReadableException("Unable to get bundle ID from info.plist: " + infoPlist);
    }
    final Optional<ImmutableMap<String, NSObject>> entitlements;
    final String prefix;
    if (entitlementsPlist.isPresent()) {
        try {
            NSDictionary entitlementsPlistDict = (NSDictionary) PropertyListParser.parse(entitlementsPlist.get().toFile());
            entitlements = Optional.of(ImmutableMap.copyOf(entitlementsPlistDict.getHashMap()));
            prefix = ProvisioningProfileMetadata.prefixFromEntitlements(entitlements.get()).orElse("*");
        } catch (IOException e) {
            throw new HumanReadableException("Unable to find entitlement .plist: " + entitlementsPlist.get());
        } catch (Exception e) {
            throw new HumanReadableException("Malformed entitlement .plist: " + entitlementsPlist.get());
        }
    } else {
        entitlements = ProvisioningProfileStore.MATCH_ANY_ENTITLEMENT;
        prefix = "*";
    }
    final Optional<ImmutableList<CodeSignIdentity>> identities;
    if (!codeSignIdentityStore.getIdentities().isEmpty()) {
        identities = Optional.of(codeSignIdentityStore.getIdentities());
    } else {
        identities = ProvisioningProfileStore.MATCH_ANY_IDENTITY;
    }
    Optional<ProvisioningProfileMetadata> bestProfile = provisioningProfileUUID.isPresent() ? provisioningProfileStore.getProvisioningProfileByUUID(provisioningProfileUUID.get()) : provisioningProfileStore.getBestProvisioningProfile(bundleID, platform, entitlements, identities);
    if (dryRunResultsPath.isPresent()) {
        try {
            NSDictionary dryRunResult = new NSDictionary();
            dryRunResult.put(BUNDLE_ID, bundleID);
            dryRunResult.put(ENTITLEMENTS, entitlements.orElse(ImmutableMap.of()));
            if (bestProfile.isPresent()) {
                dryRunResult.put(PROFILE_UUID, bestProfile.get().getUUID());
                dryRunResult.put(PROFILE_FILENAME, bestProfile.get().getProfilePath().getFileName().toString());
                dryRunResult.put(TEAM_IDENTIFIER, bestProfile.get().getEntitlements().get("com.apple.developer.team-identifier"));
            }
            filesystem.writeContentsToPath(dryRunResult.toXMLPropertyList(), dryRunResultsPath.get());
        } catch (IOException e) {
            context.logError(e, "Failed when trying to write dry run results: %s", getDescription(context));
            return StepExecutionResult.ERROR;
        }
    }
    selectedProvisioningProfileFuture.set(bestProfile);
    if (!bestProfile.isPresent()) {
        String message = "No valid non-expired provisioning profiles match for " + prefix + "." + bundleID;
        if (dryRunResultsPath.isPresent()) {
            LOG.warn(message);
            return StepExecutionResult.SUCCESS;
        } else {
            throw new HumanReadableException(message);
        }
    }
    Path provisioningProfileSource = bestProfile.get().getProfilePath();
    // Copy the actual .mobileprovision.
    try {
        filesystem.copy(provisioningProfileSource, provisioningProfileDestination, CopySourceMode.FILE);
    } catch (IOException e) {
        context.logError(e, "Failed when trying to copy: %s", getDescription(context));
        return StepExecutionResult.ERROR;
    }
    // Merge the entitlements with the profile, and write out.
    if (entitlementsPlist.isPresent()) {
        return (new PlistProcessStep(filesystem, entitlementsPlist.get(), Optional.empty(), signingEntitlementsTempPath, bestProfile.get().getMergeableEntitlements(), ImmutableMap.of(), PlistProcessStep.OutputFormat.XML)).execute(context);
    } else {
        // No entitlements.plist explicitly specified; write out the minimal entitlements needed.
        String appID = bestProfile.get().getAppID().getFirst() + "." + bundleID;
        NSDictionary entitlementsPlist = new NSDictionary();
        entitlementsPlist.putAll(bestProfile.get().getMergeableEntitlements());
        entitlementsPlist.put(APPLICATION_IDENTIFIER, appID);
        entitlementsPlist.put(KEYCHAIN_ACCESS_GROUPS, new String[] { appID });
        return (new WriteFileStep(filesystem, entitlementsPlist.toXMLPropertyList(), signingEntitlementsTempPath, /* executable */
        false)).execute(context);
    }
}
Also used : Path(java.nio.file.Path) NSDictionary(com.dd.plist.NSDictionary) ImmutableList(com.google.common.collect.ImmutableList) IOException(java.io.IOException) ImmutableMap(com.google.common.collect.ImmutableMap) IOException(java.io.IOException) HumanReadableException(com.facebook.buck.util.HumanReadableException) HumanReadableException(com.facebook.buck.util.HumanReadableException) WriteFileStep(com.facebook.buck.step.fs.WriteFileStep)

Example 89 with ImmutableList

use of com.google.common.collect.ImmutableList in project buck by facebook.

the class RuleUtils method createGroupsFromEntryMaps.

@VisibleForTesting
static ImmutableList<GroupedSource> createGroupsFromEntryMaps(Multimap<Path, String> subgroups, Multimap<Path, GroupedSource> entries, Comparator<GroupedSource> comparator, Path rootGroupPath, Path groupPath) {
    ImmutableList.Builder<GroupedSource> groupBuilder = ImmutableList.builder();
    for (String subgroupName : ImmutableSortedSet.copyOf(subgroups.get(groupPath))) {
        Path subgroupPath = groupPath.resolve(subgroupName);
        groupBuilder.add(GroupedSource.ofSourceGroup(subgroupName, subgroupPath.subpath(rootGroupPath.getNameCount(), subgroupPath.getNameCount()), createGroupsFromEntryMaps(subgroups, entries, comparator, rootGroupPath, subgroupPath)));
    }
    SortedSet<GroupedSource> sortedEntries = ImmutableSortedSet.copyOf(comparator, entries.get(groupPath));
    for (GroupedSource groupedSource : sortedEntries) {
        groupBuilder.add(groupedSource);
    }
    return groupBuilder.build().asList();
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) ImmutableList(com.google.common.collect.ImmutableList) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 90 with ImmutableList

use of com.google.common.collect.ImmutableList in project buck by facebook.

the class SceneKitAssets method getBuildSteps.

@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
    ImmutableList.Builder<Step> stepsBuilder = ImmutableList.builder();
    stepsBuilder.add(new MakeCleanDirectoryStep(getProjectFilesystem(), outputDir));
    for (SourcePath inputPath : sceneKitAssetsPaths) {
        final Path absoluteInputPath = context.getSourcePathResolver().getAbsolutePath(inputPath);
        if (copySceneKitAssets.isPresent()) {
            stepsBuilder.add(new ShellStep(getProjectFilesystem().getRootPath()) {

                @Override
                protected ImmutableList<String> getShellCommandInternal(ExecutionContext executionContext) {
                    ImmutableList.Builder<String> commandBuilder = ImmutableList.builder();
                    commandBuilder.addAll(copySceneKitAssets.get().getCommandPrefix(context.getSourcePathResolver()));
                    commandBuilder.add(absoluteInputPath.toString(), "-o", getProjectFilesystem().resolve(outputDir).resolve(absoluteInputPath.getFileName()).toString(), "--target-platform=" + sdkName, "--target-version=" + minOSVersion);
                    return commandBuilder.build();
                }

                @Override
                public ImmutableMap<String, String> getEnvironmentVariables(ExecutionContext executionContext) {
                    return copySceneKitAssets.get().getEnvironment(context.getSourcePathResolver());
                }

                @Override
                public String getShortName() {
                    return "copy-scenekit-assets";
                }
            });
        } else {
            stepsBuilder.add(CopyStep.forDirectory(getProjectFilesystem(), absoluteInputPath, outputDir, CopyStep.DirectoryMode.CONTENTS_ONLY));
        }
    }
    buildableContext.recordArtifact(context.getSourcePathResolver().getRelativePath(getSourcePathToOutput()));
    return stepsBuilder.build();
}
Also used : ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) ExecutionContext(com.facebook.buck.step.ExecutionContext) ImmutableList(com.google.common.collect.ImmutableList) ShellStep(com.facebook.buck.shell.ShellStep) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) Step(com.facebook.buck.step.Step) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) CopyStep(com.facebook.buck.step.fs.CopyStep) ShellStep(com.facebook.buck.shell.ShellStep) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)552 Path (java.nio.file.Path)130 List (java.util.List)112 SourcePath (com.facebook.buck.rules.SourcePath)91 Test (org.junit.Test)78 Step (com.facebook.buck.step.Step)76 ImmutableMap (com.google.common.collect.ImmutableMap)69 IOException (java.io.IOException)64 ArrayList (java.util.ArrayList)63 Map (java.util.Map)62 ExplicitBuildTargetSourcePath (com.facebook.buck.rules.ExplicitBuildTargetSourcePath)52 MakeCleanDirectoryStep (com.facebook.buck.step.fs.MakeCleanDirectoryStep)52 BuildTarget (com.facebook.buck.model.BuildTarget)47 ImmutableSet (com.google.common.collect.ImmutableSet)44 MkdirStep (com.facebook.buck.step.fs.MkdirStep)39 Arguments (com.spectralogic.ds3autogen.api.models.Arguments)38 Optional (java.util.Optional)38 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)36 HumanReadableException (com.facebook.buck.util.HumanReadableException)36 HashMap (java.util.HashMap)35