Search in sources :

Example 21 with SourcePathRuleFinder

use of com.facebook.buck.rules.SourcePathRuleFinder in project buck by facebook.

the class HalideLibraryDescription method createBuildRule.

@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver, A args) throws NoSuchBuildTargetException {
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    BuildTarget target = params.getBuildTarget();
    ImmutableSet<Flavor> flavors = ImmutableSet.copyOf(target.getFlavors());
    CxxPlatform cxxPlatform = cxxPlatforms.getValue(flavors).orElse(defaultCxxPlatform);
    if (flavors.contains(CxxDescriptionEnhancer.EXPORTED_HEADER_SYMLINK_TREE_FLAVOR)) {
        ImmutableMap.Builder<Path, SourcePath> headersBuilder = ImmutableMap.builder();
        BuildTarget compileTarget = resolver.requireRule(target.withFlavors(HALIDE_COMPILE_FLAVOR, cxxPlatform.getFlavor())).getBuildTarget();
        Path outputPath = HalideCompile.headerOutputPath(compileTarget, params.getProjectFilesystem(), args.functionName);
        headersBuilder.put(outputPath.getFileName(), new ExplicitBuildTargetSourcePath(compileTarget, outputPath));
        return CxxDescriptionEnhancer.createHeaderSymlinkTree(params, resolver, cxxPlatform, headersBuilder.build(), HeaderVisibility.PUBLIC, true);
    } else if (flavors.contains(CxxDescriptionEnhancer.SANDBOX_TREE_FLAVOR)) {
        CxxPlatform hostCxxPlatform = cxxPlatforms.getValue(CxxPlatforms.getHostFlavor());
        return CxxDescriptionEnhancer.createSandboxTreeBuildRule(resolver, args, hostCxxPlatform, params);
    } else if (flavors.contains(HALIDE_COMPILER_FLAVOR)) {
        // We always want to build the halide "compiler" for the host platform, so
        // we use the host flavor here, regardless of the flavors on the build
        // target.
        CxxPlatform hostCxxPlatform = cxxPlatforms.getValue(CxxPlatforms.getHostFlavor());
        final ImmutableSortedSet<BuildTarget> compilerDeps = args.compilerDeps;
        return createHalideCompiler(params.withAppendedFlavor(HALIDE_COMPILER_FLAVOR).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(resolver.getAllRules(compilerDeps)), Suppliers.ofInstance(ImmutableSortedSet.of())), resolver, pathResolver, ruleFinder, hostCxxPlatform, args.srcs, args.compilerFlags, args.platformCompilerFlags, args.langCompilerFlags, args.linkerFlags, args.platformLinkerFlags, args.includeDirs);
    } else if (flavors.contains(CxxDescriptionEnhancer.STATIC_FLAVOR) || flavors.contains(CxxDescriptionEnhancer.STATIC_PIC_FLAVOR)) {
        // See: https://github.com/halide/Halide/blob/e3c301f3/src/LLVM_Output.cpp#L152
        return createHalideStaticLibrary(params, resolver, ruleFinder, cxxPlatform, args);
    } else if (flavors.contains(CxxDescriptionEnhancer.SHARED_FLAVOR)) {
        throw new HumanReadableException("halide_library '%s' does not support shared libraries as output", params.getBuildTarget());
    } else if (flavors.contains(HALIDE_COMPILE_FLAVOR)) {
        return createHalideCompile(params.copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of()), Suppliers.ofInstance(ImmutableSortedSet.of())), resolver, cxxPlatform, Optional.of(args.compilerInvocationFlags), args.functionName);
    }
    return new HalideLibrary(params, resolver, args.supportedPlatformsRegex);
}
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) CxxPlatform(com.facebook.buck.cxx.CxxPlatform) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) InternalFlavor(com.facebook.buck.model.InternalFlavor) Flavor(com.facebook.buck.model.Flavor) ImmutableMap(com.google.common.collect.ImmutableMap) SourcePath(com.facebook.buck.rules.SourcePath) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) BuildTarget(com.facebook.buck.model.BuildTarget) HumanReadableException(com.facebook.buck.util.HumanReadableException) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath)

Example 22 with SourcePathRuleFinder

use of com.facebook.buck.rules.SourcePathRuleFinder in project buck by facebook.

the class CxxLuaExtensionDescription method createExtensionBuildRule.

private <A extends Arg> BuildRule createExtensionBuildRule(BuildRuleParams params, BuildRuleResolver ruleResolver, CxxPlatform cxxPlatform, A args) throws NoSuchBuildTargetException {
    if (params.getBuildTarget().getFlavors().contains(CxxDescriptionEnhancer.SANDBOX_TREE_FLAVOR)) {
        return CxxDescriptionEnhancer.createSandboxTreeBuildRule(ruleResolver, args, cxxPlatform, params);
    }
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    String extensionName = getExtensionName(params.getBuildTarget(), cxxPlatform);
    Path extensionPath = getExtensionPath(params.getProjectFilesystem(), params.getBuildTarget(), cxxPlatform);
    return CxxLinkableEnhancer.createCxxLinkableBuildRule(cxxBuckConfig, cxxPlatform, params, ruleResolver, pathResolver, ruleFinder, getExtensionTarget(params.getBuildTarget(), cxxPlatform.getFlavor()), Linker.LinkType.SHARED, Optional.of(extensionName), extensionPath, Linker.LinkableDepType.SHARED, FluentIterable.from(params.getDeps()).filter(NativeLinkable.class).append(luaConfig.getLuaCxxLibrary(ruleResolver)), args.cxxRuntimeType, Optional.empty(), ImmutableSet.of(), NativeLinkableInput.builder().setArgs(getExtensionArgs(params.withoutFlavor(LinkerMapMode.NO_LINKER_MAP.getFlavor()), ruleResolver, pathResolver, ruleFinder, cxxPlatform, args)).build());
}
Also used : Path(java.nio.file.Path) SourcePath(com.facebook.buck.rules.SourcePath) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver)

Example 23 with SourcePathRuleFinder

use of com.facebook.buck.rules.SourcePathRuleFinder in project buck by facebook.

the class ScalaTestDescription method createBuildRule.

@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, final BuildRuleParams rawParams, final BuildRuleResolver resolver, A args) throws NoSuchBuildTargetException {
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    if (CalculateAbi.isAbiTarget(rawParams.getBuildTarget())) {
        BuildTarget testTarget = CalculateAbi.getLibraryTarget(rawParams.getBuildTarget());
        BuildRule testRule = resolver.requireRule(testTarget);
        return CalculateAbi.of(rawParams.getBuildTarget(), ruleFinder, rawParams, Preconditions.checkNotNull(testRule.getSourcePathToOutput()));
    }
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    final BuildRule scalaLibrary = resolver.getRule(config.getScalaLibraryTarget());
    BuildRuleParams params = rawParams.copyReplacingDeclaredAndExtraDeps(() -> ImmutableSortedSet.<BuildRule>naturalOrder().addAll(rawParams.getDeclaredDeps().get()).add(scalaLibrary).build(), rawParams.getExtraDeps());
    JavaTestDescription.CxxLibraryEnhancement cxxLibraryEnhancement = new JavaTestDescription.CxxLibraryEnhancement(params, args.useCxxLibraries, args.cxxLibraryWhitelist, resolver, ruleFinder, cxxPlatform);
    params = cxxLibraryEnhancement.updatedParams;
    Tool scalac = config.getScalac(resolver);
    BuildRuleParams javaLibraryParams = params.copyAppendingExtraDeps(Iterables.concat(BuildRules.getExportedRules(Iterables.concat(params.getDeclaredDeps().get(), resolver.getAllRules(args.providedDeps))), scalac.getDeps(ruleFinder))).withAppendedFlavor(JavaTest.COMPILED_TESTS_LIBRARY_FLAVOR);
    JavaLibrary testsLibrary = resolver.addToIndex(new DefaultJavaLibrary(javaLibraryParams, pathResolver, ruleFinder, args.srcs, ResourceValidator.validateResources(pathResolver, params.getProjectFilesystem(), args.resources), /* generatedSourceFolderName */
    Optional.empty(), /* proguardConfig */
    Optional.empty(), /* postprocessClassesCommands */
    ImmutableList.of(), /* exportDeps */
    ImmutableSortedSet.of(), /* providedDeps */
    ImmutableSortedSet.of(), JavaLibraryRules.getAbiInputs(resolver, javaLibraryParams.getDeps()), /* trackClassUsage */
    false, /* additionalClasspathEntries */
    ImmutableSet.of(), new ScalacToJarStepFactory(scalac, config.getCompilerFlags(), args.extraArguments, ImmutableSet.of()), args.resourcesRoot, args.manifestFile, args.mavenCoords, /* tests */
    ImmutableSortedSet.of(), /* classesToRemoveFromJar */
    ImmutableSet.of()));
    return new JavaTest(params.copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of(testsLibrary)), Suppliers.ofInstance(ImmutableSortedSet.of())), pathResolver, testsLibrary, /* additionalClasspathEntries */
    ImmutableSet.of(), args.labels, args.contacts, args.testType.orElse(TestType.JUNIT), javaOptions.getJavaRuntimeLauncher(), args.vmArgs, cxxLibraryEnhancement.nativeLibsEnvironment, args.testRuleTimeoutMs.map(Optional::of).orElse(defaultTestRuleTimeoutMs), args.testCaseTimeoutMs, args.env, args.runTestSeparately.orElse(false), args.forkMode.orElse(ForkMode.NONE), args.stdOutLogLevel, args.stdErrLogLevel);
}
Also used : Optional(java.util.Optional) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) DefaultJavaLibrary(com.facebook.buck.jvm.java.DefaultJavaLibrary) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) JavaLibrary(com.facebook.buck.jvm.java.JavaLibrary) DefaultJavaLibrary(com.facebook.buck.jvm.java.DefaultJavaLibrary) BuildTarget(com.facebook.buck.model.BuildTarget) JavaTestDescription(com.facebook.buck.jvm.java.JavaTestDescription) JavaTest(com.facebook.buck.jvm.java.JavaTest) BuildRule(com.facebook.buck.rules.BuildRule) Tool(com.facebook.buck.rules.Tool)

Example 24 with SourcePathRuleFinder

use of com.facebook.buck.rules.SourcePathRuleFinder in project buck by facebook.

the class ShTestDescription method createBuildRule.

@Override
public <A extends Arg> ShTest createBuildRule(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver, A args) {
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    Function<String, com.facebook.buck.rules.args.Arg> toArg = MacroArg.toMacroArgFunction(MACRO_HANDLER, params.getBuildTarget(), params.getCellRoots(), resolver);
    final ImmutableList<com.facebook.buck.rules.args.Arg> testArgs = args.args.stream().map(toArg::apply).collect(MoreCollectors.toImmutableList());
    final ImmutableMap<String, com.facebook.buck.rules.args.Arg> testEnv = ImmutableMap.copyOf(Maps.transformValues(args.env, toArg));
    return new ShTest(params.copyAppendingExtraDeps(() -> FluentIterable.from(testArgs).append(testEnv.values()).transformAndConcat(arg -> arg.getDeps(ruleFinder))), ruleFinder, args.test, testArgs, testEnv, FluentIterable.from(args.resources).transform(p -> new PathSourcePath(params.getProjectFilesystem(), p)).toSortedSet(Ordering.natural()), args.testRuleTimeoutMs.map(Optional::of).orElse(defaultTestRuleTimeoutMs), args.runTestSeparately.orElse(false), args.labels, args.contacts);
}
Also used : Optional(java.util.Optional) MacroArg(com.facebook.buck.rules.args.MacroArg) AbstractDescriptionArg(com.facebook.buck.rules.AbstractDescriptionArg) PathSourcePath(com.facebook.buck.rules.PathSourcePath) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder)

Example 25 with SourcePathRuleFinder

use of com.facebook.buck.rules.SourcePathRuleFinder in project buck by facebook.

the class ExportFileDescription method createBuildRule.

@Override
public <A extends Arg> ExportFile createBuildRule(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver, A args) {
    BuildTarget target = params.getBuildTarget();
    Mode mode = args.mode.orElse(Mode.COPY);
    String name;
    if (args.out.isPresent()) {
        if (mode == ExportFileDescription.Mode.REFERENCE) {
            throw new HumanReadableException("%s: must not set `out` for `export_file` when using `REFERENCE` mode", params.getBuildTarget());
        }
        name = args.out.get();
    } else {
        name = target.getShortNameAndFlavorPostfix();
    }
    SourcePath src;
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    if (args.src.isPresent()) {
        if (mode == ExportFileDescription.Mode.REFERENCE && !pathResolver.getFilesystem(args.src.get()).equals(params.getProjectFilesystem())) {
            throw new HumanReadableException("%s: must use `COPY` mode for `export_file` when source (%s) uses a different cell", target, args.src.get());
        }
        src = args.src.get();
    } else {
        src = new PathSourcePath(params.getProjectFilesystem(), target.getBasePath().resolve(target.getShortNameAndFlavorPostfix()));
    }
    return new ExportFile(params, ruleFinder, pathResolver, name, mode, src);
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) BuildTarget(com.facebook.buck.model.BuildTarget) HumanReadableException(com.facebook.buck.util.HumanReadableException) PathSourcePath(com.facebook.buck.rules.PathSourcePath) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver)

Aggregations

SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)517 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)466 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)405 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)376 Test (org.junit.Test)352 BuildTarget (com.facebook.buck.model.BuildTarget)250 BuildRule (com.facebook.buck.rules.BuildRule)188 SourcePath (com.facebook.buck.rules.SourcePath)151 Path (java.nio.file.Path)151 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)149 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)139 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)131 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)94 PathSourcePath (com.facebook.buck.rules.PathSourcePath)92 TargetGraph (com.facebook.buck.rules.TargetGraph)91 FakeBuildRuleParamsBuilder (com.facebook.buck.rules.FakeBuildRuleParamsBuilder)87 FakeBuildRule (com.facebook.buck.rules.FakeBuildRule)73 RuleKey (com.facebook.buck.rules.RuleKey)72 ImmutableList (com.google.common.collect.ImmutableList)52 ExecutionContext (com.facebook.buck.step.ExecutionContext)50