use of com.facebook.buck.rules.BuildRule in project buck by facebook.
the class NativeRelinker method makeRelinkerRule.
private RelinkerRule makeRelinkerRule(TargetCpuType cpuType, SourcePath source, ImmutableList<RelinkerRule> relinkerDeps) {
Function<RelinkerRule, SourcePath> getSymbolsNeeded = RelinkerRule::getSymbolsNeededPath;
String libname = resolver.getAbsolutePath(source).getFileName().toString();
BuildRuleParams relinkerParams = buildRuleParams.withAppendedFlavor(InternalFlavor.of("xdso-dce")).withAppendedFlavor(InternalFlavor.of(Flavor.replaceInvalidCharacters(cpuType.toString()))).withAppendedFlavor(InternalFlavor.of(Flavor.replaceInvalidCharacters(libname))).copyAppendingExtraDeps(relinkerDeps);
BuildRule baseRule = ruleFinder.getRule(source).orElse(null);
ImmutableList<Arg> linkerArgs = ImmutableList.of();
Linker linker = null;
if (baseRule != null && baseRule instanceof CxxLink) {
CxxLink link = (CxxLink) baseRule;
linkerArgs = link.getArgs();
linker = link.getLinker();
}
return new RelinkerRule(relinkerParams, resolver, ruleFinder, ImmutableSortedSet.copyOf(Lists.transform(relinkerDeps, getSymbolsNeeded)), cpuType, Preconditions.checkNotNull(nativePlatforms.get(cpuType)).getObjdump(), cxxBuckConfig, source, linker, linkerArgs);
}
use of com.facebook.buck.rules.BuildRule in project buck by facebook.
the class BuildCommand method showOutputs.
private void showOutputs(CommandRunnerParams params, ActionGraphAndResolver actionGraphAndResolver) {
Optional<DefaultRuleKeyFactory> ruleKeyFactory = Optional.empty();
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(actionGraphAndResolver.getResolver());
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
if (showRuleKey) {
RuleKeyFieldLoader fieldLoader = new RuleKeyFieldLoader(params.getBuckConfig().getKeySeed());
ruleKeyFactory = Optional.of(new DefaultRuleKeyFactory(fieldLoader, params.getFileHashCache(), pathResolver, ruleFinder));
}
params.getConsole().getStdOut().println("The outputs are:");
for (BuildTarget buildTarget : buildTargets) {
try {
BuildRule rule = actionGraphAndResolver.getResolver().requireRule(buildTarget);
Optional<Path> outputPath = TargetsCommand.getUserFacingOutputPath(pathResolver, rule, showFullOutput, params.getBuckConfig().getBuckOutCompatLink());
params.getConsole().getStdOut().printf("%s%s%s\n", rule.getFullyQualifiedName(), showRuleKey ? " " + ruleKeyFactory.get().build(rule).toString() : "", showOutput || showFullOutput ? " " + outputPath.map(Object::toString).orElse("") : "");
} catch (NoSuchBuildTargetException e) {
throw new HumanReadableException(MoreExceptions.getHumanReadableOrLocalizedMessage(e));
}
}
}
use of com.facebook.buck.rules.BuildRule in project buck by facebook.
the class BuildCommand method processSuccessfulBuild.
private int processSuccessfulBuild(CommandRunnerParams params, ActionAndTargetGraphs graphs) throws IOException {
if (showOutput || showFullOutput || showRuleKey) {
showOutputs(params, graphs.actionGraph);
}
if (outputPathForSingleBuildTarget != null) {
BuildTarget loneTarget = Iterables.getOnlyElement(graphs.getTargetGraphForLocalBuild().getBuildTargets());
BuildRule rule = graphs.actionGraph.getResolver().getRule(loneTarget);
if (!rule.outputFileCanBeCopied()) {
params.getConsole().printErrorText(String.format("%s does not have an output that is compatible with `buck build --out`", loneTarget));
return 1;
} else {
SourcePath output = Preconditions.checkNotNull(rule.getSourcePathToOutput(), "%s specified a build target that does not have an output file: %s", OUT_LONG_ARG, loneTarget);
ProjectFilesystem projectFilesystem = rule.getProjectFilesystem();
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(graphs.actionGraph.getResolver()));
projectFilesystem.copyFile(pathResolver.getAbsolutePath(output), outputPathForSingleBuildTarget);
}
}
return 0;
}
use of com.facebook.buck.rules.BuildRule in project buck by facebook.
the class CxxLibrary method getSharedLibraries.
@Override
public ImmutableMap<String, SourcePath> getSharedLibraries(CxxPlatform cxxPlatform) throws NoSuchBuildTargetException {
if (headerOnly.apply(cxxPlatform)) {
return ImmutableMap.of();
}
if (!isPlatformSupported(cxxPlatform)) {
return ImmutableMap.of();
}
ImmutableMap.Builder<String, SourcePath> libs = ImmutableMap.builder();
String sharedLibrarySoname = CxxDescriptionEnhancer.getSharedLibrarySoname(soname, getBuildTarget(), cxxPlatform);
BuildRule sharedLibraryBuildRule = requireBuildRule(cxxPlatform.getFlavor(), CxxDescriptionEnhancer.SHARED_FLAVOR);
libs.put(sharedLibrarySoname, sharedLibraryBuildRule.getSourcePathToOutput());
return libs.build();
}
use of com.facebook.buck.rules.BuildRule in project buck by facebook.
the class DistBuildFileHashes method ruleKeyComputation.
private static ListenableFuture<ImmutableMap<BuildRule, RuleKey>> ruleKeyComputation(ActionGraph actionGraph, final LoadingCache<ProjectFilesystem, DefaultRuleKeyFactory> ruleKeyFactories, ListeningExecutorService executorService) {
List<ListenableFuture<Map.Entry<BuildRule, RuleKey>>> ruleKeyEntries = new ArrayList<>();
for (final BuildRule rule : actionGraph.getNodes()) {
ruleKeyEntries.add(executorService.submit(() -> Maps.immutableEntry(rule, ruleKeyFactories.get(rule.getProjectFilesystem()).build(rule))));
}
ListenableFuture<List<Map.Entry<BuildRule, RuleKey>>> ruleKeyComputation = Futures.allAsList(ruleKeyEntries);
return Futures.transform(ruleKeyComputation, new Function<List<Map.Entry<BuildRule, RuleKey>>, ImmutableMap<BuildRule, RuleKey>>() {
@Override
public ImmutableMap<BuildRule, RuleKey> apply(List<Map.Entry<BuildRule, RuleKey>> input) {
return ImmutableMap.copyOf(input);
}
}, executorService);
}
Aggregations