summaryrefslogtreecommitdiffstats
path: root/Tests/RunCMake/File_Generate
diff options
context:
space:
mode:
authorAsit Dhal <dhal.asitk@gmail.com>2020-10-28 10:07:57 (GMT)
committerAsit Dhal <dhal.asitk@gmail.com>2020-12-21 11:16:16 (GMT)
commitc3385dd8bd7c78cf03d7e52ae0f49e8216cdaaea (patch)
tree429c6d6e88db90402670eef5e288f7f4a1bb29ca /Tests/RunCMake/File_Generate
parentc89514a6a47b678dddb703c302def4fe56abe275 (diff)
downloadCMake-c3385dd8bd7c78cf03d7e52ae0f49e8216cdaaea.zip
CMake-c3385dd8bd7c78cf03d7e52ae0f49e8216cdaaea.tar.gz
CMake-c3385dd8bd7c78cf03d7e52ae0f49e8216cdaaea.tar.bz2
file(GENERATE): Support options to manipulate file permissions
Fixes: #15653
Diffstat (limited to 'Tests/RunCMake/File_Generate')
-rw-r--r--Tests/RunCMake/File_Generate/CustomFilePermissions.cmake15
-rw-r--r--Tests/RunCMake/File_Generate/CustomFilePermissionsVerify.cmake36
-rw-r--r--Tests/RunCMake/File_Generate/NoSourcePermissions.cmake10
-rw-r--r--Tests/RunCMake/File_Generate/NoSourcePermissionsVerify.cmake36
-rw-r--r--Tests/RunCMake/File_Generate/RunCMakeTest.cmake21
-rw-r--r--Tests/RunCMake/File_Generate/SourcePermissions1-result.txt1
-rw-r--r--Tests/RunCMake/File_Generate/SourcePermissions1-stderr.txt5
-rw-r--r--Tests/RunCMake/File_Generate/SourcePermissions1.cmake5
-rw-r--r--Tests/RunCMake/File_Generate/SourcePermissions2-result.txt1
-rw-r--r--Tests/RunCMake/File_Generate/SourcePermissions2-stderr.txt5
-rw-r--r--Tests/RunCMake/File_Generate/SourcePermissions2.cmake5
-rw-r--r--Tests/RunCMake/File_Generate/SourcePermissions3-result.txt1
-rw-r--r--Tests/RunCMake/File_Generate/SourcePermissions3-stderr.txt5
-rw-r--r--Tests/RunCMake/File_Generate/SourcePermissions3.cmake5
-rw-r--r--Tests/RunCMake/File_Generate/SourcePermissions4-result.txt1
-rw-r--r--Tests/RunCMake/File_Generate/SourcePermissions4-stderr.txt4
-rw-r--r--Tests/RunCMake/File_Generate/SourcePermissions4.cmake4
-rw-r--r--Tests/RunCMake/File_Generate/SourcePermissions5-result.txt1
-rw-r--r--Tests/RunCMake/File_Generate/SourcePermissions5-stderr.txt4
-rw-r--r--Tests/RunCMake/File_Generate/SourcePermissions5.cmake4
-rw-r--r--Tests/RunCMake/File_Generate/UseSourcePermissions.cmake11
-rw-r--r--Tests/RunCMake/File_Generate/UseSourcePermissionsVerify.cmake51
22 files changed, 231 insertions, 0 deletions
diff --git a/Tests/RunCMake/File_Generate/CustomFilePermissions.cmake b/Tests/RunCMake/File_Generate/CustomFilePermissions.cmake
new file mode 100644
index 0000000..0000ef9
--- /dev/null
+++ b/Tests/RunCMake/File_Generate/CustomFilePermissions.cmake
@@ -0,0 +1,15 @@
+file(REMOVE "${CMAKE_CURRENT_BINARY_DIR}/customfilepermissions.txt")
+
+file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/$<LOWER_CASE:$<CONFIG>>/customfilepermissions.txt"
+ INPUT "${CMAKE_CURRENT_SOURCE_DIR}/input.txt"
+ FILE_PERMISSIONS
+ OWNER_READ OWNER_WRITE OWNER_EXECUTE
+ GROUP_EXECUTE
+ WORLD_EXECUTE
+ )
+
+add_custom_target(checkCustomFilePermissions ALL
+ COMMAND ${CMAKE_COMMAND}
+ -DgeneratedFile=${CMAKE_CURRENT_BINARY_DIR}/$<LOWER_CASE:$<CONFIG>>/customfilepermissions.txt
+ -P "${CMAKE_CURRENT_SOURCE_DIR}/CustomFilePermissionsVerify.cmake"
+ )
diff --git a/Tests/RunCMake/File_Generate/CustomFilePermissionsVerify.cmake b/Tests/RunCMake/File_Generate/CustomFilePermissionsVerify.cmake
new file mode 100644
index 0000000..a87e916
--- /dev/null
+++ b/Tests/RunCMake/File_Generate/CustomFilePermissionsVerify.cmake
@@ -0,0 +1,36 @@
+if(NOT EXISTS "${generatedFile}")
+ message(SEND_ERROR "Missing file:\n ${generatedFile}")
+endif()
+
+if (UNIX)
+ find_program(STAT_EXECUTABLE NAMES stat)
+ if(NOT STAT_EXECUTABLE)
+ return()
+ endif()
+
+ if (CMAKE_HOST_SYSTEM_NAME MATCHES "FreeBSD")
+ execute_process(COMMAND "${STAT_EXECUTABLE}" -f %Lp "${generatedFile}"
+ OUTPUT_VARIABLE output
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ COMMAND_ERROR_IS_FATAL ANY
+ )
+ elseif (CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin")
+ execute_process(COMMAND "${STAT_EXECUTABLE}" -f %A "${generatedFile}"
+ OUTPUT_VARIABLE output
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ COMMAND_ERROR_IS_FATAL ANY
+ )
+ else()
+ execute_process(COMMAND "${STAT_EXECUTABLE}" -c %a "${generatedFile}"
+ OUTPUT_VARIABLE output
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ COMMAND_ERROR_IS_FATAL ANY
+ )
+ endif()
+
+ if (NOT output EQUAL "711")
+ message(SEND_ERROR "file generate has different permissions source "
+ "permissions: \"${output}\" desired permissions: \"711\"")
+ endif()
+
+endif()
diff --git a/Tests/RunCMake/File_Generate/NoSourcePermissions.cmake b/Tests/RunCMake/File_Generate/NoSourcePermissions.cmake
new file mode 100644
index 0000000..868a045
--- /dev/null
+++ b/Tests/RunCMake/File_Generate/NoSourcePermissions.cmake
@@ -0,0 +1,10 @@
+file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/$<LOWER_CASE:$<CONFIG>>/nosourcepermissions.txt"
+ INPUT "${CMAKE_CURRENT_SOURCE_DIR}/input.txt"
+ NO_SOURCE_PERMISSIONS
+ )
+
+add_custom_target(checkNoSourcePermission ALL
+ COMMAND ${CMAKE_COMMAND}
+ -DgeneratedFile=${CMAKE_CURRENT_BINARY_DIR}/$<LOWER_CASE:$<CONFIG>>/nosourcepermissions.txt
+ -P "${CMAKE_CURRENT_SOURCE_DIR}/NoSourcePermissionsVerify.cmake"
+ )
diff --git a/Tests/RunCMake/File_Generate/NoSourcePermissionsVerify.cmake b/Tests/RunCMake/File_Generate/NoSourcePermissionsVerify.cmake
new file mode 100644
index 0000000..7981ccc
--- /dev/null
+++ b/Tests/RunCMake/File_Generate/NoSourcePermissionsVerify.cmake
@@ -0,0 +1,36 @@
+if(NOT EXISTS "${generatedFile}")
+ message(SEND_ERROR "Missing generated file:\n ${generatedFile}")
+endif()
+
+if (UNIX)
+ find_program(STAT_EXECUTABLE NAMES stat)
+ if(NOT STAT_EXECUTABLE)
+ return()
+ endif()
+
+ if (CMAKE_HOST_SYSTEM_NAME MATCHES "FreeBSD")
+ execute_process(COMMAND "${STAT_EXECUTABLE}" -f %Lp "${generatedFile}"
+ OUTPUT_VARIABLE output
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ COMMAND_ERROR_IS_FATAL ANY
+ )
+ elseif(CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin")
+ execute_process(COMMAND "${STAT_EXECUTABLE}" -f %A "${generatedFile}"
+ OUTPUT_VARIABLE output
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ COMMAND_ERROR_IS_FATAL ANY
+ )
+ else()
+ execute_process(COMMAND "${STAT_EXECUTABLE}" -c %a "${generatedFile}"
+ OUTPUT_VARIABLE output
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ COMMAND_ERROR_IS_FATAL ANY
+ )
+ endif()
+
+ if (NOT output EQUAL "644")
+ message(SEND_ERROR "generated file has different permissions than "
+ "desired, generated permissions: \"${output}\"")
+ endif()
+
+endif()
diff --git a/Tests/RunCMake/File_Generate/RunCMakeTest.cmake b/Tests/RunCMake/File_Generate/RunCMakeTest.cmake
index 48fb71c..51491af 100644
--- a/Tests/RunCMake/File_Generate/RunCMakeTest.cmake
+++ b/Tests/RunCMake/File_Generate/RunCMakeTest.cmake
@@ -123,3 +123,24 @@ set(RunCMake_TEST_NO_CLEAN 1)
run_cmake_command(AdjacentInOut-nowork ${CMAKE_COMMAND} --build .)
unset(RunCMake_TEST_BINARY_DIR)
unset(RunCMake_TEST_NO_CLEAN)
+
+run_cmake(SourcePermissions1)
+run_cmake(SourcePermissions2)
+run_cmake(SourcePermissions3)
+run_cmake(SourcePermissions4)
+run_cmake(SourcePermissions5)
+
+function(run_cmake_and_verify_after_build case)
+ set(RunCMake_TEST_BINARY_DIR "${RunCMake_BINARY_DIR}/${case}-build")
+ file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
+ file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
+ set(RunCMake_TEST_NO_CLEAN 1)
+ run_cmake(${case})
+ run_cmake_command("${case}-build" ${CMAKE_COMMAND} --build .)
+ unset(RunCMake_TEST_NO_CLEAN)
+ unset(RunCMake_TEST_BINARY_DIR)
+endfunction()
+
+run_cmake_and_verify_after_build(NoSourcePermissions)
+run_cmake_and_verify_after_build(UseSourcePermissions)
+run_cmake_and_verify_after_build(CustomFilePermissions)
diff --git a/Tests/RunCMake/File_Generate/SourcePermissions1-result.txt b/Tests/RunCMake/File_Generate/SourcePermissions1-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/File_Generate/SourcePermissions1-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/File_Generate/SourcePermissions1-stderr.txt b/Tests/RunCMake/File_Generate/SourcePermissions1-stderr.txt
new file mode 100644
index 0000000..730800d
--- /dev/null
+++ b/Tests/RunCMake/File_Generate/SourcePermissions1-stderr.txt
@@ -0,0 +1,5 @@
+CMake Error at SourcePermissions1.cmake:[0-9]+ \(file\):
+ file given both NO_SOURCE_PERMISSIONS and USE_SOURCE_PERMISSIONS. Only one
+ option allowed.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/File_Generate/SourcePermissions1.cmake b/Tests/RunCMake/File_Generate/SourcePermissions1.cmake
new file mode 100644
index 0000000..d25e66a
--- /dev/null
+++ b/Tests/RunCMake/File_Generate/SourcePermissions1.cmake
@@ -0,0 +1,5 @@
+file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/output-sourcepermission1.txt"
+ INPUT "${CMAKE_CURRENT_SOURCE_DIR}/input.txt"
+ NO_SOURCE_PERMISSIONS
+ USE_SOURCE_PERMISSIONS
+ )
diff --git a/Tests/RunCMake/File_Generate/SourcePermissions2-result.txt b/Tests/RunCMake/File_Generate/SourcePermissions2-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/File_Generate/SourcePermissions2-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/File_Generate/SourcePermissions2-stderr.txt b/Tests/RunCMake/File_Generate/SourcePermissions2-stderr.txt
new file mode 100644
index 0000000..e8184cc
--- /dev/null
+++ b/Tests/RunCMake/File_Generate/SourcePermissions2-stderr.txt
@@ -0,0 +1,5 @@
+CMake Error at SourcePermissions2.cmake:[0-9]+ \(file\):
+ file given both NO_SOURCE_PERMISSIONS and FILE_PERMISSIONS. Only one
+ option allowed.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/File_Generate/SourcePermissions2.cmake b/Tests/RunCMake/File_Generate/SourcePermissions2.cmake
new file mode 100644
index 0000000..2a1e3ea
--- /dev/null
+++ b/Tests/RunCMake/File_Generate/SourcePermissions2.cmake
@@ -0,0 +1,5 @@
+file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/output-sourcepermission2.txt"
+ INPUT "${CMAKE_CURRENT_SOURCE_DIR}/input.txt"
+ NO_SOURCE_PERMISSIONS
+ FILE_PERMISSIONS OWNER_READ
+ )
diff --git a/Tests/RunCMake/File_Generate/SourcePermissions3-result.txt b/Tests/RunCMake/File_Generate/SourcePermissions3-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/File_Generate/SourcePermissions3-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/File_Generate/SourcePermissions3-stderr.txt b/Tests/RunCMake/File_Generate/SourcePermissions3-stderr.txt
new file mode 100644
index 0000000..1143c78
--- /dev/null
+++ b/Tests/RunCMake/File_Generate/SourcePermissions3-stderr.txt
@@ -0,0 +1,5 @@
+CMake Error at SourcePermissions3.cmake:[0-9]+ \(file\):
+ file given both USE_SOURCE_PERMISSIONS and FILE_PERMISSIONS. Only one
+ option allowed.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/File_Generate/SourcePermissions3.cmake b/Tests/RunCMake/File_Generate/SourcePermissions3.cmake
new file mode 100644
index 0000000..97e0deb
--- /dev/null
+++ b/Tests/RunCMake/File_Generate/SourcePermissions3.cmake
@@ -0,0 +1,5 @@
+file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/output-sourcepermission3.txt"
+ INPUT "${CMAKE_CURRENT_SOURCE_DIR}/input.txt"
+ USE_SOURCE_PERMISSIONS
+ FILE_PERMISSIONS OWNER_READ
+ )
diff --git a/Tests/RunCMake/File_Generate/SourcePermissions4-result.txt b/Tests/RunCMake/File_Generate/SourcePermissions4-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/File_Generate/SourcePermissions4-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/File_Generate/SourcePermissions4-stderr.txt b/Tests/RunCMake/File_Generate/SourcePermissions4-stderr.txt
new file mode 100644
index 0000000..84368cd
--- /dev/null
+++ b/Tests/RunCMake/File_Generate/SourcePermissions4-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at SourcePermissions4.cmake:[0-9]+ \(file\):
+ file given USE_SOURCE_PERMISSIONS without a file INPUT.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/File_Generate/SourcePermissions4.cmake b/Tests/RunCMake/File_Generate/SourcePermissions4.cmake
new file mode 100644
index 0000000..f4127a6
--- /dev/null
+++ b/Tests/RunCMake/File_Generate/SourcePermissions4.cmake
@@ -0,0 +1,4 @@
+file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/output-sourcepermission4.txt"
+ CONTENT "Input is content"
+ USE_SOURCE_PERMISSIONS
+ )
diff --git a/Tests/RunCMake/File_Generate/SourcePermissions5-result.txt b/Tests/RunCMake/File_Generate/SourcePermissions5-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/File_Generate/SourcePermissions5-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/File_Generate/SourcePermissions5-stderr.txt b/Tests/RunCMake/File_Generate/SourcePermissions5-stderr.txt
new file mode 100644
index 0000000..d66d488
--- /dev/null
+++ b/Tests/RunCMake/File_Generate/SourcePermissions5-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at SourcePermissions5.cmake:[0-9]+ \(file\):
+ file given invalid permission "GROUP_RWX","USER_ALL".
+Call Stack \(most recent call first\):
+ CMakeLists.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/File_Generate/SourcePermissions5.cmake b/Tests/RunCMake/File_Generate/SourcePermissions5.cmake
new file mode 100644
index 0000000..4eb4c36
--- /dev/null
+++ b/Tests/RunCMake/File_Generate/SourcePermissions5.cmake
@@ -0,0 +1,4 @@
+file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/output-sourcepermission5.txt"
+ INPUT "${CMAKE_CURRENT_SOURCE_DIR}/input.txt"
+ FILE_PERMISSIONS OWNER_READ GROUP_RWX USER_ALL
+ )
diff --git a/Tests/RunCMake/File_Generate/UseSourcePermissions.cmake b/Tests/RunCMake/File_Generate/UseSourcePermissions.cmake
new file mode 100644
index 0000000..7cca9bf
--- /dev/null
+++ b/Tests/RunCMake/File_Generate/UseSourcePermissions.cmake
@@ -0,0 +1,11 @@
+file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/$<LOWER_CASE:$<CONFIG>>/usesourcepermissions.txt"
+ INPUT "${CMAKE_CURRENT_SOURCE_DIR}/input.txt"
+ USE_SOURCE_PERMISSIONS
+ )
+
+add_custom_target(checkUseSourcePermissions ALL
+ COMMAND ${CMAKE_COMMAND}
+ -DsourceFile=${CMAKE_CURRENT_SOURCE_DIR}/input.txt
+ -DgeneratedFile=${CMAKE_CURRENT_BINARY_DIR}/$<LOWER_CASE:$<CONFIG>>/usesourcepermissions.txt
+ -P "${CMAKE_CURRENT_SOURCE_DIR}/UseSourcePermissionsVerify.cmake"
+ )
diff --git a/Tests/RunCMake/File_Generate/UseSourcePermissionsVerify.cmake b/Tests/RunCMake/File_Generate/UseSourcePermissionsVerify.cmake
new file mode 100644
index 0000000..8b30f96
--- /dev/null
+++ b/Tests/RunCMake/File_Generate/UseSourcePermissionsVerify.cmake
@@ -0,0 +1,51 @@
+if(NOT EXISTS "${generatedFile}")
+ message(SEND_ERROR "Missing generated file:\n ${generatedFile}")
+endif()
+
+if (UNIX)
+ find_program(STAT_EXECUTABLE NAMES stat)
+ if(NOT STAT_EXECUTABLE)
+ return()
+ endif()
+
+ if (CMAKE_HOST_SYSTEM_NAME MATCHES "FreeBSD")
+ execute_process(COMMAND "${STAT_EXECUTABLE}" -f %Lp "${sourceFile}"
+ OUTPUT_VARIABLE output1
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ COMMAND_ERROR_IS_FATAL ANY
+ )
+ execute_process(COMMAND "${STAT_EXECUTABLE}" -f %Lp "${generatedFile}"
+ OUTPUT_VARIABLE output2
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ COMMAND_ERROR_IS_FATAL ANY
+ )
+ elseif (CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin")
+ execute_process(COMMAND "${STAT_EXECUTABLE}" -f %A "${sourceFile}"
+ OUTPUT_VARIABLE output1
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ COMMAND_ERROR_IS_FATAL ANY
+ )
+ execute_process(COMMAND "${STAT_EXECUTABLE}" -f %A "${generatedFile}"
+ OUTPUT_VARIABLE output2
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ COMMAND_ERROR_IS_FATAL ANY
+ )
+ else()
+ execute_process(COMMAND "${STAT_EXECUTABLE}" -c %a "${sourceFile}"
+ OUTPUT_VARIABLE output1
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ COMMAND_ERROR_IS_FATAL ANY
+ )
+ execute_process(COMMAND "${STAT_EXECUTABLE}" -c %a "${generatedFile}"
+ OUTPUT_VARIABLE output2
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ COMMAND_ERROR_IS_FATAL ANY
+ )
+ endif()
+
+ if (NOT output1 EQUAL output2)
+ message(SEND_ERROR "generated file has a different permissions source "
+ "permissions: \"${output1}\" generated permissions: \"${output2}\"")
+ endif()
+
+endif()