Search in sources :

Example 91 with FakeProjectFilesystem

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));
}
Also used : BuildTarget(com.facebook.buck.model.BuildTarget) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) BuildRule(com.facebook.buck.rules.BuildRule) TargetGraph(com.facebook.buck.rules.TargetGraph) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) GenruleBuilder(com.facebook.buck.shell.GenruleBuilder) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 92 with FakeProjectFilesystem

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")))));
}
Also used : FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) TargetGraph(com.facebook.buck.rules.TargetGraph) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 93 with FakeProjectFilesystem

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));
}
Also used : Path(java.nio.file.Path) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

Example 94 with FakeProjectFilesystem

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)));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Path(java.nio.file.Path) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) CxxSymlinkTreeHeaders(com.facebook.buck.cxx.CxxSymlinkTreeHeaders) Linker(com.facebook.buck.cxx.Linker) FakeBuildContext(com.facebook.buck.rules.FakeBuildContext) Step(com.facebook.buck.step.Step) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) Matchers.not(org.hamcrest.Matchers.not) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) Archive(com.facebook.buck.cxx.Archive) SourcePath(com.facebook.buck.rules.SourcePath) FakeBuildableContext(com.facebook.buck.rules.FakeBuildableContext) Matchers.hasItems(org.hamcrest.Matchers.hasItems) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) BuildRule(com.facebook.buck.rules.BuildRule) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) CxxPlatformUtils(com.facebook.buck.cxx.CxxPlatformUtils) ImmutableList(com.google.common.collect.ImmutableList) FluentIterable(com.google.common.collect.FluentIterable) CxxPreprocessables(com.facebook.buck.cxx.CxxPreprocessables) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) BuildTargetFactory(com.facebook.buck.model.BuildTargetFactory) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Path(java.nio.file.Path) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) ImmutableMap(com.google.common.collect.ImmutableMap) NativeLinkableInput(com.facebook.buck.cxx.NativeLinkableInput) TargetGraph(com.facebook.buck.rules.TargetGraph) Matchers(org.hamcrest.Matchers) Test(org.junit.Test) CxxPlatform(com.facebook.buck.cxx.CxxPlatform) BuildTarget(com.facebook.buck.model.BuildTarget) HeaderVisibility(com.facebook.buck.cxx.HeaderVisibility) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) Matchers.hasItem(org.hamcrest.Matchers.hasItem) SourceWithFlags(com.facebook.buck.rules.SourceWithFlags) Paths(java.nio.file.Paths) TargetGraphFactory(com.facebook.buck.testutil.TargetGraphFactory) Optional(java.util.Optional) Matchers.is(org.hamcrest.Matchers.is) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Pattern(java.util.regex.Pattern) CxxLibraryBuilder(com.facebook.buck.cxx.CxxLibraryBuilder) CxxPlatform(com.facebook.buck.cxx.CxxPlatform) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) TargetGraph(com.facebook.buck.rules.TargetGraph) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) NativeLinkableInput(com.facebook.buck.cxx.NativeLinkableInput) CxxSymlinkTreeHeaders(com.facebook.buck.cxx.CxxSymlinkTreeHeaders) BuildTarget(com.facebook.buck.model.BuildTarget) BuildRule(com.facebook.buck.rules.BuildRule) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) Test(org.junit.Test)

Example 95 with FakeProjectFilesystem

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()));
}
Also used : Hasher(com.google.common.hash.Hasher) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) SettableFakeClock(com.facebook.buck.timing.SettableFakeClock) Test(org.junit.Test)

Aggregations

FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)438 Test (org.junit.Test)384 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)268 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)189 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)186 Path (java.nio.file.Path)169 BuildTarget (com.facebook.buck.model.BuildTarget)138 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)111 TargetGraph (com.facebook.buck.rules.TargetGraph)107 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)103 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)85 PathSourcePath (com.facebook.buck.rules.PathSourcePath)68 BuildRule (com.facebook.buck.rules.BuildRule)61 SourcePath (com.facebook.buck.rules.SourcePath)56 RuleKey (com.facebook.buck.rules.RuleKey)42 AllExistingProjectFilesystem (com.facebook.buck.testutil.AllExistingProjectFilesystem)40 TestExecutionContext (com.facebook.buck.step.TestExecutionContext)39 ExecutionContext (com.facebook.buck.step.ExecutionContext)38 Before (org.junit.Before)30 FakeFileHashCache (com.facebook.buck.testutil.FakeFileHashCache)29