Search in sources :

Example 21 with BuildRule

use of com.facebook.buck.rules.BuildRule 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)

Example 22 with BuildRule

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

the class CxxDescriptionEnhancer method requireSandboxSymlinkTree.

private static SymlinkTree requireSandboxSymlinkTree(BuildRuleParams params, BuildRuleResolver ruleResolver, CxxPlatform cxxPlatform) throws NoSuchBuildTargetException {
    BuildRuleParams untypedParams = CxxLibraryDescription.getUntypedParams(params);
    BuildTarget headerSymlinkTreeTarget = CxxDescriptionEnhancer.createSandboxSymlinkTreeTarget(untypedParams.getBuildTarget(), cxxPlatform.getFlavor());
    BuildRule rule = ruleResolver.requireRule(headerSymlinkTreeTarget);
    Preconditions.checkState(rule instanceof SymlinkTree, rule.getBuildTarget() + " " + rule.getClass().toString());
    return (SymlinkTree) rule;
}
Also used : SymlinkTree(com.facebook.buck.rules.SymlinkTree) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) BuildTarget(com.facebook.buck.model.BuildTarget) BuildRule(com.facebook.buck.rules.BuildRule)

Example 23 with BuildRule

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

the class CxxDescriptionEnhancer method createCxxStripRule.

public static CxxStrip createCxxStripRule(BuildRuleParams params, BuildRuleResolver resolver, StripStyle stripStyle, BuildRule unstrippedBinaryRule, CxxPlatform cxxPlatform) {
    BuildRuleParams stripRuleParams = params.withBuildTarget(params.getBuildTarget().withAppendedFlavors(CxxStrip.RULE_FLAVOR, stripStyle.getFlavor())).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of(unstrippedBinaryRule)), Suppliers.ofInstance(ImmutableSortedSet.of()));
    Optional<BuildRule> exisitingRule = resolver.getRuleOptional(stripRuleParams.getBuildTarget());
    if (exisitingRule.isPresent()) {
        Preconditions.checkArgument(exisitingRule.get() instanceof CxxStrip);
        return (CxxStrip) exisitingRule.get();
    } else {
        CxxStrip cxxStrip = new CxxStrip(stripRuleParams, stripStyle, Preconditions.checkNotNull(unstrippedBinaryRule.getSourcePathToOutput()), cxxPlatform.getStrip(), CxxDescriptionEnhancer.getBinaryOutputPath(stripRuleParams.getBuildTarget(), params.getProjectFilesystem(), cxxPlatform.getBinaryExtension()));
        resolver.addToIndex(cxxStrip);
        return cxxStrip;
    }
}
Also used : BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) BuildRule(com.facebook.buck.rules.BuildRule)

Example 24 with BuildRule

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

the class AbstractCxxPreprocessorInput method getDeps.

public Iterable<BuildRule> getDeps(BuildRuleResolver ruleResolver, SourcePathRuleFinder ruleFinder) {
    ImmutableList.Builder<BuildRule> builder = ImmutableList.builder();
    for (CxxHeaders cxxHeaders : getIncludes()) {
        builder.addAll(cxxHeaders.getDeps(ruleFinder));
    }
    builder.addAll(ruleResolver.getAllRules(getRules()));
    for (FrameworkPath frameworkPath : getFrameworks()) {
        if (frameworkPath.getSourcePath().isPresent()) {
            Optional<BuildRule> frameworkRule = ruleFinder.getRule(frameworkPath.getSourcePath().get());
            if (frameworkRule.isPresent()) {
                builder.add(frameworkRule.get());
            }
        }
    }
    return builder.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) BuildRule(com.facebook.buck.rules.BuildRule) FrameworkPath(com.facebook.buck.rules.coercer.FrameworkPath)

Example 25 with BuildRule

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

the class HaskellDescriptionUtils method createCompileRule.

/**
   * Create a Haskell compile rule that compiles all the given haskell sources in one step and
   * pulls interface files from all transitive haskell dependencies.
   */
private static HaskellCompileRule createCompileRule(BuildTarget target, final BuildRuleParams baseParams, final BuildRuleResolver resolver, SourcePathRuleFinder ruleFinder, ImmutableSet<BuildRule> deps, final CxxPlatform cxxPlatform, HaskellConfig haskellConfig, final Linker.LinkableDepType depType, Optional<String> main, Optional<HaskellPackageInfo> packageInfo, ImmutableList<String> flags, HaskellSources sources) throws NoSuchBuildTargetException {
    final Map<BuildTarget, ImmutableList<String>> depFlags = new TreeMap<>();
    final Map<BuildTarget, ImmutableList<SourcePath>> depIncludes = new TreeMap<>();
    final ImmutableSortedMap.Builder<String, HaskellPackage> exposedPackagesBuilder = ImmutableSortedMap.naturalOrder();
    final ImmutableSortedMap.Builder<String, HaskellPackage> packagesBuilder = ImmutableSortedMap.naturalOrder();
    new AbstractBreadthFirstThrowingTraversal<BuildRule, NoSuchBuildTargetException>(deps) {

        private final ImmutableSet<BuildRule> empty = ImmutableSet.of();

        @Override
        public Iterable<BuildRule> visit(BuildRule rule) throws NoSuchBuildTargetException {
            ImmutableSet<BuildRule> ruleDeps = empty;
            if (rule instanceof HaskellCompileDep) {
                ruleDeps = rule.getDeps();
                HaskellCompileInput compileInput = ((HaskellCompileDep) rule).getCompileInput(cxxPlatform, depType);
                depFlags.put(rule.getBuildTarget(), compileInput.getFlags());
                depIncludes.put(rule.getBuildTarget(), compileInput.getIncludes());
                // We add packages from first-order deps as expose modules, and transitively included
                // packages as hidden ones.
                boolean firstOrderDep = deps.contains(rule);
                for (HaskellPackage pkg : compileInput.getPackages()) {
                    if (firstOrderDep) {
                        exposedPackagesBuilder.put(pkg.getInfo().getIdentifier(), pkg);
                    } else {
                        packagesBuilder.put(pkg.getInfo().getIdentifier(), pkg);
                    }
                }
            }
            return ruleDeps;
        }
    }.start();
    Collection<CxxPreprocessorInput> cxxPreprocessorInputs = CxxPreprocessables.getTransitiveCxxPreprocessorInput(cxxPlatform, deps);
    ExplicitCxxToolFlags.Builder toolFlagsBuilder = CxxToolFlags.explicitBuilder();
    PreprocessorFlags.Builder ppFlagsBuilder = PreprocessorFlags.builder();
    toolFlagsBuilder.setPlatformFlags(CxxSourceTypes.getPlatformPreprocessFlags(cxxPlatform, CxxSource.Type.C));
    for (CxxPreprocessorInput input : cxxPreprocessorInputs) {
        ppFlagsBuilder.addAllIncludes(input.getIncludes());
        ppFlagsBuilder.addAllFrameworkPaths(input.getFrameworks());
        toolFlagsBuilder.addAllRuleFlags(input.getPreprocessorFlags().get(CxxSource.Type.C));
    }
    ppFlagsBuilder.setOtherFlags(toolFlagsBuilder.build());
    PreprocessorFlags ppFlags = ppFlagsBuilder.build();
    ImmutableList<String> compileFlags = ImmutableList.<String>builder().addAll(haskellConfig.getCompilerFlags()).addAll(flags).addAll(Iterables.concat(depFlags.values())).build();
    ImmutableList<SourcePath> includes = ImmutableList.copyOf(Iterables.concat(depIncludes.values()));
    ImmutableSortedMap<String, HaskellPackage> exposedPackages = exposedPackagesBuilder.build();
    ImmutableSortedMap<String, HaskellPackage> packages = packagesBuilder.build();
    return HaskellCompileRule.from(target, baseParams, ruleFinder, haskellConfig.getCompiler().resolve(resolver), haskellConfig.getHaskellVersion(), compileFlags, ppFlags, cxxPlatform, depType == Linker.LinkableDepType.STATIC ? CxxSourceRuleFactory.PicType.PDC : CxxSourceRuleFactory.PicType.PIC, main, packageInfo, includes, exposedPackages, packages, sources, CxxSourceTypes.getPreprocessor(cxxPlatform, CxxSource.Type.C).resolve(resolver));
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) SourcePath(com.facebook.buck.rules.SourcePath) ImmutableSet(com.google.common.collect.ImmutableSet) BuildTarget(com.facebook.buck.model.BuildTarget) BuildRule(com.facebook.buck.rules.BuildRule) PreprocessorFlags(com.facebook.buck.cxx.PreprocessorFlags) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) TreeMap(java.util.TreeMap) NoSuchBuildTargetException(com.facebook.buck.parser.NoSuchBuildTargetException) CxxPreprocessorInput(com.facebook.buck.cxx.CxxPreprocessorInput) ExplicitCxxToolFlags(com.facebook.buck.cxx.ExplicitCxxToolFlags)

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