Search in sources :

Example 86 with SourcePath

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();
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) WriteFile(com.facebook.buck.file.WriteFile) BuildTarget(com.facebook.buck.model.BuildTarget)

Example 87 with SourcePath

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());
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) SymlinkTree(com.facebook.buck.rules.SymlinkTree) WindowsLinker(com.facebook.buck.cxx.WindowsLinker) HumanReadableException(com.facebook.buck.util.HumanReadableException) BuildTarget(com.facebook.buck.model.BuildTarget)

Example 88 with SourcePath

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();
}
Also used : ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) NativeLinkableInput(com.facebook.buck.cxx.NativeLinkableInput) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath)

Example 89 with SourcePath

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);
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) Path(java.nio.file.Path) SourcePath(com.facebook.buck.rules.SourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) TargetGraph(com.facebook.buck.rules.TargetGraph) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePath(com.facebook.buck.rules.SourcePath) VersionPropagator(com.facebook.buck.versions.VersionPropagator) BuildTarget(com.facebook.buck.model.BuildTarget) SuppressFieldNotInitialized(com.facebook.infer.annotation.SuppressFieldNotInitialized) AbstractDescriptionArg(com.facebook.buck.rules.AbstractDescriptionArg) ImmutableList(com.google.common.collect.ImmutableList) PathSourcePath(com.facebook.buck.rules.PathSourcePath) Optional(java.util.Optional) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) Path(java.nio.file.Path) Description(com.facebook.buck.rules.Description) MoreCollectors(com.facebook.buck.util.MoreCollectors) BuildTarget(com.facebook.buck.model.BuildTarget) PathSourcePath(com.facebook.buck.rules.PathSourcePath) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder)

Example 90 with SourcePath

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());
}
Also used : FrameworkPath(com.facebook.buck.rules.coercer.FrameworkPath) SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) Iterables(com.google.common.collect.Iterables) Step(com.facebook.buck.step.Step) SourcePathArg(com.facebook.buck.rules.args.SourcePathArg) FrameworkPath(com.facebook.buck.rules.coercer.FrameworkPath) SourcePath(com.facebook.buck.rules.SourcePath) CxxHeaders(com.facebook.buck.cxx.CxxHeaders) MkdirStep(com.facebook.buck.step.fs.MkdirStep) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) BuildRule(com.facebook.buck.rules.BuildRule) Tool(com.facebook.buck.rules.Tool) ImmutableList(com.google.common.collect.ImmutableList) CxxPreprocessables(com.facebook.buck.cxx.CxxPreprocessables) NoSuchBuildTargetException(com.facebook.buck.parser.NoSuchBuildTargetException) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) StringArg(com.facebook.buck.rules.args.StringArg) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) Path(java.nio.file.Path) CxxDescriptionEnhancer(com.facebook.buck.cxx.CxxDescriptionEnhancer) LinkedHashSet(java.util.LinkedHashSet) MoreCollectors(com.facebook.buck.util.MoreCollectors) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) FileListableLinkerInputArg(com.facebook.buck.rules.args.FileListableLinkerInputArg) Function(com.google.common.base.Function) ImmutableSet(com.google.common.collect.ImmutableSet) AddToRuleKey(com.facebook.buck.rules.AddToRuleKey) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) ImmutableMap(com.google.common.collect.ImmutableMap) BuildableContext(com.facebook.buck.rules.BuildableContext) CxxPlatform(com.facebook.buck.cxx.CxxPlatform) BuildTarget(com.facebook.buck.model.BuildTarget) HeaderVisibility(com.facebook.buck.cxx.HeaderVisibility) AbstractBuildRule(com.facebook.buck.rules.AbstractBuildRule) LinkerMapMode(com.facebook.buck.cxx.LinkerMapMode) Arg(com.facebook.buck.rules.args.Arg) CxxPreprocessorInput(com.facebook.buck.cxx.CxxPreprocessorInput) BuildContext(com.facebook.buck.rules.BuildContext) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) MoreIterables(com.facebook.buck.util.MoreIterables) ImmutableList(com.google.common.collect.ImmutableList) FrameworkPath(com.facebook.buck.rules.coercer.FrameworkPath) SourcePath(com.facebook.buck.rules.SourcePath) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) BuildRule(com.facebook.buck.rules.BuildRule) AbstractBuildRule(com.facebook.buck.rules.AbstractBuildRule) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem)

Aggregations

SourcePath (com.facebook.buck.rules.SourcePath)285 Path (java.nio.file.Path)151 BuildTarget (com.facebook.buck.model.BuildTarget)111 Test (org.junit.Test)105 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)102 PathSourcePath (com.facebook.buck.rules.PathSourcePath)100 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)96 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)90 BuildRule (com.facebook.buck.rules.BuildRule)79 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)69 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)69 ExplicitBuildTargetSourcePath (com.facebook.buck.rules.ExplicitBuildTargetSourcePath)64 ImmutableList (com.google.common.collect.ImmutableList)64 DefaultBuildTargetSourcePath (com.facebook.buck.rules.DefaultBuildTargetSourcePath)53 ImmutableMap (com.google.common.collect.ImmutableMap)48 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)43 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)42 HumanReadableException (com.facebook.buck.util.HumanReadableException)39 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)37 ImmutableSet (com.google.common.collect.ImmutableSet)34