|
| 1 | +#### PostBuildAutogenWrapperScript.cmake : Create the post-build wrapper / runner script source |
| 2 | +#### to run the PMFE utilities with the correct |
| 3 | +#### absolute paths local to this build. |
| 4 | +#### Author: Maxie D. Schmidt (github.com/maxieds) |
| 5 | +#### Created: 2020.11.02 |
| 6 | + |
| 7 | +## Set the absolute location of the path to the PMFE sources: |
| 8 | +if(APPLE) |
| 9 | + execute_process ( |
| 10 | + COMMAND bash -c "greadlink -f ." |
| 11 | + OUTPUT_VARIABLE BuildAbsPath |
| 12 | + ) |
| 13 | +elseif(UNIX AND NOT APPLE) |
| 14 | + execute_process ( |
| 15 | + COMMAND bash -c "readlink -f ." |
| 16 | + OUTPUT_VARIABLE BuildAbsPath |
| 17 | + ) |
| 18 | +endif() |
| 19 | + |
| 20 | +## Set the build time datestamp for reference: |
| 21 | +execute_process ( |
| 22 | + COMMAND bash -c "date +'%F @ %T%p (%Y.%m.%d-%H%M%S)'" |
| 23 | + OUTPUT_VARIABLE BuildTimeStamp |
| 24 | +) |
| 25 | + |
| 26 | +## Create a record of which GitHub commit or tag the PMFE sources reference: |
| 27 | +execute_process ( |
| 28 | + COMMAND bash -c "git --no-pager log -1 --format='%H [-- %h --]'" |
| 29 | + OUTPUT_VARIABLE BuildGitCommitHash |
| 30 | +) |
| 31 | +execute_process ( |
| 32 | + COMMAND bash -c "git --no-pager log -1 --format='%ai'" |
| 33 | + OUTPUT_VARIABLE BuildGitCommitDate |
| 34 | +) |
| 35 | + |
| 36 | +## Define all of the file placeholders we will substitute the live configuration data into: |
| 37 | +## Syntax: "[SUBST_PLACEHOLDER_NAME]->ActualValue" denotes that we will replace the string |
| 38 | +## '${SUBST_PLACEHOLDER_NAME}' with 'ActualValue' below. |
| 39 | +list(APPEND PMFEWrapperRunnerScriptSubstsList "[PMFE_BUILD_TIMESTAMP]->${BuildTimeStamp}") |
| 40 | +list(APPEND PMFEWrapperRunnerScriptSubstsList "[PMFE_BUILD_GIT_COMMIT_HASH]->${BuildGitCommitHash}") |
| 41 | +list(APPEND PMFEWrapperRunnerScriptSubstsList "[PMFE_BUILD_GIT_COMMIT_DATE]->${BuildGitCommitDate}") |
| 42 | +list(APPEND PMFEWrapperRunnerScriptSubstsList "[PMFE_BUILD_ABS_BINARY_DIR_PATH]->${BuildAbsPath}") |
| 43 | + |
| 44 | +## Copy the stub header file to the build-time location: |
| 45 | +set(PMFEWrapperRunnerScriptStubPath "${buildAbsPath}/wrapper-runner-script/PMFECommandRunner.sh.in") |
| 46 | +set(PMFEWrapperRunnerScriptNewPath "${buildAbsPath}/wrapper-runner-script/PMFECommandRunner.sh") |
| 47 | +file( |
| 48 | + COPY ${PMFEWrapperRunnerScriptStubPath} |
| 49 | + DESTINATION ${PMFEWrapperRunnerScriptNewPath} |
| 50 | +) |
| 51 | +set(PMFEWrapperDevRunnerScriptStubPath "${buildAbsPath}/wrapper-runner-script/PMFEDeveloperCommandRunner.sh.in") |
| 52 | +set(PMFEWrapperDevRunnerScriptNewPath "${buildAbsPath}/wrapper-runner-script/PMFEDeveloperCommandRunner.sh") |
| 53 | +file( |
| 54 | + COPY ${PMFEWrapperDevRunnerScriptStubPath} |
| 55 | + DESTINATION ${PMFEWrapperDevRunnerScriptNewPath} |
| 56 | +) |
| 57 | + |
| 58 | +## Substitute the placeholders in that file with the live build config information: |
| 59 | +function(Func_substPMFEWrapperRunnerScriptParam "${SUBST_VAR_NAME}" "${SUBST_VAR_VALUE}" "${OUTFILE_PATH}") |
| 60 | + message(DEBUG "Substituting ${SUBST_VAR_NAME} -> ${SUBST_VAR_VALUE} in ${OUTFILE_PATH} ...") |
| 61 | + execute_process ( |
| 62 | + COMMAND bash -c "sed -i 's/\$\{${SUBST_VAR_NAME}\}/${SUBST_VAR_VALUE}/' ${OUTFILE_PATHh}" |
| 63 | + ) |
| 64 | +endfunction(Func_substPMFEConfigHeaderParam) |
| 65 | + |
| 66 | +function(Func_substPMFEWrapperRunnerScriptParamFromSpec "${FULL_CONFIG_SUBST_SPEC}" "${OUTFILE_PATH}") |
| 67 | + string(REGEX "(\[[^\ ]+\])->" FuncInput_localParamName "${FULL_CONFIG_SUBST_SPEC}") |
| 68 | + string(REGEX "->[^\ ]+$" FuncInput_localParamValue "${FULL_CONFIG_SUBST_SPEC}") |
| 69 | + Func_substPMFEWrapperRunnerScriptParam( |
| 70 | + "${FuncInput_localParamName}" |
| 71 | + "${FuncInput_localParamValue}" |
| 72 | + "${OUTFILE_PATH}" |
| 73 | + ) |
| 74 | +endfunction(Func_substPMFEConfigHeaderParamFromSpec) |
| 75 | + |
| 76 | +foreach(PMFE_RUNNER_SCRIPT_SUBST_SPEC ${PMFEWrapperRunnerScriptSubstsList} "${OUTFILE_PATH}") |
| 77 | + Func_substPMFEWrapperRunnerScriptParamFromSpec( |
| 78 | + "${PMFE_RUNNER_SCRIPT_SUBST_SPEC}" |
| 79 | + "${PMFEWrapperRunnerScriptNewPath}" |
| 80 | + ) |
| 81 | + Func_substPMFEWrapperRunnerScriptParamFromSpec( |
| 82 | + "${PMFE_RUNNER_SCRIPT_SUBST_SPEC}" |
| 83 | + "${PMFEWrapperDevRunnerScriptNewPath}" |
| 84 | + ) |
| 85 | +endforeach() |
| 86 | + |
| 87 | +message(STATUS "Installed the autogenerated wrapper (binary runner) scripts into: ") |
| 88 | +message(STATUS " >> \"${PMFEWrapperRunnerScriptNewPath}\" [user runner script]") |
| 89 | +message(STATUS " >> \"${PMFEWrapperRunnerDevScriptNewPath}\" [developer script]\n") |
0 commit comments