use of com.facebook.buck.model.UnflavoredBuildTarget 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.facebook.buck.model.UnflavoredBuildTarget 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);
}
use of com.facebook.buck.model.UnflavoredBuildTarget in project buck by facebook.
the class DistBuildTargetGraphCodec method decodeBuildTarget.
public static BuildTarget decodeBuildTarget(BuildJobStateBuildTarget remoteTarget, Cell cell) {
UnflavoredBuildTarget unflavoredBuildTarget = UnflavoredBuildTarget.builder().setShortName(remoteTarget.getShortName()).setBaseName(remoteTarget.getBaseName()).setCellPath(cell.getRoot()).setCell(Optional.ofNullable(remoteTarget.getCellName())).build();
ImmutableSet<Flavor> flavors = remoteTarget.flavors.stream().map(InternalFlavor::of).collect(MoreCollectors.toImmutableSet());
return BuildTarget.builder().setUnflavoredBuildTarget(unflavoredBuildTarget).setFlavors(flavors).build();
}
use of com.facebook.buck.model.UnflavoredBuildTarget in project buck by facebook.
the class OcamlStaticLibrary method getLinkableInput.
private NativeLinkableInput getLinkableInput(boolean isBytecode) {
NativeLinkableInput.Builder inputBuilder = NativeLinkableInput.builder();
// Add linker flags.
inputBuilder.addAllArgs(StringArg.from(linkerFlags));
// Add arg and input for static library.
UnflavoredBuildTarget staticBuildTarget = staticLibraryTarget.getUnflavoredBuildTarget();
inputBuilder.addArgs(SourcePathArg.of(new ExplicitBuildTargetSourcePath(ocamlLibraryBuild.getBuildTarget(), isBytecode ? OcamlBuildContext.getBytecodeOutputPath(staticBuildTarget, getProjectFilesystem(), /* isLibrary */
true) : OcamlBuildContext.getNativeOutputPath(staticBuildTarget, getProjectFilesystem(), /* isLibrary */
true))));
// Add args and inputs for C object files.
for (SourcePath objFile : objFiles) {
inputBuilder.addArgs(SourcePathArg.of(objFile));
}
return inputBuilder.build();
}
use of com.facebook.buck.model.UnflavoredBuildTarget in project buck by facebook.
the class DefaultParserTargetNodeFactory method createTargetNode.
@Override
public TargetNode<?, ?> createTargetNode(Cell cell, Path buildFile, BuildTarget target, Map<String, Object> rawNode, Function<PerfEventId, SimplePerfEvent.Scope> perfEventScope) {
BuildRuleType buildRuleType = parseBuildRuleTypeFromRawRule(cell, rawNode);
// Because of the way that the parser works, we know this can never return null.
Description<?> description = cell.getDescription(buildRuleType);
UnflavoredBuildTarget unflavoredBuildTarget = target.withoutCell().getUnflavoredBuildTarget();
if (target.isFlavored()) {
if (description instanceof Flavored) {
if (!((Flavored) description).hasFlavors(ImmutableSet.copyOf(target.getFlavors()))) {
throw UnexpectedFlavorException.createWithSuggestions(cell, target);
}
} else {
LOG.warn("Target %s (type %s) must implement the Flavored interface " + "before we can check if it supports flavors: %s", unflavoredBuildTarget, buildRuleType, target.getFlavors());
throw new HumanReadableException("Target %s (type %s) does not currently support flavors (tried %s)", unflavoredBuildTarget, buildRuleType, target.getFlavors());
}
}
UnflavoredBuildTarget unflavoredBuildTargetFromRawData = RawNodeParsePipeline.parseBuildTargetFromRawRule(cell.getRoot(), rawNode, buildFile);
if (!unflavoredBuildTarget.equals(unflavoredBuildTargetFromRawData)) {
throw new IllegalStateException(String.format("Inconsistent internal state, target from data: %s, expected: %s, raw data: %s", unflavoredBuildTargetFromRawData, unflavoredBuildTarget, Joiner.on(',').withKeyValueSeparator("->").join(rawNode)));
}
Cell targetCell = cell.getCell(target);
Object constructorArg = description.createUnpopulatedConstructorArg();
try {
ImmutableSet.Builder<BuildTarget> declaredDeps = ImmutableSet.builder();
ImmutableSet.Builder<VisibilityPattern> visibilityPatterns = ImmutableSet.builder();
try (SimplePerfEvent.Scope scope = perfEventScope.apply(PerfEventId.of("MarshalledConstructorArg"))) {
marshaller.populate(targetCell.getCellPathResolver(), targetCell.getFilesystem(), target, constructorArg, declaredDeps, visibilityPatterns, rawNode);
}
try (SimplePerfEvent.Scope scope = perfEventScope.apply(PerfEventId.of("CreatedTargetNode"))) {
Hasher hasher = Hashing.sha1().newHasher();
hasher.putString(BuckVersion.getVersion(), UTF_8);
JsonObjectHashing.hashJsonObject(hasher, rawNode);
TargetNode<?, ?> node = targetNodeFactory.createFromObject(hasher.hash(), description, constructorArg, targetCell.getFilesystem(), target, declaredDeps.build(), visibilityPatterns.build(), targetCell.getCellPathResolver());
if (buildFileTrees.isPresent() && cell.isEnforcingBuckPackageBoundaries(target.getBasePath())) {
enforceBuckPackageBoundaries(target, buildFileTrees.get().getUnchecked(targetCell), node.getInputs());
}
nodeListener.onCreate(buildFile, node);
return node;
}
} catch (NoSuchBuildTargetException e) {
throw new HumanReadableException(e);
} catch (ParamInfoException e) {
throw new HumanReadableException(e, "%s: %s", target, e.getMessage());
} catch (IOException e) {
throw new HumanReadableException(e.getMessage(), e);
}
}
Aggregations