From 81afbbc09bac6913e2b83f7eb68923ff5b1911d5 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Tue, 22 Jul 2014 15:10:57 +0200 Subject: [PATCH] file(GENERATE): Use permissions of input file if present. --- Source/cmGeneratorExpressionEvaluationFile.cxx | 10 ++++++++-- Source/cmGeneratorExpressionEvaluationFile.h | 2 +- .../File_Generate/CarryPermissions-result.txt | 1 + .../File_Generate/CarryPermissions-stderr.txt | 1 + .../File_Generate/CarryPermissions.cmake | 5 +++++ .../RunCMake/File_Generate/RunCMakeTest.cmake | 18 ++++++++++++++++++ Tests/RunCMake/File_Generate/input_script.sh | 3 +++ 7 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 Tests/RunCMake/File_Generate/CarryPermissions-result.txt create mode 100644 Tests/RunCMake/File_Generate/CarryPermissions-stderr.txt create mode 100644 Tests/RunCMake/File_Generate/CarryPermissions.cmake create mode 100755 Tests/RunCMake/File_Generate/input_script.sh diff --git a/Source/cmGeneratorExpressionEvaluationFile.cxx b/Source/cmGeneratorExpressionEvaluationFile.cxx index f9067cf9a..3a8dc4843 100644 --- a/Source/cmGeneratorExpressionEvaluationFile.cxx +++ b/Source/cmGeneratorExpressionEvaluationFile.cxx @@ -36,7 +36,7 @@ cmGeneratorExpressionEvaluationFile::cmGeneratorExpressionEvaluationFile( //---------------------------------------------------------------------------- void cmGeneratorExpressionEvaluationFile::Generate(const std::string& config, cmCompiledGeneratorExpression* inputExpression, - std::map &outputFiles) + std::map &outputFiles, mode_t perm) { std::string rawCondition = this->Condition->GetInput(); if (!rawCondition.empty()) @@ -83,11 +83,16 @@ void cmGeneratorExpressionEvaluationFile::Generate(const std::string& config, cmGeneratedFileStream fout(outputFileName.c_str()); fout.SetCopyIfDifferent(true); fout << outputContent; + if (fout.Close() && perm) + { + cmSystemTools::SetPermissions(outputFileName.c_str(), perm); + } } //---------------------------------------------------------------------------- void cmGeneratorExpressionEvaluationFile::Generate() { + mode_t perm = 0; std::string inputContent; if (this->InputIsContent) { @@ -95,6 +100,7 @@ void cmGeneratorExpressionEvaluationFile::Generate() } else { + cmSystemTools::GetPermissions(this->Input.c_str(), perm); cmsys::ifstream fin(this->Input.c_str()); if(!fin) { @@ -131,7 +137,7 @@ void cmGeneratorExpressionEvaluationFile::Generate() for(std::vector::const_iterator li = allConfigs.begin(); li != allConfigs.end(); ++li) { - this->Generate(*li, inputExpression.get(), outputFiles); + this->Generate(*li, inputExpression.get(), outputFiles, perm); if(cmSystemTools::GetFatalErrorOccured()) { return; diff --git a/Source/cmGeneratorExpressionEvaluationFile.h b/Source/cmGeneratorExpressionEvaluationFile.h index f939916d6..4e87a88a6 100644 --- a/Source/cmGeneratorExpressionEvaluationFile.h +++ b/Source/cmGeneratorExpressionEvaluationFile.h @@ -34,7 +34,7 @@ public: private: void Generate(const std::string& config, cmCompiledGeneratorExpression* inputExpression, - std::map &outputFiles); + std::map &outputFiles, mode_t perm); private: const std::string Input; diff --git a/Tests/RunCMake/File_Generate/CarryPermissions-result.txt b/Tests/RunCMake/File_Generate/CarryPermissions-result.txt new file mode 100644 index 000000000..573541ac9 --- /dev/null +++ b/Tests/RunCMake/File_Generate/CarryPermissions-result.txt @@ -0,0 +1 @@ +0 diff --git a/Tests/RunCMake/File_Generate/CarryPermissions-stderr.txt b/Tests/RunCMake/File_Generate/CarryPermissions-stderr.txt new file mode 100644 index 000000000..10f32932e --- /dev/null +++ b/Tests/RunCMake/File_Generate/CarryPermissions-stderr.txt @@ -0,0 +1 @@ +^$ diff --git a/Tests/RunCMake/File_Generate/CarryPermissions.cmake b/Tests/RunCMake/File_Generate/CarryPermissions.cmake new file mode 100644 index 000000000..a04334f8e --- /dev/null +++ b/Tests/RunCMake/File_Generate/CarryPermissions.cmake @@ -0,0 +1,5 @@ + +file(GENERATE + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/output_script.sh" + INPUT "${CMAKE_CURRENT_SOURCE_DIR}/input_script.sh" +) diff --git a/Tests/RunCMake/File_Generate/RunCMakeTest.cmake b/Tests/RunCMake/File_Generate/RunCMakeTest.cmake index dee069262..578df817d 100644 --- a/Tests/RunCMake/File_Generate/RunCMakeTest.cmake +++ b/Tests/RunCMake/File_Generate/RunCMakeTest.cmake @@ -35,3 +35,21 @@ unset(RunCMake_TEST_NO_CLEAN) if (NOT timestamp_after STREQUAL timestamp) message(SEND_ERROR "WriteIfDifferent changed output file.") endif() + +if (UNIX AND EXISTS /bin/sh) + set(RunCMake_TEST_NO_CLEAN ON) + run_cmake(CarryPermissions) + execute_process( + COMMAND "${RunCMake_BINARY_DIR}/CarryPermissions-build/output_script.sh" + OUTPUT_VARIABLE script_output + RESULT_VARIABLE script_result + ERROR_VARIABLE script_error + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + if (script_result) + message(SEND_ERROR "Generated script did not execute correctly: [${script_result}]\n${script_output}\n====\n${script_error}") + endif() + if (NOT script_output STREQUAL SUCCESS) + message(SEND_ERROR "Generated script did not execute correctly:\n${script_output}\n====\n${script_error}") + endif() +endif() diff --git a/Tests/RunCMake/File_Generate/input_script.sh b/Tests/RunCMake/File_Generate/input_script.sh new file mode 100755 index 000000000..2cc098384 --- /dev/null +++ b/Tests/RunCMake/File_Generate/input_script.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +echo "$<$:SUCCESS>"