Search in sources :

Example 21 with BuildTarget

use of com.facebook.buck.model.BuildTarget in project buck by facebook.

the class ResolveAliasHelper method validateBuildTargetForFullyQualifiedTarget.

/**
   * Verify that the given target is a valid full-qualified (non-alias) target.
   */
@Nullable
static String validateBuildTargetForFullyQualifiedTarget(CommandRunnerParams params, ListeningExecutorService executor, boolean enableProfiling, String target, Parser parser) {
    BuildTarget buildTarget = getBuildTargetForFullyQualifiedTarget(params.getBuckConfig(), target);
    Cell owningCell = params.getCell().getCell(buildTarget);
    Path buildFile;
    try {
        buildFile = owningCell.getAbsolutePathToBuildFile(buildTarget);
    } catch (Cell.MissingBuildFileException e) {
        throw new HumanReadableException(e);
    }
    // Get all valid targets in our target directory by reading the build file.
    ImmutableSet<TargetNode<?, ?>> targetNodes;
    try {
        targetNodes = parser.getAllTargetNodes(params.getBuckEventBus(), owningCell, enableProfiling, executor, buildFile);
    } catch (BuildFileParseException e) {
        throw new HumanReadableException(e);
    }
    // Check that the given target is a valid target.
    for (TargetNode<?, ?> candidate : targetNodes) {
        if (candidate.getBuildTarget().equals(buildTarget)) {
            return buildTarget.getFullyQualifiedName();
        }
    }
    return null;
}
Also used : Path(java.nio.file.Path) TargetNode(com.facebook.buck.rules.TargetNode) BuildTarget(com.facebook.buck.model.BuildTarget) HumanReadableException(com.facebook.buck.util.HumanReadableException) Cell(com.facebook.buck.rules.Cell) BuildFileParseException(com.facebook.buck.json.BuildFileParseException) Nullable(javax.annotation.Nullable)

Example 22 with BuildTarget

use of com.facebook.buck.model.BuildTarget in project buck by facebook.

the class TestRunning method getRulesUnderTest.

/**
   * Generates the set of Java library rules under test.
   */
private static ImmutableSet<JavaLibrary> getRulesUnderTest(Iterable<TestRule> tests) {
    ImmutableSet.Builder<JavaLibrary> rulesUnderTest = ImmutableSet.builder();
    // Gathering all rules whose source will be under test.
    for (TestRule test : tests) {
        if (test instanceof JavaTest) {
            // Look at the transitive dependencies for `tests` attribute that refers to this test.
            JavaTest javaTest = (JavaTest) test;
            ImmutableSet<JavaLibrary> transitiveDeps = javaTest.getCompiledTestsLibrary().getTransitiveClasspathDeps();
            for (JavaLibrary dep : transitiveDeps) {
                if (dep instanceof JavaLibraryWithTests) {
                    ImmutableSortedSet<BuildTarget> depTests = ((JavaLibraryWithTests) dep).getTests();
                    if (depTests.contains(test.getBuildTarget())) {
                        rulesUnderTest.add(dep);
                    }
                }
            }
        }
    }
    return rulesUnderTest.build();
}
Also used : TestRule(com.facebook.buck.rules.TestRule) JavaLibraryWithTests(com.facebook.buck.jvm.java.JavaLibraryWithTests) ImmutableSet(com.google.common.collect.ImmutableSet) JavaLibrary(com.facebook.buck.jvm.java.JavaLibrary) DefaultJavaLibrary(com.facebook.buck.jvm.java.DefaultJavaLibrary) BuildTarget(com.facebook.buck.model.BuildTarget) JavaTest(com.facebook.buck.jvm.java.JavaTest)

Example 23 with BuildTarget

use of com.facebook.buck.model.BuildTarget in project buck by facebook.

the class CxxDescriptionEnhancer method parseOnlyPlatformHeaders.

static ImmutableMap<String, SourcePath> parseOnlyPlatformHeaders(BuildTarget buildTarget, BuildRuleResolver resolver, SourcePathRuleFinder ruleFinder, SourcePathResolver sourcePathResolver, CxxPlatform cxxPlatform, String headersParameterName, SourceList headers, String platformHeadersParameterName, PatternMatchedCollection<SourceList> platformHeaders) throws NoSuchBuildTargetException {
    ImmutableMap.Builder<String, SourcePath> parsed = ImmutableMap.builder();
    java.util.function.Function<SourcePath, SourcePath> fixup = path -> {
        try {
            return CxxGenruleDescription.fixupSourcePath(resolver, ruleFinder, cxxPlatform, path);
        } catch (NoSuchBuildTargetException e) {
            throw new RuntimeException(e);
        }
    };
    // Include all normal exported headers that are generated by `cxx_genrule`.
    parsed.putAll(headers.toNameMap(buildTarget, sourcePathResolver, headersParameterName, path -> CxxGenruleDescription.wrapsCxxGenrule(ruleFinder, path), fixup));
    // Include all platform specific headers.
    for (SourceList sourceList : platformHeaders.getMatchingValues(cxxPlatform.getFlavor().toString())) {
        parsed.putAll(sourceList.toNameMap(buildTarget, sourcePathResolver, platformHeadersParameterName, path -> true, fixup));
    }
    return parsed.build();
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) PatternMatchedCollection(com.facebook.buck.rules.coercer.PatternMatchedCollection) ImmutableCollection(com.google.common.collect.ImmutableCollection) RichStream(com.facebook.buck.util.RichStream) InternalFlavor(com.facebook.buck.model.InternalFlavor) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) SymlinkTree(com.facebook.buck.rules.SymlinkTree) FlavorDomain(com.facebook.buck.model.FlavorDomain) Matcher(java.util.regex.Matcher) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) StringArg(com.facebook.buck.rules.args.StringArg) Map(java.util.Map) SourceList(com.facebook.buck.rules.coercer.SourceList) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) RuleKeyObjectSink(com.facebook.buck.rules.RuleKeyObjectSink) Path(java.nio.file.Path) JsonConcatenate(com.facebook.buck.json.JsonConcatenate) Function(com.google.common.base.Function) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) TargetGraph(com.facebook.buck.rules.TargetGraph) BuildTarget(com.facebook.buck.model.BuildTarget) RuleKeyAppendableFunction(com.facebook.buck.rules.args.RuleKeyAppendableFunction) SourceWithFlags(com.facebook.buck.rules.SourceWithFlags) Predicate(com.google.common.base.Predicate) Optional(java.util.Optional) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Pattern(java.util.regex.Pattern) Joiner(com.google.common.base.Joiner) CellPathResolver(com.facebook.buck.rules.CellPathResolver) SourcePathArg(com.facebook.buck.rules.args.SourcePathArg) FrameworkPath(com.facebook.buck.rules.coercer.FrameworkPath) SourcePath(com.facebook.buck.rules.SourcePath) HashMap(java.util.HashMap) BuildRule(com.facebook.buck.rules.BuildRule) ImmutableList(com.google.common.collect.ImmutableList) Files(com.google.common.io.Files) NoSuchBuildTargetException(com.facebook.buck.parser.NoSuchBuildTargetException) Suppliers(com.google.common.base.Suppliers) StreamSupport(java.util.stream.StreamSupport) StringWithMacros(com.facebook.buck.rules.macros.StringWithMacros) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) MoreCollectors(com.facebook.buck.util.MoreCollectors) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) Logger(com.facebook.buck.log.Logger) Functions(com.google.common.base.Functions) FileListableLinkerInputArg(com.facebook.buck.rules.args.FileListableLinkerInputArg) HumanReadableException(com.facebook.buck.util.HumanReadableException) QueryUtils(com.facebook.buck.rules.query.QueryUtils) Arg(com.facebook.buck.rules.args.Arg) Paths(java.nio.file.Paths) CommandTool(com.facebook.buck.rules.CommandTool) StringWithMacrosArg(com.facebook.buck.rules.args.StringWithMacrosArg) LocationMacroExpander(com.facebook.buck.rules.macros.LocationMacroExpander) Preconditions(com.google.common.base.Preconditions) Flavor(com.facebook.buck.model.Flavor) MacroHandler(com.facebook.buck.rules.macros.MacroHandler) VisibleForTesting(com.google.common.annotations.VisibleForTesting) BuildTargets(com.facebook.buck.model.BuildTargets) SourceList(com.facebook.buck.rules.coercer.SourceList) NoSuchBuildTargetException(com.facebook.buck.parser.NoSuchBuildTargetException) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 24 with BuildTarget

use of com.facebook.buck.model.BuildTarget in project buck by facebook.

the class CxxDescriptionEnhancer method requireSharedLibrarySymlinkTree.

public static SymlinkTree requireSharedLibrarySymlinkTree(BuildTarget buildTarget, ProjectFilesystem filesystem, BuildRuleResolver resolver, SourcePathRuleFinder ruleFinder, CxxPlatform cxxPlatform, Iterable<? extends BuildRule> deps, Predicate<Object> traverse) throws NoSuchBuildTargetException {
    BuildTarget target = createSharedLibrarySymlinkTreeTarget(buildTarget, cxxPlatform.getFlavor());
    SymlinkTree tree = resolver.getRuleOptionalWithType(target, SymlinkTree.class).orElse(null);
    if (tree == null) {
        tree = resolver.addToIndex(createSharedLibrarySymlinkTree(ruleFinder, buildTarget, filesystem, cxxPlatform, deps, traverse));
    }
    return tree;
}
Also used : SymlinkTree(com.facebook.buck.rules.SymlinkTree) BuildTarget(com.facebook.buck.model.BuildTarget)

Example 25 with BuildTarget

use of com.facebook.buck.model.BuildTarget in project buck by facebook.

the class CxxDescriptionEnhancer method createCompilationDatabaseDependencies.

public static Optional<CxxCompilationDatabaseDependencies> createCompilationDatabaseDependencies(BuildTarget buildTarget, FlavorDomain<CxxPlatform> platforms, BuildRuleResolver resolver, CxxConstructorArg args) throws NoSuchBuildTargetException {
    Preconditions.checkState(buildTarget.getFlavors().contains(CxxCompilationDatabase.COMPILATION_DATABASE));
    Optional<Flavor> cxxPlatformFlavor = platforms.getFlavor(buildTarget);
    Preconditions.checkState(cxxPlatformFlavor.isPresent(), "Could not find cxx platform in:\n%s", Joiner.on(", ").join(buildTarget.getFlavors()));
    ImmutableSet.Builder<SourcePath> sourcePaths = ImmutableSet.builder();
    for (BuildTarget dep : args.deps) {
        Optional<CxxCompilationDatabaseDependencies> compilationDatabases = resolver.requireMetadata(BuildTarget.builder(dep).addFlavors(CxxCompilationDatabase.COMPILATION_DATABASE).addFlavors(cxxPlatformFlavor.get()).build(), CxxCompilationDatabaseDependencies.class);
        if (compilationDatabases.isPresent()) {
            sourcePaths.addAll(compilationDatabases.get().getSourcePaths());
        }
    }
    // Not all parts of Buck use require yet, so require the rule here so it's available in the
    // resolver for the parts that don't.
    BuildRule buildRule = resolver.requireRule(buildTarget);
    sourcePaths.add(buildRule.getSourcePathToOutput());
    return Optional.of(CxxCompilationDatabaseDependencies.of(sourcePaths.build()));
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) ImmutableSet(com.google.common.collect.ImmutableSet) BuildTarget(com.facebook.buck.model.BuildTarget) BuildRule(com.facebook.buck.rules.BuildRule) InternalFlavor(com.facebook.buck.model.InternalFlavor) Flavor(com.facebook.buck.model.Flavor)

Aggregations

BuildTarget (com.facebook.buck.model.BuildTarget)1045 Test (org.junit.Test)758 Path (java.nio.file.Path)323 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)289 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)254 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)248 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)226 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)216 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)209 BuildRule (com.facebook.buck.rules.BuildRule)196 ProjectWorkspace (com.facebook.buck.testutil.integration.ProjectWorkspace)178 SourcePath (com.facebook.buck.rules.SourcePath)163 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)161 TargetGraph (com.facebook.buck.rules.TargetGraph)156 PathSourcePath (com.facebook.buck.rules.PathSourcePath)116 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)108 DefaultBuildTargetSourcePath (com.facebook.buck.rules.DefaultBuildTargetSourcePath)91 ImmutableSet (com.google.common.collect.ImmutableSet)90 ImmutableMap (com.google.common.collect.ImmutableMap)78 FakeBuildRuleParamsBuilder (com.facebook.buck.rules.FakeBuildRuleParamsBuilder)75