use of com.facebook.buck.testutil.FakeProjectFilesystem in project buck by facebook.
the class AuditInputCommandTest method setUp.
@Before
public void setUp() throws IOException, InterruptedException {
console = new TestConsole();
FakeProjectFilesystem projectFilesystem = new FakeProjectFilesystem();
projectFilesystem.touch(Paths.get("src/com/facebook/AndroidLibraryTwo.java"));
projectFilesystem.touch(Paths.get("src/com/facebook/TestAndroidLibrary.java"));
projectFilesystem.touch(Paths.get("src/com/facebook/TestJavaLibrary.java"));
Cell cell = new TestCellBuilder().setFilesystem(projectFilesystem).build();
ArtifactCache artifactCache = new NoopArtifactCache();
BuckEventBus eventBus = BuckEventBusFactory.newInstance();
ObjectMapper objectMapper = ObjectMappers.newDefaultInstance();
auditInputCommand = new AuditInputCommand();
params = CommandRunnerParamsForTesting.createCommandRunnerParamsForTesting(console, cell, new FakeAndroidDirectoryResolver(), artifactCache, eventBus, FakeBuckConfig.builder().build(), Platform.detect(), ImmutableMap.copyOf(System.getenv()), new FakeJavaPackageFinder(), objectMapper, Optional.empty());
}
use of com.facebook.buck.testutil.FakeProjectFilesystem in project buck by facebook.
the class CxxCompilationDatabaseIntegrationTest method compilationDatabaseWithDepsFetchedFromCacheAlsoFetchesSymlinkTreeOrHeaderMapOfDeps.
@Test
public void compilationDatabaseWithDepsFetchedFromCacheAlsoFetchesSymlinkTreeOrHeaderMapOfDeps() throws Exception {
// Create a new temporary path since this test uses a different testdata directory than the
// one used in the common setup method.
tmp.after();
tmp = new TemporaryPaths();
tmp.before();
ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "compilation_database_with_deps", tmp);
workspace.setUp();
workspace.writeContentsToPath("[cxx]\ngtest_dep = //:fake-gtest\nsandbox_sources=" + sandboxSources, ".buckconfig");
ProjectFilesystem filesystem = new FakeProjectFilesystem();
// This test only fails if the directory cache is enabled and we don't update
// the header map/symlink tree correctly when fetching from the cache.
workspace.enableDirCache();
addDepLibraryHeaderFiles(workspace);
BuildTarget target = BuildTargetFactory.newInstance("//:library_with_header#default,compilation-database");
// Populate the cache with the built rule
workspace.buildAndReturnOutput(target.getFullyQualifiedName());
Path dep1ExportedSymlinkTreeFolder = CxxDescriptionEnhancer.getHeaderSymlinkTreePath(filesystem, BuildTargetFactory.newInstance("//dep1:dep1"), HeaderVisibility.PUBLIC, CxxPlatformUtils.getHeaderModeForDefaultPlatform(tmp.getRoot()).getFlavor());
Path dep2ExportedSymlinkTreeFolder = CxxDescriptionEnhancer.getHeaderSymlinkTreePath(filesystem, BuildTargetFactory.newInstance("//dep2:dep2"), HeaderVisibility.PUBLIC, CxxPlatformUtils.getHeaderModeForDefaultPlatform(tmp.getRoot()).getFlavor());
// Validate the deps' symlink tree/header maps
verifyHeaders(workspace, dep1ExportedSymlinkTreeFolder, "dep1/dep1.h", "dep1/dep1_new.h");
verifyHeaders(workspace, dep2ExportedSymlinkTreeFolder, "dep2/dep2.h", "dep2/dep2_new.h");
// Delete the newly-added files and build again
Files.delete(workspace.getPath("dep1/dep1_new.h"));
Files.delete(workspace.getPath("dep2/dep2_new.h"));
workspace.buildAndReturnOutput(target.getFullyQualifiedName());
verifyHeaders(workspace, dep1ExportedSymlinkTreeFolder, "dep1/dep1.h");
verifyHeaders(workspace, dep2ExportedSymlinkTreeFolder, "dep2/dep2.h");
// Restore the headers, build again, and check the deps' symlink tree/header maps
addDepLibraryHeaderFiles(workspace);
workspace.buildAndReturnOutput(target.getFullyQualifiedName());
verifyHeaders(workspace, dep1ExportedSymlinkTreeFolder, "dep1/dep1.h", "dep1/dep1_new.h");
verifyHeaders(workspace, dep2ExportedSymlinkTreeFolder, "dep2/dep2.h", "dep2/dep2_new.h");
}
use of com.facebook.buck.testutil.FakeProjectFilesystem in project buck by facebook.
the class CxxCompilationDatabaseIntegrationTest method testUberCompilationDatabase.
@Test
public void testUberCompilationDatabase() throws IOException {
ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "compilation_database", tmp);
workspace.setUp();
BuildTarget target = BuildTargetFactory.newInstance("//:test#default,uber-compilation-database");
ProjectFilesystem filesystem = new FakeProjectFilesystem();
Path compilationDatabase = workspace.buildAndReturnOutput(target.getFullyQualifiedName());
Path rootPath = tmp.getRoot();
assertEquals(BuildTargets.getGenPath(filesystem, target, "uber-compilation-database-%s/compile_commands.json"), rootPath.relativize(compilationDatabase));
Path binaryHeaderSymlinkTreeFolder = BuildTargets.getGenPath(filesystem, target.withFlavors(InternalFlavor.of("default"), CxxDescriptionEnhancer.HEADER_SYMLINK_TREE_FLAVOR), "%s");
Map<String, CxxCompilationDatabaseEntry> fileToEntry = CxxCompilationDatabaseUtils.parseCompilationDatabaseJsonFile(compilationDatabase);
assertEquals(1, fileToEntry.size());
String path = sandboxSources ? "buck-out/gen/test#default,sandbox/test.cpp" : "test.cpp";
BuildTarget compilationTarget = target.withFlavors(InternalFlavor.of("default"), InternalFlavor.of("compile-" + sanitize("test.cpp.o")));
assertHasEntry(fileToEntry, path, new ImmutableList.Builder<String>().add(COMPILER_PATH).add("-I").add(headerSymlinkTreePath(binaryHeaderSymlinkTreeFolder).toString()).addAll(getExtraFlagsForHeaderMaps(filesystem)).addAll(COMPILER_SPECIFIC_FLAGS).add("-x").add("c++").add("-fdebug-prefix-map=" + rootPath + "=.").addAll(MORE_COMPILER_SPECIFIC_FLAGS).add("-c").add("-MD").add("-MF").add(BuildTargets.getGenPath(filesystem, compilationTarget, "%s/test.cpp.o.dep").toString()).add(Paths.get(path).toString()).add("-o").add(BuildTargets.getGenPath(filesystem, compilationTarget, "%s/test.cpp.o").toString()).build());
}
use of com.facebook.buck.testutil.FakeProjectFilesystem in project buck by facebook.
the class CxxCompilationDatabaseIntegrationTest method compilationDatabaseWithGeneratedFilesFetchedFromCacheAlsoFetchesGeneratedSources.
@Test
public void compilationDatabaseWithGeneratedFilesFetchedFromCacheAlsoFetchesGeneratedSources() throws Exception {
// Create a new temporary path since this test uses a different testdata directory than the
// one used in the common setup method.
tmp.after();
tmp = new TemporaryPaths();
tmp.before();
ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "compilation_database_with_generated_files", tmp);
workspace.setUp();
workspace.enableDirCache();
BuildTarget target = BuildTargetFactory.newInstance("//dep1:dep1#default,compilation-database");
workspace.runBuckBuild(target.getFullyQualifiedName()).assertSuccess();
workspace.runBuckCommand("clean").assertSuccess();
workspace.runBuckBuild(target.getFullyQualifiedName()).assertSuccess();
ProjectFilesystem filesystem = new FakeProjectFilesystem();
BuildTarget sourceTarget = BuildTargetFactory.newInstance("//dep1:source");
Path source = workspace.getPath(BuildTargets.getGenPath(filesystem, sourceTarget, "%s"));
assertThat(Files.exists(source), is(true));
}
use of com.facebook.buck.testutil.FakeProjectFilesystem in project buck by facebook.
the class CxxCompilationDatabaseTest method testCompilationDatabase.
@Test
public void testCompilationDatabase() throws Exception {
BuildTarget testBuildTarget = BuildTarget.builder(BuildTargetFactory.newInstance("//foo:baz")).addAllFlavors(ImmutableSet.of(CxxCompilationDatabase.COMPILATION_DATABASE)).build();
final String root = "/Users/user/src";
final Path fakeRoot = Paths.get(root);
ProjectFilesystem filesystem = new FakeProjectFilesystem(fakeRoot);
BuildRuleParams testBuildRuleParams = new FakeBuildRuleParamsBuilder(testBuildTarget).setProjectFilesystem(filesystem).build();
BuildRuleResolver testBuildRuleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver testSourcePathResolver = new SourcePathResolver(new SourcePathRuleFinder(testBuildRuleResolver));
HeaderSymlinkTree privateSymlinkTree = CxxDescriptionEnhancer.createHeaderSymlinkTree(testBuildRuleParams, testBuildRuleResolver, CxxPlatformUtils.DEFAULT_PLATFORM, ImmutableMap.of(), HeaderVisibility.PRIVATE, true);
testBuildRuleResolver.addToIndex(privateSymlinkTree);
HeaderSymlinkTree exportedSymlinkTree = CxxDescriptionEnhancer.createHeaderSymlinkTree(testBuildRuleParams, testBuildRuleResolver, CxxPlatformUtils.DEFAULT_PLATFORM, ImmutableMap.of(), HeaderVisibility.PUBLIC, true);
testBuildRuleResolver.addToIndex(exportedSymlinkTree);
BuildTarget compileTarget = BuildTarget.builder(testBuildRuleParams.getBuildTarget().getUnflavoredBuildTarget()).addFlavors(InternalFlavor.of("compile-test.cpp")).build();
PreprocessorFlags preprocessorFlags = PreprocessorFlags.builder().addIncludes(CxxHeadersDir.of(CxxPreprocessables.IncludeType.SYSTEM, new FakeSourcePath("/foo/bar")), CxxHeadersDir.of(CxxPreprocessables.IncludeType.SYSTEM, new FakeSourcePath("/test"))).build();
ImmutableSortedSet.Builder<CxxPreprocessAndCompile> rules = ImmutableSortedSet.naturalOrder();
BuildRuleParams compileBuildRuleParams = new FakeBuildRuleParamsBuilder(compileTarget).setProjectFilesystem(filesystem).setDeclaredDeps(ImmutableSortedSet.of(privateSymlinkTree, exportedSymlinkTree)).build();
rules.add(testBuildRuleResolver.addToIndex(CxxPreprocessAndCompile.preprocessAndCompile(compileBuildRuleParams, new PreprocessorDelegate(testSourcePathResolver, CxxPlatformUtils.DEFAULT_COMPILER_DEBUG_PATH_SANITIZER, CxxPlatformUtils.DEFAULT_PLATFORM.getHeaderVerification(), filesystem.getRootPath(), new GccPreprocessor(new HashedFileTool(Paths.get("preprocessor"))), preprocessorFlags, new RuleKeyAppendableFunction<FrameworkPath, Path>() {
@Override
public void appendToRuleKey(RuleKeyObjectSink sink) {
// Do nothing.
}
@Override
public Path apply(FrameworkPath input) {
throw new UnsupportedOperationException("should not be called");
}
}, Optional.empty(), /* leadingIncludePaths */
Optional.empty()), new CompilerDelegate(testSourcePathResolver, CxxPlatformUtils.DEFAULT_COMPILER_DEBUG_PATH_SANITIZER, new GccCompiler(new HashedFileTool(Paths.get("compiler"))), CxxToolFlags.of()), Paths.get("test.o"), new FakeSourcePath(filesystem, "test.cpp"), CxxSource.Type.CXX, Optional.empty(), CxxPlatformUtils.DEFAULT_COMPILER_DEBUG_PATH_SANITIZER, CxxPlatformUtils.DEFAULT_ASSEMBLER_DEBUG_PATH_SANITIZER, Optional.empty())));
CxxCompilationDatabase compilationDatabase = CxxCompilationDatabase.createCompilationDatabase(testBuildRuleParams, rules.build());
testBuildRuleResolver.addToIndex(compilationDatabase);
assertThat(compilationDatabase.getRuntimeDeps().collect(MoreCollectors.toImmutableSet()), Matchers.contains(exportedSymlinkTree.getBuildTarget(), privateSymlinkTree.getBuildTarget()));
assertEquals("getPathToOutput() should be a function of the build target.", BuildTargets.getGenPath(filesystem, testBuildTarget, "__%s.json"), testSourcePathResolver.getRelativePath(compilationDatabase.getSourcePathToOutput()));
List<Step> buildSteps = compilationDatabase.getBuildSteps(FakeBuildContext.withSourcePathResolver(testSourcePathResolver), new FakeBuildableContext());
assertEquals(2, buildSteps.size());
assertTrue(buildSteps.get(0) instanceof MkdirStep);
assertTrue(buildSteps.get(1) instanceof CxxCompilationDatabase.GenerateCompilationCommandsJson);
CxxCompilationDatabase.GenerateCompilationCommandsJson step = (CxxCompilationDatabase.GenerateCompilationCommandsJson) buildSteps.get(1);
Iterable<CxxCompilationDatabaseEntry> observedEntries = step.createEntries();
Iterable<CxxCompilationDatabaseEntry> expectedEntries = ImmutableList.of(CxxCompilationDatabaseEntry.of(root, root + "/test.cpp", ImmutableList.of("compiler", "-isystem", "/foo/bar", "-isystem", "/test", "-x", "c++", "-c", "-MD", "-MF", "test.o.dep", "test.cpp", "-o", "test.o")));
MoreAsserts.assertIterablesEquals(expectedEntries, observedEntries);
}
Aggregations