use of com.facebook.buck.model.BuildTarget in project buck by facebook.
the class ProjectGenerator method generateAppleTestTarget.
@SuppressWarnings("unchecked")
private PBXTarget generateAppleTestTarget(TargetNode<AppleTestDescription.Arg, ?> testTargetNode) throws IOException {
Optional<TargetNode<AppleBundleDescription.Arg, ?>> testHostBundle;
if (testTargetNode.getConstructorArg().testHostApp.isPresent()) {
BuildTarget testHostBundleTarget = testTargetNode.getConstructorArg().testHostApp.get();
TargetNode<?, ?> testHostBundleNode = targetGraph.get(testHostBundleTarget);
if (!(testHostBundleNode.getDescription() instanceof AppleBundleDescription)) {
throw new HumanReadableException("The test host target '%s' has the wrong type (%s), must be apple_bundle", testHostBundleTarget, testHostBundleNode.getDescription().getClass());
}
testHostBundle = Optional.of((TargetNode<AppleBundleDescription.Arg, ?>) testHostBundleNode);
} else {
testHostBundle = Optional.empty();
}
return generateAppleBundleTarget(project, testTargetNode, testTargetNode, testHostBundle);
}
use of com.facebook.buck.model.BuildTarget in project buck by facebook.
the class ProjectGenerator method generateHalideLibraryTarget.
private Optional<PBXTarget> generateHalideLibraryTarget(PBXProject project, TargetNode<HalideLibraryDescription.Arg, ?> targetNode) throws IOException {
final BuildTarget buildTarget = targetNode.getBuildTarget();
boolean isFocusedOnTarget = buildTarget.matchesUnflavoredTargets(focusModules);
String productName = getProductNameForBuildTarget(buildTarget);
Path outputPath = getHalideOutputPath(targetNode.getFilesystem(), buildTarget);
Path scriptPath = halideBuckConfig.getXcodeCompileScriptPath();
Optional<String> script = projectFilesystem.readFileIfItExists(scriptPath);
PBXShellScriptBuildPhase scriptPhase = new PBXShellScriptBuildPhase();
scriptPhase.setShellScript(script.orElse(""));
NewNativeTargetProjectMutator mutator = new NewNativeTargetProjectMutator(pathRelativizer, this::resolveSourcePath);
mutator.setTargetName(getXcodeTargetName(buildTarget)).setProduct(ProductType.STATIC_LIBRARY, productName, outputPath).setPreBuildRunScriptPhases(ImmutableList.of(scriptPhase));
NewNativeTargetProjectMutator.Result targetBuilderResult;
targetBuilderResult = mutator.buildTargetAndAddToProject(project, isFocusedOnTarget);
BuildTarget compilerTarget = HalideLibraryDescription.createHalideCompilerBuildTarget(buildTarget);
Path compilerPath = BuildTargets.getGenPath(projectFilesystem, compilerTarget, "%s");
ImmutableMap<String, String> appendedConfig = ImmutableMap.of();
ImmutableMap<String, String> extraSettings = ImmutableMap.of();
ImmutableMap.Builder<String, String> defaultSettingsBuilder = ImmutableMap.builder();
defaultSettingsBuilder.put("REPO_ROOT", projectFilesystem.getRootPath().toAbsolutePath().normalize().toString());
defaultSettingsBuilder.put("HALIDE_COMPILER_PATH", compilerPath.toString());
// pass the source list to the xcode script
String halideCompilerSrcs;
Iterable<Path> compilerSrcFiles = Iterables.transform(targetNode.getConstructorArg().srcs, input -> resolveSourcePath(input.getSourcePath()));
halideCompilerSrcs = Joiner.on(" ").join(compilerSrcFiles);
defaultSettingsBuilder.put("HALIDE_COMPILER_SRCS", halideCompilerSrcs);
String halideCompilerFlags;
halideCompilerFlags = Joiner.on(" ").join(targetNode.getConstructorArg().compilerFlags);
defaultSettingsBuilder.put("HALIDE_COMPILER_FLAGS", halideCompilerFlags);
defaultSettingsBuilder.put("HALIDE_OUTPUT_PATH", outputPath.toString());
defaultSettingsBuilder.put("HALIDE_FUNC_NAME", buildTarget.getShortName());
defaultSettingsBuilder.put(PRODUCT_NAME, productName);
Optional<ImmutableSortedMap<String, ImmutableMap<String, String>>> configs = getXcodeBuildConfigurationsForTargetNode(targetNode, appendedConfig);
PBXNativeTarget target = targetBuilderResult.target;
setTargetBuildConfigurations(getConfigurationNameToXcconfigPath(buildTarget), target, project.getMainGroup(), configs.get(), extraSettings, defaultSettingsBuilder.build(), appendedConfig);
return Optional.of(target);
}
use of com.facebook.buck.model.BuildTarget in project buck by facebook.
the class CxxGenruleDescription method translateConstructorArg.
@Override
public Optional<Arg> translateConstructorArg(BuildTarget target, CellPathResolver cellNames, TargetNodeTranslator translator, Arg constructorArg) {
Arg newConstructorArg = createUnpopulatedConstructorArg();
translator.translateConstructorArg(cellNames, BuildTargetPatternParser.forBaseName(target.getBaseName()), constructorArg, newConstructorArg);
newConstructorArg.cmd = newConstructorArg.cmd.map(c -> translateCmd(target, cellNames, translator, "cmd", c));
newConstructorArg.bash = newConstructorArg.bash.map(c -> translateCmd(target, cellNames, translator, "bash", c));
newConstructorArg.cmdExe = newConstructorArg.cmdExe.map(c -> translateCmd(target, cellNames, translator, "cmd_exe", c));
return Optional.of(newConstructorArg);
}
use of com.facebook.buck.model.BuildTarget in project buck by facebook.
the class CxxBinaryDescription method createBuildRule.
@SuppressWarnings("PMD.PrematureDeclaration")
@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver, A args) throws NoSuchBuildTargetException {
// We explicitly remove some flavors below from params to make sure rule
// has the same output regardless if we will strip or not.
Optional<StripStyle> flavoredStripStyle = StripStyle.FLAVOR_DOMAIN.getValue(params.getBuildTarget());
Optional<LinkerMapMode> flavoredLinkerMapMode = LinkerMapMode.FLAVOR_DOMAIN.getValue(params.getBuildTarget());
params = CxxStrip.removeStripStyleFlavorInParams(params, flavoredStripStyle);
params = LinkerMapMode.removeLinkerMapModeFlavorInParams(params, flavoredLinkerMapMode);
// Extract the platform from the flavor, falling back to the default platform if none are
// found.
ImmutableSet<Flavor> flavors = ImmutableSet.copyOf(params.getBuildTarget().getFlavors());
CxxPlatform cxxPlatform = cxxPlatforms.getValue(flavors).orElse(defaultCxxPlatform);
if (flavors.contains(CxxDescriptionEnhancer.HEADER_SYMLINK_TREE_FLAVOR)) {
flavors = ImmutableSet.copyOf(Sets.difference(flavors, ImmutableSet.of(CxxDescriptionEnhancer.HEADER_SYMLINK_TREE_FLAVOR)));
BuildTarget target = BuildTarget.builder(params.getBuildTarget().getUnflavoredBuildTarget()).addAllFlavors(flavors).build();
BuildRuleParams typeParams = params.withBuildTarget(target);
return createHeaderSymlinkTreeBuildRule(typeParams, resolver, cxxPlatform, args);
}
if (flavors.contains(CxxCompilationDatabase.COMPILATION_DATABASE)) {
BuildRuleParams paramsWithoutFlavor = params.withoutFlavor(CxxCompilationDatabase.COMPILATION_DATABASE);
CxxLinkAndCompileRules cxxLinkAndCompileRules = CxxDescriptionEnhancer.createBuildRulesForCxxBinaryDescriptionArg(targetGraph, paramsWithoutFlavor, resolver, cxxBuckConfig, cxxPlatform, args, flavoredStripStyle, flavoredLinkerMapMode);
return CxxCompilationDatabase.createCompilationDatabase(params, cxxLinkAndCompileRules.compileRules);
}
if (flavors.contains(CxxCompilationDatabase.UBER_COMPILATION_DATABASE)) {
return CxxDescriptionEnhancer.createUberCompilationDatabase(cxxPlatforms.getValue(flavors).isPresent() ? params : params.withAppendedFlavor(defaultCxxPlatform.getFlavor()), resolver);
}
if (flavors.contains(CxxInferEnhancer.InferFlavors.INFER.get())) {
return CxxInferEnhancer.requireInferAnalyzeAndReportBuildRuleForCxxDescriptionArg(params, resolver, cxxBuckConfig, cxxPlatform, args, inferBuckConfig, new CxxInferSourceFilter(inferBuckConfig));
}
if (flavors.contains(CxxInferEnhancer.InferFlavors.INFER_ANALYZE.get())) {
return CxxInferEnhancer.requireInferAnalyzeBuildRuleForCxxDescriptionArg(params, resolver, cxxBuckConfig, cxxPlatform, args, inferBuckConfig, new CxxInferSourceFilter(inferBuckConfig));
}
if (flavors.contains(CxxInferEnhancer.InferFlavors.INFER_CAPTURE_ALL.get())) {
return CxxInferEnhancer.requireAllTransitiveCaptureBuildRules(params, resolver, cxxBuckConfig, cxxPlatform, inferBuckConfig, new CxxInferSourceFilter(inferBuckConfig), args);
}
if (flavors.contains(CxxInferEnhancer.InferFlavors.INFER_CAPTURE_ONLY.get())) {
return CxxInferEnhancer.requireInferCaptureAggregatorBuildRuleForCxxDescriptionArg(params, resolver, cxxBuckConfig, cxxPlatform, args, inferBuckConfig, new CxxInferSourceFilter(inferBuckConfig));
}
if (flavors.contains(CxxDescriptionEnhancer.SANDBOX_TREE_FLAVOR)) {
return CxxDescriptionEnhancer.createSandboxTreeBuildRule(resolver, args, cxxPlatform, params);
}
CxxLinkAndCompileRules cxxLinkAndCompileRules = CxxDescriptionEnhancer.createBuildRulesForCxxBinaryDescriptionArg(targetGraph, params, resolver, cxxBuckConfig, cxxPlatform, args, flavoredStripStyle, flavoredLinkerMapMode);
// Return a CxxBinary rule as our representative in the action graph, rather than the CxxLink
// rule above for a couple reasons:
// 1) CxxBinary extends BinaryBuildRule whereas CxxLink does not, so the former can be used
// as executables for genrules.
// 2) In some cases, users add dependencies from some rules onto other binary rules, typically
// if the binary is executed by some test or library code at test time. These target graph
// deps should *not* become build time dependencies on the CxxLink step, otherwise we'd
// have to wait for the dependency binary to link before we could link the dependent binary.
// By using another BuildRule, we can keep the original target graph dependency tree while
// preventing it from affecting link parallelism.
params = CxxStrip.restoreStripStyleFlavorInParams(params, flavoredStripStyle);
params = LinkerMapMode.restoreLinkerMapModeFlavorInParams(params, flavoredLinkerMapMode);
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
CxxBinary cxxBinary = new CxxBinary(params.copyReplacingDeclaredAndExtraDeps(() -> cxxLinkAndCompileRules.deps, params.getExtraDeps()).copyAppendingExtraDeps(cxxLinkAndCompileRules.executable.getDeps(ruleFinder)), resolver, ruleFinder, cxxLinkAndCompileRules.getBinaryRule(), cxxLinkAndCompileRules.executable, args.frameworks, args.tests, params.getBuildTarget().withoutFlavors(cxxPlatforms.getFlavors()));
resolver.addToIndex(cxxBinary);
return cxxBinary;
}
use of com.facebook.buck.model.BuildTarget in project buck by facebook.
the class TargetsCommand method computeShowTargetHash.
private void computeShowTargetHash(CommandRunnerParams params, ListeningExecutorService executor, TargetGraphAndTargetNodes targetGraphAndTargetNodes, Map<BuildTarget, ShowOptions.Builder> showRulesResult) throws IOException, InterruptedException, BuildFileParseException, BuildTargetException, CycleException {
LOG.debug("Getting target hash for %s", targetGraphAndTargetNodes.getTargetNodes());
TargetGraphAndTargetNodes targetGraphAndNodesWithTests = computeTargetsAndGraphToShowTargetHash(params, executor, targetGraphAndTargetNodes);
TargetGraph targetGraphWithTests = targetGraphAndNodesWithTests.getTargetGraph();
FileHashLoader fileHashLoader = createOrGetFileHashLoader(params);
// Hash each target's rule description and contents of any files.
ImmutableMap<BuildTarget, HashCode> buildTargetHashes = new TargetGraphHashing(params.getBuckEventBus(), targetGraphWithTests, fileHashLoader, targetGraphAndNodesWithTests.getTargetNodes()).setNumThreads(params.getBuckConfig().getNumThreads()).hashTargetGraph();
ImmutableMap<BuildTarget, HashCode> finalHashes = rehashWithTestsIfNeeded(targetGraphWithTests, targetGraphAndTargetNodes.getTargetNodes(), buildTargetHashes);
for (TargetNode<?, ?> targetNode : targetGraphAndTargetNodes.getTargetNodes()) {
processTargetHash(targetNode.getBuildTarget(), showRulesResult, finalHashes);
}
}
Aggregations