Search in sources :

Example 71 with ProjectFilesystem

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()));
}
Also used : ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) TestCellBuilder(com.facebook.buck.rules.TestCellBuilder) Test(org.junit.Test)

Example 72 with ProjectFilesystem

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());
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) FakeAndroidDirectoryResolver(com.facebook.buck.android.FakeAndroidDirectoryResolver) AndroidDirectoryResolver(com.facebook.buck.android.AndroidDirectoryResolver) TestCellBuilder(com.facebook.buck.rules.TestCellBuilder) FakeAndroidDirectoryResolver(com.facebook.buck.android.FakeAndroidDirectoryResolver) ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) FakeJavaPackageFinder(com.facebook.buck.jvm.java.FakeJavaPackageFinder) NoopArtifactCache(com.facebook.buck.artifact_cache.NoopArtifactCache) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) TestConsole(com.facebook.buck.testutil.TestConsole) Cell(com.facebook.buck.rules.Cell) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ArtifactCache(com.facebook.buck.artifact_cache.ArtifactCache) NoopArtifactCache(com.facebook.buck.artifact_cache.NoopArtifactCache) Before(org.junit.Before)

Example 73 with ProjectFilesystem

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());
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) AndroidDirectoryResolver(com.facebook.buck.android.AndroidDirectoryResolver) FakeAndroidDirectoryResolver(com.facebook.buck.android.FakeAndroidDirectoryResolver) FakeAndroidDirectoryResolver(com.facebook.buck.android.FakeAndroidDirectoryResolver) FakeJavaPackageFinder(com.facebook.buck.jvm.java.FakeJavaPackageFinder) NoopArtifactCache(com.facebook.buck.artifact_cache.NoopArtifactCache) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) TestConsole(com.facebook.buck.testutil.TestConsole) Cell(com.facebook.buck.rules.Cell) TestCellBuilder(com.facebook.buck.rules.TestCellBuilder) ArtifactCache(com.facebook.buck.artifact_cache.ArtifactCache) NoopArtifactCache(com.facebook.buck.artifact_cache.NoopArtifactCache) Before(org.junit.Before)

Example 74 with ProjectFilesystem

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());
}
Also used : FrameworkPath(com.facebook.buck.rules.coercer.FrameworkPath) SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) BuildTarget(com.facebook.buck.model.BuildTarget) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 75 with ProjectFilesystem

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

Aggregations

ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)654 Test (org.junit.Test)542 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)401 Path (java.nio.file.Path)324 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)207 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)204 BuildTarget (com.facebook.buck.model.BuildTarget)203 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)126 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)121 TargetGraph (com.facebook.buck.rules.TargetGraph)119 PathSourcePath (com.facebook.buck.rules.PathSourcePath)96 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)92 ProjectWorkspace (com.facebook.buck.testutil.integration.ProjectWorkspace)90 SourcePath (com.facebook.buck.rules.SourcePath)79 ExecutionContext (com.facebook.buck.step.ExecutionContext)67 AllExistingProjectFilesystem (com.facebook.buck.testutil.AllExistingProjectFilesystem)67 TestExecutionContext (com.facebook.buck.step.TestExecutionContext)63 BuildRule (com.facebook.buck.rules.BuildRule)56 RuleKey (com.facebook.buck.rules.RuleKey)43 ArchiveMemberPath (com.facebook.buck.io.ArchiveMemberPath)42