Search in sources :

Example 51 with BuildRule

use of com.facebook.buck.rules.BuildRule in project buck by facebook.

the class HalideLibraryDescription method createHalideStaticLibrary.

private BuildRule createHalideStaticLibrary(BuildRuleParams params, BuildRuleResolver ruleResolver, SourcePathRuleFinder ruleFinder, CxxPlatform platform, Arg args) throws NoSuchBuildTargetException {
    if (!isPlatformSupported(args, platform)) {
        return new NoopBuildRule(params);
    }
    BuildRule halideCompile = ruleResolver.requireRule(params.getBuildTarget().withFlavors(HALIDE_COMPILE_FLAVOR, platform.getFlavor()));
    BuildTarget buildTarget = halideCompile.getBuildTarget();
    return Archive.from(params.getBuildTarget(), params, ruleFinder, platform, cxxBuckConfig.getArchiveContents(), CxxDescriptionEnhancer.getStaticLibraryPath(params.getProjectFilesystem(), params.getBuildTarget(), platform.getFlavor(), CxxSourceRuleFactory.PicType.PIC, platform.getStaticLibraryExtension()), ImmutableList.of(new ExplicitBuildTargetSourcePath(buildTarget, HalideCompile.objectOutputPath(buildTarget, params.getProjectFilesystem(), args.functionName))));
}
Also used : NoopBuildRule(com.facebook.buck.rules.NoopBuildRule) BuildTarget(com.facebook.buck.model.BuildTarget) BuildRule(com.facebook.buck.rules.BuildRule) NoopBuildRule(com.facebook.buck.rules.NoopBuildRule) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath)

Example 52 with BuildRule

use of com.facebook.buck.rules.BuildRule in project buck by facebook.

the class CsharpLibrary method resolveReferences.

private ImmutableList<Either<Path, String>> resolveReferences(SourcePathResolver pathResolver, ImmutableList<Either<BuildRule, String>> refs) {
    ImmutableList.Builder<Either<Path, String>> resolved = ImmutableList.builder();
    for (Either<BuildRule, String> ref : refs) {
        if (ref.isLeft()) {
            // TODO(shs96c): Do this in the constructor? Or the Description?
            BuildRule rule = ref.getLeft();
            Preconditions.checkArgument(rule instanceof CsharpLibrary || rule instanceof PrebuiltDotnetLibrary);
            SourcePath outputPath = Preconditions.checkNotNull(rule.getSourcePathToOutput());
            resolved.add(Either.ofLeft(pathResolver.getAbsolutePath(outputPath)));
        } else {
            resolved.add(Either.ofRight(ref.getRight()));
        }
    }
    return resolved.build();
}
Also used : ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) ImmutableList(com.google.common.collect.ImmutableList) Either(com.facebook.buck.model.Either) AbstractBuildRule(com.facebook.buck.rules.AbstractBuildRule) BuildRule(com.facebook.buck.rules.BuildRule)

Example 53 with BuildRule

use of com.facebook.buck.rules.BuildRule in project buck by facebook.

the class DefaultSuggestBuildRules method isMissingBuildRule.

/**
   *  @param transitiveNotDeclaredRule A {@link BuildRule} that is contained in the transitive
   *      dependency list but is not declared as a dependency.
   *  @param failedImports A Set of remaining failed imports.  This function will mutate this set
   *      and remove any imports satisfied by {@code transitiveNotDeclaredDep}.
   *  @return whether or not adding {@code transitiveNotDeclaredDep} as a dependency to this build
   *      rule would have satisfied one of the {@code failedImports}.
   */
private boolean isMissingBuildRule(BuildRule transitiveNotDeclaredRule, Set<String> failedImports, JarResolver jarResolver) {
    if (!(transitiveNotDeclaredRule instanceof JavaLibrary)) {
        return false;
    }
    ImmutableSet<Path> classPaths = ((JavaLibrary) transitiveNotDeclaredRule).getOutputClasspaths().stream().map(c -> pathResolver.getAbsolutePath(c)).collect(MoreCollectors.toImmutableSet());
    boolean containsMissingBuildRule = false;
    // classpath.
    for (Path classPath : classPaths) {
        ImmutableSet<String> topLevelSymbols = jarResolver.resolve(classPath);
        for (String symbolName : topLevelSymbols) {
            if (failedImports.contains(symbolName)) {
                failedImports.remove(symbolName);
                containsMissingBuildRule = true;
                // If we've found all of the missing imports, bail out early.
                if (failedImports.isEmpty()) {
                    return true;
                }
            }
        }
    }
    return containsMissingBuildRule;
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Supplier(com.google.common.base.Supplier) Set(java.util.Set) BuildRuleDependencyVisitors(com.facebook.buck.rules.BuildRuleDependencyVisitors) Sets(com.google.common.collect.Sets) BuildRule(com.facebook.buck.rules.BuildRule) DirectedAcyclicGraph(com.facebook.buck.graph.DirectedAcyclicGraph) SuggestBuildRules(com.facebook.buck.jvm.core.SuggestBuildRules) ImmutableList(com.google.common.collect.ImmutableList) FluentIterable(com.google.common.collect.FluentIterable) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) Suppliers(com.google.common.base.Suppliers) TopologicalSort(com.facebook.buck.graph.TopologicalSort) Path(java.nio.file.Path) MoreCollectors(com.facebook.buck.util.MoreCollectors) Path(java.nio.file.Path)

Example 54 with BuildRule

use of com.facebook.buck.rules.BuildRule in project buck by facebook.

the class CopyResourcesStep method buildSteps.

@VisibleForTesting
ImmutableList<Step> buildSteps() {
    ImmutableList.Builder<Step> allSteps = ImmutableList.builder();
    if (resources.isEmpty()) {
        return allSteps.build();
    }
    String targetPackageDir = javaPackageFinder.findJavaPackage(target);
    for (SourcePath rawResource : resources) {
        // If the path to the file defining this rule were:
        // "first-party/orca/lib-http/tests/com/facebook/orca/BUCK"
        //
        // And the value of resource were:
        // "first-party/orca/lib-http/tests/com/facebook/orca/protocol/base/batch_exception1.txt"
        //
        // Assuming that `src_roots = tests` were in the [java] section of the .buckconfig file,
        // then javaPackageAsPath would be:
        // "com/facebook/orca/protocol/base/"
        //
        // And the path that we would want to copy to the classes directory would be:
        // "com/facebook/orca/protocol/base/batch_exception1.txt"
        //
        // Therefore, some path-wrangling is required to produce the correct string.
        Optional<BuildRule> underlyingRule = ruleFinder.getRule(rawResource);
        Path relativePathToResource = resolver.getRelativePath(rawResource);
        String resource;
        if (underlyingRule.isPresent()) {
            BuildTarget underlyingTarget = underlyingRule.get().getBuildTarget();
            if (underlyingRule.get() instanceof HasOutputName) {
                resource = MorePaths.pathWithUnixSeparators(underlyingTarget.getBasePath().resolve(((HasOutputName) underlyingRule.get()).getOutputName()));
            } else {
                Path genOutputParent = BuildTargets.getGenPath(filesystem, underlyingTarget, "%s").getParent();
                Path scratchOutputParent = BuildTargets.getScratchPath(filesystem, underlyingTarget, "%s").getParent();
                Optional<Path> outputPath = MorePaths.stripPrefix(relativePathToResource, genOutputParent).map(Optional::of).orElse(MorePaths.stripPrefix(relativePathToResource, scratchOutputParent));
                Preconditions.checkState(outputPath.isPresent(), "%s is used as a resource but does not output to a default output directory", underlyingTarget.getFullyQualifiedName());
                resource = MorePaths.pathWithUnixSeparators(underlyingTarget.getBasePath().resolve(outputPath.get()));
            }
        } else {
            resource = MorePaths.pathWithUnixSeparators(relativePathToResource);
        }
        Path javaPackageAsPath = javaPackageFinder.findJavaPackageFolder(outputDirectory.getFileSystem().getPath(resource));
        Path relativeSymlinkPath;
        if ("".equals(javaPackageAsPath.toString())) {
            // In this case, the project root is acting as the default package, so the resource path
            // works fine.
            relativeSymlinkPath = relativePathToResource.getFileName();
        } else {
            int lastIndex = resource.lastIndexOf(MorePaths.pathWithUnixSeparatorsAndTrailingSlash(javaPackageAsPath));
            if (lastIndex < 0) {
                Preconditions.checkState(rawResource instanceof BuildTargetSourcePath, "If resource path %s does not contain %s, then it must be a BuildTargetSourcePath.", relativePathToResource, javaPackageAsPath);
                // Handle the case where we depend on the output of another BuildRule. In that case, just
                // grab the output and put in the same package as this target would be in.
                relativeSymlinkPath = outputDirectory.getFileSystem().getPath(String.format("%s%s%s", targetPackageDir, targetPackageDir.isEmpty() ? "" : "/", resolver.getRelativePath(rawResource).getFileName()));
            } else {
                relativeSymlinkPath = outputDirectory.getFileSystem().getPath(resource.substring(lastIndex));
            }
        }
        Path target = outputDirectory.resolve(relativeSymlinkPath);
        MkdirAndSymlinkFileStep link = new MkdirAndSymlinkFileStep(filesystem, resolver.getAbsolutePath(rawResource), target);
        allSteps.add(link);
    }
    return allSteps.build();
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) BuildTargetSourcePath(com.facebook.buck.rules.BuildTargetSourcePath) Path(java.nio.file.Path) HasOutputName(com.facebook.buck.model.HasOutputName) ImmutableList(com.google.common.collect.ImmutableList) Step(com.facebook.buck.step.Step) MkdirAndSymlinkFileStep(com.facebook.buck.step.fs.MkdirAndSymlinkFileStep) BuildTargetSourcePath(com.facebook.buck.rules.BuildTargetSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) BuildTargetSourcePath(com.facebook.buck.rules.BuildTargetSourcePath) BuildTarget(com.facebook.buck.model.BuildTarget) BuildRule(com.facebook.buck.rules.BuildRule) MkdirAndSymlinkFileStep(com.facebook.buck.step.fs.MkdirAndSymlinkFileStep) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 55 with BuildRule

use of com.facebook.buck.rules.BuildRule in project buck by facebook.

the class AbstractJavacOptions method getInputs.

public ImmutableSortedSet<SourcePath> getInputs(SourcePathRuleFinder ruleFinder) {
    ImmutableSortedSet.Builder<SourcePath> builder = ImmutableSortedSet.<SourcePath>naturalOrder().addAll(getAnnotationProcessingParams().getInputs());
    Optional<SourcePath> javacJarPath = getJavacJarPath();
    if (javacJarPath.isPresent()) {
        SourcePath sourcePath = javacJarPath.get();
        // Add the original rule regardless of what happens next.
        builder.add(sourcePath);
        Optional<BuildRule> possibleRule = ruleFinder.getRule(sourcePath);
        if (possibleRule.isPresent()) {
            BuildRule rule = possibleRule.get();
            // And now include any transitive deps that contribute to the classpath.
            if (rule instanceof JavaLibrary) {
                builder.addAll(((JavaLibrary) rule).getDepsForTransitiveClasspathEntries().stream().map(BuildRule::getSourcePathToOutput).collect(MoreCollectors.toImmutableList()));
            } else {
                builder.add(sourcePath);
            }
        }
    }
    return builder.build();
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) BuildRule(com.facebook.buck.rules.BuildRule)

Aggregations

BuildRule (com.facebook.buck.rules.BuildRule)361 BuildTarget (com.facebook.buck.model.BuildTarget)199 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)190 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)189 Test (org.junit.Test)175 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)165 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)162 SourcePath (com.facebook.buck.rules.SourcePath)118 Path (java.nio.file.Path)95 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)70 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)70 FakeBuildRule (com.facebook.buck.rules.FakeBuildRule)66 TargetGraph (com.facebook.buck.rules.TargetGraph)63 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)61 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)61 ImmutableList (com.google.common.collect.ImmutableList)58 PathSourcePath (com.facebook.buck.rules.PathSourcePath)51 ImmutableSet (com.google.common.collect.ImmutableSet)45 ImmutableMap (com.google.common.collect.ImmutableMap)44 RuleKey (com.facebook.buck.rules.RuleKey)43