use of com.facebook.buck.rules.BuildRule in project buck by facebook.
the class AppleTestDescription method createTestLibraryRule.
private <A extends Arg> BuildRule createTestLibraryRule(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver, A args, Optional<SourcePath> testHostAppBinarySourcePath, ImmutableSet<BuildTarget> blacklist, BuildTarget libraryTarget) throws NoSuchBuildTargetException {
BuildTarget existingLibraryTarget = libraryTarget.withAppendedFlavors(AppleDebuggableBinary.RULE_FLAVOR, CxxStrip.RULE_FLAVOR).withAppendedFlavors(StripStyle.NON_GLOBAL_SYMBOLS.getFlavor());
Optional<BuildRule> existingLibrary = resolver.getRuleOptional(existingLibraryTarget);
BuildRule library;
if (existingLibrary.isPresent()) {
library = existingLibrary.get();
} else {
library = appleLibraryDescription.createLibraryBuildRule(targetGraph, params.withBuildTarget(libraryTarget), resolver, args, // we'll just link them statically.
Optional.of(Linker.LinkableDepType.STATIC), testHostAppBinarySourcePath, blacklist);
resolver.addToIndex(library);
}
return library;
}
use of com.facebook.buck.rules.BuildRule in project buck by facebook.
the class BuiltinApplePackage method appendAdditionalAppleWatchSteps.
private void appendAdditionalAppleWatchSteps(ImmutableList.Builder<Step> commands) {
// 2. WatchKitSupport instead of WatchKitSupport2.
for (BuildRule rule : bundle.getDeps()) {
if (rule instanceof AppleBundle) {
AppleBundle appleBundle = (AppleBundle) rule;
if (appleBundle.getBinary().isPresent()) {
BuildRule binary = appleBundle.getBinary().get();
if (binary instanceof WriteFile && appleBundle.getPlatformName().startsWith("watch")) {
commands.add(new MkdirStep(getProjectFilesystem(), temp.resolve("Symbols")));
Path watchKitSupportDir = temp.resolve("WatchKitSupport2");
commands.add(new MkdirStep(getProjectFilesystem(), watchKitSupportDir));
commands.add(new WriteFileStep(getProjectFilesystem(), ByteSource.wrap(((WriteFile) binary).getFileContents()), watchKitSupportDir.resolve("WK"), true));
} else {
Optional<WriteFile> legacyWatchStub = getLegacyWatchStubFromDeps(appleBundle);
if (legacyWatchStub.isPresent()) {
Path watchKitSupportDir = temp.resolve("WatchKitSupport");
commands.add(new MkdirStep(getProjectFilesystem(), watchKitSupportDir));
commands.add(new WriteFileStep(getProjectFilesystem(), ByteSource.wrap(legacyWatchStub.get().getFileContents()), watchKitSupportDir.resolve("WK"), true));
}
}
}
}
}
}
use of com.facebook.buck.rules.BuildRule in project buck by facebook.
the class MultiarchFile method copyLinkMaps.
private void copyLinkMaps(BuildableContext buildableContext, ImmutableList.Builder<Step> steps) {
Path linkMapDir = Paths.get(output + "-LinkMap");
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), linkMapDir));
for (SourcePath thinBinary : thinBinaries) {
Optional<BuildRule> maybeRule = ruleFinder.getRule(thinBinary);
if (maybeRule.isPresent()) {
BuildRule rule = maybeRule.get();
if (rule instanceof CxxBinary) {
rule = ((CxxBinary) rule).getLinkRule();
}
if (rule instanceof CxxLink && !rule.getBuildTarget().getFlavors().contains(LinkerMapMode.NO_LINKER_MAP.getFlavor())) {
Optional<Path> maybeLinkerMapPath = ((CxxLink) rule).getLinkerMapPath();
if (maybeLinkerMapPath.isPresent()) {
Path source = maybeLinkerMapPath.get();
Path dest = linkMapDir.resolve(source.getFileName());
steps.add(CopyStep.forFile(getProjectFilesystem(), source, dest));
buildableContext.recordArtifact(dest);
}
}
}
}
}
use of com.facebook.buck.rules.BuildRule in project buck by facebook.
the class MultiarchFileInfos method requireMultiarchRule.
/**
* Generate a fat rule from thin rules.
*
* Invariant: thinRules contain all the thin rules listed in info.getThinTargets().
*/
public static BuildRule requireMultiarchRule(BuildRuleParams params, BuildRuleResolver resolver, MultiarchFileInfo info, ImmutableSortedSet<BuildRule> thinRules) {
Optional<BuildRule> existingRule = resolver.getRuleOptional(info.getFatTarget());
if (existingRule.isPresent()) {
return existingRule.get();
}
ImmutableSortedSet<SourcePath> inputs = FluentIterable.from(thinRules).transform(BuildRule::getSourcePathToOutput).toSortedSet(Ordering.natural());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
MultiarchFile multiarchFile = new MultiarchFile(params.copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of()), Suppliers.ofInstance(thinRules)), ruleFinder, info.getRepresentativePlatform().getLipo(), inputs, BuildTargets.getGenPath(params.getProjectFilesystem(), params.getBuildTarget(), "%s"));
resolver.addToIndex(multiarchFile);
return multiarchFile;
}
use of com.facebook.buck.rules.BuildRule in project buck by facebook.
the class CxxGenruleDescription method getMacroHandler.
@Override
protected <A extends Arg> MacroHandler getMacroHandler(BuildTarget buildTarget, ProjectFilesystem filesystem, BuildRuleResolver resolver, TargetGraph targetGraph, A args) {
CxxPlatform cxxPlatform = cxxPlatforms.getRequiredValue(buildTarget);
ImmutableMap.Builder<String, MacroExpander> macros = ImmutableMap.builder();
macros.put("exe", new ExecutableMacroExpander());
macros.put("location", new CxxLocationMacroExpander(cxxPlatform));
macros.put("platform-name", new StringExpander(cxxPlatform.getFlavor().toString()));
macros.put("location-platform", new LocationMacroExpander() {
@Override
protected BuildRule resolve(BuildRuleResolver resolver, LocationMacro input) throws MacroException {
try {
return resolver.requireRule(input.getTarget().withAppendedFlavors(cxxPlatform.getFlavor()));
} catch (NoSuchBuildTargetException e) {
throw new MacroException(e.getHumanReadableErrorMessage());
}
}
});
macros.put("cc", new ToolExpander(cxxPlatform.getCc().resolve(resolver)));
macros.put("cxx", new ToolExpander(cxxPlatform.getCxx().resolve(resolver)));
ImmutableList<String> asflags = cxxPlatform.getAsflags();
ImmutableList<String> cflags = cxxPlatform.getCflags();
ImmutableList<String> cxxflags = cxxPlatform.getCxxflags();
macros.put("cflags", new StringExpander(shquoteJoin(Iterables.concat(cflags, asflags))));
macros.put("cxxflags", new StringExpander(shquoteJoin(Iterables.concat(cxxflags, asflags))));
macros.put("cppflags", new CxxPreprocessorFlagsExpander(cxxPlatform, CxxSource.Type.C));
macros.put("cxxppflags", new CxxPreprocessorFlagsExpander(cxxPlatform, CxxSource.Type.CXX));
macros.put("ld", new ToolExpander(cxxPlatform.getLd().resolve(resolver)));
for (Linker.LinkableDepType depType : Linker.LinkableDepType.values()) {
for (Filter filter : Filter.values()) {
macros.put(String.format("ldflags-%s%s", depType.toString().toLowerCase().replace('_', '-'), filter == Filter.PARAM ? "-filter" : ""), new CxxLinkerFlagsExpander(buildTarget, filesystem, cxxPlatform, depType, args.out, filter));
}
}
return new MacroHandler(macros.build());
}
Aggregations