Search in sources :

Example 81 with BuildTarget

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

the class DDescriptionUtils method createNativeLinkable.

/**
   * Creates a {@link com.facebook.buck.cxx.NativeLinkable} using sources compiled by
   * the D compiler.
   *
   * @param params build parameters for the build target
   * @param sources source files to compile
   * @param compilerFlags flags to pass to the compiler
   * @param buildRuleResolver resolver for build rules
   * @param cxxPlatform the C++ platform to compile for
   * @param dBuckConfig the Buck configuration for D
   * @return the new build rule
   */
public static CxxLink createNativeLinkable(BuildRuleParams params, BuildRuleResolver buildRuleResolver, CxxPlatform cxxPlatform, DBuckConfig dBuckConfig, CxxBuckConfig cxxBuckConfig, ImmutableList<String> compilerFlags, SourceList sources, ImmutableList<String> linkerFlags, DIncludes includes) throws NoSuchBuildTargetException {
    BuildTarget buildTarget = params.getBuildTarget();
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(buildRuleResolver);
    SourcePathResolver sourcePathResolver = new SourcePathResolver(ruleFinder);
    ImmutableList<SourcePath> sourcePaths = sourcePathsForCompiledSources(params, buildRuleResolver, sourcePathResolver, ruleFinder, cxxPlatform, dBuckConfig, compilerFlags, sources, includes);
    // dependencies.
    return CxxLinkableEnhancer.createCxxLinkableBuildRule(cxxBuckConfig, cxxPlatform, params, buildRuleResolver, sourcePathResolver, ruleFinder, buildTarget, Linker.LinkType.EXECUTABLE, Optional.empty(), BuildTargets.getGenPath(params.getProjectFilesystem(), buildTarget, "%s/" + buildTarget.getShortName()), Linker.LinkableDepType.STATIC, FluentIterable.from(params.getDeps()).filter(NativeLinkable.class), /* cxxRuntimeType */
    Optional.empty(), /* bundleLoader */
    Optional.empty(), ImmutableSet.of(), NativeLinkableInput.builder().addAllArgs(StringArg.from(dBuckConfig.getLinkerFlags())).addAllArgs(StringArg.from(linkerFlags)).addAllArgs(SourcePathArg.from(sourcePaths)).build());
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) BuildTarget(com.facebook.buck.model.BuildTarget) NativeLinkable(com.facebook.buck.cxx.NativeLinkable) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver)

Example 82 with BuildTarget

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

the class DDescriptionUtils method requireBuildRule.

/**
   * Ensures that a DCompileBuildRule exists for the given target, creating a DCompileBuildRule
   * if neccesary.
   * @param baseParams build parameters for the rule
   * @param buildRuleResolver BuildRuleResolver the rule should be in
   * @param src the source file to be compiled
   * @param compilerFlags flags to pass to the compiler
   * @param compileTarget the target the rule should be for
   * @param dBuckConfig the Buck configuration for D
   * @return the build rule
   */
public static DCompileBuildRule requireBuildRule(BuildTarget compileTarget, BuildRuleParams baseParams, BuildRuleResolver buildRuleResolver, SourcePathRuleFinder ruleFinder, DBuckConfig dBuckConfig, ImmutableList<String> compilerFlags, String name, SourcePath src, DIncludes includes) throws NoSuchBuildTargetException {
    Optional<BuildRule> existingRule = buildRuleResolver.getRuleOptional(compileTarget);
    if (existingRule.isPresent()) {
        return (DCompileBuildRule) existingRule.get();
    } else {
        Tool compiler = dBuckConfig.getDCompiler();
        Map<BuildTarget, DIncludes> transitiveIncludes = new TreeMap<>();
        transitiveIncludes.put(baseParams.getBuildTarget(), includes);
        for (Map.Entry<BuildTarget, DLibrary> library : getTransitiveDLibraryRules(baseParams.getDeps()).entrySet()) {
            transitiveIncludes.put(library.getKey(), library.getValue().getIncludes());
        }
        ImmutableSortedSet.Builder<BuildRule> depsBuilder = ImmutableSortedSet.naturalOrder();
        depsBuilder.addAll(compiler.getDeps(ruleFinder));
        depsBuilder.addAll(ruleFinder.filterBuildRuleInputs(src));
        for (DIncludes dIncludes : transitiveIncludes.values()) {
            depsBuilder.addAll(dIncludes.getDeps(ruleFinder));
        }
        ImmutableSortedSet<BuildRule> deps = depsBuilder.build();
        return buildRuleResolver.addToIndex(new DCompileBuildRule(baseParams.withBuildTarget(compileTarget).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(deps), Suppliers.ofInstance(ImmutableSortedSet.of())), compiler, ImmutableList.<String>builder().addAll(dBuckConfig.getBaseCompilerFlags()).addAll(compilerFlags).build(), name, ImmutableSortedSet.of(src), ImmutableList.copyOf(transitiveIncludes.values())));
    }
}
Also used : TreeMap(java.util.TreeMap) BuildTarget(com.facebook.buck.model.BuildTarget) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) BuildRule(com.facebook.buck.rules.BuildRule) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) TreeMap(java.util.TreeMap) Tool(com.facebook.buck.rules.Tool)

Example 83 with BuildTarget

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

the class DTestDescription method createBuildRule.

@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver buildRuleResolver, A args) throws NoSuchBuildTargetException {
    BuildTarget target = params.getBuildTarget();
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(buildRuleResolver);
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    SymlinkTree sourceTree = buildRuleResolver.addToIndex(DDescriptionUtils.createSourceSymlinkTree(DDescriptionUtils.getSymlinkTreeTarget(params.getBuildTarget()), params, ruleFinder, pathResolver, args.srcs));
    // Create a helper rule to build the test binary.
    // The rule needs its own target so that we can depend on it without creating cycles.
    BuildTarget binaryTarget = DDescriptionUtils.createBuildTargetForFile(target, "build-", target.getFullyQualifiedName(), cxxPlatform);
    BuildRule binaryRule = DDescriptionUtils.createNativeLinkable(params.withBuildTarget(binaryTarget), buildRuleResolver, cxxPlatform, dBuckConfig, cxxBuckConfig, ImmutableList.of("-unittest"), args.srcs, args.linkerFlags, DIncludes.builder().setLinkTree(sourceTree.getSourcePathToOutput()).addAllSources(args.srcs.getPaths()).build());
    buildRuleResolver.addToIndex(binaryRule);
    return new DTest(params.copyAppendingExtraDeps(ImmutableList.of(binaryRule)), binaryRule, args.contacts, args.labels, args.testRuleTimeoutMs.map(Optional::of).orElse(defaultTestRuleTimeoutMs));
}
Also used : SymlinkTree(com.facebook.buck.rules.SymlinkTree) Optional(java.util.Optional) BuildTarget(com.facebook.buck.model.BuildTarget) BuildRule(com.facebook.buck.rules.BuildRule) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver)

Example 84 with BuildTarget

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

the class CxxPrecompiledHeaderTemplate method requireAggregatedDepsRule.

public DependencyAggregation requireAggregatedDepsRule(CxxPlatform cxxPlatform) {
    BuildTarget depAggTarget = createAggregatedDepsTarget(cxxPlatform);
    Optional<DependencyAggregation> existingRule = ruleResolver.getRuleOptionalWithType(depAggTarget, DependencyAggregation.class);
    if (existingRule.isPresent()) {
        return existingRule.get();
    }
    BuildRuleParams depAggParams = params.withBuildTarget(depAggTarget).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(getPreprocessDeps(cxxPlatform)), Suppliers.ofInstance(ImmutableSortedSet.of()));
    DependencyAggregation depAgg = new DependencyAggregation(depAggParams);
    ruleResolver.addToIndex(depAgg);
    return depAgg;
}
Also used : BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) BuildTarget(com.facebook.buck.model.BuildTarget) DependencyAggregation(com.facebook.buck.rules.DependencyAggregation)

Example 85 with BuildTarget

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

the class CxxTestDescription method findDepsForTargetFromConstructorArgs.

@Override
public Iterable<BuildTarget> findDepsForTargetFromConstructorArgs(BuildTarget buildTarget, CellPathResolver cellRoots, Arg constructorArg) {
    ImmutableSet.Builder<BuildTarget> deps = ImmutableSet.builder();
    // Get any parse time deps from the C/C++ platforms.
    deps.addAll(CxxPlatforms.getParseTimeDeps(cxxPlatforms.getValue(buildTarget.getFlavors()).orElse(defaultCxxPlatform)));
    // Extract parse time deps from flags, args, and environment parameters.
    Iterable<Iterable<String>> macroStrings = ImmutableList.<Iterable<String>>builder().add(constructorArg.args).add(constructorArg.env.values()).build();
    for (String macroString : Iterables.concat(macroStrings)) {
        try {
            deps.addAll(CxxDescriptionEnhancer.MACRO_HANDLER.extractParseTimeDeps(buildTarget, cellRoots, macroString));
        } catch (MacroException e) {
            throw new HumanReadableException(e, "%s: %s", buildTarget, e.getMessage());
        }
    }
    CxxTestType type = constructorArg.framework.orElse(getDefaultTestType());
    switch(type) {
        case GTEST:
            {
                cxxBuckConfig.getGtestDep().ifPresent(deps::add);
                if (constructorArg.useDefaultTestMain.orElse(true)) {
                    cxxBuckConfig.getGtestDefaultTestMainDep().ifPresent(deps::add);
                }
                break;
            }
        case BOOST:
            {
                cxxBuckConfig.getBoostTestDep().ifPresent(deps::add);
                break;
            }
        default:
            {
                break;
            }
    }
    constructorArg.depsQuery.ifPresent(depsQuery -> QueryUtils.extractParseTimeTargets(buildTarget, cellRoots, depsQuery).forEach(deps::add));
    return deps.build();
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) FluentIterable(com.google.common.collect.FluentIterable) BuildTarget(com.facebook.buck.model.BuildTarget) HumanReadableException(com.facebook.buck.util.HumanReadableException) MacroException(com.facebook.buck.model.MacroException)

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