Search in sources :

Example 1 with TargetNodeSpec

use of com.facebook.buck.parser.TargetNodeSpec 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 2 with TargetNodeSpec

use of com.facebook.buck.parser.TargetNodeSpec in project buck by facebook.

the class InstallCommand method getInstallHelperTargets.

private ImmutableSet<String> getInstallHelperTargets(CommandRunnerParams params, ListeningExecutorService executor) throws IOException, InterruptedException, BuildTargetException, BuildFileParseException {
    ParserConfig parserConfig = params.getBuckConfig().getView(ParserConfig.class);
    ImmutableSet.Builder<String> installHelperTargets = ImmutableSet.builder();
    for (int index = 0; index < getArguments().size(); index++) {
        // TODO(ryu2): Cache argument parsing
        TargetNodeSpec spec = parseArgumentsAsTargetNodeSpecs(params.getBuckConfig(), getArguments()).get(index);
        BuildTarget target = FluentIterable.from(params.getParser().resolveTargetSpecs(params.getBuckEventBus(), params.getCell(), getEnableParserProfiling(), executor, ImmutableList.of(spec), SpeculativeParsing.of(false), parserConfig.getDefaultFlavorsMode())).transformAndConcat(Functions.identity()).first().get();
        TargetNode<?, ?> node = params.getParser().getTargetNode(params.getBuckEventBus(), params.getCell(), getEnableParserProfiling(), executor, target);
        if (node != null && Description.getBuildRuleType(node.getDescription()).equals(Description.getBuildRuleType(AppleBundleDescription.class))) {
            for (Flavor flavor : node.getBuildTarget().getFlavors()) {
                if (ApplePlatform.needsInstallHelper(flavor.getName())) {
                    AppleConfig appleConfig = new AppleConfig(params.getBuckConfig());
                    Optional<BuildTarget> deviceHelperTarget = appleConfig.getAppleDeviceHelperTarget();
                    Optionals.addIfPresent(Optionals.bind(deviceHelperTarget, input -> !input.toString().isEmpty() ? Optional.of(input.toString()) : Optional.empty()), installHelperTargets);
                }
            }
        }
    }
    return installHelperTargets.build();
}
Also used : AppleConfig(com.facebook.buck.apple.AppleConfig) AppleSimulatorDiscovery(com.facebook.buck.apple.simulator.AppleSimulatorDiscovery) TargetNodeSpec(com.facebook.buck.parser.TargetNodeSpec) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) AdbOptions(com.facebook.buck.step.AdbOptions) AdbHelper(com.facebook.buck.android.AdbHelper) InstallEvent(com.facebook.buck.event.InstallEvent) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) AppleConfig(com.facebook.buck.apple.AppleConfig) ProcessExecutor(com.facebook.buck.util.ProcessExecutor) FluentIterable(com.google.common.collect.FluentIterable) ApplePlatform(com.facebook.buck.apple.ApplePlatform) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) Locale(java.util.Locale) AppleCoreSimulatorServiceController(com.facebook.buck.apple.simulator.AppleCoreSimulatorServiceController) Path(java.nio.file.Path) Optionals(com.facebook.buck.util.Optionals) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) AppleSimulator(com.facebook.buck.apple.simulator.AppleSimulator) BuildTargetException(com.facebook.buck.model.BuildTargetException) Option(org.kohsuke.args4j.Option) AppleInfoPlistParsing(com.facebook.buck.apple.AppleInfoPlistParsing) BuildTarget(com.facebook.buck.model.BuildTarget) SuppressFieldNotInitialized(com.facebook.infer.annotation.SuppressFieldNotInitialized) List(java.util.List) AppleBundleDescription(com.facebook.buck.apple.AppleBundleDescription) AppleSimulatorController(com.facebook.buck.apple.simulator.AppleSimulatorController) UninstallOptions(com.facebook.buck.cli.UninstallCommand.UninstallOptions) Optional(java.util.Optional) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Description(com.facebook.buck.rules.Description) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) Assertions(com.facebook.infer.annotation.Assertions) Build(com.facebook.buck.command.Build) MoreExceptions(com.facebook.buck.util.MoreExceptions) SourcePath(com.facebook.buck.rules.SourcePath) ConsoleEvent(com.facebook.buck.event.ConsoleEvent) BuildRule(com.facebook.buck.rules.BuildRule) ExecutionContext(com.facebook.buck.step.ExecutionContext) Lists(com.google.common.collect.Lists) AppleDeviceHelper(com.facebook.buck.apple.device.AppleDeviceHelper) ParserConfig(com.facebook.buck.parser.ParserConfig) ImmutableList(com.google.common.collect.ImmutableList) NoSuchBuildTargetException(com.facebook.buck.parser.NoSuchBuildTargetException) BuildFileParseException(com.facebook.buck.json.BuildFileParseException) Nullable(javax.annotation.Nullable) Logger(com.facebook.buck.log.Logger) Functions(com.google.common.base.Functions) UnixUserIdFetcher(com.facebook.buck.util.UnixUserIdFetcher) TargetNode(com.facebook.buck.rules.TargetNode) TargetDeviceOptions(com.facebook.buck.step.TargetDeviceOptions) IOException(java.io.IOException) HumanReadableException(com.facebook.buck.util.HumanReadableException) AppleBundle(com.facebook.buck.apple.AppleBundle) HasInstallableApk(com.facebook.buck.android.HasInstallableApk) SpeculativeParsing(com.facebook.buck.parser.SpeculativeParsing) Preconditions(com.google.common.base.Preconditions) Flavor(com.facebook.buck.model.Flavor) VisibleForTesting(com.google.common.annotations.VisibleForTesting) InputStream(java.io.InputStream) ImmutableSet(com.google.common.collect.ImmutableSet) BuildTarget(com.facebook.buck.model.BuildTarget) Flavor(com.facebook.buck.model.Flavor) ParserConfig(com.facebook.buck.parser.ParserConfig) TargetNodeSpec(com.facebook.buck.parser.TargetNodeSpec)

Example 3 with TargetNodeSpec

use of com.facebook.buck.parser.TargetNodeSpec in project buck by facebook.

the class PublishCommand method parseArgumentsAsTargetNodeSpecs.

@Override
public ImmutableList<TargetNodeSpec> parseArgumentsAsTargetNodeSpecs(BuckConfig config, Iterable<String> targetsAsArgs) {
    ImmutableList<TargetNodeSpec> specs = super.parseArgumentsAsTargetNodeSpecs(config, targetsAsArgs);
    if (includeSource) {
        specs = ImmutableList.<TargetNodeSpec>builder().addAll(specs).addAll(specs.stream().filter(input -> {
            if (!(input instanceof BuildTargetSpec)) {
                throw new IllegalArgumentException("Targets must be explicitly defined when using " + INCLUDE_SOURCE_LONG_ARG);
            }
            return !((BuildTargetSpec) input).getBuildTarget().getFlavors().contains(JavaLibrary.SRC_JAR);
        }).map(input -> BuildTargetSpec.of(((BuildTargetSpec) input).getBuildTarget().withFlavors(JavaLibrary.SRC_JAR), input.getBuildFileSpec())).iterator()).build();
    }
    // Append "maven" flavor
    specs = specs.stream().map(input -> {
        if (!(input instanceof BuildTargetSpec)) {
            throw new IllegalArgumentException("Need to specify build targets explicitly when publishing. " + "Cannot modify " + input);
        }
        BuildTargetSpec buildTargetSpec = (BuildTargetSpec) input;
        BuildTarget buildTarget = Preconditions.checkNotNull(buildTargetSpec.getBuildTarget());
        return buildTargetSpec.withBuildTarget(BuildTarget.builder(buildTarget).addFlavors(JavaLibrary.MAVEN_JAR).build());
    }).collect(MoreCollectors.toImmutableList());
    return specs;
}
Also used : DeployResult(org.eclipse.aether.deployment.DeployResult) URL(java.net.URL) TargetNodeSpec(com.facebook.buck.parser.TargetNodeSpec) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) JavaLibrary(com.facebook.buck.jvm.java.JavaLibrary) ConsoleEvent(com.facebook.buck.event.ConsoleEvent) BuildRule(com.facebook.buck.rules.BuildRule) ImmutableList(com.google.common.collect.ImmutableList) FluentIterable(com.google.common.collect.FluentIterable) NoSuchBuildTargetException(com.facebook.buck.parser.NoSuchBuildTargetException) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildTargetSpec(com.facebook.buck.parser.BuildTargetSpec) Nullable(javax.annotation.Nullable) MoreCollectors(com.facebook.buck.util.MoreCollectors) ImmutableSet(com.google.common.collect.ImmutableSet) MavenPublishable(com.facebook.buck.jvm.java.MavenPublishable) Artifact(org.eclipse.aether.artifact.Artifact) IOException(java.io.IOException) Option(org.kohsuke.args4j.Option) BuildTarget(com.facebook.buck.model.BuildTarget) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) Publisher(com.facebook.buck.maven.Publisher) DeploymentException(org.eclipse.aether.deployment.DeploymentException) Joiner(com.google.common.base.Joiner) BuildTarget(com.facebook.buck.model.BuildTarget) BuildTargetSpec(com.facebook.buck.parser.BuildTargetSpec) TargetNodeSpec(com.facebook.buck.parser.TargetNodeSpec)

Example 4 with TargetNodeSpec

use of com.facebook.buck.parser.TargetNodeSpec in project buck by facebook.

the class TargetPatternEvaluator method resolveBuildTargetPatterns.

ImmutableMap<String, ImmutableSet<QueryTarget>> resolveBuildTargetPatterns(List<String> patterns, ListeningExecutorService executor) throws InterruptedException, BuildFileParseException, BuildTargetException, IOException {
    // Build up an ordered list of patterns and pass them to the parse to get resolved in one go.
    // The returned list of nodes maintains the spec list ordering.
    List<TargetNodeSpec> specs = new ArrayList<>();
    for (String pattern : patterns) {
        specs.addAll(targetNodeSpecParser.parse(rootCell.getCellPathResolver(), pattern));
    }
    ImmutableList<ImmutableSet<BuildTarget>> buildTargets = parser.resolveTargetSpecs(eventBus, rootCell, enableProfiling, executor, specs, SpeculativeParsing.of(false), // because the query engine doesn't handle flavors very well.
    ParserConfig.ApplyDefaultFlavorsMode.DISABLED);
    LOG.verbose("Resolved target patterns %s -> targets %s", patterns, buildTargets);
    // Convert the ordered result into a result map of pattern to set of resolved targets.
    ImmutableMap.Builder<String, ImmutableSet<QueryTarget>> queryTargets = ImmutableMap.builder();
    for (int index = 0; index < buildTargets.size(); index++) {
        ImmutableSet<BuildTarget> targets = buildTargets.get(index);
        // Sorting to have predictable results across different java libraries implementations.
        ImmutableSet.Builder<QueryTarget> builder = ImmutableSortedSet.naturalOrder();
        for (BuildTarget target : targets) {
            builder.add(QueryBuildTarget.of(target));
        }
        queryTargets.put(patterns.get(index), builder.build());
    }
    return queryTargets.build();
}
Also used : ArrayList(java.util.ArrayList) ImmutableMap(com.google.common.collect.ImmutableMap) QueryTarget(com.facebook.buck.query.QueryTarget) ImmutableSet(com.google.common.collect.ImmutableSet) QueryBuildTarget(com.facebook.buck.query.QueryBuildTarget) BuildTarget(com.facebook.buck.model.BuildTarget) TargetNodeSpec(com.facebook.buck.parser.TargetNodeSpec)

Example 5 with TargetNodeSpec

use of com.facebook.buck.parser.TargetNodeSpec in project buck by facebook.

the class AbstractCommand method parseArgumentsAsTargetNodeSpecs.

public ImmutableList<TargetNodeSpec> parseArgumentsAsTargetNodeSpecs(BuckConfig config, Iterable<String> targetsAsArgs) {
    ImmutableList.Builder<TargetNodeSpec> specs = ImmutableList.builder();
    CommandLineTargetNodeSpecParser parser = new CommandLineTargetNodeSpecParser(config, new BuildTargetPatternTargetNodeParser());
    for (String arg : targetsAsArgs) {
        specs.addAll(parser.parse(config.getCellPathResolver(), arg));
    }
    return specs.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) BuildTargetPatternTargetNodeParser(com.facebook.buck.parser.BuildTargetPatternTargetNodeParser) TargetNodeSpec(com.facebook.buck.parser.TargetNodeSpec)

Aggregations

TargetNodeSpec (com.facebook.buck.parser.TargetNodeSpec)5 BuildTarget (com.facebook.buck.model.BuildTarget)4 ImmutableSet (com.google.common.collect.ImmutableSet)4 ImmutableList (com.google.common.collect.ImmutableList)3 ConsoleEvent (com.facebook.buck.event.ConsoleEvent)2 BuildFileParseException (com.facebook.buck.json.BuildFileParseException)2 BuildTargetException (com.facebook.buck.model.BuildTargetException)2 NoSuchBuildTargetException (com.facebook.buck.parser.NoSuchBuildTargetException)2 BuildRule (com.facebook.buck.rules.BuildRule)2 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)2 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)2 Preconditions (com.google.common.base.Preconditions)2 FluentIterable (com.google.common.collect.FluentIterable)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 IOException (java.io.IOException)2 Optional (java.util.Optional)2 Nullable (javax.annotation.Nullable)2 Option (org.kohsuke.args4j.Option)2 AdbHelper (com.facebook.buck.android.AdbHelper)1 HasInstallableApk (com.facebook.buck.android.HasInstallableApk)1