Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complete deprecation work (#429) #552

Merged
merged 10 commits into from
Dec 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions refactoring/replace_include_directories_r.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash
#
# Run this in a subdir to replace all occurrences of INCLUDE_DIRECTORIES with
# TRIBITS_INCLUDE_DIRECTORIES (and lower-case versions). Take into account
# token boundaries so will not replace in the middle of a token.
#
# Run as:
#
# $ cd <some-base-dir>
# $ <this-script-dir>/replace_include_directories_r.sh
#

_SCRIPT_DIR=`echo $0 | sed "s/\(.*\)\/.*replace_include_directories_r.sh/\1/g"`
#echo $_SCRIPT_DIR

echo
echo "Replacing INCLUDE_DIRECTORIES with TRIBITS_INCLUDE_DIRECTORIES in all CMakeList.txt and *.cmake files ..."
echo

find . \( -name CMakeLists.txt -or -name "*.cmake" \) -exec ${_SCRIPT_DIR}/token-replace.py -t INCLUDE_DIRECTORIES -r TRIBITS_INCLUDE_DIRECTORIES -f {} \;

echo
echo "Replacing include_directories with tribits_include_directories in all CMakeList.txt and *.cmake files ..."
echo

find . \( -name CMakeLists.txt -or -name "*.cmake" \) -exec ${_SCRIPT_DIR}/token-replace.py -t include_directories -r tribits_include_directories -f {} \;
64 changes: 64 additions & 0 deletions refactoring/string-replace.py
Original file line number Diff line number Diff line change
@@ -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 <file> not specified)" )

clp.add_argument(
"-o", dest="outputFile", default="",
help="Input file (and also output if -o <file> not specified)" )

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)
77 changes: 77 additions & 0 deletions refactoring/token-replace.py
Original file line number Diff line number Diff line change
@@ -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_])|^)<token-to-replace)[^A-Za-z0-9_]
"""


def getCmndLineOptions():
from argparse import ArgumentParser, RawDescriptionHelpFormatter

clp = ArgumentParser(description=usageHelp,
formatter_class=RawDescriptionHelpFormatter)

clp.add_argument(
"-t", dest="tokenToReplace", required=True,
bartlettroscoe marked this conversation as resolved.
Show resolved Hide resolved
help="Token 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 <file> not specified)" )

clp.add_argument(
"-o", dest="outputFile", default="",
help="Input file (and also output if -o <file> not specified)" )

options = clp.parse_args(sys.argv[1:])

if options.outputFile == "":
options.outputFile = options.inputFile

return options


#
# Main()
#

if __name__ == '__main__':

import sys, re

inOptions = getCmndLineOptions()

beginLineTokenPattern = re.compile(
r'^' + inOptions.tokenToReplace + r'([^A-Za-z0-9_])' )
bartlettroscoe marked this conversation as resolved.
Show resolved Hide resolved
midLineTokenPattern = re.compile(
r'([^A-Za-z0-9_])' + inOptions.tokenToReplace + r'([^A-Za-z0-9_])' )

with open(inOptions.inputFile, 'r') as file:
lines = file.readlines()

fileWasChanged = False
newLines = []
for line in lines:
newLine = beginLineTokenPattern.sub(
inOptions.replacementString + r'\1',
line)
newLine = midLineTokenPattern.sub(
r'\1' + inOptions.replacementString + r'\2',
newLine)
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)
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ if(NOT subpackageA_turn_off_passing_call_order)
# C) Add the libraries, tests, and examples
#

include_directories(${CMAKE_CURRENT_SOURCE_DIR})
tribits_include_directories(${CMAKE_CURRENT_SOURCE_DIR})
tribits_add_library(pwswue_a
SOURCES A.cpp
HEADERS A.hpp
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
include_directories(${CMAKE_CURRENT_BINARY_DIR})
tribits_include_directories(${CMAKE_CURRENT_BINARY_DIR})

include_directories(${CMAKE_CURRENT_SOURCE_DIR})
tribits_include_directories(${CMAKE_CURRENT_SOURCE_DIR})
tribits_add_library(pwswue_b
SOURCES B.cpp
HEADERS B.hpp
Expand Down
16 changes: 8 additions & 8 deletions test/core/ExamplesUnitTests/PkgWithUserErrors/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
###############################################################
if(NOT ${PACKAGE_NAME}_turn_off_passing_call_order)
tribits_package(PkgWithUserErrors)
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
tribits_include_directories(${CMAKE_CURRENT_SOURCE_DIR})
tribits_add_library(
pkgwithusererrors
HEADERS PkgWithUserErrorsLib.hpp
Expand All @@ -21,7 +21,7 @@ endif()
if(${PACKAGE_NAME}_no_POSTPROCESS_call)
message("User forgets to call TRIBITS_PACKAGE_POSTPROCESS")
tribits_package(PkgWithUserErrors)
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
tribits_include_directories(${CMAKE_CURRENT_SOURCE_DIR})
tribits_add_library(
pkgwithusererrors
HEADERS PkgWithUserErrorsLib.hpp
Expand All @@ -36,7 +36,7 @@ endif()
###############################################################
if(${PACKAGE_NAME}_ADD_LIBRARY_with_no_package_init)
message("")
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
tribits_include_directories(${CMAKE_CURRENT_SOURCE_DIR})
tribits_add_library(
pkgwithusererrors
HEADERS PkgWithUserErrorsLib.hpp
Expand All @@ -52,7 +52,7 @@ endif()
###############################################################
if(${PACKAGE_NAME}_ADD_EXECUTABLE_with_no_package_init)
message("User forgets to call TRIBITS_PACKAGE before adding exe")
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
tribits_include_directories(${CMAKE_CURRENT_SOURCE_DIR})
tribits_add_executable(
usererrorexec
SOURCES PkgWithUserErrorsEX.cpp
Expand Down Expand Up @@ -88,7 +88,7 @@ endif()
if(${PACKAGE_NAME}_ADD_LIBRARY_after_POSTPROCESS)
message("adding a library after POSTPROCESS")
tribits_package(PkgWithUserErrors)
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
tribits_include_directories(${CMAKE_CURRENT_SOURCE_DIR})
tribits_package_postprocess()
tribits_add_library(
pkgwithusererrors
Expand All @@ -104,7 +104,7 @@ endif()
if(${PACKAGE_NAME}_ADD_EXECUTABLE_after_POSTPROCESS)
message("adding an exe after POSTPROCESS")
tribits_package(PkgWithUserErrors)
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
tribits_include_directories(${CMAKE_CURRENT_SOURCE_DIR})
tribits_package_postprocess()
tribits_add_executable(
usererrorexec
Expand All @@ -130,7 +130,7 @@ endif()
if(${PACKAGE_NAME}_UNPARSED_ARGUMENTS_ADD_LIBRARY)
message("unparsed arguments in ADD_LIBRARY")
tribits_package(PkgWithUserErrors)
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
tribits_include_directories(${CMAKE_CURRENT_SOURCE_DIR})
message("building library")
tribits_add_library(
pkgwithusererrors
Expand All @@ -149,7 +149,7 @@ endif()
if(${PACKAGE_NAME}_UNPARSED_ARGUMENTS_ADD_EXECUTABLE)
message("unparsed arguments in ADD_EXECUTABLE")
tribits_package(PkgWithUserErrors)
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
tribits_include_directories(${CMAKE_CURRENT_SOURCE_DIR})
message("building executable")
tribits_add_executable(
usererrorexec
Expand Down
64 changes: 32 additions & 32 deletions test/core/ExamplesUnitTests/TribitsExampleProject_Tests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -989,12 +989,10 @@ tribits_add_advanced_test( TribitsExampleProject_ALL_ST_NoFortran_enable_install
ARGS -E copy_directory
${${PROJECT_NAME}_TRIBITS_DIR}/examples/TribitsExampleProject
TribitsExampleProject
ALWAYS_FAIL_ON_NONZERO_RETURN

TEST_1
MESSAGE "Do the initial configure of just the libraries"
WORKING_DIRECTORY BUILD_LIBS
SKIP_CLEAN_WORKING_DIRECTORY
WORKING_DIRECTORY BUILD_LIBS/BUILD
CMND ${CMAKE_COMMAND}
ARGS
${TribitsExampleProject_COMMON_CONFIG_ARGS}
Expand All @@ -1004,20 +1002,17 @@ tribits_add_advanced_test( TribitsExampleProject_ALL_ST_NoFortran_enable_install
-DTribitsExProj_ENABLE_SECONDARY_TESTED_CODE=ON
-DTribitsExProj_ENABLE_INSTALL_CMAKE_CONFIG_FILES=ON
-DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_NAME}_TribitsExampleProject_ALL_ST_NoFortran_enable_installation_testing/install
TribitsExampleProject
ALWAYS_FAIL_ON_NONZERO_RETURN
../TribitsExampleProject

TEST_2
MESSAGE "Do Make install "
WORKING_DIRECTORY BUILD_LIBS
WORKING_DIRECTORY BUILD_LIBS/BUILD
SKIP_CLEAN_WORKING_DIRECTORY
CMND make ARGS ${CTEST_BUILD_FLAGS} install
ALWAYS_FAIL_ON_NONZERO_RETURN

TEST_3
MESSAGE "BUILD_LIBS dir to a subdir to make sure install is independent of build and source tree"
MESSAGE "Move BUILD_LIBS dir to a subdir to make sure install is independent of build and source tree"
WORKING_DIRECTORY BUILD_LIBS_MOVED_BASE
SKIP_CLEAN_WORKING_DIRECTORY
CMND mv ARGS ../BUILD_LIBS .

TEST_4
Expand All @@ -1027,24 +1022,25 @@ tribits_add_advanced_test( TribitsExampleProject_ALL_ST_NoFortran_enable_install
ARGS -E copy_directory
${${PROJECT_NAME}_TRIBITS_DIR}/examples/TribitsExampleProject
TribitsExampleProject
ALWAYS_FAIL_ON_NONZERO_RETURN

TEST_5
MESSAGE "Remove some lib header and source files from local TribitsExampleProject source tree!"
MESSAGE "Remove some lib source files from local TribitsExampleProject source tree"
CMND rm ARGS
BUILD_TESTS/TribitsExampleProject/packages/simple_cxx/src/SimpleCxx_HelloWorld.hpp
BUILD_TESTS/TribitsExampleProject/packages/simple_cxx/src/SimpleCxx_HelloWorld.cpp
BUILD_TESTS/TribitsExampleProject/packages/with_subpackages/a/A.hpp
BUILD_TESTS/TribitsExampleProject/packages/with_subpackages/a/A.cpp
BUILD_TESTS/TribitsExampleProject/packages/with_subpackages/b/src/B.hpp
BUILD_TESTS/TribitsExampleProject/packages/with_subpackages/b/src/B.cpp
BUILD_TESTS/TribitsExampleProject/packages/with_subpackages/c/C.cpp
BUILD_TESTS/TribitsExampleProject/packages/with_subpackages/c/wsp_c/C.hpp

TEST_6
MESSAGE "Break a lib header file in the source tree to ensure include path does not find them"
CMND ${CMAKE_CURRENT_SOURCE_DIR}/append_line_to_files.sh ARGS "This header file is broken"
BUILD_TESTS/TribitsExampleProject/packages/with_subpackages/a/A.hpp
BUILD_TESTS/TribitsExampleProject/packages/with_subpackages/b/src/B.hpp
BUILD_TESTS/TribitsExampleProject/packages/with_subpackages/c/wsp_c/C.hpp

TEST_7
MESSAGE "Do the configure of just the tests/examples pointing to existing install"
WORKING_DIRECTORY BUILD_TESTS
SKIP_CLEAN_WORKING_DIRECTORY
WORKING_DIRECTORY BUILD_TESTS/BUILD
CMND ${CMAKE_COMMAND}
ARGS
${TribitsExampleProject_COMMON_CONFIG_ARGS}
Expand All @@ -1056,19 +1052,17 @@ tribits_add_advanced_test( TribitsExampleProject_ALL_ST_NoFortran_enable_install
-DTribitsExProj_ENABLE_INSTALL_CMAKE_CONFIG_FILES=ON
-DTribitsExProj_ENABLE_INSTALLATION_TESTING=ON
-DTribitsExProj_INSTALLATION_DIR=${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_NAME}_TribitsExampleProject_ALL_ST_NoFortran_enable_installation_testing/install
TribitsExampleProject
ALWAYS_FAIL_ON_NONZERO_RETURN
../TribitsExampleProject

TEST_7
TEST_8
MESSAGE "Build 'all' target"
WORKING_DIRECTORY BUILD_TESTS
WORKING_DIRECTORY BUILD_TESTS/BUILD
SKIP_CLEAN_WORKING_DIRECTORY
CMND make ARGS ${CTEST_BUILD_FLAGS}
ALWAYS_FAIL_ON_NONZERO_RETURN

TEST_8
TEST_9
MESSAGE "Run all the tests with ctest"
WORKING_DIRECTORY BUILD_TESTS
WORKING_DIRECTORY BUILD_TESTS/BUILD
SKIP_CLEAN_WORKING_DIRECTORY
CMND ${CMAKE_CTEST_COMMAND}
PASS_REGULAR_EXPRESSION_ALL
Expand All @@ -1082,14 +1076,20 @@ tribits_add_advanced_test( TribitsExampleProject_ALL_ST_NoFortran_enable_install

)
# NOTE: Above is a very strong test that ensures that the
# <Project>_ENABLE_INSTALLATION_TESTING option works as it should. This above
# test also shows the the installation of the non-Fortran packages in
# TribitsExampleProject works and is independent from the source and build
# trees. If you comment out the cmake options
# TribitsExProj_ENABLE_INSTALLATION_TESTING and TribitsExProj_INSTALLATION_DIR
# you will see that build of the project fails because we removed some source
# files that are needed. This proves that they are being used from the
# install tree!
# <Project>_ENABLE_INSTALLATION_TESTING option works as it should. It removes
# source files from the installation testing source tree which shows that
# those files are not being built. It also leaves the library header files
# but it breaks them to ensure that they do not get selected therefore include
# dirs from the soruce tree are not added. Since the include directories from
# the installed project are pulled in with -isystem, the -I for the local
# source tree would be searched first. Therefore, this test shows that those
# -I directories are not added to the compile lines. This above test also
# shows the installation of the non-Fortran packages in TribitsExampleProject
# works and is independent from the source and build trees. If you comment
# out the cmake options TribitsExProj_ENABLE_INSTALLATION_TESTING and
# TribitsExProj_INSTALLATION_DIR you will see that build of the project fails
# because we removed some source files that are needed. This proves that they
# are being used from the install tree!


########################################################################
Expand Down
12 changes: 12 additions & 0 deletions test/core/ExamplesUnitTests/append_line_to_files.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash -e
#
# Append a line to one or more files:
#
# append_line_to_files.sh <line-to-append> <file0> <file1> ...

LINE_TO_APPEND=$1 ; shift

for file in $@ ; do
echo "Appending '$LINE_TO_APPEND' to file '${file}'"
echo "$LINE_TO_APPEND" >> $file
done
Loading