Search in sources :

Example 96 with PathSourcePath

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

the class CxxLibraryDescriptionTest method locationMacroExpandedExportedPlatformLinkerFlagNoPlatformMatch.

@Test
public void locationMacroExpandedExportedPlatformLinkerFlagNoPlatformMatch() throws Exception {
    BuildTarget location = BuildTargetFactory.newInstance("//:loc");
    BuildTarget target = BuildTargetFactory.newInstance("//foo:bar").withFlavors(CxxLibraryBuilder.createDefaultPlatform().getFlavor());
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    ExportFileBuilder locBuilder = ExportFileBuilder.newExportFileBuilder(location);
    locBuilder.setOut("somewhere.over.the.rainbow");
    CxxLibraryBuilder libBuilder = new CxxLibraryBuilder(target, cxxBuckConfig);
    libBuilder.setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new PathSourcePath(filesystem, Paths.get("test.cpp")))));
    libBuilder.setExportedPlatformLinkerFlags(PatternMatchedCollection.<ImmutableList<StringWithMacros>>builder().add(Pattern.compile("notarealplatform"), ImmutableList.of(StringWithMacrosUtils.format("-Wl,--version-script=%s", LocationMacro.of(location)))).build());
    TargetGraph targetGraph = TargetGraphFactory.newInstance(libBuilder.build(), locBuilder.build());
    BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    ExportFile loc = locBuilder.build(resolver, filesystem, targetGraph);
    CxxLibrary lib = (CxxLibrary) libBuilder.build(resolver, filesystem, targetGraph);
    NativeLinkableInput nativeLinkableInput = lib.getNativeLinkableInput(CxxLibraryBuilder.createDefaultPlatform(), Linker.LinkableDepType.SHARED);
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    assertThat(FluentIterable.from(nativeLinkableInput.getArgs()).transformAndConcat(arg -> arg.getDeps(ruleFinder)).toSet(), not(hasItem(loc)));
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    assertThat(Arg.stringify(nativeLinkableInput.getArgs(), pathResolver), not(hasItem(containsString(pathResolver.getRelativePath(Preconditions.checkNotNull(loc.getSourcePathToOutput())).toString()))));
}
Also used : FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ExportFileBuilder(com.facebook.buck.shell.ExportFileBuilder) PathSourcePath(com.facebook.buck.rules.PathSourcePath) TargetGraph(com.facebook.buck.rules.TargetGraph) StringWithMacros(com.facebook.buck.rules.macros.StringWithMacros) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) ExportFile(com.facebook.buck.shell.ExportFile) BuildTarget(com.facebook.buck.model.BuildTarget) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 97 with PathSourcePath

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

the class JvmLibraryArgInterpreterTest method omittingTheCompilerArgMeansThatExistingBehaviourIsMaintained.

@Test
public void omittingTheCompilerArgMeansThatExistingBehaviourIsMaintained() {
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    Path expected = Paths.get("does-not-exist");
    arg.compiler = Optional.empty();
    arg.javacJar = Optional.of(new PathSourcePath(new FakeProjectFilesystem(), expected));
    JavacOptions options = createJavacOptions(arg);
    Javac javac = options.getJavac();
    assertEquals(Optional.of(new PathSourcePath(filesystem, expected)), options.getJavacJarPath());
    assertEquals(Optional.empty(), options.getJavacPath());
    assertTrue(javac.getClass().getName(), javac instanceof Jsr199Javac);
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Path(java.nio.file.Path) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

Example 98 with PathSourcePath

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

the class JvmLibraryArgInterpreterTest method compilerArgTakesPrecedenceOverJavacJarArg.

@Test
public void compilerArgTakesPrecedenceOverJavacJarArg() throws Exception {
    Path javacJarPath = Paths.get("langtools").resolve("javac.jar");
    BuildTarget target = BuildTargetFactory.newInstance("//langtools:javac");
    PrebuiltJarBuilder.createBuilder(target).setBinaryJar(javacJarPath).build(ruleResolver);
    SourcePath sourcePath = new DefaultBuildTargetSourcePath(target);
    Either<BuiltInJavac, SourcePath> either = Either.ofRight(sourcePath);
    arg.compiler = Optional.of(either);
    arg.javacJar = Optional.of(new PathSourcePath(new FakeProjectFilesystem(), Paths.get("does-not-exist")));
    JavacOptions options = createJavacOptions(arg);
    Javac javac = options.getJavac();
    assertEquals(pathResolver.getRelativePath(sourcePath), pathResolver.getRelativePath(options.getJavacJarPath().get()));
    assertEquals(Optional.empty(), options.getJavacPath());
    assertTrue(javac.getClass().getName(), javac instanceof Jsr199Javac);
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Path(java.nio.file.Path) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) BuildTarget(com.facebook.buck.model.BuildTarget) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) PathSourcePath(com.facebook.buck.rules.PathSourcePath) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) Test(org.junit.Test)

Example 99 with PathSourcePath

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

the class PythonPackagedBinaryTest method getRuleKeyForModuleLayout.

private RuleKey getRuleKeyForModuleLayout(DefaultRuleKeyFactory ruleKeyFactory, SourcePathRuleFinder ruleFinder, String main, Path mainSrc, String mod1, Path src1, String mod2, Path src2) throws IOException {
    ProjectFilesystem projectFilesystem = new FakeProjectFilesystem();
    // The top-level python binary that lists the above libraries as deps.
    PythonBinary binary = PythonPackagedBinary.from(new FakeBuildRuleParamsBuilder("//:bin").build(), ruleFinder, PythonTestUtils.PYTHON_PLATFORM, PEX, ImmutableList.of(), new HashedFileTool(Paths.get("dummy_path_to_pex_runner")), ".pex", new PythonEnvironment(Paths.get("fake_python"), PythonVersion.of("CPython", "2.7")), "main", PythonPackageComponents.of(ImmutableMap.of(Paths.get(main), new PathSourcePath(projectFilesystem, mainSrc), Paths.get(mod1), new PathSourcePath(projectFilesystem, src1), Paths.get(mod2), new PathSourcePath(projectFilesystem, src2)), ImmutableMap.of(), ImmutableMap.of(), ImmutableSet.of(), Optional.empty()), ImmutableSortedSet.of(), /* cache */
    true, /* legacyOutputPath */
    false);
    // Calculate and return the rule key.
    return ruleKeyFactory.build(binary);
}
Also used : HashedFileTool(com.facebook.buck.rules.HashedFileTool) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder)

Example 100 with PathSourcePath

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

the class RobolectricTestRuleTest method testRobolectricResourceDependenciesVmArgHasCorrectFormat.

@Test
public void testRobolectricResourceDependenciesVmArgHasCorrectFormat() throws Exception {
    ProjectFilesystem filesystem = new FakeProjectFilesystem(temporaryFolder.getRoot());
    filesystem.mkdirs(Paths.get("res1/values"));
    filesystem.mkdirs(Paths.get("res2/values"));
    filesystem.mkdirs(Paths.get("res3/values"));
    filesystem.mkdirs(Paths.get("res4_to_ignore"));
    Path resDep1 = Paths.get("res1");
    Path resDep2 = Paths.get("res2");
    Path resDep3 = Paths.get("res3");
    Path resDep4 = Paths.get("res4_to_ignore");
    StringBuilder expectedVmArgBuilder = new StringBuilder();
    expectedVmArgBuilder.append("-D").append(RobolectricTest.LIST_OF_RESOURCE_DIRECTORIES_PROPERTY_NAME).append("=").append(resDep1).append(File.pathSeparator).append(resDep2).append(File.pathSeparator).append(resDep3);
    BuildTarget robolectricBuildTarget = BuildTargetFactory.newInstance("//java/src/com/facebook/base/robolectricTest:robolectricTest");
    TargetNode<?, ?> robolectricTestNode = RobolectricTestBuilder.createBuilder(robolectricBuildTarget, filesystem).build();
    TargetGraph targetGraph = TargetGraphFactory.newInstance(robolectricTestNode);
    BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
    RobolectricTest robolectricTest = (RobolectricTest) resolver.requireRule(robolectricBuildTarget);
    String result = robolectricTest.getRobolectricResourceDirectories(pathResolver, ImmutableList.of(new ResourceRule(new PathSourcePath(filesystem, resDep1)), new ResourceRule(new PathSourcePath(filesystem, resDep2)), new ResourceRule(new PathSourcePath(filesystem, resDep3)), new ResourceRule(new PathSourcePath(filesystem, resDep4))));
    assertEquals(expectedVmArgBuilder.toString(), result);
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Path(java.nio.file.Path) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) PathSourcePath(com.facebook.buck.rules.PathSourcePath) TargetGraph(com.facebook.buck.rules.TargetGraph) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) BuildTarget(com.facebook.buck.model.BuildTarget) 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