Search in sources :

Example 81 with SourcePathRuleFinder

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

the class CxxLibraryDescription method createExportedPlatformHeaderSymlinkTreeBuildRule.

/**
   * @return a {@link HeaderSymlinkTree} for the exported headers of this C/C++ library.
   */
private <A extends Arg> HeaderSymlinkTree createExportedPlatformHeaderSymlinkTreeBuildRule(BuildRuleParams params, BuildRuleResolver resolver, CxxPlatform cxxPlatform, A args) throws NoSuchBuildTargetException {
    boolean shouldCreatePublicHeaderSymlinks = args.xcodePublicHeadersSymlinks.orElse(true);
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    return CxxDescriptionEnhancer.createHeaderSymlinkTree(params, resolver, cxxPlatform, CxxDescriptionEnhancer.parseExportedPlatformHeaders(params.getBuildTarget(), resolver, ruleFinder, pathResolver, cxxPlatform, args), HeaderVisibility.PUBLIC, shouldCreatePublicHeaderSymlinks);
}
Also used : SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver)

Example 82 with SourcePathRuleFinder

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

the class DDescriptionUtils method createNativeLinkable.

/**
   * Creates a {@link com.facebook.buck.cxx.NativeLinkable} using sources compiled by
   * the D compiler.
   *
   * @param params build parameters for the build target
   * @param sources source files to compile
   * @param compilerFlags flags to pass to the compiler
   * @param buildRuleResolver resolver for build rules
   * @param cxxPlatform the C++ platform to compile for
   * @param dBuckConfig the Buck configuration for D
   * @return the new build rule
   */
public static CxxLink createNativeLinkable(BuildRuleParams params, BuildRuleResolver buildRuleResolver, CxxPlatform cxxPlatform, DBuckConfig dBuckConfig, CxxBuckConfig cxxBuckConfig, ImmutableList<String> compilerFlags, SourceList sources, ImmutableList<String> linkerFlags, DIncludes includes) throws NoSuchBuildTargetException {
    BuildTarget buildTarget = params.getBuildTarget();
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(buildRuleResolver);
    SourcePathResolver sourcePathResolver = new SourcePathResolver(ruleFinder);
    ImmutableList<SourcePath> sourcePaths = sourcePathsForCompiledSources(params, buildRuleResolver, sourcePathResolver, ruleFinder, cxxPlatform, dBuckConfig, compilerFlags, sources, includes);
    // dependencies.
    return CxxLinkableEnhancer.createCxxLinkableBuildRule(cxxBuckConfig, cxxPlatform, params, buildRuleResolver, sourcePathResolver, ruleFinder, buildTarget, Linker.LinkType.EXECUTABLE, Optional.empty(), BuildTargets.getGenPath(params.getProjectFilesystem(), buildTarget, "%s/" + buildTarget.getShortName()), Linker.LinkableDepType.STATIC, FluentIterable.from(params.getDeps()).filter(NativeLinkable.class), /* cxxRuntimeType */
    Optional.empty(), /* bundleLoader */
    Optional.empty(), ImmutableSet.of(), NativeLinkableInput.builder().addAllArgs(StringArg.from(dBuckConfig.getLinkerFlags())).addAllArgs(StringArg.from(linkerFlags)).addAllArgs(SourcePathArg.from(sourcePaths)).build());
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) BuildTarget(com.facebook.buck.model.BuildTarget) NativeLinkable(com.facebook.buck.cxx.NativeLinkable) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver)

Example 83 with SourcePathRuleFinder

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

the class DTestDescription method createBuildRule.

@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver buildRuleResolver, A args) throws NoSuchBuildTargetException {
    BuildTarget target = params.getBuildTarget();
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(buildRuleResolver);
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    SymlinkTree sourceTree = buildRuleResolver.addToIndex(DDescriptionUtils.createSourceSymlinkTree(DDescriptionUtils.getSymlinkTreeTarget(params.getBuildTarget()), params, ruleFinder, pathResolver, args.srcs));
    // Create a helper rule to build the test binary.
    // The rule needs its own target so that we can depend on it without creating cycles.
    BuildTarget binaryTarget = DDescriptionUtils.createBuildTargetForFile(target, "build-", target.getFullyQualifiedName(), cxxPlatform);
    BuildRule binaryRule = DDescriptionUtils.createNativeLinkable(params.withBuildTarget(binaryTarget), buildRuleResolver, cxxPlatform, dBuckConfig, cxxBuckConfig, ImmutableList.of("-unittest"), args.srcs, args.linkerFlags, DIncludes.builder().setLinkTree(sourceTree.getSourcePathToOutput()).addAllSources(args.srcs.getPaths()).build());
    buildRuleResolver.addToIndex(binaryRule);
    return new DTest(params.copyAppendingExtraDeps(ImmutableList.of(binaryRule)), binaryRule, args.contacts, args.labels, args.testRuleTimeoutMs.map(Optional::of).orElse(defaultTestRuleTimeoutMs));
}
Also used : SymlinkTree(com.facebook.buck.rules.SymlinkTree) Optional(java.util.Optional) BuildTarget(com.facebook.buck.model.BuildTarget) BuildRule(com.facebook.buck.rules.BuildRule) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver)

Example 84 with SourcePathRuleFinder

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

the class PrebuiltCxxLibraryDescription method createSharedLibraryInterface.

private <A extends Arg> BuildRule createSharedLibraryInterface(BuildTarget baseTarget, BuildRuleParams baseParams, BuildRuleResolver resolver, CxxPlatform cxxPlatform, Optional<String> versionSubdir, A args) throws NoSuchBuildTargetException {
    if (!args.supportsSharedLibraryInterface) {
        throw new HumanReadableException("%s: rule does not support shared library interfaces", baseTarget, cxxPlatform.getFlavor());
    }
    Optional<SharedLibraryInterfaceFactory> factory = cxxPlatform.getSharedLibraryInterfaceFactory();
    if (!factory.isPresent()) {
        throw new HumanReadableException("%s: C/C++ platform %s does not support shared library interfaces", baseTarget, cxxPlatform.getFlavor());
    }
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    SourcePath sharedLibrary = requireSharedLibrary(baseTarget, resolver, pathResolver, baseParams.getCellRoots(), baseParams.getProjectFilesystem(), cxxPlatform, versionSubdir, args);
    return factory.get().createSharedInterfaceLibrary(baseTarget.withAppendedFlavors(Type.SHARED_INTERFACE.getFlavor(), cxxPlatform.getFlavor()), baseParams, resolver, pathResolver, ruleFinder, sharedLibrary);
}
Also used : PathSourcePath(com.facebook.buck.rules.PathSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) BuildTargetSourcePath(com.facebook.buck.rules.BuildTargetSourcePath) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) HumanReadableException(com.facebook.buck.util.HumanReadableException) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver)

Example 85 with SourcePathRuleFinder

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

the class DBinaryDescription method createBuildRule.

@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver buildRuleResolver, A args) throws NoSuchBuildTargetException {
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(buildRuleResolver);
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    SymlinkTree sourceTree = buildRuleResolver.addToIndex(DDescriptionUtils.createSourceSymlinkTree(DDescriptionUtils.getSymlinkTreeTarget(params.getBuildTarget()), params, ruleFinder, pathResolver, args.srcs));
    // Create a rule that actually builds the binary, and add that
    // rule to the index.
    CxxLink nativeLinkable = DDescriptionUtils.createNativeLinkable(params.withAppendedFlavor(BINARY_FLAVOR), buildRuleResolver, cxxPlatform, dBuckConfig, cxxBuckConfig, /* compilerFlags */
    ImmutableList.of(), args.srcs, args.linkerFlags, DIncludes.builder().setLinkTree(sourceTree.getSourcePathToOutput()).addAllSources(args.srcs.getPaths()).build());
    buildRuleResolver.addToIndex(nativeLinkable);
    // Create a Tool for the executable.
    CommandTool.Builder executableBuilder = new CommandTool.Builder();
    executableBuilder.addArg(SourcePathArg.of(nativeLinkable.getSourcePathToOutput()));
    // with buck run etc.
    return new DBinary(params.copyReplacingExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of(nativeLinkable))), ruleFinder, executableBuilder.build(), nativeLinkable.getSourcePathToOutput());
}
Also used : SymlinkTree(com.facebook.buck.rules.SymlinkTree) CommandTool(com.facebook.buck.rules.CommandTool) CxxLink(com.facebook.buck.cxx.CxxLink) 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