use of com.facebook.buck.testutil.FakeProjectFilesystem in project buck by facebook.
the class PrebuiltCxxLibraryDescriptionTest method findDepsFromParamsWithLocation.
@Test
public void findDepsFromParamsWithLocation() throws NoSuchBuildTargetException {
BuildTarget genTarget = BuildTargetFactory.newInstance("//other:gen_lib");
GenruleBuilder genruleBuilder = GenruleBuilder.newGenruleBuilder(genTarget).setOut("lib_dir");
PrebuiltCxxLibraryBuilder builder = new PrebuiltCxxLibraryBuilder(TARGET);
builder.setSoname("test");
builder.setLibDir("$(location //other:gen_lib)");
TargetGraph targetGraph = TargetGraphFactory.newInstance(genruleBuilder.build(), builder.build());
ProjectFilesystem filesystem = new FakeProjectFilesystem();
BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
BuildRule genrule = genruleBuilder.build(resolver, filesystem, targetGraph);
PrebuiltCxxLibrary lib = (PrebuiltCxxLibrary) builder.build(resolver, filesystem, targetGraph);
Iterable<BuildTarget> implicit = builder.findImplicitDeps();
assertEquals(1, Iterables.size(implicit));
assertTrue(Iterables.contains(implicit, genTarget));
assertThat(lib.getDeps(), Matchers.contains(genrule));
}
use of com.facebook.buck.testutil.FakeProjectFilesystem in project buck by facebook.
the class PrebuiltCxxLibraryDescriptionTest method includesDirs.
@Test
public void includesDirs() throws Exception {
ProjectFilesystem filesystem = new FakeProjectFilesystem();
PrebuiltCxxLibraryBuilder prebuiltCxxLibraryBuilder = new PrebuiltCxxLibraryBuilder(BuildTargetFactory.newInstance("//:r")).setIncludeDirs(ImmutableList.of("include"));
TargetGraph targetGraph = TargetGraphFactory.newInstance(prebuiltCxxLibraryBuilder.build());
BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
PrebuiltCxxLibrary rule = (PrebuiltCxxLibrary) prebuiltCxxLibraryBuilder.build(resolver, filesystem, targetGraph);
assertThat(rule.getCxxPreprocessorInput(CxxPlatformUtils.DEFAULT_PLATFORM, HeaderVisibility.PUBLIC).getIncludes(), Matchers.contains(CxxHeadersDir.of(CxxPreprocessables.IncludeType.SYSTEM, new PathSourcePath(filesystem, rule.getBuildTarget().getBasePath().resolve("include")))));
}
use of com.facebook.buck.testutil.FakeProjectFilesystem in project buck by facebook.
the class ProgressEstimatorTest method testByDefaultProvidesNoProcessingBuckFilesProgress.
@Test
public void testByDefaultProvidesNoProcessingBuckFilesProgress() {
ProjectFilesystem filesystem = new FakeProjectFilesystem();
Path p = filesystem.resolve(ProgressEstimator.PROGRESS_ESTIMATIONS_JSON);
ProgressEstimator e = new ProgressEstimator(p, getBuckEventBus(), MAPPER);
assertThat(e.getEstimatedProgressOfProcessingBuckFiles().isPresent(), Matchers.equalTo(false));
}
use of com.facebook.buck.testutil.FakeProjectFilesystem in project buck by facebook.
the class HalideLibraryDescriptionTest method testCreateBuildRule.
@Test
public void testCreateBuildRule() throws Exception {
// Set up a #halide-compiler rule, then set up a halide_library rule, and
// check that the library rule depends on the compiler rule.
BuildTarget compilerTarget = BuildTargetFactory.newInstance("//:rule").withFlavors(HalideLibraryDescription.HALIDE_COMPILER_FLAVOR);
BuildTarget libTarget = BuildTargetFactory.newInstance("//:rule");
ProjectFilesystem filesystem = new FakeProjectFilesystem();
HalideLibraryBuilder compilerBuilder = new HalideLibraryBuilder(compilerTarget);
compilerBuilder.setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("main.cpp"))));
HalideLibraryBuilder libBuilder = new HalideLibraryBuilder(libTarget);
TargetGraph targetGraph = TargetGraphFactory.newInstance(compilerBuilder.build(), libBuilder.build());
BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
HalideLibrary lib = (HalideLibrary) libBuilder.build(resolver, filesystem, targetGraph);
// Check that the library rule has the correct preprocessor input.
CxxPlatform cxxPlatform = CxxLibraryBuilder.createDefaultPlatform();
String headerName = "rule.h";
BuildTarget flavoredLibTarget = libTarget.withFlavors(HalideLibraryDescription.HALIDE_COMPILE_FLAVOR, cxxPlatform.getFlavor());
Path headerPath = HalideCompile.headerOutputPath(flavoredLibTarget, lib.getProjectFilesystem(), Optional.empty());
CxxSymlinkTreeHeaders publicHeaders = (CxxSymlinkTreeHeaders) lib.getCxxPreprocessorInput(cxxPlatform, HeaderVisibility.PUBLIC).getIncludes().get(0);
assertThat(publicHeaders.getIncludeType(), Matchers.equalTo(CxxPreprocessables.IncludeType.SYSTEM));
assertThat(publicHeaders.getNameToPathMap(), Matchers.equalTo(ImmutableMap.<Path, SourcePath>of(Paths.get(headerName), new ExplicitBuildTargetSourcePath(flavoredLibTarget, headerPath))));
// Check that the library rule has the correct native linkable input.
NativeLinkableInput input = lib.getNativeLinkableInput(cxxPlatform, Linker.LinkableDepType.STATIC);
BuildRule buildRule = FluentIterable.from(input.getArgs()).transformAndConcat(arg -> arg.getDeps(new SourcePathRuleFinder(resolver))).get(0);
assertThat(buildRule, is(instanceOf(Archive.class)));
}
use of com.facebook.buck.testutil.FakeProjectFilesystem in project buck by facebook.
the class PathHashingTest method sameContentsSameNameHaveSameHash.
@Test
public void sameContentsSameNameHaveSameHash() throws IOException {
SettableFakeClock clock = new SettableFakeClock(1000, 0);
FakeProjectFilesystem filesystem1 = new FakeProjectFilesystem(clock);
filesystem1.touch(Paths.get("foo/bar.txt"));
FakeProjectFilesystem filesystem2 = new FakeProjectFilesystem(clock);
filesystem2.touch(Paths.get("foo/bar.txt"));
Hasher hasher1 = Hashing.sha1().newHasher();
PathHashing.hashPath(hasher1, fileHashCache, filesystem1, Paths.get("foo"));
Hasher hasher2 = Hashing.sha1().newHasher();
PathHashing.hashPath(hasher2, fileHashCache, filesystem2, Paths.get("foo"));
assertThat(hasher1.hash(), equalTo(hasher2.hash()));
}
Aggregations