mirror of
https://github.com/Kitware/CMake.git
synced 2026-05-03 12:49:50 -05:00
Merge topic 'file-GENERATE-tmp'
4d40253f1cTests: Cover file(GENERATE) using 'foo.tmp' as input for output 'foo'eaa420e99ccmGeneratedFileStream: Use random temporary file extension by default09ff1cb650cmCTest: Explicitly specify '.tmp' extension on in-progress log files0d3a034725cmGeneratedFileStream: Optionally use custom temporary file extension Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !4992
This commit is contained in:
@@ -841,6 +841,7 @@ bool cmCTest::OpenOutputFile(const std::string& path, const std::string& name,
|
||||
}
|
||||
}
|
||||
std::string filename = testingDir + "/" + name;
|
||||
stream.SetTempExt("tmp");
|
||||
stream.Open(filename);
|
||||
if (!stream) {
|
||||
cmCTestLog(this, ERROR_MESSAGE,
|
||||
|
||||
@@ -122,10 +122,17 @@ void cmGeneratedFileStreamBase::Open(std::string const& name)
|
||||
// Create the name of the temporary file.
|
||||
this->TempName = name;
|
||||
#if defined(__VMS)
|
||||
this->TempName += "_tmp";
|
||||
this->TempName += "_";
|
||||
#else
|
||||
this->TempName += ".tmp";
|
||||
this->TempName += ".";
|
||||
#endif
|
||||
if (!this->TempExt.empty()) {
|
||||
this->TempName += this->TempExt;
|
||||
} else {
|
||||
char buf[64];
|
||||
sprintf(buf, "tmp%05x", cmSystemTools::RandomSeed() & 0xFFFFF);
|
||||
this->TempName += buf;
|
||||
}
|
||||
|
||||
// Make sure the temporary file that will be used is not present.
|
||||
cmSystemTools::RemoveFile(this->TempName);
|
||||
@@ -216,3 +223,8 @@ void cmGeneratedFileStream::SetName(const std::string& fname)
|
||||
{
|
||||
this->Name = fname;
|
||||
}
|
||||
|
||||
void cmGeneratedFileStream::SetTempExt(std::string const& ext)
|
||||
{
|
||||
this->TempExt = ext;
|
||||
}
|
||||
|
||||
@@ -43,6 +43,9 @@ protected:
|
||||
// The name of the final destination file for the output.
|
||||
std::string Name;
|
||||
|
||||
// The extension of the temporary file.
|
||||
std::string TempExt;
|
||||
|
||||
// The name of the temporary file.
|
||||
std::string TempName;
|
||||
|
||||
@@ -138,6 +141,12 @@ public:
|
||||
* the output file to be changed during the use of cmGeneratedFileStream.
|
||||
*/
|
||||
void SetName(const std::string& fname);
|
||||
|
||||
/**
|
||||
* Set set a custom temporary file extension used with 'Open'.
|
||||
* This does not work if the file was opened by the constructor.
|
||||
*/
|
||||
void SetTempExt(std::string const& ext);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
cmake_policy(SET CMP0070 NEW)
|
||||
if(EXISTS "${CMAKE_CURRENT_BINARY_DIR}/AdjacentInOut.txt")
|
||||
message(FATAL_ERROR "CMake should not re-run during the build!")
|
||||
endif()
|
||||
configure_file(AdjacentInOut.in ${CMAKE_CURRENT_BINARY_DIR}/AdjacentInOut.txt.tmp)
|
||||
file(GENERATE OUTPUT AdjacentInOut.txt INPUT ${CMAKE_CURRENT_BINARY_DIR}/AdjacentInOut.txt.tmp)
|
||||
@@ -0,0 +1 @@
|
||||
Sample Text File
|
||||
@@ -72,6 +72,7 @@ if (UNIX AND EXISTS /bin/sh)
|
||||
if (NOT script_output STREQUAL SUCCESS)
|
||||
message(SEND_ERROR "Generated script did not execute correctly:\n${script_output}\n====\n${script_error}")
|
||||
endif()
|
||||
unset(RunCMake_TEST_NO_CLEAN)
|
||||
endif()
|
||||
|
||||
if (RunCMake_GENERATOR MATCHES Makefiles)
|
||||
@@ -104,3 +105,10 @@ if (RunCMake_GENERATOR MATCHES Makefiles)
|
||||
message(SEND_ERROR "File did not re-generate: \"${RunCMake_BINARY_DIR}/ReRunCMake-build/output_file.txt\"")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/AdjacentInOut-build)
|
||||
run_cmake(AdjacentInOut)
|
||||
set(RunCMake_TEST_NO_CLEAN 1)
|
||||
run_cmake_command(AdjacentInOut-nowork ${CMAKE_COMMAND} --build .)
|
||||
unset(RunCMake_TEST_BINARY_DIR)
|
||||
unset(RunCMake_TEST_NO_CLEAN)
|
||||
|
||||
Reference in New Issue
Block a user