use of com.facebook.buck.rules.SourcePath 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.rules.SourcePath in project buck by facebook.
the class PythonBinaryDescription method createInPlaceBinaryRule.
private PythonInPlaceBinary createInPlaceBinaryRule(BuildRuleParams params, BuildRuleResolver resolver, SourcePathRuleFinder ruleFinder, PythonPlatform pythonPlatform, CxxPlatform cxxPlatform, String mainModule, Optional<String> extension, PythonPackageComponents components, ImmutableSet<String> preloadLibraries) {
// We don't currently support targeting Windows.
if (cxxPlatform.getLd().resolve(resolver) instanceof WindowsLinker) {
throw new HumanReadableException("%s: cannot build in-place python binaries for Windows (%s)", params.getBuildTarget(), cxxPlatform.getFlavor());
}
// Add in any missing init modules into the python components.
SourcePath emptyInit = createEmptyInitModule(params, resolver);
components = components.withModules(addMissingInitModules(components.getModules(), emptyInit));
BuildTarget linkTreeTarget = params.getBuildTarget().withAppendedFlavors(InternalFlavor.of("link-tree"));
Path linkTreeRoot = BuildTargets.getGenPath(params.getProjectFilesystem(), linkTreeTarget, "%s");
SymlinkTree linkTree = resolver.addToIndex(new SymlinkTree(linkTreeTarget, params.getProjectFilesystem(), linkTreeRoot, ImmutableMap.<Path, SourcePath>builder().putAll(components.getModules()).putAll(components.getResources()).putAll(components.getNativeLibraries()).build(), ruleFinder));
return PythonInPlaceBinary.from(params, resolver, cxxPlatform, pythonPlatform, mainModule, components, extension.orElse(pythonBuckConfig.getPexExtension()), preloadLibraries, pythonBuckConfig.legacyOutputPath(), ruleFinder, linkTree, pythonPlatform.getEnvironment());
}
use of com.facebook.buck.rules.SourcePath in project buck by facebook.
the class OcamlStaticLibrary method getLinkableInput.
private NativeLinkableInput getLinkableInput(boolean isBytecode) {
NativeLinkableInput.Builder inputBuilder = NativeLinkableInput.builder();
// Add linker flags.
inputBuilder.addAllArgs(StringArg.from(linkerFlags));
// Add arg and input for static library.
UnflavoredBuildTarget staticBuildTarget = staticLibraryTarget.getUnflavoredBuildTarget();
inputBuilder.addArgs(SourcePathArg.of(new ExplicitBuildTargetSourcePath(ocamlLibraryBuild.getBuildTarget(), isBytecode ? OcamlBuildContext.getBytecodeOutputPath(staticBuildTarget, getProjectFilesystem(), /* isLibrary */
true) : OcamlBuildContext.getNativeOutputPath(staticBuildTarget, getProjectFilesystem(), /* isLibrary */
true))));
// Add args and inputs for C object files.
for (SourcePath objFile : objFiles) {
inputBuilder.addArgs(SourcePathArg.of(objFile));
}
return inputBuilder.build();
}
use of com.facebook.buck.rules.SourcePath in project buck by facebook.
the class PrebuiltOcamlLibraryDescription method createBuildRule.
@Override
public <A extends Arg> OcamlLibrary createBuildRule(TargetGraph targetGraph, final BuildRuleParams params, BuildRuleResolver resolver, final A args) {
final BuildTarget target = params.getBuildTarget();
final boolean bytecodeOnly = args.bytecodeOnly.orElse(false);
final String libDir = args.libDir.orElse("lib");
final String libName = args.libName.orElse(target.getShortName());
final String nativeLib = args.nativeLib.orElse(String.format("%s.cmxa", libName));
final String bytecodeLib = args.bytecodeLib.orElse(String.format("%s.cma", libName));
final ImmutableList<String> cLibs = args.cLibs;
final Path libPath = target.getBasePath().resolve(libDir);
final Path includeDir = libPath.resolve(args.includeDir.orElse(""));
final Optional<SourcePath> staticNativeLibraryPath = bytecodeOnly ? Optional.empty() : Optional.of(new PathSourcePath(params.getProjectFilesystem(), libPath.resolve(nativeLib)));
final SourcePath staticBytecodeLibraryPath = new PathSourcePath(params.getProjectFilesystem(), libPath.resolve(bytecodeLib));
final ImmutableList<SourcePath> staticCLibraryPaths = cLibs.stream().map(input -> new PathSourcePath(params.getProjectFilesystem(), libPath.resolve(input))).collect(MoreCollectors.toImmutableList());
final SourcePath bytecodeLibraryPath = new PathSourcePath(params.getProjectFilesystem(), libPath.resolve(bytecodeLib));
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
return new PrebuiltOcamlLibrary(params, ruleFinder, staticNativeLibraryPath, staticBytecodeLibraryPath, staticCLibraryPaths, bytecodeLibraryPath, libPath, includeDir);
}
use of com.facebook.buck.rules.SourcePath in project buck by facebook.
the class SwiftCompile method makeCompileStep.
private SwiftCompileStep makeCompileStep(SourcePathResolver resolver) {
ImmutableList.Builder<String> compilerCommand = ImmutableList.builder();
compilerCommand.addAll(swiftCompiler.getCommandPrefix(resolver));
if (bridgingHeader.isPresent()) {
compilerCommand.add("-import-objc-header", resolver.getRelativePath(bridgingHeader.get()).toString());
}
final Function<FrameworkPath, Path> frameworkPathToSearchPath = CxxDescriptionEnhancer.frameworkPathToSearchPath(cxxPlatform, resolver);
compilerCommand.addAll(frameworks.stream().map(frameworkPathToSearchPath::apply).flatMap(searchPath -> ImmutableSet.of("-F", searchPath.toString()).stream()).iterator());
compilerCommand.addAll(MoreIterables.zipAndConcat(Iterables.cycle("-Xcc"), getSwiftIncludeArgs(resolver)));
compilerCommand.addAll(MoreIterables.zipAndConcat(Iterables.cycle(INCLUDE_FLAG), getDeps().stream().filter(SwiftCompile.class::isInstance).map(BuildRule::getSourcePathToOutput).map(input -> resolver.getAbsolutePath(input).toString()).collect(MoreCollectors.toImmutableSet())));
Optional<Iterable<String>> configFlags = swiftBuckConfig.getFlags();
if (configFlags.isPresent()) {
compilerCommand.addAll(configFlags.get());
}
boolean hasMainEntry = srcs.stream().map(input -> resolver.getAbsolutePath(input).getFileName().toString()).anyMatch(SwiftDescriptions.SWIFT_MAIN_FILENAME::equalsIgnoreCase);
compilerCommand.add("-c", enableObjcInterop ? "-enable-objc-interop" : "", hasMainEntry ? "" : "-parse-as-library", "-module-name", moduleName, "-emit-module", "-emit-module-path", modulePath.toString(), "-o", objectPath.toString(), "-emit-objc-header-path", headerPath.toString());
compilerCommand.addAll(compilerFlags);
for (SourcePath sourcePath : srcs) {
compilerCommand.add(resolver.getRelativePath(sourcePath).toString());
}
ProjectFilesystem projectFilesystem = getProjectFilesystem();
return new SwiftCompileStep(projectFilesystem.getRootPath(), ImmutableMap.of(), compilerCommand.build());
}
Aggregations