From f1eeb689abb911c3c531286d07f3511ed42878c9 Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Tue, 29 Oct 2019 16:51:12 +0000 Subject: [PATCH] Pull in r373338 from upstream llvm trunk (by Simon Pilgrim): Revert rL349624 : Let TableGen write output only if it changed, instead of doing so in cmake, attempt 2 Differential Revision: https://reviews.llvm.org/D55842 ----------------- As discussed on PR43385 this is causing Visual Studio msbuilds to perpetually rebuild all tablegen generated files Pull in r373664 from upstream llvm trunk (by Nico Weber): Reland r349624: Let TableGen write output only if it changed, instead of doing so in cmake Move the write-if-changed logic behind a flag and don't pass it with the MSVC generator. msbuild doesn't have a restat optimization, so not doing write-if-change there doesn't have a cost, and it should fix whatever causes PR43385. This should fix the scenario where an incremental build from before r353358 (the clang 9.0.0 upgrade) to r353358 or later fails to update the timestamp of the generated lib/clang/headers/arm_fp16.h header. After such a build, installing world from read-only source and object directories would attempt to generate the header again, leading to "clang-tblgen: error opening arm_fp16.h.d:Read-only file system". Reported by: avg, np PR: 241402 MFC after: 1 month X-MFC-With: r353358 --- contrib/llvm/lib/TableGen/Main.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/contrib/llvm/lib/TableGen/Main.cpp b/contrib/llvm/lib/TableGen/Main.cpp index bcd39584e450..b6ccc2a08593 100644 --- a/contrib/llvm/lib/TableGen/Main.cpp +++ b/contrib/llvm/lib/TableGen/Main.cpp @@ -49,6 +49,9 @@ static cl::list MacroNames("D", cl::desc("Name of the macro to be defined"), cl::value_desc("macro name"), cl::Prefix); +static cl::opt +WriteIfChanged("write-if-changed", cl::desc("Only write output if it changed")); + static int reportError(const char *ProgName, Twine Msg) { errs() << ProgName << ": " << Msg; errs().flush(); @@ -114,12 +117,14 @@ int llvm::TableGenMain(char *argv0, TableGenMainFn *MainFn) { return Ret; } - // Only updates the real output file if there are any differences. - // This prevents recompilation of all the files depending on it if there - // aren't any. - if (auto ExistingOrErr = MemoryBuffer::getFile(OutputFilename)) - if (std::move(ExistingOrErr.get())->getBuffer() == Out.str()) - return 0; + if (WriteIfChanged) { + // Only updates the real output file if there are any differences. + // This prevents recompilation of all the files depending on it if there + // aren't any. + if (auto ExistingOrErr = MemoryBuffer::getFile(OutputFilename)) + if (std::move(ExistingOrErr.get())->getBuffer() == Out.str()) + return 0; + } std::error_code EC; ToolOutputFile OutFile(OutputFilename, EC, sys::fs::F_Text);