Browse Source

Merge topic 'commands-file-permissions'

769ff05483 Help: Clarify permission-related command options
900184616a Cleanup: Fix misspelt name of local C++ variable
635431a0c9 Tests: Check host platform instead of target for running stat
4ceb0ca59e Tests: Remove redundant files for configure_file() tests

Acked-by: Kitware Robot <[email protected]>
Merge-request: !5945
Brad King 4 năm trước cách đây
mục cha
commit
75dd9b6c97

+ 22 - 15
Help/command/configure_file.rst

@@ -6,9 +6,9 @@ Copy a file to another location and modify its contents.
 .. code-block:: cmake
 .. code-block:: cmake
 
 
   configure_file(<input> <output>
   configure_file(<input> <output>
-                 [FILE_PERMISSIONS <permissions>...]
+                 [NO_SOURCE_PERMISSIONS | USE_SOURCE_PERMISSIONS |
+                  FILE_PERMISSIONS <permissions>...]
                  [COPYONLY] [ESCAPE_QUOTES] [@ONLY]
                  [COPYONLY] [ESCAPE_QUOTES] [@ONLY]
-                 [NO_SOURCE_PERMISSIONS] [USE_SOURCE_PERMISSIONS]
                  [NEWLINE_STYLE [UNIX|DOS|WIN32|LF|CRLF] ])
                  [NEWLINE_STYLE [UNIX|DOS|WIN32|LF|CRLF] ])
 
 
 Copies an ``<input>`` file to an ``<output>`` file and substitutes
 Copies an ``<input>`` file to an ``<output>`` file and substitutes
@@ -97,8 +97,27 @@ The arguments are:
   If the path names an existing directory the output file is placed
   If the path names an existing directory the output file is placed
   in that directory with the same file name as the input file.
   in that directory with the same file name as the input file.
 
 
+``NO_SOURCE_PERMISSIONS``
+  .. versionadded:: 3.19
+
+  Do not transfer the permissions of the input file to the output file.
+  The copied file permissions default to the standard 644 value
+  (-rw-r--r--).
+
+``USE_SOURCE_PERMISSIONS``
+  .. versionadded:: 3.20
+
+  Transfer the permissions of the input file to the output file.
+  This is already the default behavior if none of the three permissions-related
+  keywords are given (``NO_SOURCE_PERMISSIONS``, ``USE_SOURCE_PERMISSIONS``
+  or ``FILE_PERMISSIONS``).  The ``USE_SOURCE_PERMISSIONS`` keyword mostly
+  serves as a way of making the intended behavior clearer at the call site.
+
 ``FILE_PERMISSIONS <permissions>...``
 ``FILE_PERMISSIONS <permissions>...``
-  Use user provided permissions for the output file.
+  .. versionadded:: 3.20
+
+  Ignore the input file's permissions and use the specified ``<permissions>``
+  for the output file instead.
 
 
 ``COPYONLY``
 ``COPYONLY``
   Copy the file without replacing any variable references or other
   Copy the file without replacing any variable references or other
@@ -111,18 +130,6 @@ The arguments are:
   Restrict variable replacement to references of the form ``@VAR@``.
   Restrict variable replacement to references of the form ``@VAR@``.
   This is useful for configuring scripts that use ``${VAR}`` syntax.
   This is useful for configuring scripts that use ``${VAR}`` syntax.
 
 
-``NO_SOURCE_PERMISSIONS``
-  .. versionadded:: 3.19
-
-  Does not transfer the file permissions of the original file to the copy.
-  The copied file permissions default to the standard 644 value
-  (-rw-r--r--).
-
-``USE_SOURCE_PERMISSIONS``
-  .. versionadded:: 3.20
-
-  Transfer the file permissions of the original file to the output file.
-
 ``NEWLINE_STYLE <style>``
 ``NEWLINE_STYLE <style>``
   Specify the newline style for the output file.  Specify
   Specify the newline style for the output file.  Specify
   ``UNIX`` or ``LF`` for ``\n`` newlines, or specify
   ``UNIX`` or ``LF`` for ``\n`` newlines, or specify

+ 18 - 8
Help/command/file.rst

@@ -481,8 +481,8 @@ modified.
   file(GENERATE OUTPUT output-file
   file(GENERATE OUTPUT output-file
        <INPUT input-file|CONTENT content>
        <INPUT input-file|CONTENT content>
        [CONDITION expression] [TARGET target]
        [CONDITION expression] [TARGET target]
-       [FILE_PERMISSIONS <permissions>...]
-       [NO_SOURCE_PERMISSIONS] [USE_SOURCE_PERMISSIONS]
+       [NO_SOURCE_PERMISSIONS | USE_SOURCE_PERMISSIONS |
+        FILE_PERMISSIONS <permissions>...]
        [NEWLINE_STYLE [UNIX|DOS|WIN32|LF|CRLF] ])
        [NEWLINE_STYLE [UNIX|DOS|WIN32|LF|CRLF] ])
 
 
 Generate an output file for each build configuration supported by the current
 Generate an output file for each build configuration supported by the current
@@ -524,16 +524,26 @@ from the input content to produce the output content.  The options are:
   require a target for evaluation (e.g. ``$<COMPILE_FEATURES:...>``,
   require a target for evaluation (e.g. ``$<COMPILE_FEATURES:...>``,
   ``$<TARGET_PROPERTY:prop>``).
   ``$<TARGET_PROPERTY:prop>``).
 
 
-``FILE_PERMISSIONS <permissions>...``
-  Use user provided permissions for the generated file.
-
 ``NO_SOURCE_PERMISSIONS``
 ``NO_SOURCE_PERMISSIONS``
+  .. versionadded:: 3.20
+
   The generated file permissions default to the standard 644 value
   The generated file permissions default to the standard 644 value
   (-rw-r--r--).
   (-rw-r--r--).
 
 
 ``USE_SOURCE_PERMISSIONS``
 ``USE_SOURCE_PERMISSIONS``
-  Transfer the file permissions of the original file to the generated file.
-  This option expects INPUT option.
+  .. versionadded:: 3.20
+
+  Transfer the file permissions of the ``INPUT`` file to the generated file.
+  This is already the default behavior if none of the three permissions-related
+  keywords are given (``NO_SOURCE_PERMISSIONS``, ``USE_SOURCE_PERMISSIONS``
+  or ``FILE_PERMISSIONS``).  The ``USE_SOURCE_PERMISSIONS`` keyword mostly
+  serves as a way of making the intended behavior clearer at the call site.
+  It is an error to specify this option without ``INPUT``.
+
+``FILE_PERMISSIONS <permissions>...``
+  .. versionadded:: 3.20
+
+  Use the specified permissions for the generated file.
 
 
 ``NEWLINE_STYLE <style>``
 ``NEWLINE_STYLE <style>``
   .. versionadded:: 3.20
   .. versionadded:: 3.20
@@ -738,9 +748,9 @@ Create the given directories and their parents as needed.
 .. code-block:: cmake
 .. code-block:: cmake
 
 
   file(<COPY|INSTALL> <files>... DESTINATION <dir>
   file(<COPY|INSTALL> <files>... DESTINATION <dir>
+       [NO_SOURCE_PERMISSIONS | USE_SOURCE_PERMISSIONS]
        [FILE_PERMISSIONS <permissions>...]
        [FILE_PERMISSIONS <permissions>...]
        [DIRECTORY_PERMISSIONS <permissions>...]
        [DIRECTORY_PERMISSIONS <permissions>...]
-       [NO_SOURCE_PERMISSIONS] [USE_SOURCE_PERMISSIONS]
        [FOLLOW_SYMLINK_CHAIN]
        [FOLLOW_SYMLINK_CHAIN]
        [FILES_MATCHING]
        [FILES_MATCHING]
        [[PATTERN <pattern> | REGEX <regex>]
        [[PATTERN <pattern> | REGEX <regex>]

+ 7 - 7
Source/cmConfigureFileCommand.cxx

@@ -165,7 +165,7 @@ bool cmConfigureFileCommand(std::vector<std::string> const& args,
     return false;
     return false;
   }
   }
 
 
-  mode_t permisiions = 0;
+  mode_t permissions = 0;
 
 
   if (filePermissions) {
   if (filePermissions) {
     if (filePermissionOptions.empty()) {
     if (filePermissionOptions.empty()) {
@@ -175,7 +175,7 @@ bool cmConfigureFileCommand(std::vector<std::string> const& args,
 
 
     std::vector<std::string> invalidOptions;
     std::vector<std::string> invalidOptions;
     for (auto const& e : filePermissionOptions) {
     for (auto const& e : filePermissionOptions) {
-      if (!cmFSPermissions::stringToModeT(e, permisiions)) {
+      if (!cmFSPermissions::stringToModeT(e, permissions)) {
         invalidOptions.push_back(e);
         invalidOptions.push_back(e);
       }
       }
     }
     }
@@ -197,14 +197,14 @@ bool cmConfigureFileCommand(std::vector<std::string> const& args,
   }
   }
 
 
   if (noSourcePermissions) {
   if (noSourcePermissions) {
-    permisiions |= cmFSPermissions::mode_owner_read;
-    permisiions |= cmFSPermissions::mode_owner_write;
-    permisiions |= cmFSPermissions::mode_group_read;
-    permisiions |= cmFSPermissions::mode_world_read;
+    permissions |= cmFSPermissions::mode_owner_read;
+    permissions |= cmFSPermissions::mode_owner_write;
+    permissions |= cmFSPermissions::mode_group_read;
+    permissions |= cmFSPermissions::mode_world_read;
   }
   }
 
 
   if (!status.GetMakefile().ConfigureFile(inputFile, outputFile, copyOnly,
   if (!status.GetMakefile().ConfigureFile(inputFile, outputFile, copyOnly,
-                                          atOnly, escapeQuotes, permisiions,
+                                          atOnly, escapeQuotes, permissions,
                                           newLineStyle)) {
                                           newLineStyle)) {
     status.SetError("Problem configuring file");
     status.SetError("Problem configuring file");
     return false;
     return false;

+ 7 - 7
Source/cmFileCommand.cxx

@@ -2577,18 +2577,18 @@ bool HandleGenerateCommand(std::vector<std::string> const& args,
     }
     }
   }
   }
 
 
-  mode_t permisiions = 0;
+  mode_t permissions = 0;
   if (arguments.NoSourcePermissions) {
   if (arguments.NoSourcePermissions) {
-    permisiions |= cmFSPermissions::mode_owner_read;
-    permisiions |= cmFSPermissions::mode_owner_write;
-    permisiions |= cmFSPermissions::mode_group_read;
-    permisiions |= cmFSPermissions::mode_world_read;
+    permissions |= cmFSPermissions::mode_owner_read;
+    permissions |= cmFSPermissions::mode_owner_write;
+    permissions |= cmFSPermissions::mode_group_read;
+    permissions |= cmFSPermissions::mode_world_read;
   }
   }
 
 
   if (!arguments.FilePermissions.empty()) {
   if (!arguments.FilePermissions.empty()) {
     std::vector<std::string> invalidOptions;
     std::vector<std::string> invalidOptions;
     for (auto const& e : arguments.FilePermissions) {
     for (auto const& e : arguments.FilePermissions) {
-      if (!cmFSPermissions::stringToModeT(e, permisiions)) {
+      if (!cmFSPermissions::stringToModeT(e, permissions)) {
         invalidOptions.push_back(e);
         invalidOptions.push_back(e);
       }
       }
     }
     }
@@ -2610,7 +2610,7 @@ bool HandleGenerateCommand(std::vector<std::string> const& args,
 
 
   AddEvaluationFile(input, arguments.Target, arguments.Output,
   AddEvaluationFile(input, arguments.Target, arguments.Output,
                     arguments.Condition, inputIsContent,
                     arguments.Condition, inputIsContent,
-                    newLineStyle.GetCharacters(), permisiions, status);
+                    newLineStyle.GetCharacters(), permissions, status);
   return true;
   return true;
 }
 }
 
 

+ 1 - 1
Tests/RunCMake/File_Generate/UseSourcePermissionsVerify.cmake

@@ -2,7 +2,7 @@ if(NOT EXISTS "${generatedFile}")
   message(SEND_ERROR "Missing generated file:\n  ${generatedFile}")
   message(SEND_ERROR "Missing generated file:\n  ${generatedFile}")
 endif()
 endif()
 
 
-if (UNIX)
+if (CMAKE_HOST_UNIX)
   find_program(STAT_EXECUTABLE NAMES stat)
   find_program(STAT_EXECUTABLE NAMES stat)
   if(NOT STAT_EXECUTABLE)
   if(NOT STAT_EXECUTABLE)
     return()
     return()

+ 0 - 0
Tests/RunCMake/configure_file/SourcePermissions-result.txt


+ 0 - 0
Tests/RunCMake/configure_file/SourcePermissions-stderr.txt


+ 3 - 3
Tests/RunCMake/configure_file/SourcePermissions.cmake

@@ -6,17 +6,17 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/sourcefile.txt
         WORLD_READ
         WORLD_READ
 )
 )
 
 
-if (UNIX)
+if (CMAKE_HOST_UNIX)
   find_program(STAT_EXECUTABLE NAMES stat)
   find_program(STAT_EXECUTABLE NAMES stat)
   if(NOT STAT_EXECUTABLE)
   if(NOT STAT_EXECUTABLE)
     return()
     return()
   endif()
   endif()
 
 
-  if (CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
+  if (CMAKE_HOST_SYSTEM_NAME MATCHES "FreeBSD")
     execute_process(COMMAND "${STAT_EXECUTABLE}" -f %Lp "${CMAKE_CURRENT_BINARY_DIR}/sourcefile-source-permissions.txt"
     execute_process(COMMAND "${STAT_EXECUTABLE}" -f %Lp "${CMAKE_CURRENT_BINARY_DIR}/sourcefile-source-permissions.txt"
       OUTPUT_VARIABLE output
       OUTPUT_VARIABLE output
     )
     )
-  elseif(CMAKE_SYSTEM_NAME MATCHES "Darwin")
+  elseif(CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin")
     execute_process(COMMAND "${STAT_EXECUTABLE}" -f %A "${CMAKE_CURRENT_BINARY_DIR}/sourcefile-source-permissions.txt"
     execute_process(COMMAND "${STAT_EXECUTABLE}" -f %A "${CMAKE_CURRENT_BINARY_DIR}/sourcefile-source-permissions.txt"
       OUTPUT_VARIABLE output
       OUTPUT_VARIABLE output
     )
     )

+ 3 - 3
Tests/RunCMake/configure_file/UseSourcePermissions.cmake

@@ -3,20 +3,20 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/sourcefile.txt
     USE_SOURCE_PERMISSIONS
     USE_SOURCE_PERMISSIONS
 )
 )
 
 
-if (UNIX)
+if (CMAKE_HOST_UNIX)
   find_program(STAT_EXECUTABLE NAMES stat)
   find_program(STAT_EXECUTABLE NAMES stat)
   if(NOT STAT_EXECUTABLE)
   if(NOT STAT_EXECUTABLE)
     return()
     return()
   endif()
   endif()
 
 
-  if (CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
+  if (CMAKE_HOST_SYSTEM_NAME MATCHES "FreeBSD")
     execute_process(COMMAND "${STAT_EXECUTABLE}" -f %Lp "${CMAKE_CURRENT_SOURCE_DIR}/sourcefile.txt"
     execute_process(COMMAND "${STAT_EXECUTABLE}" -f %Lp "${CMAKE_CURRENT_SOURCE_DIR}/sourcefile.txt"
       OUTPUT_VARIABLE output1
       OUTPUT_VARIABLE output1
     )
     )
     execute_process(COMMAND "${STAT_EXECUTABLE}" -f %Lp "${CMAKE_CURRENT_BINARY_DIR}/sourcefile-use-source-permissions.txt"
     execute_process(COMMAND "${STAT_EXECUTABLE}" -f %Lp "${CMAKE_CURRENT_BINARY_DIR}/sourcefile-use-source-permissions.txt"
       OUTPUT_VARIABLE output2
       OUTPUT_VARIABLE output2
     )
     )
-  elseif (CMAKE_SYSTEM_NAME MATCHES "Darwin")
+  elseif (CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin")
     execute_process(COMMAND "${STAT_EXECUTABLE}" -f %A "${CMAKE_CURRENT_SOURCE_DIR}/sourcefile.txt"
     execute_process(COMMAND "${STAT_EXECUTABLE}" -f %A "${CMAKE_CURRENT_SOURCE_DIR}/sourcefile.txt"
       OUTPUT_VARIABLE output1
       OUTPUT_VARIABLE output1
     )
     )