use of com.facebook.buck.io.ProjectFilesystem in project buck by facebook.
the class DaemonIntegrationTest method whenAndroidNdkVersionChangesParserInvalidated.
@Test
public void whenAndroidNdkVersionChangesParserInvalidated() throws IOException, InterruptedException {
ProjectFilesystem filesystem = new ProjectFilesystem(tmp.getRoot());
BuckConfig buckConfig1 = FakeBuckConfig.builder().setSections(ImmutableMap.of("ndk", ImmutableMap.of("ndk_version", "something"))).build();
BuckConfig buckConfig2 = FakeBuckConfig.builder().setSections(ImmutableMap.of("ndk", ImmutableMap.of("ndk_version", "different"))).build();
Object daemon = Main.getDaemon(new TestCellBuilder().setBuckConfig(buckConfig1).setFilesystem(filesystem).build(), ObjectMappers.newDefaultInstance());
assertNotEquals("Daemon should be replaced when not equal.", daemon, Main.getDaemon(new TestCellBuilder().setBuckConfig(buckConfig2).setFilesystem(filesystem).build(), ObjectMappers.newDefaultInstance()));
}
use of com.facebook.buck.io.ProjectFilesystem in project buck by facebook.
the class QueryCommandTest method setUp.
@Before
public void setUp() throws IOException, InterruptedException {
TestConsole console = new TestConsole();
ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "query_command", tmp);
workspace.setUp();
ProjectFilesystem filesystem = new ProjectFilesystem(workspace.getDestPath().toRealPath().normalize());
Cell cell = new TestCellBuilder().setFilesystem(filesystem).build();
AndroidDirectoryResolver androidDirectoryResolver = new FakeAndroidDirectoryResolver();
ArtifactCache artifactCache = new NoopArtifactCache();
BuckEventBus eventBus = BuckEventBusFactory.newInstance();
ObjectMapper objectMapper = ObjectMappers.newDefaultInstance();
queryCommand = new QueryCommand();
queryCommand.outputAttributes = Suppliers.ofInstance(ImmutableSet.<String>of());
params = CommandRunnerParamsForTesting.createCommandRunnerParamsForTesting(console, cell, androidDirectoryResolver, artifactCache, eventBus, FakeBuckConfig.builder().build(), Platform.detect(), ImmutableMap.copyOf(System.getenv()), new FakeJavaPackageFinder(), objectMapper, Optional.empty());
executor = MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor());
}
use of com.facebook.buck.io.ProjectFilesystem in project buck by facebook.
the class TargetsCommandTest method setUp.
@Before
public void setUp() throws IOException, InterruptedException {
console = new TestConsole();
workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "target_command", tmp);
workspace.setUp();
filesystem = new ProjectFilesystem(workspace.getDestPath().toRealPath().normalize());
Cell cell = new TestCellBuilder().setFilesystem(filesystem).build();
AndroidDirectoryResolver androidDirectoryResolver = new FakeAndroidDirectoryResolver();
ArtifactCache artifactCache = new NoopArtifactCache();
BuckEventBus eventBus = BuckEventBusFactory.newInstance();
objectMapper = ObjectMappers.newDefaultInstance();
targetsCommand = new TargetsCommand();
params = CommandRunnerParamsForTesting.createCommandRunnerParamsForTesting(console, cell, androidDirectoryResolver, artifactCache, eventBus, FakeBuckConfig.builder().build(), Platform.detect(), ImmutableMap.copyOf(System.getenv()), new FakeJavaPackageFinder(), objectMapper, Optional.empty());
executor = MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor());
}
use of com.facebook.buck.io.ProjectFilesystem in project buck by facebook.
the class CxxCollectAndLogInferDependenciesStepTest method testStepWritesOneCellTokenInFileWhenOneCellIsAbsent.
@Test
public void testStepWritesOneCellTokenInFileWhenOneCellIsAbsent() throws Exception {
assumeThat(Platform.detect(), is(not(WINDOWS)));
// filesystem, buildTarget and buildRuleParams for first, unnamed cell (analysis)
ProjectFilesystem filesystem1 = createFakeFilesystem("/Users/user/default_cell");
BuildTarget buildTarget1 = BuildTarget.builder().setUnflavoredBuildTarget(UnflavoredBuildTarget.of(filesystem1.getRootPath(), Optional.empty(), "//target/in_default_cell", "short")).addFlavors(CxxInferEnhancer.InferFlavors.INFER.get()).build();
BuildRuleParams buildRuleParams1 = new FakeBuildRuleParamsBuilder(buildTarget1).setProjectFilesystem(filesystem1).build();
// filesystem, buildTarget and buildRuleParams for second cell (capture)
ProjectFilesystem filesystem2 = createFakeFilesystem("/Users/user/cell_two");
BuildTarget buildTarget2 = BuildTarget.builder().setUnflavoredBuildTarget(UnflavoredBuildTarget.of(filesystem2.getRootPath(), Optional.of("cell2"), "//target/in_cell_two", "short2")).addFlavors(CxxInferEnhancer.InferFlavors.INFER_CAPTURE.get()).build();
BuildRuleParams buildRuleParams2 = new FakeBuildRuleParamsBuilder(buildTarget2).setProjectFilesystem(filesystem2).build();
BuildRuleResolver testBuildRuleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver testSourcePathResolver = new SourcePathResolver(new SourcePathRuleFinder(testBuildRuleResolver));
InferBuckConfig inferBuckConfig = new InferBuckConfig(FakeBuckConfig.builder().build());
CxxInferCapture captureRule = createCaptureRule(buildRuleParams2, testSourcePathResolver, filesystem2, inferBuckConfig);
CxxInferCaptureAndAggregatingRules<CxxInferAnalyze> captureAndAggregatingRules = new CxxInferCaptureAndAggregatingRules<>(ImmutableSet.of(captureRule), ImmutableSet.<CxxInferAnalyze>of());
CxxInferAnalyze analyzeRule = new CxxInferAnalyze(buildRuleParams1, inferBuckConfig, captureAndAggregatingRules);
Path outputFile = Paths.get("infer-deps.txt");
CxxCollectAndLogInferDependenciesStep step = CxxCollectAndLogInferDependenciesStep.fromAnalyzeRule(analyzeRule, filesystem1, outputFile);
ExecutionContext executionContext = TestExecutionContext.newInstance();
int exitCode = step.execute(executionContext).getExitCode();
assertThat(exitCode, is(StepExecutionResult.SUCCESS.getExitCode()));
String expectedOutput = InferLogLine.fromBuildTarget(buildTarget1, analyzeRule.getAbsolutePathToResultsDir()).toString() + "\n" + InferLogLine.fromBuildTarget(buildTarget2, captureRule.getAbsolutePathToOutput()).toString();
assertEquals(expectedOutput + "\n", filesystem1.readFileIfItExists(outputFile).get());
}
use of com.facebook.buck.io.ProjectFilesystem 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");
}
Aggregations