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()))));
}
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);
}
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);
}
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);
}
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);
}
Aggregations