@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( ImmutableFlavor.of("default"), CxxDescriptionEnhancer.HEADER_SYMLINK_TREE_FLAVOR), "%s"); Path binaryExportedHeaderSymlinkTreeFolder = BuildTargets.getGenPath( filesystem, target.withFlavors( ImmutableFlavor.of("default"), CxxDescriptionEnhancer.EXPORTED_HEADER_SYMLINK_TREE_FLAVOR), "%s"); Map<String, CxxCompilationDatabaseEntry> fileToEntry = CxxCompilationDatabaseUtils.parseCompilationDatabaseJsonFile(compilationDatabase); assertEquals(1, fileToEntry.size()); assertHasEntry( fileToEntry, "test.cpp", new ImmutableList.Builder<String>() .add(COMPILER_PATH) .add("-fPIC") .add("-fPIC") .add("-I") .add(headerSymlinkTreePath(binaryHeaderSymlinkTreeFolder).toString()) .add("-I") .add(headerSymlinkTreePath(binaryExportedHeaderSymlinkTreeFolder).toString()) .addAll(getExtraFlagsForHeaderMaps(filesystem)) .addAll(COMPILER_SPECIFIC_FLAGS) .add("-x") .add("c++") .add("-c") .add("-o") .add( BuildTargets.getGenPath( filesystem, target.withFlavors( ImmutableFlavor.of("default"), ImmutableFlavor.of("compile-pic-" + sanitize("test.cpp.o"))), "%s/test.cpp.o") .toString()) .add(rootPath.resolve(Paths.get("test.cpp")).toRealPath().toString()) .build()); }
@Test public void depfileBasedRuleKeyAvoidsRecompilingAfterChangeToUnusedHeader() throws Exception { CxxPlatform cxxPlatform = DefaultCxxPlatforms.build(new CxxBuckConfig(FakeBuckConfig.builder().build())); BuildTarget target = BuildTargetFactory.newInstance("//:binary_with_unused_header"); String unusedHeaderName = "unused_header.h"; String sourceName = "source.cpp"; BuildTarget preprocessTarget = getPreprocessTarget(cxxPlatform, target, sourceName, AbstractCxxSource.Type.CXX); // Run the build and verify that the C++ source was preprocessed. workspace.runBuckBuild("--config", "build.depfiles=true", target.toString()).assertSuccess(); BuckBuildLog.BuildLogEntry firstRunEntry = workspace.getBuildLog().getLogEntry(preprocessTarget); assertThat( firstRunEntry.getSuccessType(), equalTo(Optional.of(BuildRuleSuccessType.BUILT_LOCALLY))); // Now modify the unused header. workspace.writeContentsToPath( "static inline int newFunction() { return 20; }", unusedHeaderName); // Run the build again and verify that got a matching depfile rule key, and therefore // didn't recompile. workspace.runBuckBuild("--config", "build.depfiles=true", target.toString()).assertSuccess(); BuckBuildLog.BuildLogEntry secondRunEntry = workspace.getBuildLog().getLogEntry(preprocessTarget); assertThat( secondRunEntry.getSuccessType(), equalTo(Optional.of(BuildRuleSuccessType.MATCHING_DEP_FILE_RULE_KEY))); // Also, make sure the original rule keys are actually different. assertThat(secondRunEntry.getRuleKey(), Matchers.not(equalTo(firstRunEntry.getRuleKey()))); }
@Test public void sanitizeWorkingDirectory() throws IOException { workspace.runBuckBuild("//:simple#default,static").assertSuccess(); Path lib = workspace.getPath("buck-out/gen/simple#default,static/libsimple.a"); String contents = Files.asByteSource(lib.toFile()).asCharSource(Charsets.ISO_8859_1).read(); assertFalse(lib.toString(), contents.contains(tmp.getRootPath().toString())); }
@Test public void sanitizeSymlinkedWorkingDirectory() throws IOException { TemporaryFolder folder = new TemporaryFolder(); folder.create(); // Setup up a symlink to our working directory. Path symlinkedRoot = folder.getRoot().toPath().resolve("symlinked-root"); java.nio.file.Files.createSymbolicLink(symlinkedRoot, tmp.getRootPath()); // Run the build, setting PWD to the above symlink. Typically, this causes compilers to use // the symlinked directory, even though it's not the right project root. Map<String, String> envCopy = Maps.newHashMap(System.getenv()); envCopy.put("PWD", symlinkedRoot.toString()); workspace .runBuckCommandWithEnvironmentAndContext( tmp.getRootPath(), Optional.<NGContext>absent(), Optional.<BuckEventListener>absent(), Optional.of(ImmutableMap.copyOf(envCopy)), "build", "//:simple#default,static") .assertSuccess(); // Verify that we still sanitized this path correctly. Path lib = workspace.getPath("buck-out/gen/simple#default,static/libsimple.a"); String contents = Files.asByteSource(lib.toFile()).asCharSource(Charsets.ISO_8859_1).read(); assertFalse(lib.toString(), contents.contains(tmp.getRootPath().toString())); assertFalse(lib.toString(), contents.contains(symlinkedRoot.toString())); folder.delete(); }
@Test public void depfileBasedRuleKeyRebuildsAfterChangeToUsedHeaderUsingFileRelativeInclusion() throws Exception { CxxPlatform cxxPlatform = DefaultCxxPlatforms.build(new CxxBuckConfig(FakeBuckConfig.builder().build())); BuildTarget target = BuildTargetFactory.newInstance("//:binary_with_used_relative_header"); String usedHeaderName = "source_relative_header.h"; String sourceName = "source_relative_header.cpp"; BuildTarget preprocessTarget = getPreprocessTarget(cxxPlatform, target, sourceName, AbstractCxxSource.Type.CXX); // Run the build and verify that the C++ source was preprocessed. workspace.runBuckBuild("--config", "build.depfiles=true", target.toString()).assertSuccess(); BuckBuildLog.BuildLogEntry firstRunEntry = workspace.getBuildLog().getLogEntry(preprocessTarget); assertThat( firstRunEntry.getSuccessType(), equalTo(Optional.of(BuildRuleSuccessType.BUILT_LOCALLY))); // Modify the used header. workspace.writeContentsToPath("static inline int newFunction() { return 20; }", usedHeaderName); // Run the build again and verify that we recompiled as the header caused the depfile rule key // to change. workspace.runBuckBuild("--config", "build.depfiles=true", target.toString()).assertSuccess(); BuckBuildLog.BuildLogEntry secondRunEntry = workspace.getBuildLog().getLogEntry(preprocessTarget); assertThat( secondRunEntry.getSuccessType(), equalTo(Optional.of(BuildRuleSuccessType.BUILT_LOCALLY))); // Also, make sure all three rule keys are actually different. assertThat(secondRunEntry.getRuleKey(), Matchers.not(equalTo(firstRunEntry.getRuleKey()))); }
@Test public void javacOptionsChanged() throws Exception { ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "diff_rulekeys_script", tmp); workspace.setUp(); writeBuckConfig(workspace, "6"); invokeBuckCommand(workspace, "buck-0.log"); writeBuckConfig(workspace, "7"); invokeBuckCommand(workspace, "buck-1.log"); String expectedResult = Joiner.on('\n') .join( "Change details for " + "[//:java_lib_2->compileStepFactory.appendableSubKey->javacOptions.appendableSubKey]", " (sourceLevel):", " -[string(\"6\")]", " +[string(\"7\")]", " (targetLevel):", " -[string(\"6\")]", " +[string(\"7\")]", ""); assertThat( runRuleKeyDiffer(workspace).getStdout(), Matchers.equalTo(Optional.of(expectedResult))); }
@Test public void testJsonOutputWithDirectDependencies() throws IOException { // Run Buck targets command on a case where the deps and direct_dependencies differ ProcessResult result = workspace.runBuckCommand("targets", "--json", "//:B"); // Parse the observed JSON. JsonNode observed = objectMapper.readTree( objectMapper .getJsonFactory() .createJsonParser(result.getStdout()) .enable(Feature.ALLOW_COMMENTS)); // Parse the expected JSON. String expectedJson = workspace.getFileContents("TargetsCommandTestBuckJson2.js"); JsonNode expected = objectMapper.readTree( objectMapper .getJsonFactory() .createJsonParser(expectedJson) .enable(Feature.ALLOW_COMMENTS)); assertThat( "Output from targets command should match expected JSON.", observed, is(equalTo(expected))); assertThat( "Nothing should be printed to stderr.", console.getTextWrittenToStdErr(), is(equalTo(""))); }
@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 = new ObjectMapper(); targetsCommand = new TargetsCommand(); params = CommandRunnerParamsForTesting.createCommandRunnerParamsForTesting( console, cell, androidDirectoryResolver, artifactCache, eventBus, FakeBuckConfig.builder().build(), Platform.detect(), ImmutableMap.copyOf(System.getenv()), new FakeJavaPackageFinder(), objectMapper, Optional.<WebServer>absent()); executor = MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor()); }
@Before public void initializeWorkspace() throws IOException { workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "compilation_database", tmp); workspace.setUp(); // cxx_test requires gtest_dep to be set workspace.writeContentsToPath("[cxx]\ngtest_dep = //:fake-gtest", ".buckconfig"); }
@Test public void testSimpleCxxBinaryMissingDependencyOnCxxLibraryWithHeader() throws IOException { ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "simple", tmp); workspace.setUp(); workspace.runBuckCommand("build", "//foo:binary_without_dep").assertFailure(); }
@Test public void fatJarWithExitCode() throws IOException { ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "fat_jar", tmp); workspace.setUp(); workspace.runBuckCommand("run", "//:bin-exit-code").assertSpecialExitCode("error", 5); }
/** * Verifies that a client timeout will be detected by a Nailgun NGInputStream reading from a * blocking heartbeat stream. */ @Test(expected = InterruptedException.class) public void whenClientTimeoutDetectedThenMainThreadIsInterrupted() throws InterruptedException, IOException { final long timeoutMillis = 100; final long intervalMillis = timeoutMillis * 2; // Interval > timeout to trigger disconnection. final ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "exclusive_execution", tmp); workspace.setUp(); // Build an NGContext connected to an NGInputStream reading from a stream that will timeout. Thread.currentThread().setName("Test"); try (TestContext context = new TestContext( ImmutableMap.copyOf(System.getenv()), TestContext.createHeartBeatStream(intervalMillis), timeoutMillis)) { final Thread commandThread = Thread.currentThread(); context.addClientListener( new NGClientListener() { @Override public void clientDisconnected() throws InterruptedException { commandThread.interrupt(); } }); Thread.sleep(1000); fail("Should have been interrupted."); } }
@Test public void testAppleDynamicLibraryWithDsym() throws Exception { assumeTrue(Platform.detect() == Platform.MACOS); assumeTrue(AppleNativeIntegrationTestUtils.isApplePlatformAvailable(ApplePlatform.MACOSX)); ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "apple_library_shared", tmp); workspace.setUp(); ProjectFilesystem filesystem = new ProjectFilesystem(workspace.getDestPath()); ProjectWorkspace.ProcessResult result = workspace.runBuckCommand( "build", "//Libraries/TestLibrary:TestLibrary#shared,macosx-x86_64,dwarf-and-dsym", "--config", "cxx.cflags=-g"); result.assertSuccess(); Path output = tmp.getRoot() .resolve(filesystem.getBuckPaths().getGenDir()) .resolve("Libraries/TestLibrary/TestLibrary#macosx-x86_64,shared") .resolve("libLibraries_TestLibrary_TestLibrary.dylib"); assertThat(Files.exists(output), is(true)); Path dsymPath = tmp.getRoot() .resolve(filesystem.getBuckPaths().getGenDir()) .resolve("Libraries/TestLibrary") .resolve("TestLibrary#apple-dsym,macosx-x86_64,shared.dSYM"); assertThat(Files.exists(dsymPath), is(true)); AppleDsymTestUtil.checkDsymFileHasDebugSymbol("+[TestClass answer]", workspace, dsymPath); }
@Test public void frameworkDependenciesDoNotContainTransitiveDependencies() throws Exception { assumeTrue(Platform.detect() == Platform.MACOS); assumeTrue(AppleNativeIntegrationTestUtils.isApplePlatformAvailable(ApplePlatform.MACOSX)); ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario( this, "apple_library_with_library_dependencies", tmp); workspace.setUp(); ProjectFilesystem filesystem = new ProjectFilesystem(workspace.getDestPath()); BuildTarget target = BuildTargetFactory.newInstance( "//Libraries/TestLibrary:TestLibrary#framework,macosx-x86_64"); ProjectWorkspace.ProcessResult result = workspace.runBuckCommand("build", target.getFullyQualifiedName()); result.assertSuccess(); Path frameworkPath = workspace.getPath( BuildTargets.getGenPath( filesystem, BuildTarget.builder(target) .addFlavors(AppleDebugFormat.DWARF.getFlavor()) .addFlavors(AppleDescriptions.INCLUDE_FRAMEWORKS_FLAVOR) .build(), "%s") .resolve("TestLibrary.framework")); assertThat(Files.exists(frameworkPath), is(true)); Path frameworksPath = frameworkPath.resolve("Frameworks"); assertThat(Files.exists(frameworksPath), is(true)); Path depFrameworksPath = frameworksPath.resolve("TestLibraryDep.framework/Frameworks"); assertThat(Files.exists(depFrameworksPath), is(false)); }
@Test public void testEditingNativeAndSecondaryDexFileGetsAbiHitForDexAndNativeExopackage() throws IOException, InterruptedException { // Sleep 1 second (plus another half to be super duper safe) to make sure that // fakesystem.c gets a later timestamp than the fakesystem.o that was produced // during the build in setUp. If we don't do this, there's a chance that the // ndk-build we run during the upcoming build will not rebuild it (on filesystems // that have 1-second granularity for last modified). // To verify this, create a Makefile with the following rule (don't forget to use a tab): // out: in // cat $< > $@ // Run: echo foo > in ; make ; cat out ; echo bar > in ; make ; cat out // On a filesystem with 1-second mtime granularity, the last "cat" should print "foo" // (with very high probability). Thread.sleep(1500); // Change the binary and ensure that we re-run apkbuilder. workspace.replaceFileContents( "native/fakenative/jni/fakesystem.c", "exit(status)", "exit(1+status)"); workspace.replaceFileContents("java/com/sample/lib/Sample.java", "package com", "package\ncom"); workspace.resetBuildLogFile(); workspace.runBuckBuild(DEX_AND_NATIVE_EXOPACKAGE_TARGET).assertSuccess(); workspace.getBuildLog().assertTargetHadMatchingDepsAbi(DEX_AND_NATIVE_EXOPACKAGE_TARGET); }
@Test public void testUnbundleOutputContainsJSAndResources() throws IOException { workspace.runBuckBuild("//:DemoApp-Unbundle#iphonesimulator-x86_64,no-debug").assertSuccess(); workspace.verify( createPath("buck-out", "gen", "DemoApp-Unbundle#iphonesimulator-x86_64,no-debug")); }
@Test public void resolveHeadersBehindSymlinkTreesInPreprocessedOutput() throws IOException { BuckConfig buckConfig = new FakeBuckConfig(); CxxPlatform cxxPlatform = DefaultCxxPlatforms.build(new CxxBuckConfig(buckConfig)); ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "resolved", tmp); workspace.setUp(); workspace.writeContentsToPath("", "lib2.h"); BuildTarget target = BuildTargetFactory.newInstance("//:bin"); CxxSourceRuleFactory cxxSourceRuleFactory = CxxSourceRuleFactoryHelper.of(target, cxxPlatform); workspace.runBuckCommand("build", target.toString()).assertSuccess(); // Verify that the preprocessed source contains no references to the symlink tree used to // setup the headers. BuildTarget ppTarget = cxxSourceRuleFactory.createPreprocessBuildTarget( "bin.cpp", CxxSource.Type.CXX, CxxSourceRuleFactory.PicType.PDC); Path output = cxxSourceRuleFactory.getPreprocessOutputPath(ppTarget, CxxSource.Type.CXX, "bin.cpp"); String contents = workspace.getFileContents(output.toString()); assertThat(contents, Matchers.not(Matchers.containsString(BuckConstant.SCRATCH_DIR))); assertThat(contents, Matchers.not(Matchers.containsString(BuckConstant.GEN_DIR))); assertThat(contents, Matchers.containsString("# 1 \"bin.h")); assertThat(contents, Matchers.containsString("# 1 \"lib1.h")); assertThat(contents, Matchers.containsString("# 1 \"lib2.h")); }
@Test public void testVariousSuccessTypesInReport() throws IOException { ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "keep_going", tmp).setUp(); ProcessResult result1 = buildTwoGoodRulesAndAssertSuccess(workspace); String expectedReport1 = "OK //:rule_with_output BUILT_LOCALLY " + GENRULE_OUTPUT + "\n" + "OK //:rule_without_output BUILT_LOCALLY\n"; assertThat(result1.getStderr(), containsString(expectedReport1)); ProcessResult result2 = buildTwoGoodRulesAndAssertSuccess(workspace); String expectedReport2 = "OK //:rule_with_output MATCHING_RULE_KEY " + GENRULE_OUTPUT + "\n" + "OK //:rule_without_output MATCHING_RULE_KEY\n"; assertThat(result2.getStderr(), containsString(expectedReport2)); workspace.runBuckCommand("clean").assertSuccess(); ProcessResult result3 = buildTwoGoodRulesAndAssertSuccess(workspace); String expectedReport3 = "OK //:rule_with_output FETCHED_FROM_CACHE " + GENRULE_OUTPUT + "\n" + "OK //:rule_without_output FETCHED_FROM_CACHE\n"; assertThat(result3.getStderr(), containsString(expectedReport3)); }
@Test public void fatJarLoadingNativeLibraries() throws IOException { ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "fat_jar", tmp); workspace.setUp(); workspace.runBuckCommand("run", "//:bin-fat").assertSuccess(); }
@Test public void testCxxBinaryWithGeneratedSourceAndHeader() throws IOException { ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "simple", tmp); workspace.setUp(); workspace.runBuckCommand("build", "//foo:binary_without_dep").assertFailure(); }
@Test public void testHeaderNamespace() throws IOException { ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "header_namespace", tmp); workspace.setUp(); workspace.runBuckCommand("build", "//:test").assertSuccess(); }
@Test public void testAppleLibraryExportedHeaderSymlinkTree() throws IOException { assumeTrue(Platform.detect() == Platform.MACOS); ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario( this, "apple_library_header_symlink_tree", tmp); workspace.setUp(); BuildTarget buildTarget = BuildTargetFactory.newInstance( "//Libraries/TestLibrary:TestLibrary#" + "default," + CxxDescriptionEnhancer.EXPORTED_HEADER_SYMLINK_TREE_FLAVOR); ProjectWorkspace.ProcessResult result = workspace.runBuckCommand("build", buildTarget.getFullyQualifiedName()); result.assertSuccess(); Path projectRoot = tmp.getRootPath().toRealPath(); Path inputPath = projectRoot.resolve(buildTarget.getBasePath()); Path outputPath = projectRoot.resolve(BuildTargets.getGenPath(buildTarget, "%s")); assertIsSymbolicLink( outputPath.resolve("TestLibrary/PublicHeader.h"), inputPath.resolve("PublicHeader.h")); }
@Test public void testSimpleCxxBinaryWithoutHeader() throws IOException { ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "simple", tmp); workspace.setUp(); workspace.runBuckCommand("build", "//foo:simple_without_header").assertFailure(); }
@Before public void setUp() throws IOException, InterruptedException { ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "query_command", tmp); workspace.setUp(); Cell cell = new TestCellBuilder().setFilesystem(new ProjectFilesystem(workspace.getDestPath())).build(); TestConsole console = new TestConsole(); CommandRunnerParams params = CommandRunnerParamsForTesting.createCommandRunnerParamsForTesting( console, cell, new FakeAndroidDirectoryResolver(), new NoopArtifactCache(), BuckEventBusFactory.newInstance(), FakeBuckConfig.builder().build(), Platform.detect(), ImmutableMap.copyOf(System.getenv()), new FakeJavaPackageFinder(), new ObjectMapper(), Optional.<WebServer>absent()); buckQueryEnvironment = new BuckQueryEnvironment(params, /* enableProfiling */ false); cellRoot = workspace.getDestPath(); executor = MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor()); }
@Test public void testAppleLibraryBuildsFramework() throws Exception { assumeTrue(Platform.detect() == Platform.MACOS); assumeTrue( AppleNativeIntegrationTestUtils.isApplePlatformAvailable( ApplePlatform.builder().setName(ApplePlatform.Name.MACOSX).build())); ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario( this, "apple_library_builds_something", tmp); workspace.setUp(); ProjectWorkspace.ProcessResult result = workspace.runBuckCommand( "build", "//Libraries/TestLibrary:TestLibrary#framework,macosx-x86_64"); result.assertSuccess(); Path frameworkPath = tmp.getRootPath() .resolve(BuckConstant.GEN_DIR) .resolve( "Libraries/TestLibrary/TestLibrary#framework,macosx-x86_64/TestLibrary.framework"); assertThat(Files.exists(frameworkPath), is(true)); assertThat(Files.exists(frameworkPath.resolve("Contents/Info.plist")), is(true)); Path libraryPath = frameworkPath.resolve("Contents/MacOS/TestLibrary"); assertThat(Files.exists(libraryPath), is(true)); assertThat( workspace.runCommand("file", libraryPath.toString()).getStdout().get(), containsString("dynamically linked shared library")); }
@Test public void testInferCxxBinaryDepsCaching() throws IOException { assumeTrue(Platform.detect() != Platform.WINDOWS); ProjectWorkspace workspace = InferHelper.setupCxxInferWorkspace(this, tmp); workspace.enableDirCache(); // enable the cache CxxPlatform cxxPlatform = DefaultCxxPlatforms.build(new CxxBuckConfig(new FakeBuckConfig())); BuildTarget inputBuildTarget = BuildTargetFactory.newInstance("//foo:binary_with_deps"); String inputBuildTargetName = inputBuildTarget.withFlavors(CxxInferEnhancer.INFER).getFullyQualifiedName(); /* * Build the given target and check that it succeeds. */ workspace.runBuckCommand("build", inputBuildTargetName).assertSuccess(); /* * Check that building after clean will use the cache */ workspace.runBuckCommand("clean").assertSuccess(); workspace.runBuckCommand("build", inputBuildTargetName).assertSuccess(); BuckBuildLog buildLog = workspace.getBuildLog(); for (BuildTarget buildTarget : buildLog.getAllTargets()) { buildLog.assertTargetWasFetchedFromCache(buildTarget.toString()); } /* * Check that if the file in the binary target changes, then all the deps will be fetched * from the cache */ String sourceName = "src_with_deps.c"; workspace.replaceFileContents("foo/" + sourceName, "10", "30"); workspace.runBuckCommand("clean").assertSuccess(); workspace.runBuckCommand("build", inputBuildTargetName).assertSuccess(); buildLog = workspace.getBuildLog(); CxxSourceRuleFactory cxxSourceRuleFactory = CxxSourceRuleFactoryHelper.of(inputBuildTarget, cxxPlatform); BuildTarget captureBuildTarget = cxxSourceRuleFactory.createInferCaptureBuildTarget(sourceName); // this is flavored, and denotes the analysis step (generates a local report) BuildTarget inferAnalysisTarget = inputBuildTarget.withFlavors(CxxInferEnhancer.INFER_ANALYZE); // this is the flavored version of the top level target (the one give in input to buck) BuildTarget inferReportTarget = inputBuildTarget.withFlavors(CxxInferEnhancer.INFER); String bt; for (BuildTarget buildTarget : buildLog.getAllTargets()) { bt = buildTarget.toString(); if (bt.equals(inferAnalysisTarget.toString()) || bt.equals(captureBuildTarget.toString()) || bt.equals(inferReportTarget.toString())) { buildLog.assertTargetBuiltLocally(bt); } else { buildLog.assertTargetWasFetchedFromCache(buildTarget.toString()); } } }
@Test public void genruleUsingBinaryUsingSharedLinkStyle() throws IOException { assumeThat(Platform.detect(), oneOf(Platform.LINUX, Platform.MACOS)); ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "shared_link_style", tmp); workspace.setUp(); workspace.runBuckBuild("//:gen").assertSuccess(); }
/** Tests that a Test Rule without any tests to run does not fail. */ @Test public void testEmptyTestRule() throws IOException { ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "empty_test", tmp); workspace.setUp(); ProjectWorkspace.ProcessResult result = workspace.runBuckCommand("test", "//:test"); result.assertSuccess("An empty test rule should pass."); }
@Test public void buildBinaryWithSharedDependencies() throws IOException { ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "shared_library", tmp); workspace.setUp(); ProjectWorkspace.ProcessResult result = workspace.runBuckBuild("//:binary"); result.assertSuccess(); }
@Test public void incorrectPerFileFlagsUsedForCompilation() throws IOException { ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "compiling_per_file_flags", tmp); workspace.setUp(); ProjectWorkspace.ProcessResult result = workspace.runBuckBuild("//:broken-bin"); result.assertFailure(); }