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());
}
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())));
}
}
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));
}
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;
}
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();
}
Aggregations