summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2020-10-27 11:10:58 (GMT)
committerKitware Robot <kwrobot@kitware.com>2020-10-27 11:11:13 (GMT)
commitc79e02c4c3acb16d81d1b940074853f653634546 (patch)
tree3c3b014531fa053942bb39ed385880c5cabf5031 /Source
parentecab18bb7ccfc8e91f1465aec32f98afd1b2a4ef (diff)
parent03ad0e61c19304ae145cfa0683b43d9756d37ff5 (diff)
downloadCMake-c79e02c4c3acb16d81d1b940074853f653634546.zip
CMake-c79e02c4c3acb16d81d1b940074853f653634546.tar.gz
CMake-c79e02c4c3acb16d81d1b940074853f653634546.tar.bz2
Merge topic 'cmake-20866'
03ad0e61c1 configure_file: Add option for user defined permissions Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !5320
Diffstat (limited to 'Source')
-rw-r--r--Source/CPack/cmCPackGenerator.cxx2
-rw-r--r--Source/cmConfigureFileCommand.cxx109
-rw-r--r--Source/cmCreateTestSourceList.cxx2
-rw-r--r--Source/cmLocalGenerator.cxx4
-rw-r--r--Source/cmMakefile.cxx20
-rw-r--r--Source/cmMakefile.h5
-rw-r--r--Source/cmVisualStudio10TargetGenerator.cxx2
7 files changed, 117 insertions, 27 deletions
diff --git a/Source/CPack/cmCPackGenerator.cxx b/Source/CPack/cmCPackGenerator.cxx
index a9fe91c..8b544b4 100644
--- a/Source/CPack/cmCPackGenerator.cxx
+++ b/Source/CPack/cmCPackGenerator.cxx
@@ -1329,7 +1329,7 @@ bool cmCPackGenerator::ConfigureFile(const std::string& inName,
bool copyOnly /* = false */)
{
return this->MakefileMap->ConfigureFile(inName, outName, copyOnly, true,
- false, true) == 1;
+ false) == 1;
}
int cmCPackGenerator::CleanTemporaryDirectory()
diff --git a/Source/cmConfigureFileCommand.cxx b/Source/cmConfigureFileCommand.cxx
index 68322cc..edd261d 100644
--- a/Source/cmConfigureFileCommand.cxx
+++ b/Source/cmConfigureFileCommand.cxx
@@ -3,11 +3,15 @@
#include "cmConfigureFileCommand.h"
#include <set>
+#include <sstream>
#include <cm/string_view>
#include <cmext/string_view>
+#include <sys/types.h>
+
#include "cmExecutionStatus.h"
+#include "cmFSPermissions.h"
#include "cmMakefile.h"
#include "cmMessageType.h"
#include "cmNewLineStyle.h"
@@ -60,7 +64,19 @@ bool cmConfigureFileCommand(std::vector<std::string> const& args,
}
bool copyOnly = false;
bool escapeQuotes = false;
- bool use_source_permissions = true;
+ bool useSourcePermissions = false;
+ bool noSourcePermissions = false;
+ bool filePermissions = false;
+ std::vector<std::string> filePermissionOptions;
+
+ enum class Doing
+ {
+ DoingNone,
+ DoingFilePermissions,
+ DoneFilePermissions
+ };
+
+ Doing doing = Doing::DoingNone;
static std::set<cm::string_view> noopOptions = {
/* Legacy. */
@@ -78,6 +94,9 @@ bool cmConfigureFileCommand(std::vector<std::string> const& args,
bool atOnly = false;
for (unsigned int i = 2; i < args.size(); ++i) {
if (args[i] == "COPYONLY") {
+ if (doing == Doing::DoingFilePermissions) {
+ doing = Doing::DoneFilePermissions;
+ }
copyOnly = true;
if (newLineStyle.IsValid()) {
status.SetError("COPYONLY could not be used in combination "
@@ -85,13 +104,49 @@ bool cmConfigureFileCommand(std::vector<std::string> const& args,
return false;
}
} else if (args[i] == "ESCAPE_QUOTES") {
+ if (doing == Doing::DoingFilePermissions) {
+ doing = Doing::DoneFilePermissions;
+ }
escapeQuotes = true;
} else if (args[i] == "@ONLY") {
+ if (doing == Doing::DoingFilePermissions) {
+ doing = Doing::DoneFilePermissions;
+ }
atOnly = true;
} else if (args[i] == "NO_SOURCE_PERMISSIONS") {
- use_source_permissions = false;
+ if (doing == Doing::DoingFilePermissions) {
+ status.SetError(" given both FILE_PERMISSIONS and "
+ "NO_SOURCE_PERMISSIONS. Only one option allowed.");
+ return false;
+ }
+ noSourcePermissions = true;
+ } else if (args[i] == "USE_SOURCE_PERMISSIONS") {
+ if (doing == Doing::DoingFilePermissions) {
+ status.SetError(" given both FILE_PERMISSIONS and "
+ "USE_SOURCE_PERMISSIONS. Only one option allowed.");
+ return false;
+ }
+ useSourcePermissions = true;
+ } else if (args[i] == "FILE_PERMISSIONS") {
+ if (useSourcePermissions) {
+ status.SetError(" given both FILE_PERMISSIONS and "
+ "USE_SOURCE_PERMISSIONS. Only one option allowed.");
+ return false;
+ }
+ if (noSourcePermissions) {
+ status.SetError(" given both FILE_PERMISSIONS and "
+ "NO_SOURCE_PERMISSIONS. Only one option allowed.");
+ return false;
+ }
+
+ if (doing == Doing::DoingNone) {
+ doing = Doing::DoingFilePermissions;
+ filePermissions = true;
+ }
} else if (noopOptions.find(args[i]) != noopOptions.end()) {
/* Ignore no-op options. */
+ } else if (doing == Doing::DoingFilePermissions) {
+ filePermissionOptions.push_back(args[i]);
} else {
unknown_args += " ";
unknown_args += args[i];
@@ -104,9 +159,53 @@ bool cmConfigureFileCommand(std::vector<std::string> const& args,
status.GetMakefile().IssueMessage(MessageType::AUTHOR_WARNING, msg);
}
- if (!status.GetMakefile().ConfigureFile(
- inputFile, outputFile, copyOnly, atOnly, escapeQuotes,
- use_source_permissions, newLineStyle)) {
+ if (useSourcePermissions && noSourcePermissions) {
+ status.SetError(" given both USE_SOURCE_PERMISSIONS and "
+ "NO_SOURCE_PERMISSIONS. Only one option allowed.");
+ return false;
+ }
+
+ mode_t permisiions = 0;
+
+ if (filePermissions) {
+ if (filePermissionOptions.empty()) {
+ status.SetError(" given FILE_PERMISSIONS without any options.");
+ return false;
+ }
+
+ std::vector<std::string> invalidOptions;
+ for (auto const& e : filePermissionOptions) {
+ if (!cmFSPermissions::stringToModeT(e, permisiions)) {
+ invalidOptions.push_back(e);
+ }
+ }
+
+ if (!invalidOptions.empty()) {
+ std::ostringstream oss;
+ oss << " given invalid permission ";
+ for (auto i = 0u; i < invalidOptions.size(); i++) {
+ if (i == 0u) {
+ oss << "\"" << invalidOptions[i] << "\"";
+ } else {
+ oss << ",\"" << invalidOptions[i] << "\"";
+ }
+ }
+ oss << ".";
+ status.SetError(oss.str());
+ return false;
+ }
+ }
+
+ if (noSourcePermissions) {
+ permisiions |= cmFSPermissions::mode_owner_read;
+ permisiions |= cmFSPermissions::mode_owner_write;
+ permisiions |= cmFSPermissions::mode_group_read;
+ permisiions |= cmFSPermissions::mode_world_read;
+ }
+
+ if (!status.GetMakefile().ConfigureFile(inputFile, outputFile, copyOnly,
+ atOnly, escapeQuotes, permisiions,
+ newLineStyle)) {
status.SetError("Problem configuring file");
return false;
}
diff --git a/Source/cmCreateTestSourceList.cxx b/Source/cmCreateTestSourceList.cxx
index 9c4deea..9d492ba 100644
--- a/Source/cmCreateTestSourceList.cxx
+++ b/Source/cmCreateTestSourceList.cxx
@@ -127,7 +127,7 @@ bool cmCreateTestSourceList(std::vector<std::string> const& args,
mf.AddDefinition("CMAKE_FORWARD_DECLARE_TESTS", forwardDeclareCode);
mf.AddDefinition("CMAKE_FUNCTION_TABLE_ENTIRES", functionMapCode);
bool res = true;
- if (!mf.ConfigureFile(configFile, driver, false, true, false, true)) {
+ if (!mf.ConfigureFile(configFile, driver, false, true, false)) {
res = false;
}
diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx
index 47e10e0..288172e 100644
--- a/Source/cmLocalGenerator.cxx
+++ b/Source/cmLocalGenerator.cxx
@@ -3768,7 +3768,7 @@ void cmLocalGenerator::GenerateAppleInfoPList(cmGeneratorTarget* target,
cmLGInfoProp(mf, target, "MACOSX_BUNDLE_SHORT_VERSION_STRING");
cmLGInfoProp(mf, target, "MACOSX_BUNDLE_BUNDLE_VERSION");
cmLGInfoProp(mf, target, "MACOSX_BUNDLE_COPYRIGHT");
- mf->ConfigureFile(inFile, fname, false, false, false, true);
+ mf->ConfigureFile(inFile, fname, false, false, false);
}
void cmLocalGenerator::GenerateFrameworkInfoPList(
@@ -3803,7 +3803,7 @@ void cmLocalGenerator::GenerateFrameworkInfoPList(
cmLGInfoProp(mf, target, "MACOSX_FRAMEWORK_IDENTIFIER");
cmLGInfoProp(mf, target, "MACOSX_FRAMEWORK_SHORT_VERSION_STRING");
cmLGInfoProp(mf, target, "MACOSX_FRAMEWORK_BUNDLE_VERSION");
- mf->ConfigureFile(inFile, fname, false, false, false, true);
+ mf->ConfigureFile(inFile, fname, false, false, false);
}
namespace {
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index 6d1868c..56b7ae1 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -29,15 +29,12 @@
#include "cmsys/FStream.hxx"
#include "cmsys/RegularExpression.hxx"
-#include "cm_sys_stat.h"
-
#include "cmCommandArgumentParserHelper.h"
#include "cmCustomCommand.h"
#include "cmCustomCommandLines.h"
#include "cmExecutionStatus.h"
#include "cmExpandedCommandArgument.h" // IWYU pragma: keep
#include "cmExportBuildFileGenerator.h"
-#include "cmFSPermissions.h"
#include "cmFileLockPool.h"
#include "cmFunctionBlocker.h"
#include "cmGeneratedFileStream.h"
@@ -72,8 +69,6 @@
class cmMessenger;
-using namespace cmFSPermissions;
-
cmDirectoryId::cmDirectoryId(std::string s)
: String(std::move(s))
{
@@ -3850,8 +3845,7 @@ void cmMakefile::ConfigureString(const std::string& input, std::string& output,
int cmMakefile::ConfigureFile(const std::string& infile,
const std::string& outfile, bool copyonly,
bool atOnly, bool escapeQuotes,
- bool use_source_permissions,
- cmNewLineStyle newLine)
+ mode_t permissions, cmNewLineStyle newLine)
{
int res = 1;
if (!this->CanIWriteThisFile(outfile)) {
@@ -3873,12 +3867,8 @@ int cmMakefile::ConfigureFile(const std::string& infile,
// output files that now don't exist.
this->AddCMakeOutputFile(soutfile);
- mode_t perm = 0;
- if (!use_source_permissions) {
- perm = perm | mode_owner_read | mode_owner_write | mode_group_read |
- mode_world_read;
- } else {
- cmSystemTools::GetPermissions(sinfile, perm);
+ if (permissions == 0) {
+ cmSystemTools::GetPermissions(sinfile, permissions);
}
std::string::size_type pos = soutfile.rfind('/');
@@ -3893,7 +3883,7 @@ int cmMakefile::ConfigureFile(const std::string& infile,
cmSystemTools::GetLastSystemError());
return 0;
}
- if (!cmSystemTools::SetPermissions(soutfile, perm)) {
+ if (!cmSystemTools::SetPermissions(soutfile, permissions)) {
this->IssueMessage(MessageType::FATAL_ERROR,
cmSystemTools::GetLastSystemError());
return 0;
@@ -3950,7 +3940,7 @@ int cmMakefile::ConfigureFile(const std::string& infile,
cmSystemTools::GetLastSystemError());
res = 0;
} else {
- if (!cmSystemTools::SetPermissions(soutfile, perm)) {
+ if (!cmSystemTools::SetPermissions(soutfile, permissions)) {
this->IssueMessage(MessageType::FATAL_ERROR,
cmSystemTools::GetLastSystemError());
res = 0;
diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h
index 26ed737..edee02b 100644
--- a/Source/cmMakefile.h
+++ b/Source/cmMakefile.h
@@ -20,6 +20,8 @@
#include "cmsys/RegularExpression.hxx"
+#include "cm_sys_stat.h"
+
#include "cmAlgorithms.h"
#include "cmCustomCommandTypes.h"
#include "cmListFileCache.h"
@@ -659,8 +661,7 @@ public:
*/
int ConfigureFile(const std::string& infile, const std::string& outfile,
bool copyonly, bool atOnly, bool escapeQuotes,
- bool use_source_permissions,
- cmNewLineStyle = cmNewLineStyle());
+ mode_t permissions = 0, cmNewLineStyle = cmNewLineStyle());
/**
* Print a command's invocation
diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx
index 1ca7de8..0d31c5e 100644
--- a/Source/cmVisualStudio10TargetGenerator.cxx
+++ b/Source/cmVisualStudio10TargetGenerator.cxx
@@ -676,7 +676,7 @@ void cmVisualStudio10TargetGenerator::Generate()
cmStrCat(this->DefaultArtifactDir, "\\nasm.props");
ConvertToWindowsSlash(propsLocal);
this->Makefile->ConfigureFile(propsTemplate, propsLocal, false, true,
- true, true);
+ true);
Elem(e1, "Import").Attribute("Project", propsLocal);
}
}