From e127b7b7415ba2bb7ed5ec0deb0359d2df522cdf Mon Sep 17 00:00:00 2001 From: "Roscoe A. Bartlett" Date: Thu, 10 Oct 2024 16:53:21 -0600 Subject: [PATCH] Automatic snapshot commit from tribits at 3dca0964 Origin repo remote tracking branch: 'github/master' Origin repo remote repo URL: 'github = git@github.com:TriBITSPub/TriBITS.git' Git describe: tribits_start-3502-g28a36351 At commit: commit 3dca096437acbb7a16b88bee7d9569bccd8e6317 Author: Samuel E. Browne Date: Thu Jun 6 15:26:15 2024 -0600 Summary: Add Python3 requirement to user guide (#610) Mostly, this was done to brings in the changes for transitioning to find_package(Python3) (see TriBITSPub/TriBITS#610). But the full set of TriBITS PRs merged in were: * TriBITSPub/TriBITS#608 sebrowne/python3 * TriBITSPub/TriBITS#617 TriBITSPub/610-python3-2 * TriBITSPub/TriBITS#616 bartlettroscoe/610-python3 * TriBITSPub/TriBITS#615 bartlettroscoe/enable-disable-doc-update-2024-08-29 * TriBITSPub/TriBITS#611 bartlettroscoe/tril-13133-TriBITS-Update-License-and-Copyright-2 * TriBITSPub/TriBITS#614 bartlettroscoe/tribits-updates-2024-08-01 * TriBITSPub/TriBITS#613 TriBITSPub/612-improve-tribits-version-error * TriBITSPub/TriBITS#609 bartlettroscoe/tril-13133-TriBITS-Update-License-and-Copyright Signed-off-by: Roscoe A. Bartlett --- cmake/tribits/CHANGELOG.md | 40 ++++++ cmake/tribits/LICENSE | 2 + .../tribits/ci_support/TribitsDependencies.py | 2 +- .../TribitsWriteXmlDependenciesFiles.cmake | 4 +- .../ci_support/cdash_analyze_and_report.py | 2 +- .../ci_support/cdash_build_testing_date.py | 2 +- cmake/tribits/ci_support/checkin-test.py | 2 +- cmake/tribits/ci_support/clone_extra_repos.py | 2 +- .../ci_support/dump-package-dep-table.py | 2 +- .../ci_support/filter-packages-list.py | 2 +- .../get-tribits-packages-from-files-list.py | 2 +- ...tribits-packages-from-last-tests-failed.py | 2 +- .../ci_support/get-tribits-packages.py | 2 +- .../ci_support/is_checkin_tested_commit.py | 2 +- .../core/common/TribitsConstants.cmake | 5 +- .../TribitsAdjustPackageEnables.cmake | 118 ++++++++---------- .../TribitsFindPythonInterp.cmake | 95 +++++++++----- .../TribitsGetPackageEnableStatus.cmake | 64 +++++++++- .../package_arch/TribitsGlobalMacros.cmake | 4 +- .../test_support/TribitsAddAdvancedTest.cmake | 4 +- .../ctest_driver/TribitsCTestDriverCore.cmake | 2 +- .../TribitsCTestDriverCoreHelpers.cmake | 8 +- .../ctest_driver/dump-cdash-deps-xml-file.py | 2 +- cmake/tribits/dashboard_driver/tdd_driver.py | 2 +- .../devtools_install/install-autoconf.py | 2 +- .../tribits/devtools_install/install-cmake.py | 2 +- cmake/tribits/devtools_install/install-gcc.py | 2 +- cmake/tribits/devtools_install/install-git.py | 2 +- .../tribits/devtools_install/install-mpich.py | 2 +- .../devtools_install/install-openmpi.py | 2 +- .../devtools_install/install_devtools.py | 2 +- .../build_ref/TribitsBuildReferenceBody.rst | 20 ++- .../doc/build_ref/create-project-build-ref.py | 2 +- .../tribits/doc/guides/TribitsGuidesBody.rst | 38 +++--- .../TribitsMacroFunctionDocTemplate.rst | 5 +- .../examples/MockTrilinos/Copyright.txt | 38 ------ .../TribitsExampleProject/Copyright.txt | 46 ++----- .../examples/TribitsExampleProject/LICENSE | 37 +++++- .../cmake/CallbackSetupExtraOptions.cmake | 4 +- .../packages/wrap_external/CMakeLists.txt | 2 +- .../wrap_external/external_func/configure.py | 2 +- cmake/tribits/python_utils/download-cmake.py | 2 +- .../python_utils/extract_rst_cmake_doc.py | 2 +- .../python_utils/generate-docutils-output.py | 2 +- .../python_utils/generic-looping-demon.py | 2 +- cmake/tribits/python_utils/gitdist.py | 2 +- .../tribits/python_utils/lower_case_cmake.py | 2 +- cmake/tribits/python_utils/mailmsg.py | 2 +- cmake/tribits/python_utils/mockprogram.py | 2 +- cmake/tribits/python_utils/snapshot-dir.py | 2 +- cmake/tribits/python_utils/tree.py | 2 +- cmake/tribits/refactoring/string-replace.py | 64 ++++++++++ cmake/tribits/refactoring/to-python3.sh | 23 ++++ cmake/tribits/refactoring/token-replace.py | 77 ++++++++++++ 54 files changed, 514 insertions(+), 250 deletions(-) delete mode 100644 cmake/tribits/examples/MockTrilinos/Copyright.txt create mode 100755 cmake/tribits/refactoring/string-replace.py create mode 100755 cmake/tribits/refactoring/to-python3.sh create mode 100755 cmake/tribits/refactoring/token-replace.py diff --git a/cmake/tribits/CHANGELOG.md b/cmake/tribits/CHANGELOG.md index b3f1edd1ef0d..d824c7810d16 100644 --- a/cmake/tribits/CHANGELOG.md +++ b/cmake/tribits/CHANGELOG.md @@ -2,6 +2,46 @@ ChangeLog for TriBITS ---------------------------------------- +## 2024-10-08: + +* **Changed:** The TriBITS framework find operation for + Python[†](#tribits_python_support) has been changed from + calling `find_package(PythonInterp)` (which uses the deprecated + `FindPythonInterp.cmake` module) to calling `find_package(Python3)` (which + uses [FindPython3.cmake]). In the process, the internal CMake cache + variable set by this operation was changed from `PYTHON_EXECUTABLE` to + `Python3_EXECUTABLE`, and TriBITS projects need make that change as well + when upgrading TriBITS. (This change can be made automatically in all of + the project's CMake files by running the script + `tribits/refactoring/to-python3.sh `.) However, backward compatibility + is provided for users confiugring TriBITS CMake projects which set `-D + PYTHON_EXECUTABLE=`. In this case, if user sets `-D + PYTHON_EXECUTABLE=` in the cache, TriBITS will set that value `` + to the variable `Python3_EXECUTABLE` and avoid the call to + `find_package(Python3)` (however, a deprecation warning we be issued by + default, see [tribits_deprecated()] and [adjusting CMake DEPRECATION + warnings]). TriBITS project users should change to use `-D + Python3_EXECUTABLE=` instead, or just remove setting + `PYTHON_EXECUTABLE` or `Python3_EXECUTABLE` altogether and just make sure + that the desired `python3` executable is in the path. See issue + [TriBITSPub/TriBITS#610] for more details. + +† **TriBITS Python Support**: See "Find Python" at [Full Processing of TriBITS Project Files], [Python Support] and [Setting or disabling Python] + +[FindPython3.cmake]: https://cmake.org/cmake/help/latest/module/FindPython3.html + +[Full Processing of TriBITS Project Files]: https://tribitspub.github.io/TriBITS/users_guide/index.html#full-tribits-project-configuration + +[Python Support]: https://tribitspub.github.io/TriBITS/users_guide/index.html#python-support + +[Setting or disabling Python]: https://tribitspub.github.io/TriBITS/build_ref/index.html#setting-or-disabling-python + +[tribits_deprecated()]: https://tribitspub.github.io/TriBITS/users_guide/index.html#tribits-deprecated + +[Adjusting CMake DEPRECATION warnings]: https://tribitspub.github.io/TriBITS/build_ref/index.html#adjusting-cmake-deprecation-warnings + +[TriBITSPub/TriBITS#610]: https://github.com/TriBITSPub/TriBITS/issues/610 + ## 2023-06-22: * **Added:** Packages are now determined to be missing if their dependencies diff --git a/cmake/tribits/LICENSE b/cmake/tribits/LICENSE index 107d3f0d3c7e..266ee2add564 100644 --- a/cmake/tribits/LICENSE +++ b/cmake/tribits/LICENSE @@ -1,3 +1,5 @@ +SPDX-License-Identifier: BSD-3-Clause + Copyright (c) 2013 NTESS and the TriBITS contributors. Redistribution and use in source and binary forms, with or without diff --git a/cmake/tribits/ci_support/TribitsDependencies.py b/cmake/tribits/ci_support/TribitsDependencies.py index fae95321a442..2ba8d611ec6f 100644 --- a/cmake/tribits/ci_support/TribitsDependencies.py +++ b/cmake/tribits/ci_support/TribitsDependencies.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # @HEADER # ***************************************************************************** diff --git a/cmake/tribits/ci_support/TribitsWriteXmlDependenciesFiles.cmake b/cmake/tribits/ci_support/TribitsWriteXmlDependenciesFiles.cmake index 75b0a02763a4..021a235e45a3 100644 --- a/cmake/tribits/ci_support/TribitsWriteXmlDependenciesFiles.cmake +++ b/cmake/tribits/ci_support/TribitsWriteXmlDependenciesFiles.cmake @@ -52,7 +52,7 @@ macro(tribits_write_xml_dependency_files) " ${${PROJECT_NAME}_DEPS_HTML_OUTPUT_FILE} ..." ) set(tribitsCiSupportDir "${${PROJECT_NAME}_TRIBITS_DIR}/${TRIBITS_CI_SUPPORT_DIR}") execute_process( - COMMAND ${PYTHON_EXECUTABLE} + COMMAND ${Python3_EXECUTABLE} ${tribitsCiSupportDir}/dump-package-dep-table.py --input-xml-deps-file=${${PROJECT_NAME}_DEPS_XML_OUTPUT_FILE} --output-html-deps-file=${${PROJECT_NAME}_DEPS_HTML_OUTPUT_FILE} ) @@ -70,7 +70,7 @@ macro(tribits_write_xml_dependency_files) "${${PROJECT_NAME}_TRIBITS_DIR}/${TRIBITS_CTEST_DRIVER_DIR}") if (EXISTS "${tribitsCtestDriverDir}") execute_process( - COMMAND ${PYTHON_EXECUTABLE} + COMMAND ${Python3_EXECUTABLE} ${tribitsCtestDriverDir}/dump-cdash-deps-xml-file.py --input-xml-deps-file=${${PROJECT_NAME}_DEPS_XML_OUTPUT_FILE} --output-cdash-deps-xml-file=${${PROJECT_NAME}_CDASH_DEPS_XML_OUTPUT_FILE}) diff --git a/cmake/tribits/ci_support/cdash_analyze_and_report.py b/cmake/tribits/ci_support/cdash_analyze_and_report.py index 6062f4526eff..9f64282df9d2 100755 --- a/cmake/tribits/ci_support/cdash_analyze_and_report.py +++ b/cmake/tribits/ci_support/cdash_analyze_and_report.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # @HEADER # ***************************************************************************** diff --git a/cmake/tribits/ci_support/cdash_build_testing_date.py b/cmake/tribits/ci_support/cdash_build_testing_date.py index 1791e68da2cc..fb2fb04ee568 100755 --- a/cmake/tribits/ci_support/cdash_build_testing_date.py +++ b/cmake/tribits/ci_support/cdash_build_testing_date.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # @HEADER # ***************************************************************************** diff --git a/cmake/tribits/ci_support/checkin-test.py b/cmake/tribits/ci_support/checkin-test.py index b7132ea32335..23d95e307570 100755 --- a/cmake/tribits/ci_support/checkin-test.py +++ b/cmake/tribits/ci_support/checkin-test.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # @HEADER # ***************************************************************************** diff --git a/cmake/tribits/ci_support/clone_extra_repos.py b/cmake/tribits/ci_support/clone_extra_repos.py index 0b7d457c6b1a..cc2d6f5cfa7f 100755 --- a/cmake/tribits/ci_support/clone_extra_repos.py +++ b/cmake/tribits/ci_support/clone_extra_repos.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # @HEADER # ***************************************************************************** diff --git a/cmake/tribits/ci_support/dump-package-dep-table.py b/cmake/tribits/ci_support/dump-package-dep-table.py index 7bfe11fe303b..216a7c2f7f5f 100755 --- a/cmake/tribits/ci_support/dump-package-dep-table.py +++ b/cmake/tribits/ci_support/dump-package-dep-table.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # @HEADER # ***************************************************************************** diff --git a/cmake/tribits/ci_support/filter-packages-list.py b/cmake/tribits/ci_support/filter-packages-list.py index 6bb1f7fea5fd..8a70816c4df5 100755 --- a/cmake/tribits/ci_support/filter-packages-list.py +++ b/cmake/tribits/ci_support/filter-packages-list.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # @HEADER # ***************************************************************************** diff --git a/cmake/tribits/ci_support/get-tribits-packages-from-files-list.py b/cmake/tribits/ci_support/get-tribits-packages-from-files-list.py index 342f95cdba41..6cb76171da72 100755 --- a/cmake/tribits/ci_support/get-tribits-packages-from-files-list.py +++ b/cmake/tribits/ci_support/get-tribits-packages-from-files-list.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # @HEADER # ***************************************************************************** diff --git a/cmake/tribits/ci_support/get-tribits-packages-from-last-tests-failed.py b/cmake/tribits/ci_support/get-tribits-packages-from-last-tests-failed.py index 3f322e1c5330..8e9d6d0e2a48 100755 --- a/cmake/tribits/ci_support/get-tribits-packages-from-last-tests-failed.py +++ b/cmake/tribits/ci_support/get-tribits-packages-from-last-tests-failed.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # @HEADER # ***************************************************************************** diff --git a/cmake/tribits/ci_support/get-tribits-packages.py b/cmake/tribits/ci_support/get-tribits-packages.py index 1f5c0e8b7598..6454ad55d632 100755 --- a/cmake/tribits/ci_support/get-tribits-packages.py +++ b/cmake/tribits/ci_support/get-tribits-packages.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # @HEADER # ***************************************************************************** diff --git a/cmake/tribits/ci_support/is_checkin_tested_commit.py b/cmake/tribits/ci_support/is_checkin_tested_commit.py index 19a68702ead8..e09ced5be1b6 100755 --- a/cmake/tribits/ci_support/is_checkin_tested_commit.py +++ b/cmake/tribits/ci_support/is_checkin_tested_commit.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # @HEADER # ***************************************************************************** diff --git a/cmake/tribits/core/common/TribitsConstants.cmake b/cmake/tribits/core/common/TribitsConstants.cmake index 8c5906c78efd..26af761c39ed 100644 --- a/cmake/tribits/core/common/TribitsConstants.cmake +++ b/cmake/tribits/core/common/TribitsConstants.cmake @@ -14,8 +14,9 @@ set(TRIBITS_CMAKE_MINIMUM_REQUIRED 3.23.0) macro(tribits_asesrt_minimum_cmake_version) if (CMAKE_VERSION VERSION_LESS ${TRIBITS_CMAKE_MINIMUM_REQUIRED}) - message(FATAL_ERROR "Error, TriBiTS must have version" - " ${TRIBITS_CMAKE_MINIMUM_REQUIRED} or higher!") + message(FATAL_ERROR "Error, this TriBITS project ${PROJECT_NAME} must have a" + " version of CMake ${TRIBITS_CMAKE_MINIMUM_REQUIRED} or higher but was" + " only provided CMake version ${CMAKE_VERSION}!" ) endif() endmacro() diff --git a/cmake/tribits/core/package_arch/TribitsAdjustPackageEnables.cmake b/cmake/tribits/core/package_arch/TribitsAdjustPackageEnables.cmake index 120f2f65d776..d62d67fbb396 100644 --- a/cmake/tribits/core/package_arch/TribitsAdjustPackageEnables.cmake +++ b/cmake/tribits/core/package_arch/TribitsAdjustPackageEnables.cmake @@ -418,20 +418,23 @@ endmacro() # macro(tribits_disable_parents_subpackages parentPackageName) - if(NOT ${PROJECT_NAME}_ENABLE_${parentPackageName} - AND (NOT ${PROJECT_NAME}_ENABLE_${parentPackageName} STREQUAL "") - ) + tribits_package_is_explicitly_disabled(${PROJECT_NAME}_ENABLE_${parentPackageName} + parentPackageIsExplicityDisabled) + + if(parentPackageIsExplicityDisabled) foreach(tap2_subPkgName IN LISTS ${parentPackageName}_SUBPACKAGES) set(subpkgFullName ${parentPackageName}${tap2_subPkgName}) - if (NOT ${PROJECT_NAME}_ENABLE_${subpkgFullName} STREQUAL "OFF") - set(packageBeingDisabledVarName ${PROJECT_NAME}_ENABLE_${subpkgFullName}) + set(subpkgBeingDisabledVarName ${PROJECT_NAME}_ENABLE_${subpkgFullName}) + tribits_package_is_explicitly_disabled(${subpkgBeingDisabledVarName} + subpkgIExplicitlyDisabled) + if (NOT subpkgIsExplicitlyDisabled) message("-- " - "Setting subpackage enable ${packageBeingDisabledVarName}=OFF" + "Setting subpackage enable ${subpkgBeingDisabledVarName}=OFF" " because parent package ${PROJECT_NAME}_ENABLE_${parentPackageName}=OFF") - set(${packageBeingDisabledVarName} OFF) + set(${subpkgBeingDisabledVarName} OFF) endif() endforeach() @@ -439,13 +442,20 @@ macro(tribits_disable_parents_subpackages parentPackageName) endif() endmacro() +# +# NOTE: Above, we don't need to use the function +# tribits_get_package_enable_status() because a subpackage in this context +# will never be an external package and therefore the enable var name will +# always be ${PROJECT_NAME}_ENABLE_${subpkgFullName}. (At least I can't think +# of a use case where that would occur.) # Macro that disables forward package that depends on the passed-in package # macro(tribits_disable_forward_required_dep_packages packageName) tribits_get_package_enable_status(${packageName} packageEnable "") - if ((NOT packageEnable) AND (NOT "${packageEnable}" STREQUAL "")) + tribits_package_is_explicitly_disabled(packageEnable packageIsExplicitlyDisabled) + if (packageIsExplicitlyDisabled) foreach(fwdDepPkg IN LISTS ${packageName}_FORWARD_LIB_DEFINED_DEPENDENCIES) if (${fwdDepPkg}_LIB_DEP_REQUIRED_${packageName}) tribits_private_disable_required_package_enables(${fwdDepPkg} @@ -475,13 +485,13 @@ macro(tribits_enable_parents_subpackages parentPackageName) foreach(tap2_subPkgName IN LISTS ${parentPackageName}_SUBPACKAGES) set(subpkgFullName ${parentPackageName}${tap2_subPkgName}) + tribits_package_is_explicitly_disabled(${PROJECT_NAME}_ENABLE_${subpkgFullName} + subpkgIsExplicitlyDisabled) - if (NOT ${PROJECT_NAME}_ENABLE_${subpkgFullName} AND - NOT "${${PROJECT_NAME}_ENABLE_${subpkgFullName}}" STREQUAL "" - ) - # The subpackage is already disabled and is not just empty! + if (subpkgIsExplicitlyDisabled) + # The subpackage is already explicitly disabled elseif (${PROJECT_NAME}_ENABLE_${subpkgFullName}) - # The subpackage is already enabled so there is no reason to enable it! + # The subpackage is already enabled so there is no reason to enable it else() # The subpackage is not hard off or on so turn it on by default tribits_implicit_package_enable_is_allowed( "" ${subpkgFullName} @@ -513,7 +523,7 @@ macro(tribits_apply_all_package_enables packageName) tribits_implicit_package_enable_is_allowed( "" ${packageName} processThisPackageEnable ) if (packageIsPmpp AND processThisPackageEnable) - tribits_set_package_enable_based_on_project_enable( + tribits_enable_package_based_on_project_enable_on( ${PROJECT_NAME}_ENABLE_ALL_PACKAGES ${PROJECT_NAME}_ENABLE_${packageName} ) endif() endmacro() @@ -548,8 +558,9 @@ endmacro() # ${parentPackageName)_ENABLE_TESTS is explicitly disabled. # macro(tribits_apply_package_examples_disable parentPackageName) - if ( (NOT ${parentPackageName}_ENABLE_TESTS) - AND (NOT "${${parentPackageName}_ENABLE_TESTS}" STREQUAL "") + tribits_package_is_explicitly_disabled(${parentPackageName}_ENABLE_TESTS + parentPackageTestsIsExplicitlyDisabled) + if (parentPackageTestsIsExplicitlyDisabled AND ("${${parentPackageName}_ENABLE_EXAMPLES}" STREQUAL "") ) message("-- " "Setting" @@ -574,7 +585,9 @@ macro(tribits_apply_subpackage_tests_or_examples_disables parentPackageName testsOrExamples ) set(parentPkgEnableVar ${parentPackageName}_ENABLE_${testsOrExamples}) - if ((NOT ${parentPkgEnableVar}) AND (NOT "${${parentPkgEnableVar}}" STREQUAL "")) + tribits_package_is_explicitly_disabled(${parentPkgEnableVar} + parentPkgIsExplicitlyDisabled) + if (parentPkgIsExplicitlyDisabled) foreach(subpkgName IN LISTS ${parentPackageName}_SUBPACKAGES) set(fullSpkgName ${parentPackageName}${subpkgName}) if (${PROJECT_NAME}_ENABLE_${fullSpkgName}) @@ -599,9 +612,9 @@ macro(tribits_apply_test_example_enables packageName) if (${PROJECT_NAME}_ENABLE_${packageName}) tribits_is_primary_meta_project_package(${packageName} packageIsPmmp) if (packageIsPmmp) - tribits_set_package_enable_based_on_project_enable_on( + tribits_enable_package_based_on_project_enable_on( ${PROJECT_NAME}_ENABLE_TESTS ${packageName}_ENABLE_TESTS ) - tribits_set_package_enable_based_on_project_enable_on( + tribits_enable_package_based_on_project_enable_on( ${PROJECT_NAME}_ENABLE_EXAMPLES ${packageName}_ENABLE_EXAMPLES ) endif() endif() @@ -936,7 +949,9 @@ macro(tribits_private_disable_required_package_enables fwdDepPkgName packageName libraryDep ) tribits_get_package_enable_status(${fwdDepPkgName} "" fwdDepPkgEnableVarName) - if (${fwdDepPkgEnableVarName} OR "${${fwdDepPkgEnableVarName}}" STREQUAL "") + tribits_package_is_enabled_or_unset(${fwdDepPkgEnableVarName} + fwdDepPkgIsEnabledOrUnset) + if (fwdDepPkgIsEnabledOrUnset) if ("${libraryDep}" STREQUAL "TRUE") tribits_private_print_disable_required_package_enable( ${packageName} ${fwdDepPkgEnableVarName} @@ -944,18 +959,18 @@ macro(tribits_private_disable_required_package_enables set(${fwdDepPkgEnableVarName} OFF) else() set(depTypeStr "test/example") - if (${fwdDepPkgName}_ENABLE_TESTS - OR "${${fwdDepPkgName}_ENABLE_TESTS}" STREQUAL "" - ) + tribits_package_is_enabled_or_unset(${fwdDepPkgName}_ENABLE_TESTS + fwdDepPkgEnableTestsIsEnabledOrUnset) + if (fwdDepPkgEnableTestsIsEnabledOrUnset) tribits_private_print_disable_required_package_enable( ${packageName} ${fwdDepPkgName}_ENABLE_TESTS ${fwdDepPkgName} "${depTypeStr}" ) set(${fwdDepPkgName}_ENABLE_TESTS OFF) endif() - if (${fwdDepPkgName}_ENABLE_EXAMPLES - OR "${${fwdDepPkgName}_ENABLE_EXAMPLES}" STREQUAL "" - ) + tribits_package_is_enabled_or_unset(${fwdDepPkgName}_ENABLE_EXAMPLES + fwdDepPkgEnableExamplesIsEnabledOrUnset) + if (fwdDepPkgEnableExamplesIsEnabledOrUnset) tribits_private_print_disable_required_package_enable( ${packageName} ${fwdDepPkgName}_ENABLE_EXAMPLES ${fwdDepPkgName} "${depTypeStr}" ) @@ -1013,9 +1028,9 @@ endfunction() macro(tribits_private_disable_optional_package_enables fwdDepPkgName packageName) - if (${fwdDepPkgName}_ENABLE_${packageName} - OR "${${fwdDepPkgName}_ENABLE_${packageName}}" STREQUAL "" - ) + tribits_package_is_enabled_or_unset(${fwdDepPkgName}_ENABLE_${packageName} + fwdDepPkgEnablePackageIsEnabledOrUnset) + if (fwdDepPkgEnablePackageIsEnabledOrUnset) # Always disable the conditional enable but only print the message if the # package is enabled or if a disable overrides an enable if (${PROJECT_NAME}_ENABLE_${fwdDepPkgName}) @@ -1032,10 +1047,9 @@ macro(tribits_private_disable_optional_package_enables fwdDepPkgName packageNa " on disabled package ${packageName}") endif() endif() - if (${fwdDepPkgName}_ENABLE_${packageName} - AND (NOT ${PROJECT_NAME}_ENABLE_${packageName}) - AND (NOT "${${PROJECT_NAME}_ENABLE_${packageName}}" STREQUAL "") - ) + tribits_package_is_explicitly_disabled(${PROJECT_NAME}_ENABLE_${packageName} + packageIsExplicitlyDisabled) + if (${fwdDepPkgName}_ENABLE_${packageName} AND packageIsExplicitlyDisabled) message("-- " "NOTE: ${fwdDepPkgName}_ENABLE_${packageName}=" "${${fwdDepPkgName}_ENABLE_${packageName}} but" " ${PROJECT_NAME}_ENABLE_${packageName}=" @@ -1048,37 +1062,10 @@ macro(tribits_private_disable_optional_package_enables fwdDepPkgName packageNa endmacro() -# Set an individual package variable enable variable (to ON or OFF) based on a -# global enable value -# -macro(tribits_set_package_enable_based_on_project_enable projectEnableVar - packageEnableVar - ) - - if ("${${packageEnableVar}}" STREQUAL "") - if (${projectEnableVar}) - message("-- " "Setting ${packageEnableVar}=ON") - set(${packageEnableVar} ON) - elseif ( (NOT ${projectEnableVar}) - AND (NOT "${projectEnableVar}" STREQUAL "") - ) - message("-- " "Setting ${packageEnableVar}=OFF") - set(${packageEnableVar} OFF) - else() - # Otherwise, we will leave it up the the individual package - # to decide? - endif() - else() - # "${packageEnableVar} not at the default empty '' - endif() - -endmacro() - - # Set an individual package test or examples enable to on only if global # enable var is on # -macro(tribits_set_package_enable_based_on_project_enable_on projectEnableVar +macro(tribits_enable_package_based_on_project_enable_on projectEnableVar packageEnableVar ) if (("${${packageEnableVar}}" STREQUAL "") AND ${projectEnableVar}) @@ -1133,7 +1120,9 @@ endmacro() macro(tribits_private_postprocess_optional_package_enable packageName optDepPkg) tribits_get_package_enable_status(${optDepPkg} optDepPkgEnable optDepPkgEnableVar) - tribits_get_package_enable_status(${packageName} packageEnable packageEnableVar) + tribits_get_package_enable_status(${packageName} packageEnable packageEnableVar) + tribits_package_is_explicitly_disabled(${packageName}_ENABLE_${optDepPkg} + package_Enable_OptDeptPkg_IsExplicitlyDisabled) if (${packageName}_ENABLE_${optDepPkg} AND optDepPkgEnable) message("-- " "NOTE:" @@ -1149,10 +1138,7 @@ macro(tribits_private_postprocess_optional_package_enable packageName optDepPk message("-- " "NOT setting ${packageName}_ENABLE_${optDepPkg}=ON" " since ${optDepPkg} is NOT enabled at this point!") endif() - elseif ((NOT "${${packageName}_ENABLE_${optDepPkg}}" STREQUAL "") - AND (NOT ${packageName}_ENABLE_${optDepPkg}) - AND optDepPkgEnable - ) + elseif (package_Enable_OptDeptPkg_IsExplicitlyDisabled AND optDepPkgEnable) message("-- " "NOTE: ${packageName}_ENABLE_${optDepPkg}=" "${${packageName}_ENABLE_${optDepPkg}} is already set so not enabling even" " though ${optDepPkgEnableVar}=" diff --git a/cmake/tribits/core/package_arch/TribitsFindPythonInterp.cmake b/cmake/tribits/core/package_arch/TribitsFindPythonInterp.cmake index 3e57bbbe0cc3..209fbd47e004 100644 --- a/cmake/tribits/core/package_arch/TribitsFindPythonInterp.cmake +++ b/cmake/tribits/core/package_arch/TribitsFindPythonInterp.cmake @@ -7,34 +7,6 @@ # ***************************************************************************** # @HEADER -# Find Python executable which is needed for dependency file building -macro(tribits_find_python) - set(PythonInterp_FIND_VERSION_MIN "2.6") - if ("${PythonInterp_FIND_VERSION_DEFAULT}" STREQUAL "") - set(PythonInterp_FIND_VERSION_DEFAULT "${PythonInterp_FIND_VERSION_MIN}") - endif() - advanced_set(PythonInterp_FIND_VERSION ${PythonInterp_FIND_VERSION_DEFAULT} - CACHE STRING - "Default version of Python to find (must be ${PythonInterp_FIND_VERSION_DEFAULT} or greater") - if (PythonInterp_FIND_VERSION VERSION_LESS "${PythonInterp_FIND_VERSION_MIN}") - message_wrapper(FATAL_ERROR "Error," - " PythonInterp_FIND_VERSION=${PythonInterp_FIND_VERSION} < ${PythonInterp_FIND_VERSION_MIN}" - " is not allowed!" ) - endif() - advanced_set(PythonInterp_MUST_BE_FOUND FALSE CACHE BOOL "Require Python to be found or not.") - if (${PROJECT_NAME}_REQUIRES_PYTHON) - set(PythonInterp_REQUIRED_ARG "REQUIRED") - else() - set(PythonInterp_REQUIRED_ARG "") - endif() - set(FIND_PythonInterp_ARGS PythonInterp ${PythonInterp_REQUIRED_ARG}) - if (TRIBITS_FIND_PYTHON_UNITTEST) - set(PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE_UNITTEST_VAL}) - else() - find_package(${FIND_PythonInterp_ARGS}) - endif() -endmacro() - # TriBITS Wrapper for finding Python (or not) for a TriBITS project. macro(tribits_find_python_interp) @@ -48,9 +20,9 @@ macro(tribits_find_python_interp) endif() if (${PROJECT_NAME}_USES_PYTHON) tribits_find_python() - print_var(PYTHON_EXECUTABLE) - if (${PROJECT_NAME}_REQUIRES_PYTHON AND PYTHON_EXECUTABLE STREQUAL "") - message_wrapper(FATAL_ERROR "Error, PYTHON_EXECUTABLE='' but" + print_var(Python3_EXECUTABLE) + if (${PROJECT_NAME}_REQUIRES_PYTHON AND Python3_EXECUTABLE STREQUAL "") + message_wrapper(FATAL_ERROR "Error, Python3_EXECUTABLE='' but" " ${PROJECT_NAME}_REQUIRES_PYTHON=${${PROJECT_NAME}_REQUIRES_PYTHON}!" ) endif() else() @@ -58,3 +30,64 @@ macro(tribits_find_python_interp) " ${PROJECT_NAME}_USES_PYTHON='${${PROJECT_NAME}_USES_PYTHON}'") endif() endmacro() + + +# Find Python executable which is needed for dependency file building +macro(tribits_find_python) + tribits_find_python_set_python3_find_version() + tribits_find_python_backward_compatible_python_executable() + tribits_find_python_find_python3() +endmacro() + + +macro(tribits_find_python_set_python3_find_version) + # Get minimum version of Python to find + set(${PROJECT_NAME}_Python3_FIND_VERSION_MIN "3.6") + if ("${${PROJECT_NAME}_Python3_FIND_VERSION_DEFAULT}" STREQUAL "") + set(${PROJECT_NAME}_Python3_FIND_VERSION_DEFAULT + "${${PROJECT_NAME}_Python3_FIND_VERSION_MIN}") + endif() + advanced_set(${PROJECT_NAME}_Python3_FIND_VERSION + ${${PROJECT_NAME}_Python3_FIND_VERSION_DEFAULT} + CACHE STRING + "Default version of Python to find (must be ${${PROJECT_NAME}_Python3_FIND_VERSION_DEFAULT} or greater") + if (${PROJECT_NAME}_Python3_FIND_VERSION VERSION_LESS + "${${PROJECT_NAME}_Python3_FIND_VERSION_MIN}" + ) + message_wrapper(FATAL_ERROR "Error," + " ${PROJECT_NAME}_Python3_FIND_VERSION=${${PROJECT_NAME}_Python3_FIND_VERSION} < ${${PROJECT_NAME}_Python3_FIND_VERSION_MIN}" + " is not allowed!" ) + endif() +endmacro() + + +macro(tribits_find_python_backward_compatible_python_executable) + # Provide backward compatibility for user setting PYTHON_EXECUTABLE + if ((NOT "${PYTHON_EXECUTABLE}" STREQUAL "") AND ("${Python3_EXECUTABLE}" STREQUAL "")) + tribits_deprecated("Python3_EXECUTABLE being set by default to PYTHON_EXECUTABLE = '${PYTHON_EXECUTABLE}' is deprecated!") + set(Python3_EXECUTABLE "${PYTHON_EXECUTABLE}" CACHE FILEPATH + "Set by default to PYTHON_EXECUTABLE!") + endif() +endmacro() + + +macro(tribits_find_python_find_python3) + # Find Python3 + if (${PROJECT_NAME}_REQUIRES_PYTHON) + set(Python3_REQUIRED_ARG "REQUIRED") + else() + set(Python3_REQUIRED_ARG "") + endif() + set(FIND_Python3_ARGS + Python3 ${${PROJECT_NAME}_Python3_FIND_VERSION} ${Python3_REQUIRED_ARG}) + if(DEFINED Python3_EXECUTABLE) + # Already defined (even if it is set to empty), so no need to call anything! + elseif (TRIBITS_FIND_PYTHON_UNITTEST) + set(Python3_EXECUTABLE ${Python3_EXECUTABLE_UNITTEST_VAL}) + else() + find_package(${FIND_Python3_ARGS}) + endif() +endmacro() + + + diff --git a/cmake/tribits/core/package_arch/TribitsGetPackageEnableStatus.cmake b/cmake/tribits/core/package_arch/TribitsGetPackageEnableStatus.cmake index 2cfeb4946667..062c44c35655 100644 --- a/cmake/tribits/core/package_arch/TribitsGetPackageEnableStatus.cmake +++ b/cmake/tribits/core/package_arch/TribitsGetPackageEnableStatus.cmake @@ -10,8 +10,8 @@ # @FUNCTION: tribits_get_package_enable_status() # -# Function that determines if a given external or internal package's enable -# status (e.g. 'ON' or 'OFF') +# Function that determines a given external or internal package's enable +# status (e.g. 'ON' or 'OFF' or any valid CMake bool) # # Usage:: # @@ -21,8 +21,8 @@ # On return, if non-empty, the variable ```` will contain # the actual value of ``${${PROJECT_NAME}_ENABLE_}`` or # ``${TPL_ENABLE_}`` or will return empty "". If -# ``${packageName}_PACKAGE_BUILD_STATUS == "INTERNAL", then only the value of -# ``${PROJECT_NAME}_ENABLE_`` will be considered. +# ``${packageName}_PACKAGE_BUILD_STATUS == "INTERNAL"``, then only the value +# of ``${PROJECT_NAME}_ENABLE_`` will be considered. # # On return, if non-empty, the variable ```` will be # either ``${${PROJECT_NAME}_ENABLE_}`` or @@ -61,6 +61,62 @@ function(tribits_get_package_enable_status packageName packageEnableOut endfunction() +# @FUNCTION: tribits_package_is_enabled_or_unset() +# +# Function that determines if a package's enable variable evaluates to true or +# is unset. +# +# Usage:: +# +# tribits_package_is_enabled_or_unset(( +# ) +# +# On return, the value of ```` will set to +# ``TRUE`` if the variable ```` evaluates to true and +# or is empty "". Otherwise, ```` will set +# to ``FALSE`` on return. +# +function(tribits_package_is_enabled_or_unset packageEnableVarName + packageIsEnabledOrUnsetOut + ) + if (${packageEnableVarName} OR ("${${packageEnableVarName}}" STREQUAL "")) + set(packageIsEnabledOrUnset TRUE) + else() + set(packageIsEnabledOrUnset FALSE) + endif() + set(${packageIsEnabledOrUnsetOut} ${packageIsEnabledOrUnset} + PARENT_SCOPE) +endfunction() + + +# @FUNCTION: tribits_package_is_explicitly_disabled() +# +# Function that determines if a package's enable variable is +# explicitly disabled (i.e. evaluates to false but is not emapty). +# +# Usage:: +# +# tribits_package_is_explicitly_disabled(( +# ) +# +# On return, the value of ```` will set to +# ``TRUE`` if the variable ```` evaluates to false and +# is not empty "". Otherwise, ```` will set +# to ``FALSE`` on return. +# +function(tribits_package_is_explicitly_disabled packageEnableVarName + packageIsExplicitlyDisabledOut + ) + if ((NOT ${packageEnableVarName}) AND (NOT "${${packageEnableVarName}}" STREQUAL "")) + set(packageIsExplicitlyDisabled TRUE) + else() + set(packageIsExplicitlyDisabled FALSE) + endif() + set(${packageIsExplicitlyDisabledOut} ${packageIsExplicitlyDisabled} + PARENT_SCOPE) +endfunction() + + # @FUNCTION: tribits_assert_package_enable_status() # # Function that asserts that if both ``${PROJECT_NAME}_ENABLE_${packageName}`` diff --git a/cmake/tribits/core/package_arch/TribitsGlobalMacros.cmake b/cmake/tribits/core/package_arch/TribitsGlobalMacros.cmake index 5ca67ede6e5f..d060ebd69a65 100644 --- a/cmake/tribits/core/package_arch/TribitsGlobalMacros.cmake +++ b/cmake/tribits/core/package_arch/TribitsGlobalMacros.cmake @@ -806,7 +806,7 @@ macro(tribits_define_global_options_and_define_extra_repos) "Output XML file containing ${PROJECT_NAME} dependenices used by tools (if not empty)." ) if(${PROJECT_NAME}_DEPS_DEFAULT_OUTPUT_DIR AND - ${PROJECT_NAME}_DEPS_XML_OUTPUT_FILE AND PYTHON_EXECUTABLE + ${PROJECT_NAME}_DEPS_XML_OUTPUT_FILE AND Python3_EXECUTABLE ) set(${PROJECT_NAME}_CDASH_DEPS_XML_OUTPUT_FILE_DEFAULT "${${PROJECT_NAME}_DEPS_DEFAULT_OUTPUT_DIR}/${${PROJECT_NAME}_CDASH_SUBPROJECT_DEPS_XML_FILE_NAME}" ) @@ -819,7 +819,7 @@ macro(tribits_define_global_options_and_define_extra_repos) "Output XML file used by CDash in ${PROJECT_NAME}-independent format (if not empty)." ) if(${PROJECT_NAME}_DEPS_DEFAULT_OUTPUT_DIR AND - ${PROJECT_NAME}_DEPS_XML_OUTPUT_FILE AND PYTHON_EXECUTABLE + ${PROJECT_NAME}_DEPS_XML_OUTPUT_FILE AND Python3_EXECUTABLE ) set(${PROJECT_NAME}_DEPS_HTML_OUTPUT_FILE_DEFAULT "${${PROJECT_NAME}_DEPS_DEFAULT_OUTPUT_DIR}/${${PROJECT_NAME}_PACKAGE_DEPS_TABLE_HTML_FILE_NAME}" ) diff --git a/cmake/tribits/core/test_support/TribitsAddAdvancedTest.cmake b/cmake/tribits/core/test_support/TribitsAddAdvancedTest.cmake index 3a6aa01dc29a..704a0d11e4b4 100644 --- a/cmake/tribits/core/test_support/TribitsAddAdvancedTest.cmake +++ b/cmake/tribits/core/test_support/TribitsAddAdvancedTest.cmake @@ -345,7 +345,7 @@ include("${CMAKE_CURRENT_LIST_DIR}/../utils/PrintVar.cmake") # instead. **WARNING:** If you want to run such tests using valgrind, you # have to use the raw executable as the ```` argument and *not* # the script. For example, if you have a python script -# ``my_python_test.py`` with ``/usr/bin/env python`` at the top, you can't +# ``my_python_test.py`` with ``/usr/bin/env python3`` at the top, you can't # just use:: # # CMND /my_python_test.py ARGS "" "" ... @@ -354,7 +354,7 @@ include("${CMAKE_CURRENT_LIST_DIR}/../utils/PrintVar.cmake") # # Instead, you have to use:: # -# CMND ${PYTHON_EXECUTABLE} ARGS /my_python_test.py ... +# CMND ${Python3_EXECUTABLE} ARGS /my_python_test.py ... # # ``ARGS "" "" ... ""`` # diff --git a/cmake/tribits/ctest_driver/TribitsCTestDriverCore.cmake b/cmake/tribits/ctest_driver/TribitsCTestDriverCore.cmake index ccd1a2b8c5ec..d33c29fbfc42 100644 --- a/cmake/tribits/ctest_driver/TribitsCTestDriverCore.cmake +++ b/cmake/tribits/ctest_driver/TribitsCTestDriverCore.cmake @@ -141,7 +141,7 @@ tribits_project_read_version_file(${TRIBITS_PROJECT_ROOT}) include(TribitsFindPythonInterp) tribits_find_python() -message("PYTHON_EXECUTABLE = ${PYTHON_EXECUTABLE}") +message("Python3_EXECUTABLE = ${Python3_EXECUTABLE}") ############################# ### Do some initial setup ### diff --git a/cmake/tribits/ctest_driver/TribitsCTestDriverCoreHelpers.cmake b/cmake/tribits/ctest_driver/TribitsCTestDriverCoreHelpers.cmake index 76cfa19c6222..e0b7116cc492 100644 --- a/cmake/tribits/ctest_driver/TribitsCTestDriverCoreHelpers.cmake +++ b/cmake/tribits/ctest_driver/TribitsCTestDriverCoreHelpers.cmake @@ -175,7 +175,7 @@ endfunction() # function(tribits_create_repo_updates_file) extrarepo_execute_process_wrapper( - COMMAND ${PYTHON_EXECUTABLE} + COMMAND ${Python3_EXECUTABLE} ${GITDIST_EXE} --dist-no-color log "--pretty=format:%h: %s%nAuthor: %an <%ae>%nDate: %ad%n" --name-status -C ORIG_HEAD..HEAD @@ -376,14 +376,14 @@ macro(enable_only_modified_packages) # A.3) Get the names of the modified packages - if (NOT PYTHON_EXECUTABLE) + if (NOT Python3_EXECUTABLE) message(FATAL_ERROR "Error, Python must be enabled to map from modified" " files to packages!") endif() if (EXISTS "${MODIFIED_FILES_FILE_NAME}") execute_process( - COMMAND ${PYTHON_EXECUTABLE} + COMMAND ${Python3_EXECUTABLE} ${${PROJECT_NAME}_TRIBITS_DIR}/ci_support/get-tribits-packages-from-files-list.py --files-list-file=${MODIFIED_FILES_FILE_NAME} --project-dir=${TRIBITS_PROJECT_ROOT} @@ -847,7 +847,7 @@ function(tribits_get_failed_packages_from_failed_tests LAST_TESTS_FAILED_FILE FAILED_PACKAGES_OUT ) execute_process( - COMMAND ${PYTHON_EXECUTABLE} + COMMAND ${Python3_EXECUTABLE} "${${PROJECT_NAME}_TRIBITS_DIR}/ci_support/get-tribits-packages-from-last-tests-failed.py" "--deps-xml-file=${CTEST_BINARY_DIRECTORY}/${${PROJECT_NAME}_PACKAGE_DEPS_XML_FILE_NAME}" "--last-tests-failed-file=${LAST_TESTS_FAILED_FILE}" diff --git a/cmake/tribits/ctest_driver/dump-cdash-deps-xml-file.py b/cmake/tribits/ctest_driver/dump-cdash-deps-xml-file.py index 3ebc60cd45a0..ceeebe807148 100755 --- a/cmake/tribits/ctest_driver/dump-cdash-deps-xml-file.py +++ b/cmake/tribits/ctest_driver/dump-cdash-deps-xml-file.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # @HEADER # ***************************************************************************** diff --git a/cmake/tribits/dashboard_driver/tdd_driver.py b/cmake/tribits/dashboard_driver/tdd_driver.py index 099c6b2a9f19..3d68026f46bf 100755 --- a/cmake/tribits/dashboard_driver/tdd_driver.py +++ b/cmake/tribits/dashboard_driver/tdd_driver.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # @HEADER # ***************************************************************************** diff --git a/cmake/tribits/devtools_install/install-autoconf.py b/cmake/tribits/devtools_install/install-autoconf.py index 700a2a787d40..88b9974acf9f 100755 --- a/cmake/tribits/devtools_install/install-autoconf.py +++ b/cmake/tribits/devtools_install/install-autoconf.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # @HEADER # ***************************************************************************** diff --git a/cmake/tribits/devtools_install/install-cmake.py b/cmake/tribits/devtools_install/install-cmake.py index fbf07832ad23..2c69291d1392 100755 --- a/cmake/tribits/devtools_install/install-cmake.py +++ b/cmake/tribits/devtools_install/install-cmake.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # @HEADER # ***************************************************************************** diff --git a/cmake/tribits/devtools_install/install-gcc.py b/cmake/tribits/devtools_install/install-gcc.py index d2cd4fbd1f0e..e2ab794da22b 100755 --- a/cmake/tribits/devtools_install/install-gcc.py +++ b/cmake/tribits/devtools_install/install-gcc.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # @HEADER # ***************************************************************************** diff --git a/cmake/tribits/devtools_install/install-git.py b/cmake/tribits/devtools_install/install-git.py index 4a52a2d3d102..3a9ee1ba4d66 100755 --- a/cmake/tribits/devtools_install/install-git.py +++ b/cmake/tribits/devtools_install/install-git.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # @HEADER # ***************************************************************************** diff --git a/cmake/tribits/devtools_install/install-mpich.py b/cmake/tribits/devtools_install/install-mpich.py index 529570f32c76..172f2383ff42 100755 --- a/cmake/tribits/devtools_install/install-mpich.py +++ b/cmake/tribits/devtools_install/install-mpich.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # @HEADER # ***************************************************************************** diff --git a/cmake/tribits/devtools_install/install-openmpi.py b/cmake/tribits/devtools_install/install-openmpi.py index cac874f663dd..0d975be7fe76 100755 --- a/cmake/tribits/devtools_install/install-openmpi.py +++ b/cmake/tribits/devtools_install/install-openmpi.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # @HEADER # ***************************************************************************** diff --git a/cmake/tribits/devtools_install/install_devtools.py b/cmake/tribits/devtools_install/install_devtools.py index a84e4f0aa862..0f308469b31f 100755 --- a/cmake/tribits/devtools_install/install_devtools.py +++ b/cmake/tribits/devtools_install/install_devtools.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # @HEADER # ***************************************************************************** diff --git a/cmake/tribits/doc/build_ref/TribitsBuildReferenceBody.rst b/cmake/tribits/doc/build_ref/TribitsBuildReferenceBody.rst index 3ab4ce13f1b9..b8601d6e81ad 100644 --- a/cmake/tribits/doc/build_ref/TribitsBuildReferenceBody.rst +++ b/cmake/tribits/doc/build_ref/TribitsBuildReferenceBody.rst @@ -2230,6 +2230,21 @@ This will override the global behavior set by ````. +Setting or disabling Python +---------------------------- + +To set which Python interpreter is used, configure with:: + + -D Python3_EXECUTABLE= + +Otherwise, Python will be found automatically by default using +``find_python(Python3)`` internally (see `FindPython3.cmake`_). + +To disable the finding and usage of Python, configure with (empty):: + + -D Python3_EXECUTABLE= + + Outputting package dependency information ----------------------------------------- @@ -2952,7 +2967,7 @@ printed to cmake STDOUT. Show parent(s) commit info in the repo version output ----------------------------------------------------- +----------------------------------------------------- .. __SHOW_GIT_COMMIT_PARENTS: @@ -4490,4 +4505,7 @@ dashboard``. .. _xSDK Community Package Policies: https://doi.org/10.6084/m9.figshare.4495136 +.. _FindPython3.cmake: https://cmake.org/cmake/help/latest/module/FindPython3.html + + .. LocalWords: templated instantiation Makefiles CMake diff --git a/cmake/tribits/doc/build_ref/create-project-build-ref.py b/cmake/tribits/doc/build_ref/create-project-build-ref.py index ce0ee6a92800..acd76c59a9a1 100755 --- a/cmake/tribits/doc/build_ref/create-project-build-ref.py +++ b/cmake/tribits/doc/build_ref/create-project-build-ref.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 usageHelp = r"""create-project-build-ref.py [options] diff --git a/cmake/tribits/doc/guides/TribitsGuidesBody.rst b/cmake/tribits/doc/guides/TribitsGuidesBody.rst index c978a2d103ce..29a319fc664c 100644 --- a/cmake/tribits/doc/guides/TribitsGuidesBody.rst +++ b/cmake/tribits/doc/guides/TribitsGuidesBody.rst @@ -1107,7 +1107,7 @@ can be used in the logic in these files. Some of the variables that should already be defined (in addition to all of the basic user TriBITS cache variables set in ``tribits_define_global_options_and_define_extra_repos()``) include ``CMAKE_HOST_SYSTEM_NAME``, ``${PROJECT_NAME}_HOSTNAME``, and -``PYTHON_EXECUTABLE`` (see `Python Support`_). The types of commands and +``Python3_EXECUTABLE`` (see `Python Support`_). The types of commands and logic to put in this file include: * Setting additional user cache variable options that are used by multiple @@ -2228,7 +2228,7 @@ proceeds through the call to `tribits_project()`_. | 3) Set variables ``CMAKE_HOST_SYSTEM_NAME`` and ``${PROJECT_NAME}_HOSTNAME`` | (both of these can be overridden in the cache by the user) | 4) Find some optional command-line tools: -| a) Find Python (sets ``PYTHON_EXECUTABLE``, see `Python Support`_) +| a) Find Python (sets ``Python3_EXECUTABLE``, see `Python Support`_) | b) Find Git (sets ``GIT_EXECUTABLE`` and ``GIT_VERSION_STRING``) | 5) ``include(`` `/Version.cmake`_ ``)`` | 6) Define primary TriBITS options and read in the list of extra repositories @@ -2667,6 +2667,9 @@ satisfy the following requirements: * Test names must be prefixed with the package name ``_``. +* The package name ```` must be appended to the ``LABELS`` test + property list. + * Tests should only be added if the variable ``_ENABLE_TESTS`` is true. @@ -4230,7 +4233,8 @@ repositories if specified). There are several python tools under ``tribits/ci_support/`` that read in this file and use the created data-structure for various tasks. This file and these tools are used by `checkin-test.py`_ and `tribits_ctest_driver()`_. But these tools can also be -used to construct other workflows and tools. +used to construct other workflows and tools. These tools require a Python3 +installation and for the `python3` executable to be installed. .. _TribitsDumpDepsXmlScript.cmake: @@ -7000,17 +7004,16 @@ Python Support TriBITS Core does not require anything other than raw CMake. However, Python Utils, TriBITS CI Support, and other extended TriBITS components require -Python. These extra TriBITS tools only require Python 2.7+ (and 3.x). By -default, when a TriBITS project starts to configure using CMake, it will try -to find Python 2.7+ on the system (see `Full Processing of TriBITS Project -Files`_). If Python is found, it will set the global cache variable -``PYTHON_EXECUTABLE``. If it is not found, then it will print a warning and -``PYTHON_EXECUTABLE`` will be empty. With this default behavior, if Python is -found, then the TriBITS project can use it. Otherwise, it can do without it. +Python. These extra TriBITS tools only require Python 3.6+. By default, when +a TriBITS project starts to configure using CMake, it will try to find Python +3.6+ on the system (see `Full Processing of TriBITS Project Files`_). If +Python is found, it will set the global cache variable ``Python3_EXECUTABLE``. +If it is not found, then it will print a warning and ``Python3_EXECUTABLE`` +will be empty. With this default behavior, if Python is found, then the +TriBITS project can use it. Otherwise, it can do without it. While the default behavior for finding Python described above is useful for -many TriBITS project (such as Trilinos), some TriBITS projects need different -behavior such as: +many TriBITS projects, some TriBITS projects need different behavior such as: 1. The TriBITS project may not ever use Python so there is no need to look for it at all. In this case, the TriBITS project would set @@ -7020,11 +7023,12 @@ behavior such as: can't be found. In this case, the TriBITS project would set `${PROJECT_NAME}_REQUIRES_PYTHON`_ to ``TRUE``. -3. Some TriBITS projects may require a version of Python more recent than 2.7. - In this case, the TriBITS project would set `PythonInterp_FIND_VERSION`_ to - some value higher than ``2.7``. For example, may newer systems have only - Python 3.5.2 or higher versions installed by default and projects developed - on such a system typically requires this version or higher. +3. Some TriBITS projects may require a version of Python more recent than 3.6. + In this case, the TriBITS project would set + `${PROJECT_NAME}_Python3_FIND_VERSION`_ to some value higher than ``3.6``. + For example, may newer systems have higher versions of Python installed by + default, and projects developed on such a system typically require this + version or higher. Project-Specific Build Reference diff --git a/cmake/tribits/doc/guides/TribitsMacroFunctionDocTemplate.rst b/cmake/tribits/doc/guides/TribitsMacroFunctionDocTemplate.rst index 15e079ea7067..1546777bf499 100644 --- a/cmake/tribits/doc/guides/TribitsMacroFunctionDocTemplate.rst +++ b/cmake/tribits/doc/guides/TribitsMacroFunctionDocTemplate.rst @@ -31,6 +31,7 @@ @FUNCTION: tribits_find_most_recent_binary_file_timestamp() + @FUNCTION: tribits_find_most_recent_file_timestamp() + @FUNCTION: tribits_find_most_recent_source_file_timestamp() + +@FUNCTION: tribits_get_package_enable_status() + @FUNCTION: tribits_install_headers() + @MACRO: tribits_include_directories() + @MACRO: tribits_pkg_export_cache_var() + @@ -38,9 +39,11 @@ @MACRO: tribits_package_decl() + @MACRO: tribits_package_def() + @MACRO: tribits_package_define_dependencies() + +@MACRO: tribits_process_enabled_standard_tpl() + +@FUNCTION: tribits_package_is_enabled_or_unset() + +@FUNCTION: tribits_package_is_explicitly_disabled() + @MACRO: tribits_package_postprocess() + @MACRO: tribits_process_subpackages() + -@MACRO: tribits_process_enabled_standard_tpl() + @MACRO: tribits_project() + @MACRO: tribits_project_define_extra_repositories() + @MACRO: tribits_project_enable_all() + diff --git a/cmake/tribits/examples/MockTrilinos/Copyright.txt b/cmake/tribits/examples/MockTrilinos/Copyright.txt deleted file mode 100644 index 70962ece0e27..000000000000 --- a/cmake/tribits/examples/MockTrilinos/Copyright.txt +++ /dev/null @@ -1,38 +0,0 @@ -# @HEADER -# ************************************************************************ -# -# TriBITS: Tribal Build, Integrate, and Test System -# Copyright 2013 Sandia Corporation -# -# Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, -# the U.S. Government retains certain rights in this software. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are -# met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# 3. Neither the name of the Corporation nor the names of the -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY -# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# -# ************************************************************************ -# @HEADER diff --git a/cmake/tribits/examples/TribitsExampleProject/Copyright.txt b/cmake/tribits/examples/TribitsExampleProject/Copyright.txt index 70962ece0e27..0113c98fa77b 100644 --- a/cmake/tribits/examples/TribitsExampleProject/Copyright.txt +++ b/cmake/tribits/examples/TribitsExampleProject/Copyright.txt @@ -1,38 +1,8 @@ -# @HEADER -# ************************************************************************ -# -# TriBITS: Tribal Build, Integrate, and Test System -# Copyright 2013 Sandia Corporation -# -# Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, -# the U.S. Government retains certain rights in this software. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are -# met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# 3. Neither the name of the Corporation nor the names of the -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY -# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# -# ************************************************************************ -# @HEADER + TriBITS: Tribal Build, Integrate, and Test System + Copyright (c) 2013 NTESS + +Copyright 2013 National Technology & Engineering Solutions of Sandia, +LLC (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the +U.S. Government retains certain rights in this software. + +Copyright the TriBITS contributors. diff --git a/cmake/tribits/examples/TribitsExampleProject/LICENSE b/cmake/tribits/examples/TribitsExampleProject/LICENSE index 8574da5f5a8d..266ee2add564 100644 --- a/cmake/tribits/examples/TribitsExampleProject/LICENSE +++ b/cmake/tribits/examples/TribitsExampleProject/LICENSE @@ -1,6 +1,31 @@ -TribitsExampleProject is part of the TriBITS system and is provided under a -very liberal 3-clause BSD-like license that is described in the file -~/Copyright.txt. All of the software under this directory is subject to the -conditions of this license by default unless otherwise noted in the individual -files or directories. In particular, there are no files that violate GPL or -any other licnese agreements that would limit distribution. +SPDX-License-Identifier: BSD-3-Clause + +Copyright (c) 2013 NTESS and the TriBITS contributors. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + 3. Neither the name of the copyright holder nor the names of + its contributors may be used to endorse or promote products + derived from this software without specific prior written + permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. diff --git a/cmake/tribits/examples/TribitsExampleProject/cmake/CallbackSetupExtraOptions.cmake b/cmake/tribits/examples/TribitsExampleProject/cmake/CallbackSetupExtraOptions.cmake index 7a66eb1f9969..fd9d8f539c6f 100644 --- a/cmake/tribits/examples/TribitsExampleProject/cmake/CallbackSetupExtraOptions.cmake +++ b/cmake/tribits/examples/TribitsExampleProject/cmake/CallbackSetupExtraOptions.cmake @@ -12,11 +12,11 @@ macro(TRIBITS_REPOSITORY_SETUP_EXTRA_OPTIONS) set(${PROJECT_NAME}_ENABLE_WrapExternal OFF) endif() - if ("${PYTHON_EXECUTABLE}" STREQUAL "") + if ("${Python3_EXECUTABLE}" STREQUAL "") message( "\n***" "\n*** NOTE: Setting ${PROJECT_NAME}_ENABLE_WrapExternal=OFF" - " because PYTHON_EXECUTABLE=''!" + " because Python3_EXECUTABLE=''!" "\n***\n" ) set(${PROJECT_NAME}_ENABLE_WrapExternal OFF) diff --git a/cmake/tribits/examples/TribitsExampleProject/packages/wrap_external/CMakeLists.txt b/cmake/tribits/examples/TribitsExampleProject/packages/wrap_external/CMakeLists.txt index a9f8b0a37331..bd0f4ef752ee 100644 --- a/cmake/tribits/examples/TribitsExampleProject/packages/wrap_external/CMakeLists.txt +++ b/cmake/tribits/examples/TribitsExampleProject/packages/wrap_external/CMakeLists.txt @@ -82,7 +82,7 @@ add_custom_command( OUTPUT ${EXTERNAL_FUNC_MAKEFILE} DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt ${EXTERNAL_FUNC_SOURCE_DIR}/configure.py - COMMAND ${PYTHON_EXECUTABLE} ${EXTERNAL_FUNC_SOURCE_DIR}/configure.py + COMMAND ${Python3_EXECUTABLE} ${EXTERNAL_FUNC_SOURCE_DIR}/configure.py "--cxx=${CMAKE_CXX_COMPILER}" "--cxx-flags=${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${upperBuildType}}" "--ar=${CMAKE_AR}" diff --git a/cmake/tribits/examples/TribitsExampleProject/packages/wrap_external/external_func/configure.py b/cmake/tribits/examples/TribitsExampleProject/packages/wrap_external/external_func/configure.py index 9da2e1347217..bdbba413ee82 100755 --- a/cmake/tribits/examples/TribitsExampleProject/packages/wrap_external/external_func/configure.py +++ b/cmake/tribits/examples/TribitsExampleProject/packages/wrap_external/external_func/configure.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 import sys import os diff --git a/cmake/tribits/python_utils/download-cmake.py b/cmake/tribits/python_utils/download-cmake.py index 48a92a5804c5..5a9a96f6b1f5 100755 --- a/cmake/tribits/python_utils/download-cmake.py +++ b/cmake/tribits/python_utils/download-cmake.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # @HEADER # ***************************************************************************** diff --git a/cmake/tribits/python_utils/extract_rst_cmake_doc.py b/cmake/tribits/python_utils/extract_rst_cmake_doc.py index 703896ce0f38..016757aae1c7 100755 --- a/cmake/tribits/python_utils/extract_rst_cmake_doc.py +++ b/cmake/tribits/python_utils/extract_rst_cmake_doc.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # @HEADER # ***************************************************************************** diff --git a/cmake/tribits/python_utils/generate-docutils-output.py b/cmake/tribits/python_utils/generate-docutils-output.py index 27fc8aa77c9c..bb70709d7a62 100755 --- a/cmake/tribits/python_utils/generate-docutils-output.py +++ b/cmake/tribits/python_utils/generate-docutils-output.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 usageHelp = r"""generate-docutils-output.py --file-base= [options] diff --git a/cmake/tribits/python_utils/generic-looping-demon.py b/cmake/tribits/python_utils/generic-looping-demon.py index ab6cc52d4cd0..5494278e382f 100755 --- a/cmake/tribits/python_utils/generic-looping-demon.py +++ b/cmake/tribits/python_utils/generic-looping-demon.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # @HEADER # ***************************************************************************** diff --git a/cmake/tribits/python_utils/gitdist.py b/cmake/tribits/python_utils/gitdist.py index 6800e2e20ca7..e10b6716fe28 100755 --- a/cmake/tribits/python_utils/gitdist.py +++ b/cmake/tribits/python_utils/gitdist.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- # diff --git a/cmake/tribits/python_utils/lower_case_cmake.py b/cmake/tribits/python_utils/lower_case_cmake.py index ea769dbdb877..454cabdd83ad 100755 --- a/cmake/tribits/python_utils/lower_case_cmake.py +++ b/cmake/tribits/python_utils/lower_case_cmake.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- import sys diff --git a/cmake/tribits/python_utils/mailmsg.py b/cmake/tribits/python_utils/mailmsg.py index 4c7017d698d6..220c39b4dd39 100755 --- a/cmake/tribits/python_utils/mailmsg.py +++ b/cmake/tribits/python_utils/mailmsg.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # @HEADER # ***************************************************************************** diff --git a/cmake/tribits/python_utils/mockprogram.py b/cmake/tribits/python_utils/mockprogram.py index 7813c23a9223..05b898b226f5 100755 --- a/cmake/tribits/python_utils/mockprogram.py +++ b/cmake/tribits/python_utils/mockprogram.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # @HEADER # ***************************************************************************** diff --git a/cmake/tribits/python_utils/snapshot-dir.py b/cmake/tribits/python_utils/snapshot-dir.py index 76436dca4753..e2cf687eaaac 100755 --- a/cmake/tribits/python_utils/snapshot-dir.py +++ b/cmake/tribits/python_utils/snapshot-dir.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # @HEADER # ***************************************************************************** # TriBITS: Tribal Build, Integrate, and Test System diff --git a/cmake/tribits/python_utils/tree.py b/cmake/tribits/python_utils/tree.py index 15047bf6f7a2..720ece0437b3 100755 --- a/cmake/tribits/python_utils/tree.py +++ b/cmake/tribits/python_utils/tree.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python +#! /usr/bin/env python3 # tree.py # diff --git a/cmake/tribits/refactoring/string-replace.py b/cmake/tribits/refactoring/string-replace.py new file mode 100755 index 000000000000..bb6b33a34640 --- /dev/null +++ b/cmake/tribits/refactoring/string-replace.py @@ -0,0 +1,64 @@ +#!/bin/env python3 + +usageHelp = r""" + +Replace a given string with another string in a file (but only touch the file +if there were changes). + +""" + + +def getCmndLineOptions(): + from argparse import ArgumentParser, RawDescriptionHelpFormatter + + clp = ArgumentParser(description=usageHelp, + formatter_class=RawDescriptionHelpFormatter) + + clp.add_argument( + "-s", dest="stringToReplace", required=True, + help="String to repalce" ) + + clp.add_argument( + "-r", dest="replacementString", required=True, + help="Replacement string" ) + + clp.add_argument( + "-f", dest="inputFile", required=True, + help="Input file (and also output if -o not specified)" ) + + clp.add_argument( + "-o", dest="outputFile", default="", + help="Output file (optional)" ) + + options = clp.parse_args(sys.argv[1:]) + + if options.outputFile == "": + options.outputFile = options.inputFile + + return options + + +# +# Main() +# + +if __name__ == '__main__': + + import sys + + inOptions = getCmndLineOptions() + + with open(inOptions.inputFile, 'r') as file: + lines = file.readlines() + + fileWasChanged = False + newLines = [] + for line in lines: + newLine = line.replace(inOptions.stringToReplace, inOptions.replacementString) + if newLine != line: + fileWasChanged = True + newLines.append(newLine) + + if (fileWasChanged or inOptions.outputFile != inOptions.inputFile): + with open(inOptions.outputFile, 'w') as file: + file.writelines(newLines) diff --git a/cmake/tribits/refactoring/to-python3.sh b/cmake/tribits/refactoring/to-python3.sh new file mode 100755 index 000000000000..4c40c0d67643 --- /dev/null +++ b/cmake/tribits/refactoring/to-python3.sh @@ -0,0 +1,23 @@ +#!/bin/sh +# +# Refactor a TriBITS project's CMake files for the change from +# find_package(PythonInterp) to find_package(Python3) (see CHANGELOG.md entry +# for 2024-10-08). +# +# Usage: +# +# to-python3.sh +# +# NOTES: +# * This is safe to run multiple times on the same set of files. +# * This is safe to run from the base project source tree. +# * This will exclude any files under '.git/' +# * This will exclude any files under 'tribits/' directories (so it will not mess up TriBITS) +# + +_SCRIPT_DIR=`echo $0 | sed "s/\(.*\)\/to-python3[.]sh/\1/g"` +baseDir=$1 +find ${baseDir} -type f \ + \( -name CMakeLists.txt -or -name "*.cmake" -or -name "*.cmake.in" -or -name "*.rst" \) \ + ! -wholename "*/.git/*" ! -wholename "*/tribits/*" \ + -exec $_SCRIPT_DIR/token-replace.py -t PYTHON_EXECUTABLE -r Python3_EXECUTABLE -f {} ';' diff --git a/cmake/tribits/refactoring/token-replace.py b/cmake/tribits/refactoring/token-replace.py new file mode 100755 index 000000000000..9c425a65ab52 --- /dev/null +++ b/cmake/tribits/refactoring/token-replace.py @@ -0,0 +1,77 @@ +#!/bin/env python3 + +usageHelp = r""" + +Replace a given token string with another string in a file (but only touch the +file if there were changes). + +This will only match complete tokens that match the regex: + + ([^A-Za-z0-9_])|^)