diff --git a/src/com/facebook/buck/cli/Main.java b/src/com/facebook/buck/cli/Main.java index 5ea6588ce2f..230c29da4d1 100644 --- a/src/com/facebook/buck/cli/Main.java +++ b/src/com/facebook/buck/cli/Main.java @@ -45,6 +45,7 @@ import com.facebook.buck.log.CommandThreadAssociation; import com.facebook.buck.log.LogConfig; import com.facebook.buck.log.Logger; +import com.facebook.buck.model.BuckVersion; import com.facebook.buck.model.BuildId; import com.facebook.buck.parser.Parser; import com.facebook.buck.parser.ParserConfig; @@ -567,6 +568,15 @@ public int runMainWithExitCode( if (!commandSemaphoreAcquired) { return BUSY_EXIT_CODE; } + Optional currentVersion = + filesystem.readFileIfItExists(BuckConstant.CURRENT_VERSION_FILE); + if (!currentVersion.isPresent() || !currentVersion.get().equals(BuckVersion.getVersion())) { + filesystem.deleteRecursivelyIfExists(BuckConstant.ANNOTATION_PATH); + filesystem.deleteRecursivelyIfExists(BuckConstant.GEN_PATH); + filesystem.deleteRecursivelyIfExists(BuckConstant.SCRATCH_PATH); + filesystem.mkdirs(BuckConstant.CURRENT_VERSION_FILE.getParent()); + filesystem.writeContentsToPath(BuckVersion.getVersion(), BuckConstant.CURRENT_VERSION_FILE); + } } PropertyFinder propertyFinder = new DefaultPropertyFinder( diff --git a/src/com/facebook/buck/util/BuckConstant.java b/src/com/facebook/buck/util/BuckConstant.java index 3c88dc2fec7..bde2d96eb19 100644 --- a/src/com/facebook/buck/util/BuckConstant.java +++ b/src/com/facebook/buck/util/BuckConstant.java @@ -30,6 +30,11 @@ public class BuckConstant { */ public static final String BUCK_OUTPUT_DIRECTORY = "buck-out"; public static final Path BUCK_OUTPUT_PATH = Paths.get("buck-out"); + /** + * The version the buck output directory was created for + */ + public static final Path CURRENT_VERSION_FILE = + BUCK_OUTPUT_PATH.resolve(".currentversion"); // TODO(mbolin): The constants GEN_DIR, BIN_DIR, and ANNOTATION_DIR should be // package-private to the com.facebook.buck.rules directory. Currently, they are also used in the diff --git a/test/com/facebook/buck/testutil/integration/ProjectWorkspace.java b/test/com/facebook/buck/testutil/integration/ProjectWorkspace.java index 792619da807..78bb0e44218 100644 --- a/test/com/facebook/buck/testutil/integration/ProjectWorkspace.java +++ b/test/com/facebook/buck/testutil/integration/ProjectWorkspace.java @@ -31,8 +31,10 @@ import com.facebook.buck.io.ExecutableFinder; import com.facebook.buck.io.MoreFiles; import com.facebook.buck.io.MorePaths; +import com.facebook.buck.model.BuckVersion; import com.facebook.buck.model.BuildId; import com.facebook.buck.testutil.TestConsole; +import com.facebook.buck.util.BuckConstant; import com.facebook.buck.util.CapturingPrintStream; import com.facebook.buck.util.MoreStrings; import com.facebook.buck.util.ProcessExecutor; @@ -43,21 +45,29 @@ import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; import com.google.common.eventbus.Subscribe; import com.martiansoftware.nailgun.NGContext; import org.junit.rules.TemporaryFolder; +import java.io.BufferedOutputStream; import java.io.File; import java.io.IOException; +import java.io.OutputStream; +import java.nio.channels.Channels; +import java.nio.file.FileAlreadyExistsException; import java.nio.file.FileSystems; import java.nio.file.FileVisitResult; import java.nio.file.Files; import java.nio.file.InvalidPathException; +import java.nio.file.NoSuchFileException; +import java.nio.file.OpenOption; import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.SimpleFileVisitor; import java.nio.file.StandardCopyOption; +import java.nio.file.StandardOpenOption; import java.nio.file.attribute.BasicFileAttributes; import java.util.List; @@ -135,10 +145,26 @@ public ProjectWorkspace(Path templateDir, TemporaryPaths temporaryFolder) { * This will copy the template directory, renaming files named {@code foo.fixture} to {@code foo} * in the process. Files whose names end in {@code .expected} will not be copied. */ + @SuppressWarnings("PMD.EmptyCatchBlock") public ProjectWorkspace setUp() throws IOException { MoreFiles.copyRecursively(templatePath, destPath, BUILD_FILE_RENAME); + // Stamp the buck-out directory if it exists and isn't stamped already + try (OutputStream outputStream = + new BufferedOutputStream( + Channels.newOutputStream( + Files.newByteChannel( + destPath.resolve(BuckConstant.CURRENT_VERSION_FILE), + ImmutableSet.of( + StandardOpenOption.CREATE_NEW, + StandardOpenOption.WRITE))))) { + outputStream.write(BuckVersion.getVersion().getBytes(Charsets.UTF_8)); + } catch (FileAlreadyExistsException | NoSuchFileException e) { + // If the current version file already exists we don't need to create it + // If buck-out doesn't exist we don't need to stamp it + } + // If there's a local.properties in the host project but not in the destination, make a copy. Path localProperties = FileSystems.getDefault().getPath("local.properties"); Path destLocalProperties = destPath.resolve(localProperties.getFileName());