Search in sources :

Example 61 with PathSourcePath

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

the class HeaderPathNormalizerTest method managedHeaderDir.

@Test
public void managedHeaderDir() {
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer())));
    Path header = filesystem.getPath("foo/bar.h");
    SourcePath headerDirPath = new PathSourcePath(filesystem, header.getParent());
    HeaderPathNormalizer normalizer = new HeaderPathNormalizer.Builder(pathResolver).addHeaderDir(headerDirPath).build();
    assertThat(normalizer.getAbsolutePathForUnnormalizedPath(pathResolver.getAbsolutePath(headerDirPath)), Matchers.equalTo(Optional.of(pathResolver.getAbsolutePath(headerDirPath))));
    assertThat(normalizer.getAbsolutePathForUnnormalizedPath(filesystem.resolve(header)), Matchers.equalTo(Optional.of(filesystem.resolve(header))));
    assertThat(normalizer.getSourcePathForAbsolutePath(pathResolver.getAbsolutePath(headerDirPath)), Matchers.equalTo(headerDirPath));
    assertThat(normalizer.getSourcePathForAbsolutePath(filesystem.resolve(header)), Matchers.equalTo(headerDirPath));
}
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) PathSourcePath(com.facebook.buck.rules.PathSourcePath) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 62 with PathSourcePath

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

the class FakeJavaLibrary method setJavaSrcs.

public FakeJavaLibrary setJavaSrcs(ImmutableSortedSet<Path> srcs) {
    Preconditions.checkNotNull(srcs);
    this.srcs = FluentIterable.from(srcs).transform(p -> (SourcePath) new PathSourcePath(new FakeProjectFilesystem(), p)).toSortedSet(Ordering.natural());
    return this;
}
Also used : FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) PathSourcePath(com.facebook.buck.rules.PathSourcePath)

Example 63 with PathSourcePath

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

the class CxxTestDescription method createBuildRule.

@SuppressWarnings("PMD.PrematureDeclaration")
@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams inputParams, final BuildRuleResolver resolver, final A args) throws NoSuchBuildTargetException {
    Optional<StripStyle> flavoredStripStyle = StripStyle.FLAVOR_DOMAIN.getValue(inputParams.getBuildTarget());
    Optional<LinkerMapMode> flavoredLinkerMapMode = LinkerMapMode.FLAVOR_DOMAIN.getValue(inputParams.getBuildTarget());
    inputParams = CxxStrip.removeStripStyleFlavorInParams(inputParams, flavoredStripStyle);
    inputParams = LinkerMapMode.removeLinkerMapModeFlavorInParams(inputParams, flavoredLinkerMapMode);
    final BuildRuleParams params = inputParams;
    Optional<CxxPlatform> platform = cxxPlatforms.getValue(params.getBuildTarget());
    CxxPlatform cxxPlatform = platform.orElse(defaultCxxPlatform);
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    if (params.getBuildTarget().getFlavors().contains(CxxCompilationDatabase.COMPILATION_DATABASE)) {
        BuildRuleParams paramsWithoutFlavor = params.withoutFlavor(CxxCompilationDatabase.COMPILATION_DATABASE);
        CxxLinkAndCompileRules cxxLinkAndCompileRules = CxxDescriptionEnhancer.createBuildRulesForCxxBinaryDescriptionArg(targetGraph, paramsWithoutFlavor, resolver, cxxBuckConfig, cxxPlatform, args, flavoredStripStyle, flavoredLinkerMapMode);
        return CxxCompilationDatabase.createCompilationDatabase(params, cxxLinkAndCompileRules.compileRules);
    }
    if (params.getBuildTarget().getFlavors().contains(CxxCompilationDatabase.UBER_COMPILATION_DATABASE)) {
        return CxxDescriptionEnhancer.createUberCompilationDatabase(platform.isPresent() ? params : params.withAppendedFlavor(cxxPlatform.getFlavor()), resolver);
    }
    if (params.getBuildTarget().getFlavors().contains(CxxDescriptionEnhancer.SANDBOX_TREE_FLAVOR)) {
        return CxxDescriptionEnhancer.createSandboxTreeBuildRule(resolver, args, cxxPlatform, params);
    }
    // Generate the link rule that builds the test binary.
    final CxxLinkAndCompileRules cxxLinkAndCompileRules = CxxDescriptionEnhancer.createBuildRulesForCxxBinaryDescriptionArg(targetGraph, params, resolver, cxxBuckConfig, cxxPlatform, args, flavoredStripStyle, flavoredLinkerMapMode);
    // Construct the actual build params we'll use, notably with an added dependency on the
    // CxxLink rule above which builds the test binary.
    BuildRuleParams testParams = params.copyReplacingDeclaredAndExtraDeps(() -> cxxLinkAndCompileRules.deps, params.getExtraDeps()).copyAppendingExtraDeps(cxxLinkAndCompileRules.executable.getDeps(ruleFinder));
    testParams = CxxStrip.restoreStripStyleFlavorInParams(testParams, flavoredStripStyle);
    testParams = LinkerMapMode.restoreLinkerMapModeFlavorInParams(testParams, flavoredLinkerMapMode);
    // Supplier which expands macros in the passed in test environment.
    ImmutableMap<String, String> testEnv = ImmutableMap.copyOf(Maps.transformValues(args.env, CxxDescriptionEnhancer.MACRO_HANDLER.getExpander(params.getBuildTarget(), params.getCellRoots(), resolver)));
    // Supplier which expands macros in the passed in test arguments.
    Supplier<ImmutableList<String>> testArgs = () -> args.args.stream().map(CxxDescriptionEnhancer.MACRO_HANDLER.getExpander(params.getBuildTarget(), params.getCellRoots(), resolver)::apply).collect(MoreCollectors.toImmutableList());
    Supplier<ImmutableSortedSet<BuildRule>> additionalDeps = () -> {
        ImmutableSortedSet.Builder<BuildRule> deps = ImmutableSortedSet.naturalOrder();
        // It's not uncommon for users to add dependencies onto other binaries that they run
        // during the test, so make sure to add them as runtime deps.
        deps.addAll(Sets.difference(params.getDeps(), cxxLinkAndCompileRules.getBinaryRule().getDeps()));
        // Add any build-time from any macros embedded in the `env` or `args` parameter.
        for (String part : Iterables.concat(args.args, args.env.values())) {
            try {
                deps.addAll(CxxDescriptionEnhancer.MACRO_HANDLER.extractBuildTimeDeps(params.getBuildTarget(), params.getCellRoots(), resolver, part));
            } catch (MacroException e) {
                throw new HumanReadableException(e, "%s: %s", params.getBuildTarget(), e.getMessage());
            }
        }
        return deps.build();
    };
    CxxTest test;
    CxxTestType type = args.framework.orElse(getDefaultTestType());
    switch(type) {
        case GTEST:
            {
                test = new CxxGtestTest(testParams, ruleFinder, cxxLinkAndCompileRules.getBinaryRule(), cxxLinkAndCompileRules.executable, testEnv, testArgs, FluentIterable.from(args.resources).transform(p -> new PathSourcePath(params.getProjectFilesystem(), p)).toSortedSet(Ordering.natural()), additionalDeps, args.labels, args.contacts, args.runTestSeparately.orElse(false), args.testRuleTimeoutMs.map(Optional::of).orElse(defaultTestRuleTimeoutMs), cxxBuckConfig.getMaximumTestOutputSize());
                break;
            }
        case BOOST:
            {
                test = new CxxBoostTest(testParams, ruleFinder, cxxLinkAndCompileRules.getBinaryRule(), cxxLinkAndCompileRules.executable, testEnv, testArgs, FluentIterable.from(args.resources).transform(p -> new PathSourcePath(params.getProjectFilesystem(), p)).toSortedSet(Ordering.natural()), additionalDeps, args.labels, args.contacts, args.runTestSeparately.orElse(false), args.testRuleTimeoutMs.map(Optional::of).orElse(defaultTestRuleTimeoutMs));
                break;
            }
        default:
            {
                Preconditions.checkState(false, "Unhandled C++ test type: %s", type);
                throw new RuntimeException();
            }
    }
    return test;
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) Optional(java.util.Optional) PathSourcePath(com.facebook.buck.rules.PathSourcePath) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) HumanReadableException(com.facebook.buck.util.HumanReadableException) MacroException(com.facebook.buck.model.MacroException)

Example 64 with PathSourcePath

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

the class AaptPackageResourcesTest method setUp.

@Before
public void setUp() throws NoSuchBuildTargetException {
    filesystem = new FakeProjectFilesystem();
    TargetNode<?, ?> resourceNode = AndroidResourceBuilder.createBuilder(BuildTargetFactory.newInstance("//:resource1"), filesystem).setRDotJavaPackage("package1").setRes(Paths.get("res1")).setAssets(new PathSourcePath(filesystem, Paths.get("asset1"))).build();
    TargetNode<?, ?> resourceNode2 = AndroidResourceBuilder.createBuilder(BuildTargetFactory.newInstance("//:resource2"), filesystem).setRDotJavaPackage("package2").setRes(Paths.get("res2")).setAssets(new PathSourcePath(filesystem, Paths.get("asset2"))).build();
    TargetNode<?, ?> assetsNode = AndroidResourceBuilder.createBuilder(BuildTargetFactory.newInstance("//:assets"), filesystem).setAssets(new PathSourcePath(filesystem, Paths.get("justAssets"))).build();
    TargetGraph targetGraph = TargetGraphFactory.newInstance(resourceNode, resourceNode2, assetsNode);
    ruleResolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    resource1 = (AndroidResource) ruleResolver.requireRule(resourceNode.getBuildTarget());
    resource2 = (AndroidResource) ruleResolver.requireRule(resourceNode2.getBuildTarget());
    justAssets = (AndroidResource) ruleResolver.requireRule(assetsNode.getBuildTarget());
    ruleFinder = new SourcePathRuleFinder(ruleResolver);
    pathResolver = new SourcePathResolver(ruleFinder);
    aaptTarget = BuildTargetFactory.newInstance("//foo:bar");
    params = new FakeBuildRuleParamsBuilder(aaptTarget).build();
    hashCache = new FakeFileHashCache(new HashMap<>());
    createPathSourcePath("res1", "resources1");
    createPathSourcePath("res2", "resources2");
    createPathSourcePath("res3", "resources3");
    createPathSourcePath("asset1", "assets1");
    createPathSourcePath("asset2", "assets2");
    createPathSourcePath("justAssets", "justAssets");
}
Also used : FakeFileHashCache(com.facebook.buck.testutil.FakeFileHashCache) HashMap(java.util.HashMap) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) PathSourcePath(com.facebook.buck.rules.PathSourcePath) TargetGraph(com.facebook.buck.rules.TargetGraph) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Before(org.junit.Before)

Example 65 with PathSourcePath

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

the class CxxLibraryDescriptionTest method staticPicLibUsedForStaticPicLinkage.

@Test
public void staticPicLibUsedForStaticPicLinkage() throws Exception {
    BuildTarget target = BuildTargetFactory.newInstance("//foo:bar");
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    CxxLibraryBuilder libBuilder = new CxxLibraryBuilder(target, cxxBuckConfig);
    libBuilder.setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new PathSourcePath(filesystem, Paths.get("test.cpp")))));
    TargetGraph targetGraph = TargetGraphFactory.newInstance(libBuilder.build());
    BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    CxxLibrary lib = (CxxLibrary) libBuilder.build(resolver, filesystem, targetGraph);
    NativeLinkableInput nativeLinkableInput = lib.getNativeLinkableInput(CxxLibraryBuilder.createDefaultPlatform(), Linker.LinkableDepType.STATIC_PIC);
    Arg firstArg = nativeLinkableInput.getArgs().get(0);
    assertThat(firstArg, instanceOf(FileListableLinkerInputArg.class));
    ImmutableCollection<BuildRule> deps = firstArg.getDeps(new SourcePathRuleFinder(resolver));
    assertThat(deps.size(), is(1));
    BuildRule buildRule = deps.asList().get(0);
    assertThat(buildRule.getBuildTarget().getFlavors(), hasItem(CxxDescriptionEnhancer.STATIC_PIC_FLAVOR));
}
Also used : FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) PathSourcePath(com.facebook.buck.rules.PathSourcePath) TargetGraph(com.facebook.buck.rules.TargetGraph) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) FileListableLinkerInputArg(com.facebook.buck.rules.args.FileListableLinkerInputArg) BuildTarget(com.facebook.buck.model.BuildTarget) StringArg(com.facebook.buck.rules.args.StringArg) FileListableLinkerInputArg(com.facebook.buck.rules.args.FileListableLinkerInputArg) Arg(com.facebook.buck.rules.args.Arg) BuildRule(com.facebook.buck.rules.BuildRule) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Aggregations

PathSourcePath (com.facebook.buck.rules.PathSourcePath)114 Test (org.junit.Test)82 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)69 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)68 SourcePath (com.facebook.buck.rules.SourcePath)65 Path (java.nio.file.Path)63 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)60 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)58 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)56 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)52 BuildTarget (com.facebook.buck.model.BuildTarget)51 TargetGraph (com.facebook.buck.rules.TargetGraph)37 BuildRule (com.facebook.buck.rules.BuildRule)26 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)23 DefaultBuildTargetSourcePath (com.facebook.buck.rules.DefaultBuildTargetSourcePath)21 StackedFileHashCache (com.facebook.buck.util.cache.StackedFileHashCache)16 RuleKey (com.facebook.buck.rules.RuleKey)15 DefaultFileHashCache (com.facebook.buck.util.cache.DefaultFileHashCache)15 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)14 ImmutableList (com.google.common.collect.ImmutableList)14