Skip to content

Commit

Permalink
Implement recursive chgrp and chmod for installed files/directories (T…
Browse files Browse the repository at this point in the history
…riBITSPub#314, ATDV-241)

This is needed to fix some permisisons problems related to that ATDM Trilinos
builds (see ATDV-241).

See the updated documentation and unit tests for details.

Other things I did as part of this:

* Options ${PROJECT_NAME}_MAKE_INSTALL_GROUP_READABLE and
  ${PROJECT_NAME}_MAKE_INSTALL_WORLD_READABLE no longer conditional (since
  they are enforced by recursive chmod).

* Set policy CMP0082 to make install() commands run in order based on how they
  were executed in the CMake configure.

* Added TRIBITS_DIR_IS_BASEDIR() and unit tests

* Fixed numerious mispelling of "UNITEST" to "UNITTEST".

* Refectored some other installation-cleanup code to by extracting some
  functions.
  • Loading branch information
bartlettroscoe committed Apr 29, 2020
1 parent aa0f122 commit 889fa64
Show file tree
Hide file tree
Showing 18 changed files with 940 additions and 115 deletions.
2 changes: 1 addition & 1 deletion test/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ TRIBITS_ADD_ADVANCED_TEST( TestingFunctionMacro_UnitTests
-D${PROJECT_NAME}_TRIBITS_DIR=${${PROJECT_NAME}_TRIBITS_DIR}
-P "${CMAKE_CURRENT_SOURCE_DIR}/TestingFunctionMacro_UnitTests.cmake"
PASS_REGULAR_EXPRESSION_ALL
"Final UnitTests Result: num_run = 590"
"Final UnitTests Result: num_run = 598"
"Final UnitTests Result: PASSED"
)

Expand Down
285 changes: 280 additions & 5 deletions test/core/ExamplesUnitTests/CMakeLists.txt

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions test/core/ExamplesUnitTests/append_file_with_line.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash -e

FILE_TO_EDIT=$1
LINE_TO_ADD=$2

echo "$LINE_TO_ADD" >> $FILE_TO_EDIT
139 changes: 100 additions & 39 deletions test/core/TestingFunctionMacro_UnitTests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ INCLUDE(TribitsETISupport)
INCLUDE(TribitsFindPythonInterp)
INCLUDE(TribitsStripQuotesFromStr)
INCLUDE(TribitsStandardizePaths)
INCLUDE(TribitsFilepathHelpers)
INCLUDE(TribitsGetVersionDate)
INCLUDE(TribitsTplFindIncludeDirsAndLibraries)
INCLUDE(TribitsReportInvalidTribitsUsage)
Expand Down Expand Up @@ -189,7 +190,7 @@ FUNCTION(UNITTEST_TRIBITS_FIND_PYTHON_INTERP)
ENDFUNCTION()


FUNCTION(UNITEST_TRIBITS_STANDARDIZE_ABS_PATHS)
FUNCTION(UNITTEST_TRIBITS_STANDARDIZE_ABS_PATHS)

MESSAGE("\n***")
MESSAGE("*** Testing TRIBITS_STANDARDIZE_ABS_PATHS()")
Expand All @@ -206,7 +207,65 @@ FUNCTION(UNITEST_TRIBITS_STANDARDIZE_ABS_PATHS)
ENDFUNCTION()


FUNCTION(UNITEST_TRIBITS_MISC)
FUNCTION(TRIBITS_DIR_IS_BASEDIR_TEST_CASE absBaseDir absFullDir expectedIsBaseDir)
MESSAGE("\nTRIBITS_DIR_IS_BASEDIR(\"${absBaseDir}\" \"${absFullDir}\" isBaseDir)")
TRIBITS_DIR_IS_BASEDIR("${absBaseDir}" "${absFullDir}" isBaseDir)
UNITTEST_COMPARE_CONST(isBaseDir ${expectedIsBaseDir})
ENDFUNCTION()


FUNCTION(UNITTEST_TRIBITS_DIR_IS_BASEDIR)

MESSAGE("\n***")
MESSAGE("*** Testing TRIBITS_DIR_IS_BASEDIR()")
MESSAGE("***\n")

TRIBITS_DIR_IS_BASEDIR_TEST_CASE(
"/some/base/path" "/some/base/path" TRUE)

TRIBITS_DIR_IS_BASEDIR_TEST_CASE(
"/some/base/path" "/some/base/path/more" TRUE)

TRIBITS_DIR_IS_BASEDIR_TEST_CASE(
"/some/base/path" "/some/base/pathes" FALSE)

TRIBITS_DIR_IS_BASEDIR_TEST_CASE(
"/some/base/path/more" "/some/base/path" FALSE)

TRIBITS_DIR_IS_BASEDIR_TEST_CASE(
"/some/base/path" "/some/other/path" FALSE)

ENDFUNCTION()


FUNCTION(TRIBITS_GET_DIR_ARRAY_BELOW_BASE_DIR_TEST_CASE absBaseDir absFullDir
expectedTrailingDirArrayVar
)
MESSAGE("\nTRIBITS_GET_DIR_ARRAY_BELOW_BASE_DIR(\"${absBaseDir}\" \"${absFullDir}\" trailingDirArray)")
TRIBITS_GET_DIR_ARRAY_BELOW_BASE_DIR("${absBaseDir}" "${absFullDir}" trailingDirArray)
UNITTEST_COMPARE_CONST(trailingDirArray "${expectedTrailingDirArrayVar}")
ENDFUNCTION()


FUNCTION(UNITTEST_TRIBITS_GET_DIR_ARRAY_BELOW_BASE_DIR)

MESSAGE("\n***")
MESSAGE("*** Testing TRIBITS_GET_DIR_ARRAY_BELOW_BASE_DIR()")
MESSAGE("***\n")

TRIBITS_GET_DIR_ARRAY_BELOW_BASE_DIR_TEST_CASE(
"/some/base/path" "/some/base/path" "")

TRIBITS_GET_DIR_ARRAY_BELOW_BASE_DIR_TEST_CASE(
"/some/base/path" "/some/base/path/subdir" "subdir")

TRIBITS_GET_DIR_ARRAY_BELOW_BASE_DIR_TEST_CASE(
"/some/base/path" "/some/base/path/subdir1/subdir2" "subdir1;subdir2")

ENDFUNCTION()


FUNCTION(UNITTEST_TRIBITS_MISC)

MESSAGE("\n***")
MESSAGE("*** Testing miscellaneous TriBITS macro functionality")
Expand Down Expand Up @@ -322,7 +381,7 @@ MACRO(UNITTEST_TRIBITS_TPL_ALLOW_PRE_FIND_PACKAGE_UNSET_VARS TPL_NAME)
ENDMACRO()


FUNCTION(UNITEST_TRIBITS_STRIP_QUOTES_FROM_STR)
FUNCTION(UNITTEST_TRIBITS_STRIP_QUOTES_FROM_STR)

MESSAGE("\n***")
MESSAGE("*** Testing TRIBITS_STRIP_QUOTES_FROM_STR()")
Expand Down Expand Up @@ -351,7 +410,7 @@ FUNCTION(UNITEST_TRIBITS_STRIP_QUOTES_FROM_STR)
ENDFUNCTION()


FUNCTION(UNITEST_TRIBITS_GET_RAW_GIT_COMMIT_UTC_TIME)
FUNCTION(UNITTEST_TRIBITS_GET_RAW_GIT_COMMIT_UTC_TIME)

MESSAGE("\n***")
MESSAGE("*** Testing TRIBITS_GET_RAW_GIT_COMMIT_UTC_TIME()")
Expand Down Expand Up @@ -397,7 +456,7 @@ FUNCTION(UNITEST_TRIBITS_GET_RAW_GIT_COMMIT_UTC_TIME)
ENDFUNCTION()


FUNCTION(UNITEST_TRIBITS_GET_VERSION_DATE_FROM_RAW_GIT_COMMIT_UTC_TIME)
FUNCTION(UNITTEST_TRIBITS_GET_VERSION_DATE_FROM_RAW_GIT_COMMIT_UTC_TIME)

MESSAGE("\n***")
MESSAGE("*** Testing TRIBITS_GET_VERSION_DATE_FROM_RAW_GIT_COMMIT_UTC_TIME()")
Expand Down Expand Up @@ -610,7 +669,7 @@ FUNCTION(UNITTEST_TRIBITS_REPORT_INVALID_TRIBITS_USAGE)
ENDFUNCTION()


FUNCTION(UNITEST_TRIBITS_ADD_TEST_BASIC)
FUNCTION(UNITTEST_TRIBITS_ADD_TEST_BASIC)

MESSAGE("\n***")
MESSAGE("*** Testing basic functionality of TRIBITS_ADD_TEST(...)")
Expand Down Expand Up @@ -1147,7 +1206,7 @@ FUNCTION(UNITEST_TRIBITS_ADD_TEST_BASIC)
ENDFUNCTION()


FUNCTION(UNITEST_TRIBITS_ADD_TEST_DISABLE)
FUNCTION(UNITTEST_TRIBITS_ADD_TEST_DISABLE)

MESSAGE("\n***")
MESSAGE("*** Testing test-by-test disable of TRIBITS_ADD_TEST(...)")
Expand Down Expand Up @@ -1272,7 +1331,7 @@ FUNCTION(UNITEST_TRIBITS_ADD_TEST_DISABLE)
ENDFUNCTION()


FUNCTION(UNITEST_TRIBITS_ADD_TEST_CATEGORIES)
FUNCTION(UNITTEST_TRIBITS_ADD_TEST_CATEGORIES)

MESSAGE("\n***")
MESSAGE("*** Testing TRIBITS_ADD_TEST( ... CATEGORIES ... )")
Expand Down Expand Up @@ -1423,7 +1482,7 @@ FUNCTION(UNITEST_TRIBITS_ADD_TEST_CATEGORIES)
ENDFUNCTION()


FUNCTION(UNITEST_TRIBITS_ADD_TEST_COMM)
FUNCTION(UNITTEST_TRIBITS_ADD_TEST_COMM)

MESSAGE("\n***")
MESSAGE("*** Testing TRIBITS_ADD_TEST( ... COMM ... )")
Expand Down Expand Up @@ -1738,7 +1797,7 @@ FUNCTION(UNITEST_TRIBITS_ADD_TEST_COMM)
ENDFUNCTION()


FUNCTION(UNITEST_TRIBITS_ADD_TEST_PROPERTIES)
FUNCTION(UNITTEST_TRIBITS_ADD_TEST_PROPERTIES)

MESSAGE("\n***")
MESSAGE("*** Testing the setting of test properties with TRIBITS_ADD_TEST(...)")
Expand Down Expand Up @@ -1845,7 +1904,7 @@ FUNCTION(UNITEST_TRIBITS_ADD_TEST_PROPERTIES)
ENDFUNCTION()


FUNCTION(UNITEST_TRIBITS_ADD_ADVANCED_TEST_BASIC)
FUNCTION(UNITTEST_TRIBITS_ADD_ADVANCED_TEST_BASIC)

MESSAGE("\n***")
MESSAGE("*** Testing basic functionality of TRIBITS_ADD_ADVANCED_TEST(...)")
Expand Down Expand Up @@ -2097,7 +2156,7 @@ FUNCTION(UNITEST_TRIBITS_ADD_ADVANCED_TEST_BASIC)
ENDFUNCTION()


FUNCTION(UNITEST_TRIBITS_ADD_ADVANCED_TEST_CATEGORIES)
FUNCTION(UNITTEST_TRIBITS_ADD_ADVANCED_TEST_CATEGORIES)

MESSAGE("\n***")
MESSAGE("*** Testing TRIBITS_ADD_ADVANCED_TEST( ... CATEGORIES ... )")
Expand Down Expand Up @@ -2560,7 +2619,7 @@ FUNCTION(UNITEST_TRIBITS_ADD_ADVANCED_TEST_CATEGORIES)
ENDFUNCTION()


FUNCTION(UNITEST_TRIBITS_ADD_ADVANCED_TEST_COMM)
FUNCTION(UNITTEST_TRIBITS_ADD_ADVANCED_TEST_COMM)

MESSAGE("\n***")
MESSAGE("*** Testing TRIBITS_ADD_ADVANCED_TEST( ... COMM ... )")
Expand Down Expand Up @@ -2655,7 +2714,7 @@ FUNCTION(UNITEST_TRIBITS_ADD_ADVANCED_TEST_COMM)
ENDFUNCTION()


FUNCTION(UNITEST_TRIBITS_ADD_ADVANCED_TEST_NUM_MPI_PROCS)
FUNCTION(UNITTEST_TRIBITS_ADD_ADVANCED_TEST_NUM_MPI_PROCS)

MESSAGE("\n***")
MESSAGE("*** Testing TRIBITS_ADD_ADVANCED_TEST( ... [OVERALL_]_NUM_MPI_PROCS ... )")
Expand Down Expand Up @@ -2936,7 +2995,7 @@ FUNCTION(UNITEST_TRIBITS_ADD_ADVANCED_TEST_NUM_MPI_PROCS)
ENDFUNCTION()


FUNCTION(UNITEST_TRIBITS_ADD_ADVANCED_TEST_DIRECTROY)
FUNCTION(UNITTEST_TRIBITS_ADD_ADVANCED_TEST_DIRECTROY)

MESSAGE("\n***")
MESSAGE("*** Testing TRIBITS_ADD_ADVANCED_TEST( ... DIRECTORY ... )")
Expand Down Expand Up @@ -3017,7 +3076,7 @@ FUNCTION(UNITEST_TRIBITS_ADD_ADVANCED_TEST_DIRECTROY)
ENDFUNCTION()


FUNCTION(UNITEST_TRIBITS_ADD_ADVANCED_TEST_PROPERTIES)
FUNCTION(UNITTEST_TRIBITS_ADD_ADVANCED_TEST_PROPERTIES)

MESSAGE("\n***")
MESSAGE("*** Testing the setting of test properties with TRIBITS_ADD_ADVANCED_TEST(...)")
Expand Down Expand Up @@ -3084,7 +3143,7 @@ FUNCTION(UNITEST_TRIBITS_ADD_ADVANCED_TEST_PROPERTIES)
ENDFUNCTION()


FUNCTION(UNITEST_TRIBITS_ADD_ADVANCED_TEST_COPY_FILES_TO_TEST_DIR)
FUNCTION(UNITTEST_TRIBITS_ADD_ADVANCED_TEST_COPY_FILES_TO_TEST_DIR)

MESSAGE("\n***")
MESSAGE("*** Testing COPY_FILES_TO_TEST_DIR with TRIBITS_ADD_ADVANCED_TEST(...)")
Expand Down Expand Up @@ -3190,7 +3249,7 @@ FUNCTION(UNITEST_TRIBITS_ADD_ADVANCED_TEST_COPY_FILES_TO_TEST_DIR)
ENDFUNCTION()


FUNCTION(UNITEST_TRIBITS_ADD_ADVANCED_TEST_EXCLUDES)
FUNCTION(UNITTEST_TRIBITS_ADD_ADVANCED_TEST_EXCLUDES)

MESSAGE("\n***")
MESSAGE("*** Testing excluding TRIBITS_ADD_ADVANCED_TEST(...) based on different criteria")
Expand Down Expand Up @@ -3345,7 +3404,7 @@ FUNCTION(UNITEST_TRIBITS_ADD_ADVANCED_TEST_EXCLUDES)
ENDFUNCTION()


FUNCTION(UNITEST_TRIBITS_ADD_EXECUTABLE_AND_TEST)
FUNCTION(UNITTEST_TRIBITS_ADD_EXECUTABLE_AND_TEST)

SET(TRIBITS_ADD_EXECUTABLE_AND_TEST_TEST_MODE ON)

Expand Down Expand Up @@ -3798,11 +3857,13 @@ MESSAGE("***\n")

UNITTEST_APPEND_STRING_VAR()
UNITTEST_TRIBITS_FIND_PYTHON_INTERP()
UNITEST_TRIBITS_STANDARDIZE_ABS_PATHS()
UNITEST_TRIBITS_MISC()
UNITEST_TRIBITS_STRIP_QUOTES_FROM_STR()
UNITEST_TRIBITS_GET_VERSION_DATE_FROM_RAW_GIT_COMMIT_UTC_TIME()
UNITEST_TRIBITS_GET_RAW_GIT_COMMIT_UTC_TIME()
UNITTEST_TRIBITS_STANDARDIZE_ABS_PATHS()
UNITTEST_TRIBITS_DIR_IS_BASEDIR()
UNITTEST_TRIBITS_GET_DIR_ARRAY_BELOW_BASE_DIR()
UNITTEST_TRIBITS_MISC()
UNITTEST_TRIBITS_STRIP_QUOTES_FROM_STR()
UNITTEST_TRIBITS_GET_VERSION_DATE_FROM_RAW_GIT_COMMIT_UTC_TIME()
UNITTEST_TRIBITS_GET_RAW_GIT_COMMIT_UTC_TIME()
UNITTEST_TRIBITS_TPL_ALLOW_PRE_FIND_PACKAGE()
UNITTEST_TRIBITS_REPORT_INVALID_TRIBITS_USAGE()

Expand All @@ -3813,30 +3874,30 @@ MESSAGE("\n***")
MESSAGE("*** Testing TRIBITS_ADD_TEST(...)")
MESSAGE("***\n")

UNITEST_TRIBITS_ADD_TEST_BASIC()
UNITEST_TRIBITS_ADD_TEST_DISABLE()
UNITEST_TRIBITS_ADD_TEST_CATEGORIES()
UNITEST_TRIBITS_ADD_TEST_COMM()
UNITEST_TRIBITS_ADD_TEST_PROPERTIES()
UNITTEST_TRIBITS_ADD_TEST_BASIC()
UNITTEST_TRIBITS_ADD_TEST_DISABLE()
UNITTEST_TRIBITS_ADD_TEST_CATEGORIES()
UNITTEST_TRIBITS_ADD_TEST_COMM()
UNITTEST_TRIBITS_ADD_TEST_PROPERTIES()

MESSAGE("\n***")
MESSAGE("*** Testing TRIBITS_ADD_ADVANCED_TEST(...)")
MESSAGE("***\n")

UNITEST_TRIBITS_ADD_ADVANCED_TEST_BASIC()
UNITEST_TRIBITS_ADD_ADVANCED_TEST_CATEGORIES()
UNITEST_TRIBITS_ADD_ADVANCED_TEST_COMM()
UNITEST_TRIBITS_ADD_ADVANCED_TEST_NUM_MPI_PROCS()
UNITEST_TRIBITS_ADD_ADVANCED_TEST_DIRECTROY()
UNITEST_TRIBITS_ADD_ADVANCED_TEST_PROPERTIES()
UNITEST_TRIBITS_ADD_ADVANCED_TEST_COPY_FILES_TO_TEST_DIR()
UNITEST_TRIBITS_ADD_ADVANCED_TEST_EXCLUDES()
UNITTEST_TRIBITS_ADD_ADVANCED_TEST_BASIC()
UNITTEST_TRIBITS_ADD_ADVANCED_TEST_CATEGORIES()
UNITTEST_TRIBITS_ADD_ADVANCED_TEST_COMM()
UNITTEST_TRIBITS_ADD_ADVANCED_TEST_NUM_MPI_PROCS()
UNITTEST_TRIBITS_ADD_ADVANCED_TEST_DIRECTROY()
UNITTEST_TRIBITS_ADD_ADVANCED_TEST_PROPERTIES()
UNITTEST_TRIBITS_ADD_ADVANCED_TEST_COPY_FILES_TO_TEST_DIR()
UNITTEST_TRIBITS_ADD_ADVANCED_TEST_EXCLUDES()

MESSAGE("\n***")
MESSAGE("*** Testing TRIBITS_ADD_EXECUTABLE_AND_TEST(...)")
MESSAGE("***\n")

UNITEST_TRIBITS_ADD_EXECUTABLE_AND_TEST()
UNITTEST_TRIBITS_ADD_EXECUTABLE_AND_TEST()

MESSAGE("\n***")
MESSAGE("*** Testing Explicit Template Instantiation functionality")
Expand All @@ -3856,4 +3917,4 @@ MESSAGE("*** Determine final result of all unit tests")
MESSAGE("***\n")

# Pass in the number of expected tests that must pass!
UNITTEST_FINAL_RESULT(590)
UNITTEST_FINAL_RESULT(598)
17 changes: 17 additions & 0 deletions tribits/core/add_install_group_and_perms_fixups/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
INCLUDE(TribitsAddInstallGroupAndPermsFixups)

TRIBITS_ADD_INSTALL_GROUP_AND_PERMS_FIXUPS()

# NOTE: This is a workaround for a problem with an issue with CMake where you
# must call install(SCRIPT ...) in a subdirectory added with
# add_subdirectory() in order for CMake to run that install script after all
# of the other subdirectories (which are TriBITS packages). As of CMake 3.14,
# you can set the policy set_policy(CMP0082 NEW) which would have allowed us
# to put this in the base TRIBITS_PROJECT_IMPL() macro. But since TriBITS is
# not allowed to require CMake 3.14 yet, we must use this workaround. To make
# super sure that this install(SCRIPTS ...) script will get called last, the
# policy CMP0082 is set to NEW in the TribitsCMakePolicies.cmake file. In
# automated testing of TriBITS, this seems to show that this custom script
# runs after all of the other files get installed (even with CMake 3.11) and
# passes the automated tests that ensures that the last file installed is
# given the correct permissions! At least that is what happened with TriBITS.
18 changes: 17 additions & 1 deletion tribits/core/installation/cmake_pbp_install.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,39 @@
# 'cmake -P cmake_install.cmake' command fails.
#

set(PROJECT_BINARY_DIR @PROJECT_BINARY_DIR@)
set(TRIBITS_ENABLED_PACKAGES_BINARY_DIRS @TRIBITS_ENABLED_PACKAGES_BINARY_DIRS@)

execute_process(COMMAND @CMAKE_COMMAND@ -P cmake_install.cmake
execute_process(
COMMAND @CMAKE_COMMAND@ -P "${PROJECT_BINARY_DIR}/cmake_install.cmake"
RESULT_VARIABLE global_install_rtn)

if (NOT global_install_rtn EQUAL 0)

message(
"\n"
"***\n"
"*** The global install failed so resorting to package-by-package installs\n"
"***\n"
"\n"
)

foreach (pkg_binary_dir ${TRIBITS_ENABLED_PACKAGES_BINARY_DIRS})
execute_process(COMMAND @CMAKE_COMMAND@ -P cmake_install.cmake
WORKING_DIRECTORY ${pkg_binary_dir}
RESULT_VARIABLE global_install_rtn)
endforeach()
message(SEND_ERROR "Error, full install failed!")

set(set_installed_group_and_permissions_file
"${PROJECT_BINARY_DIR}/set_installed_group_and_permissions.cmake")
if (EXISTS "${set_installed_group_and_permissions_file}")
execute_process(
COMMAND @CMAKE_COMMAND@ -P "${set_installed_group_and_permissions_file}"
RESULT_VARIABLE set_installed_rtn)
if (NOT global_install_rtn EQUAL 0)
message(SEND_ERROR "ERROR: Fixup of group and permissions filed!")
endif()
endif()

endif()
Loading

0 comments on commit 889fa64

Please sign in to comment.