public BuildResultStatus rebuild(TreeLogger logger) { logger = logger.branch(TreeLogger.INFO, "Performing an incremental rebuild"); ResourceOracleImpl.clearCache(); ZipFileClassPathEntry.clearCache(); ModuleDefLoader.clearModuleCache(); ResourceGeneratorUtilImpl.clearGeneratedFilesByName(); long beforeComputeOutputFreshnessMs = System.currentTimeMillis(); forgetAllOutputFreshness(); rootBuildTarget.computeOutputFreshness(logger); long computeOutputFreshnessDurationMs = System.currentTimeMillis() - beforeComputeOutputFreshnessMs; logger.log( TreeLogger.INFO, String.format( "%.3fs -- Computing per-target output freshness", computeOutputFreshnessDurationMs / 1000d)); if (rootBuildTarget.isOutputFreshAndGood()) { logger.log(TreeLogger.INFO, NO_FILES_HAVE_CHANGED); return BuildResultStatus.SUCCESS_NO_CHANGES; } TreeLogger branch = logger.branch(TreeLogger.INFO, "Compiling target graph"); boolean success = rootBuildTarget.link(branch); return BuildResultStatus.get(success); }
@Test public void testNotEquals() { BuildTarget utilTarget = BuildTarget.builder(ROOT, "//src/com/facebook/buck/util", "util").build(); BuildTarget ioTarget = BuildTarget.builder(ROOT, "//src/com/facebook/buck/util", "io").build(); assertFalse(utilTarget.equals(ioTarget)); }
@Test public void testBuildTargetWithoutFlavor() { BuildTarget target = BuildTarget.builder(ROOT, "//foo/bar", "baz").build(); assertEquals(target.getShortNameAndFlavorPostfix(), "baz"); assertEquals(ImmutableSortedSet.<Flavor>of(), target.getFlavors()); assertFalse(target.isFlavored()); }
public BuildResultStatus build(TreeLogger logger) { try { logger = logger.branch(TreeLogger.INFO, "Performing an incremental build"); CompilerContext compilerContext = new CompilerContext.Builder() .compileMonolithic(false) .libraryGroup(LibraryGroup.fromLibraries(Lists.<Library>newArrayList(), false)) .build(); long beforeLoadRootModuleMs = System.currentTimeMillis(); rootModule = ModuleDefLoader.loadFromResources( logger, compilerContext, rootModuleName, resourceLoader, false); finalProperties = rootModule.getProperties(); long loadRootModuleDurationMs = System.currentTimeMillis() - beforeLoadRootModuleMs; logger.log( TreeLogger.INFO, String.format( "%.3fs -- Parsing and loading root module definition in %s", loadRootModuleDurationMs / 1000d, rootModuleName)); long beforeCreateTargetGraphMs = System.currentTimeMillis(); rootBuildTarget = createBuildTarget(logger, rootModuleName); rootBuildTarget.setModule(rootModule); long createdTargetGraphDurationMs = System.currentTimeMillis() - beforeCreateTargetGraphMs; logger.log( TreeLogger.INFO, String.format( "%.3fs -- Creating target graph (%s targets)", createdTargetGraphDurationMs / 1000d, buildTargetsByCanonicalModuleName.size())); if (!circularReferenceModuleNameLoops.isEmpty()) { for (List<String> circularReferenceModuleNameLoop : circularReferenceModuleNameLoops) { logger.log( TreeLogger.ERROR, formatCircularModulePathMessage(circularReferenceModuleNameLoop)); } throw new UnableToCompleteException(); } logLoadedBuildTargetGraph(logger, buildTargetsByCanonicalModuleName); long beforeComputeOutputFreshnessMs = System.currentTimeMillis(); ModuleDefLoader.clearModuleCache(); rootBuildTarget.computeOutputFreshness(logger); long computeOutputFreshnessDurationMs = System.currentTimeMillis() - beforeComputeOutputFreshnessMs; logger.log( TreeLogger.INFO, String.format( "%.3fs -- Computing per-target output freshness", computeOutputFreshnessDurationMs / 1000d)); TreeLogger branch = logger.branch(TreeLogger.INFO, "Compiling target graph"); boolean success = rootBuildTarget.link(branch); return BuildResultStatus.get(success); } catch (UnableToCompleteException e) { // The real cause has been logged. return BuildResultStatus.FAILED; } }
@Test public void testBuildTargetWithFlavor() { BuildTarget target = BuildTarget.builder(ROOT, "//foo/bar", "baz").addFlavors(ImmutableFlavor.of("dex")).build(); assertEquals("baz#dex", target.getShortNameAndFlavorPostfix()); assertEquals(ImmutableSortedSet.of(ImmutableFlavor.of("dex")), target.getFlavors()); assertTrue(target.isFlavored()); }
@Test public void testGetUnflavoredTarget() { UnflavoredBuildTarget unflavoredTarget = UnflavoredBuildTarget.builder("//foo/bar", "baz").setCellPath(ROOT).build(); BuildTarget flavoredTarget = BuildTarget.builder(ROOT, "//foo/bar", "baz").addFlavors(ImmutableFlavor.of("biz")).build(); assertEquals(unflavoredTarget, flavoredTarget.getUnflavoredBuildTarget()); }
@Test public void testEqualsOtherBuildTarget() { BuildTarget utilTarget1 = BuildTarget.builder(ROOT, "//src/com/facebook/buck/util", "util").build(); assertEquals(utilTarget1, utilTarget1); BuildTarget utilTarget2 = BuildTarget.builder(ROOT, "//src/com/facebook/buck/util", "util").build(); assertEquals(utilTarget1, utilTarget2); }
private void logLoadedBuildTargetGraph( TreeLogger logger, Map<String, BuildTarget> buildTargetsByCanonicalModuleName) { logger.log(TreeLogger.SPAM, "Loaded build target graph:"); for (String canonicalModuleName : buildTargetsByCanonicalModuleName.keySet()) { logger.log(TreeLogger.SPAM, "\t" + canonicalModuleName); BuildTarget gwtTarget = buildTargetsByCanonicalModuleName.get(canonicalModuleName); for (BuildTarget dependencyBuildTarget : gwtTarget.getDependencyBuildTargets()) { logger.log(TreeLogger.SPAM, "\t\t" + dependencyBuildTarget.getCanonicalModuleName()); } } }
@Test public void testBuildTargetTwoLevelsDeep() { BuildTarget rootTarget = BuildTarget.builder(ROOT, "//java/com/facebook", "fb4a").build(); assertEquals("fb4a", rootTarget.getShortNameAndFlavorPostfix()); assertEquals("//java/com/facebook", rootTarget.getBaseName()); assertEquals("//java/com/facebook/", rootTarget.getBaseNameWithSlash()); assertEquals(Paths.get("java/com/facebook"), rootTarget.getBasePath()); assertEquals("java/com/facebook/", rootTarget.getBasePathWithSlash()); assertEquals("//java/com/facebook:fb4a", rootTarget.getFullyQualifiedName()); assertEquals("//java/com/facebook:fb4a", rootTarget.toString()); }
@Test public void testRootBuildTarget() { BuildTarget rootTarget = BuildTarget.builder(ROOT, "//", "fb4a").build(); assertEquals("fb4a", rootTarget.getShortNameAndFlavorPostfix()); assertEquals("//", rootTarget.getBaseName()); assertEquals("//", rootTarget.getBaseNameWithSlash()); assertEquals(Paths.get(""), rootTarget.getBasePath()); assertEquals("", rootTarget.getBasePathWithSlash()); assertEquals("//:fb4a", rootTarget.getFullyQualifiedName()); assertEquals("//:fb4a", rootTarget.toString()); }
@Test public void testFlavorIsValid() { try { BuildTarget.builder(ROOT, "//foo/bar", "baz").addFlavors(ImmutableFlavor.of("d!x")).build(); fail("Should have thrown IllegalArgumentException."); } catch (IllegalArgumentException e) { assertEquals("Invalid characters in flavor name: d!x", e.getMessage()); } }
@Test public void testShortNameCannotContainHashWhenFlavorSet() { try { BuildTarget.builder(ROOT, "//foo/bar", "baz#dex") .addFlavors(ImmutableFlavor.of("src-jar")) .build(); fail("Should have thrown IllegalArgumentException."); } catch (IllegalArgumentException e) { assertEquals("Build target name cannot contain '#' but was: baz#dex.", e.getMessage()); } }
private void forgetAllOutputFreshness() { for (BuildTarget buildTarget : buildTargetsByCanonicalModuleName.values()) { buildTarget.setOutputFreshness(OutputFreshness.UNKNOWN); } }
@Test public void testEqualsNullReturnsFalse() { BuildTarget utilTarget = BuildTarget.builder(ROOT, "//src/com/facebook/buck/util", "util").build(); assertNotNull(utilTarget); }
@Test public void testNumbersAreValidFlavors() { BuildTarget.builder(ROOT, "//foo", "bar").addFlavors(ImmutableFlavor.of("1234")).build(); }
@Test public void testFlavorDefaultsToNoneIfNotSet() { assertEquals( ImmutableSet.<Flavor>of(), BuildTarget.builder(ROOT, "//foo/bar", "baz").build().getFlavors()); }
@Test(expected = IllegalArgumentException.class) public void testShortNamesMustNotContainTheFlavorSeparator() { BuildTarget.builder(ROOT, "//foo/bar", "baz#dex").build(); }