Search in sources :

Example 1 with UnflavoredBuildTarget

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();
}
Also used : AppleConfig(com.facebook.buck.apple.AppleConfig) ExecutableFinder(com.facebook.buck.io.ExecutableFinder) TargetNode(com.facebook.buck.rules.TargetNode) CxxPlatform(com.facebook.buck.cxx.CxxPlatform) WorkspaceAndProjectGenerator(com.facebook.buck.apple.project_generator.WorkspaceAndProjectGenerator) CxxBuckConfig(com.facebook.buck.cxx.CxxBuckConfig) ImmutableSet(com.google.common.collect.ImmutableSet) XcodeWorkspaceConfigDescription(com.facebook.buck.apple.XcodeWorkspaceConfigDescription) CxxBuckConfig(com.facebook.buck.cxx.CxxBuckConfig) JavaBuckConfig(com.facebook.buck.jvm.java.JavaBuckConfig) SwiftBuckConfig(com.facebook.buck.swift.SwiftBuckConfig) HalideBuckConfig(com.facebook.buck.halide.HalideBuckConfig) PythonBuckConfig(com.facebook.buck.python.PythonBuckConfig) HalideBuckConfig(com.facebook.buck.halide.HalideBuckConfig) BuildTarget(com.facebook.buck.model.BuildTarget) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) HumanReadableException(com.facebook.buck.util.HumanReadableException) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) SwiftBuckConfig(com.facebook.buck.swift.SwiftBuckConfig) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with UnflavoredBuildTarget

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);
}
Also used : BuildTargetException(com.facebook.buck.model.BuildTargetException) Path(java.nio.file.Path) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) BuildFileParseException(com.facebook.buck.json.BuildFileParseException) ImmutableSet(com.google.common.collect.ImmutableSet) BuildTarget(com.facebook.buck.model.BuildTarget) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) HumanReadableException(com.facebook.buck.util.HumanReadableException) ParserConfig(com.facebook.buck.parser.ParserConfig) TargetNodeSpec(com.facebook.buck.parser.TargetNodeSpec)

Example 3 with UnflavoredBuildTarget

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();
}
Also used : UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) InternalFlavor(com.facebook.buck.model.InternalFlavor) Flavor(com.facebook.buck.model.Flavor)

Example 4 with UnflavoredBuildTarget

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();
}
Also used : ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) NativeLinkableInput(com.facebook.buck.cxx.NativeLinkableInput) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath)

Example 5 with UnflavoredBuildTarget

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);
    }
}
Also used : UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) IOException(java.io.IOException) Flavored(com.facebook.buck.model.Flavored) VisibilityPattern(com.facebook.buck.rules.VisibilityPattern) ParamInfoException(com.facebook.buck.rules.ParamInfoException) Hasher(com.google.common.hash.Hasher) ImmutableSet(com.google.common.collect.ImmutableSet) HumanReadableException(com.facebook.buck.util.HumanReadableException) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) BuildTarget(com.facebook.buck.model.BuildTarget) BuildRuleType(com.facebook.buck.rules.BuildRuleType) SimplePerfEvent(com.facebook.buck.event.SimplePerfEvent) Cell(com.facebook.buck.rules.Cell)

Aggregations

UnflavoredBuildTarget (com.facebook.buck.model.UnflavoredBuildTarget)19 BuildTarget (com.facebook.buck.model.BuildTarget)9 ImmutableSet (com.google.common.collect.ImmutableSet)7 HumanReadableException (com.facebook.buck.util.HumanReadableException)6 Path (java.nio.file.Path)6 BuildRule (com.facebook.buck.rules.BuildRule)4 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)4 SourcePath (com.facebook.buck.rules.SourcePath)4 Flavor (com.facebook.buck.model.Flavor)3 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)3 ImmutableList (com.google.common.collect.ImmutableList)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 SimplePerfEvent (com.facebook.buck.event.SimplePerfEvent)2 MavenPublishable (com.facebook.buck.jvm.java.MavenPublishable)2 Flavored (com.facebook.buck.model.Flavored)2 BuildRuleType (com.facebook.buck.rules.BuildRuleType)2 Cell (com.facebook.buck.rules.Cell)2 ExplicitBuildTargetSourcePath (com.facebook.buck.rules.ExplicitBuildTargetSourcePath)2 ParamInfoException (com.facebook.buck.rules.ParamInfoException)2 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)2