use of com.facebook.buck.file.WriteFile in project buck by facebook.
the class PythonBinaryDescription method createEmptyInitModule.
public static SourcePath createEmptyInitModule(BuildRuleParams params, BuildRuleResolver resolver) {
BuildTarget emptyInitTarget = getEmptyInitTarget(params.getBuildTarget());
Path emptyInitPath = BuildTargets.getGenPath(params.getProjectFilesystem(), params.getBuildTarget(), "%s/__init__.py");
WriteFile rule = resolver.addToIndex(new WriteFile(params.withBuildTarget(emptyInitTarget).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of()), Suppliers.ofInstance(ImmutableSortedSet.of())), "", emptyInitPath, /* executable */
false));
return rule.getSourcePathToOutput();
}
use of com.facebook.buck.file.WriteFile in project buck by facebook.
the class AppleBinaryDescription method requireThinBinary.
private <A extends Arg> BuildRule requireThinBinary(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver, A args) throws NoSuchBuildTargetException {
Optional<BuildRule> existingThinRule = resolver.getRuleOptional(params.getBuildTarget());
if (existingThinRule.isPresent()) {
return existingThinRule.get();
}
Optional<BuildRule> swiftCompanionBuildRule = swiftDelegate.createCompanionBuildRule(targetGraph, params, resolver, args);
if (swiftCompanionBuildRule.isPresent()) {
// otherwise, add this swift rule as a dependency.
if (isSwiftTarget(params.getBuildTarget())) {
return swiftCompanionBuildRule.get();
} else {
params = params.copyAppendingExtraDeps(ImmutableSet.of(swiftCompanionBuildRule.get()));
}
}
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
Optional<Path> stubBinaryPath = getStubBinaryPath(params, args);
if (shouldUseStubBinary(params) && stubBinaryPath.isPresent()) {
try {
return resolver.addToIndex(new WriteFile(params, Files.readAllBytes(stubBinaryPath.get()), BuildTargets.getGenPath(params.getProjectFilesystem(), params.getBuildTarget(), "%s"), true));
} catch (IOException e) {
throw new HumanReadableException("Could not read stub binary " + stubBinaryPath.get());
}
} else {
CxxBinaryDescription.Arg delegateArg = delegate.createUnpopulatedConstructorArg();
AppleDescriptions.populateCxxBinaryDescriptionArg(pathResolver, delegateArg, args, params.getBuildTarget());
return resolver.addToIndex(delegate.createBuildRule(targetGraph, params, resolver, delegateArg));
}
}
use of com.facebook.buck.file.WriteFile in project buck by facebook.
the class HaskellDescriptionUtils method createLinkRule.
/**
* Create a Haskell link rule that links the given inputs to a executable or shared library and
* pulls in transitive native linkable deps from the given dep roots.
*/
public static HaskellLinkRule createLinkRule(BuildTarget target, BuildRuleParams baseParams, BuildRuleResolver resolver, SourcePathRuleFinder ruleFinder, CxxPlatform cxxPlatform, HaskellConfig haskellConfig, Linker.LinkType linkType, ImmutableList<String> extraFlags, Iterable<Arg> linkerInputs, Iterable<? extends NativeLinkable> deps, Linker.LinkableDepType depType) throws NoSuchBuildTargetException {
Tool linker = haskellConfig.getLinker().resolve(resolver);
String name = target.getShortName();
ImmutableList.Builder<Arg> linkerArgsBuilder = ImmutableList.builder();
ImmutableList.Builder<Arg> argsBuilder = ImmutableList.builder();
// Add the base flags from the `.buckconfig` first.
argsBuilder.addAll(StringArg.from(haskellConfig.getLinkerFlags()));
// Pass in the appropriate flags to link a shared library.
if (linkType.equals(Linker.LinkType.SHARED)) {
name = CxxDescriptionEnhancer.getSharedLibrarySoname(Optional.empty(), target.withFlavors(), cxxPlatform);
argsBuilder.addAll(StringArg.from("-shared", "-dynamic"));
argsBuilder.addAll(StringArg.from(MoreIterables.zipAndConcat(Iterables.cycle("-optl"), cxxPlatform.getLd().resolve(resolver).soname(name))));
}
// Add in extra flags passed into this function.
argsBuilder.addAll(StringArg.from(extraFlags));
// We pass in the linker inputs and all native linkable deps by prefixing with `-optl` so that
// the args go straight to the linker, and preserve their order.
linkerArgsBuilder.addAll(linkerInputs);
for (NativeLinkable nativeLinkable : NativeLinkables.getNativeLinkables(cxxPlatform, deps, depType).values()) {
linkerArgsBuilder.addAll(NativeLinkables.getNativeLinkableInput(cxxPlatform, depType, nativeLinkable).getArgs());
}
// Since we use `-optl` to pass all linker inputs directly to the linker, the haskell linker
// will complain about not having any input files. So, create a dummy archive with an empty
// module and pass that in normally to work around this.
BuildTarget emptyModuleTarget = target.withAppendedFlavors(InternalFlavor.of("empty-module"));
WriteFile emptyModule = resolver.addToIndex(new WriteFile(baseParams.withBuildTarget(emptyModuleTarget), "module Unused where", BuildTargets.getGenPath(baseParams.getProjectFilesystem(), emptyModuleTarget, "%s/Unused.hs"), /* executable */
false));
HaskellCompileRule emptyCompiledModule = resolver.addToIndex(createCompileRule(target.withAppendedFlavors(InternalFlavor.of("empty-compiled-module")), baseParams, resolver, ruleFinder, // Buck dependency.
baseParams.getDeps(), cxxPlatform, haskellConfig, depType, Optional.empty(), Optional.empty(), ImmutableList.of(), HaskellSources.builder().putModuleMap("Unused", emptyModule.getSourcePathToOutput()).build()));
BuildTarget emptyArchiveTarget = target.withAppendedFlavors(InternalFlavor.of("empty-archive"));
Archive emptyArchive = resolver.addToIndex(Archive.from(emptyArchiveTarget, baseParams, ruleFinder, cxxPlatform, Archive.Contents.NORMAL, BuildTargets.getGenPath(baseParams.getProjectFilesystem(), emptyArchiveTarget, "%s/libempty.a"), emptyCompiledModule.getObjects()));
argsBuilder.add(SourcePathArg.of(emptyArchive.getSourcePathToOutput()));
ImmutableList<Arg> args = argsBuilder.build();
ImmutableList<Arg> linkerArgs = linkerArgsBuilder.build();
return resolver.addToIndex(new HaskellLinkRule(baseParams.withBuildTarget(target).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.<BuildRule>naturalOrder().addAll(linker.getDeps(ruleFinder)).addAll(Stream.of(args, linkerArgs).flatMap(Collection::stream).flatMap(arg -> arg.getDeps(ruleFinder).stream()).iterator()).build()), Suppliers.ofInstance(ImmutableSortedSet.of())), linker, name, args, linkerArgs, haskellConfig.shouldCacheLinks()));
}
use of com.facebook.buck.file.WriteFile in project buck by facebook.
the class PythonTestDescription method createTestModulesSourceBuildRule.
/**
* Return a {@link BuildRule} that constructs the source file which contains the list
* of test modules this python test rule will run. Setting up a separate build rule
* for this allows us to use the existing python binary rule without changes to account
* for the build-time creation of this file.
*/
private static BuildRule createTestModulesSourceBuildRule(BuildRuleParams params, Path outputPath, ImmutableSet<String> testModules) {
// Modify the build rule params to change the target, type, and remove all deps.
BuildRuleParams newParams = params.withBuildTarget(BuildTargets.createFlavoredBuildTarget(params.getBuildTarget().checkUnflavored(), InternalFlavor.of("test_module"))).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of()), Suppliers.ofInstance(ImmutableSortedSet.of()));
String contents = getTestModulesListContents(testModules);
return new WriteFile(newParams, contents, outputPath, /* executable */
false);
}
Aggregations