use of com.google.common.collect.ImmutableSet in project buck by facebook.
the class AppleDescriptions method createAppleBundle.
static AppleBundle createAppleBundle(FlavorDomain<CxxPlatform> cxxPlatformFlavorDomain, CxxPlatform defaultCxxPlatform, FlavorDomain<AppleCxxPlatform> appleCxxPlatforms, TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver, CodeSignIdentityStore codeSignIdentityStore, ProvisioningProfileStore provisioningProfileStore, BuildTarget binary, Either<AppleBundleExtension, String> extension, Optional<String> productName, final SourcePath infoPlist, ImmutableMap<String, String> infoPlistSubstitutions, ImmutableSortedSet<BuildTarget> deps, ImmutableSortedSet<BuildTarget> tests, AppleDebugFormat debugFormat, boolean dryRunCodeSigning, boolean cacheable) throws NoSuchBuildTargetException {
AppleCxxPlatform appleCxxPlatform = ApplePlatforms.getAppleCxxPlatformForBuildTarget(cxxPlatformFlavorDomain, defaultCxxPlatform, appleCxxPlatforms, params.getBuildTarget(), MultiarchFileInfos.create(appleCxxPlatforms, params.getBuildTarget()));
AppleBundleDestinations destinations;
if (extension.isLeft() && extension.getLeft().equals(AppleBundleExtension.FRAMEWORK)) {
destinations = AppleBundleDestinations.platformFrameworkDestinations(appleCxxPlatform.getAppleSdk().getApplePlatform());
} else {
destinations = AppleBundleDestinations.platformDestinations(appleCxxPlatform.getAppleSdk().getApplePlatform());
}
AppleBundleResources collectedResources = AppleResources.collectResourceDirsAndFiles(targetGraph, Optional.empty(), targetGraph.get(params.getBuildTarget()));
ImmutableSet.Builder<SourcePath> frameworksBuilder = ImmutableSet.builder();
if (INCLUDE_FRAMEWORKS.getRequiredValue(params.getBuildTarget())) {
for (BuildTarget dep : deps) {
Optional<FrameworkDependencies> frameworkDependencies = resolver.requireMetadata(BuildTarget.builder(dep).addFlavors(FRAMEWORK_FLAVOR).addFlavors(NO_INCLUDE_FRAMEWORKS_FLAVOR).addFlavors(appleCxxPlatform.getCxxPlatform().getFlavor()).build(), FrameworkDependencies.class);
if (frameworkDependencies.isPresent()) {
frameworksBuilder.addAll(frameworkDependencies.get().getSourcePaths());
}
}
}
ImmutableSet<SourcePath> frameworks = frameworksBuilder.build();
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver sourcePathResolver = new SourcePathResolver(ruleFinder);
BuildRuleParams paramsWithoutBundleSpecificFlavors = stripBundleSpecificFlavors(params);
Optional<AppleAssetCatalog> assetCatalog = createBuildRuleForTransitiveAssetCatalogDependencies(targetGraph, paramsWithoutBundleSpecificFlavors, sourcePathResolver, appleCxxPlatform.getAppleSdk().getApplePlatform(), appleCxxPlatform.getActool());
addToIndex(resolver, assetCatalog);
Optional<CoreDataModel> coreDataModel = createBuildRulesForCoreDataDependencies(targetGraph, paramsWithoutBundleSpecificFlavors, AppleBundle.getBinaryName(params.getBuildTarget(), productName), appleCxxPlatform);
addToIndex(resolver, coreDataModel);
Optional<SceneKitAssets> sceneKitAssets = createBuildRulesForSceneKitAssetsDependencies(targetGraph, paramsWithoutBundleSpecificFlavors, appleCxxPlatform);
addToIndex(resolver, sceneKitAssets);
// TODO(bhamiltoncx): Sort through the changes needed to make project generation work with
// binary being optional.
BuildRule flavoredBinaryRule = getFlavoredBinaryRule(cxxPlatformFlavorDomain, defaultCxxPlatform, targetGraph, paramsWithoutBundleSpecificFlavors.getBuildTarget().getFlavors(), resolver, binary);
if (!AppleDebuggableBinary.isBuildRuleDebuggable(flavoredBinaryRule)) {
debugFormat = AppleDebugFormat.NONE;
}
BuildTarget unstrippedTarget = flavoredBinaryRule.getBuildTarget().withoutFlavors(CxxStrip.RULE_FLAVOR, AppleDebuggableBinary.RULE_FLAVOR, AppleBinaryDescription.APP_FLAVOR).withoutFlavors(StripStyle.FLAVOR_DOMAIN.getFlavors()).withoutFlavors(AppleDebugFormat.FLAVOR_DOMAIN.getFlavors()).withoutFlavors(AppleDebuggableBinary.RULE_FLAVOR).withoutFlavors(ImmutableSet.of(AppleBinaryDescription.APP_FLAVOR));
Optional<LinkerMapMode> linkerMapMode = LinkerMapMode.FLAVOR_DOMAIN.getValue(params.getBuildTarget());
if (linkerMapMode.isPresent()) {
unstrippedTarget = unstrippedTarget.withAppendedFlavors(linkerMapMode.get().getFlavor());
}
BuildRule unstrippedBinaryRule = resolver.requireRule(unstrippedTarget);
BuildRule targetDebuggableBinaryRule;
Optional<AppleDsym> appleDsym;
if (unstrippedBinaryRule instanceof ProvidesLinkedBinaryDeps) {
BuildTarget binaryBuildTarget = getBinaryFromBuildRuleWithBinary(flavoredBinaryRule).getBuildTarget().withoutFlavors(AppleDebugFormat.FLAVOR_DOMAIN.getFlavors());
BuildRuleParams binaryParams = params.withBuildTarget(binaryBuildTarget);
targetDebuggableBinaryRule = createAppleDebuggableBinary(binaryParams, resolver, getBinaryFromBuildRuleWithBinary(flavoredBinaryRule), (ProvidesLinkedBinaryDeps) unstrippedBinaryRule, debugFormat, cxxPlatformFlavorDomain, defaultCxxPlatform, appleCxxPlatforms);
appleDsym = createAppleDsymForDebugFormat(debugFormat, binaryParams, resolver, (ProvidesLinkedBinaryDeps) unstrippedBinaryRule, cxxPlatformFlavorDomain, defaultCxxPlatform, appleCxxPlatforms);
} else {
targetDebuggableBinaryRule = unstrippedBinaryRule;
appleDsym = Optional.empty();
}
BuildRuleParams bundleParamsWithFlavoredBinaryDep = getBundleParamsWithUpdatedDeps(params, binary, ImmutableSet.<BuildRule>builder().add(targetDebuggableBinaryRule).addAll(OptionalCompat.asSet(assetCatalog)).addAll(OptionalCompat.asSet(coreDataModel)).addAll(OptionalCompat.asSet(sceneKitAssets)).addAll(BuildRules.toBuildRulesFor(params.getBuildTarget(), resolver, RichStream.from(collectedResources.getAll()).concat(frameworks.stream()).filter(BuildTargetSourcePath.class).map(BuildTargetSourcePath::getTarget).collect(MoreCollectors.toImmutableSet()))).addAll(OptionalCompat.asSet(appleDsym)).build());
ImmutableMap<SourcePath, String> extensionBundlePaths = collectFirstLevelAppleDependencyBundles(params.getDeps(), destinations);
return new AppleBundle(bundleParamsWithFlavoredBinaryDep, resolver, extension, productName, infoPlist, infoPlistSubstitutions, Optional.of(getBinaryFromBuildRuleWithBinary(flavoredBinaryRule)), appleDsym, destinations, collectedResources, extensionBundlePaths, frameworks, appleCxxPlatform, assetCatalog, coreDataModel, sceneKitAssets, tests, codeSignIdentityStore, provisioningProfileStore, dryRunCodeSigning, cacheable);
}
use of com.google.common.collect.ImmutableSet in project buck by facebook.
the class Symbols method getDtNeeded.
public static ImmutableSet<String> getDtNeeded(ProcessExecutor executor, Tool objdump, SourcePathResolver resolver, Path lib) throws IOException, InterruptedException {
final ImmutableSet.Builder<String> builder = ImmutableSet.builder();
final Pattern re = Pattern.compile("^ *NEEDED *(\\S*)$");
runObjdump(executor, objdump, resolver, lib, ImmutableList.of("-p"), new LineProcessor<Void>() {
@Override
public boolean processLine(String line) throws IOException {
Matcher m = re.matcher(line);
if (!m.matches()) {
return true;
}
builder.add(m.group(1));
return true;
}
@Override
public Void getResult() {
return null;
}
});
return builder.build();
}
use of com.google.common.collect.ImmutableSet in project buck by facebook.
the class MiniAapt method verifyReferences.
@VisibleForTesting
ImmutableSet<RDotTxtEntry> verifyReferences(ProjectFilesystem filesystem, ImmutableSet<RDotTxtEntry> references) throws IOException {
ImmutableSet.Builder<RDotTxtEntry> unresolved = ImmutableSet.builder();
ImmutableSet.Builder<RDotTxtEntry> definitionsBuilder = ImmutableSet.builder();
definitionsBuilder.addAll(resourceCollector.getResources());
for (Path depRTxt : pathsToSymbolsOfDeps) {
Iterable<String> lines = FluentIterable.from(filesystem.readLines(depRTxt)).filter(input -> !Strings.isNullOrEmpty(input)).toList();
for (String line : lines) {
Optional<RDotTxtEntry> entry = RDotTxtEntry.parse(line);
Preconditions.checkState(entry.isPresent());
definitionsBuilder.add(entry.get());
}
}
Set<RDotTxtEntry> definitions = definitionsBuilder.build();
for (RDotTxtEntry reference : references) {
if (!definitions.contains(reference)) {
unresolved.add(reference);
}
}
return unresolved.build();
}
use of com.google.common.collect.ImmutableSet in project buck by facebook.
the class ProjectCommand method generateWorkspacesForTargets.
@VisibleForTesting
static ImmutableSet<BuildTarget> generateWorkspacesForTargets(final CommandRunnerParams params, final TargetGraphAndTargets targetGraphAndTargets, ImmutableSet<BuildTarget> passedInTargetsSet, ImmutableSet<ProjectGenerator.Option> options, ImmutableList<String> buildWithBuckFlags, Optional<ImmutableSet<UnflavoredBuildTarget>> focusModules, Map<Path, ProjectGenerator> projectGenerators, boolean combinedProject, boolean buildWithBuck) throws IOException, InterruptedException {
ImmutableSet<BuildTarget> targets;
if (passedInTargetsSet.isEmpty()) {
targets = targetGraphAndTargets.getProjectRoots().stream().map(TargetNode::getBuildTarget).collect(MoreCollectors.toImmutableSet());
} else {
targets = passedInTargetsSet;
}
LOG.debug("Generating workspace for config targets %s", targets);
ImmutableSet.Builder<BuildTarget> requiredBuildTargetsBuilder = ImmutableSet.builder();
for (final BuildTarget inputTarget : targets) {
TargetNode<?, ?> inputNode = targetGraphAndTargets.getTargetGraph().get(inputTarget);
XcodeWorkspaceConfigDescription.Arg workspaceArgs;
if (inputNode.getDescription() instanceof XcodeWorkspaceConfigDescription) {
TargetNode<XcodeWorkspaceConfigDescription.Arg, ?> castedWorkspaceNode = castToXcodeWorkspaceTargetNode(inputNode);
workspaceArgs = castedWorkspaceNode.getConstructorArg();
} else if (canGenerateImplicitWorkspaceForDescription(inputNode.getDescription())) {
workspaceArgs = createImplicitWorkspaceArgs(inputNode);
} else {
throw new HumanReadableException("%s must be a xcode_workspace_config, apple_binary, apple_bundle, or apple_library", inputNode);
}
BuckConfig buckConfig = params.getBuckConfig();
AppleConfig appleConfig = new AppleConfig(buckConfig);
HalideBuckConfig halideBuckConfig = new HalideBuckConfig(buckConfig);
CxxBuckConfig cxxBuckConfig = new CxxBuckConfig(buckConfig);
SwiftBuckConfig swiftBuckConfig = new SwiftBuckConfig(buckConfig);
CxxPlatform defaultCxxPlatform = params.getCell().getKnownBuildRuleTypes().getDefaultCxxPlatforms();
WorkspaceAndProjectGenerator generator = new WorkspaceAndProjectGenerator(params.getCell(), targetGraphAndTargets.getTargetGraph(), workspaceArgs, inputTarget, options, combinedProject, buildWithBuck, buildWithBuckFlags, focusModules, !appleConfig.getXcodeDisableParallelizeBuild(), new ExecutableFinder(), params.getEnvironment(), params.getCell().getKnownBuildRuleTypes().getCxxPlatforms(), defaultCxxPlatform, params.getBuckConfig().getView(ParserConfig.class).getBuildFileName(), input -> ActionGraphCache.getFreshActionGraph(params.getBuckEventBus(), targetGraphAndTargets.getTargetGraph().getSubgraph(ImmutableSet.of(input))).getResolver(), params.getBuckEventBus(), halideBuckConfig, cxxBuckConfig, appleConfig, swiftBuckConfig);
ListeningExecutorService executorService = params.getExecutors().get(ExecutorPool.PROJECT);
Preconditions.checkNotNull(executorService, "CommandRunnerParams does not have executor for PROJECT pool");
generator.generateWorkspaceAndDependentProjects(projectGenerators, executorService);
ImmutableSet<BuildTarget> requiredBuildTargetsForWorkspace = generator.getRequiredBuildTargets();
LOG.debug("Required build targets for workspace %s: %s", inputTarget, requiredBuildTargetsForWorkspace);
requiredBuildTargetsBuilder.addAll(requiredBuildTargetsForWorkspace);
}
return requiredBuildTargetsBuilder.build();
}
use of com.google.common.collect.ImmutableSet in project buck by facebook.
the class ProjectCommand method getFocusModules.
private Optional<ImmutableSet<UnflavoredBuildTarget>> getFocusModules(CommandRunnerParams params, ListeningExecutorService executor) throws IOException, InterruptedException {
if (modulesToFocusOn == null) {
return Optional.empty();
}
Iterable<String> patterns = Splitter.onPattern("\\s+").split(modulesToFocusOn);
// Parse patterns with the following syntax:
// https://buckbuild.com/concept/build_target_pattern.html
ImmutableList<TargetNodeSpec> specs = parseArgumentsAsTargetNodeSpecs(params.getBuckConfig(), patterns);
// Resolve the list of targets matching the patterns.
ImmutableSet<BuildTarget> passedInTargetsSet;
ParserConfig parserConfig = params.getBuckConfig().getView(ParserConfig.class);
try {
passedInTargetsSet = params.getParser().resolveTargetSpecs(params.getBuckEventBus(), params.getCell(), getEnableParserProfiling(), executor, specs, SpeculativeParsing.of(false), parserConfig.getDefaultFlavorsMode()).stream().flatMap(Collection::stream).map(target -> target.withoutCell()).collect(MoreCollectors.toImmutableSet());
} catch (BuildTargetException | BuildFileParseException | HumanReadableException e) {
params.getBuckEventBus().post(ConsoleEvent.severe(MoreExceptions.getHumanReadableOrLocalizedMessage(e)));
return Optional.empty();
}
LOG.debug("Selected targets: %s", passedInTargetsSet.toString());
// Retrieve mapping: cell name -> path.
ImmutableMap<String, Path> cellPaths = params.getCell().getCellPathResolver().getCellPaths();
ImmutableMap<Path, String> cellNames = ImmutableBiMap.copyOf(cellPaths).inverse();
// Create a set of unflavored targets that have cell names.
ImmutableSet.Builder<UnflavoredBuildTarget> builder = ImmutableSet.builder();
for (BuildTarget target : passedInTargetsSet) {
String cell = cellNames.get(target.getCellPath());
if (cell == null) {
builder.add(target.getUnflavoredBuildTarget());
} else {
UnflavoredBuildTarget targetWithCell = UnflavoredBuildTarget.of(target.getCellPath(), Optional.of(cell), target.getBaseName(), target.getShortName());
builder.add(targetWithCell);
}
}
ImmutableSet<UnflavoredBuildTarget> passedInUnflavoredTargetsSet = builder.build();
LOG.debug("Selected unflavored targets: %s", passedInUnflavoredTargetsSet.toString());
return Optional.of(passedInUnflavoredTargetsSet);
}
Aggregations