From 489cce39364a0c7ee70c79a8855e487819d618ae Mon Sep 17 00:00:00 2001 From: Dan Ibanez Date: Tue, 16 Jan 2018 16:14:59 -0700 Subject: [PATCH 1/5] Sanitize quoted subject lines --- src/CMakeLists.txt | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index aaf8108ea..a1183117c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -39,6 +39,15 @@ IF (GIT_FOUND AND IS_GIT_PROJECT) # # Apparently custom commands need to be defined where the output is used. # If this in the main CMakeLists.txt it does not work. + + EXECUTE_PROCESS(COMMAND ${GIT_EXECUTABLE} log -1 --format=%s + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE GIT_SUBJECT_RAW + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + MESSAGE("GIT_SUBJECT_RAW ${GIT_SUBJECT_RAW}") + STRING(REPLACE "\"" "\\\"" GIT_SUBJECT "${GIT_SUBJECT_RAW}") + MESSAGE("GIT_SUBJECT ${GIT_SUBJECT}") ADD_CUSTOM_COMMAND( OUTPUT ${GITREV_TMP} COMMAND ${CMAKE_COMMAND} -E echo_append "#define GIT_BRANCH_RAW " > ${GITREV_TMP} @@ -50,9 +59,7 @@ IF (GIT_FOUND AND IS_GIT_PROJECT) COMMAND ${CMAKE_COMMAND} -E echo_append "#define GIT_COMMIT_LAST_CHANGED_RAW " >> ${GITREV_TMP} COMMAND ${GIT_EXECUTABLE} log -1 --format=%ad >> ${GITREV_TMP} COMMAND ${CMAKE_COMMAND} -E echo >> ${GITREV_TMP} - COMMAND ${CMAKE_COMMAND} -E echo_append "#define GIT_COMMIT_SUBJECT_RAW " >> ${GITREV_TMP} - COMMAND ${GIT_EXECUTABLE} log -1 --format="%s" >> ${GITREV_TMP} - COMMAND ${CMAKE_COMMAND} -E echo >> ${GITREV_TMP} + COMMAND ${CMAKE_COMMAND} -E echo "#define GIT_COMMIT_SUBJECT_RAW \"${GIT_SUBJECT}\"" >> ${GITREV_TMP} COMMAND ${CMAKE_COMMAND} -E copy_if_different ${GITREV_TMP} ${GITREV_FILE} COMMAND ${CMAKE_COMMAND} -E remove ${GITREV_TMP} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} From d9189871eeb6317e0bca1ad529f83996d2fb05d3 Mon Sep 17 00:00:00 2001 From: Dan Ibanez Date: Tue, 16 Jan 2018 16:24:08 -0700 Subject: [PATCH 2/5] remove debug messages --- src/CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a1183117c..b6d57485f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -45,9 +45,7 @@ IF (GIT_FOUND AND IS_GIT_PROJECT) OUTPUT_VARIABLE GIT_SUBJECT_RAW OUTPUT_STRIP_TRAILING_WHITESPACE ) - MESSAGE("GIT_SUBJECT_RAW ${GIT_SUBJECT_RAW}") STRING(REPLACE "\"" "\\\"" GIT_SUBJECT "${GIT_SUBJECT_RAW}") - MESSAGE("GIT_SUBJECT ${GIT_SUBJECT}") ADD_CUSTOM_COMMAND( OUTPUT ${GITREV_TMP} COMMAND ${CMAKE_COMMAND} -E echo_append "#define GIT_BRANCH_RAW " > ${GITREV_TMP} From 3d372101590ed8cfd6befc5a07ddef1742115ef5 Mon Sep 17 00:00:00 2001 From: Dan Ibanez Date: Wed, 17 Jan 2018 09:56:13 -0700 Subject: [PATCH 3/5] Try to fix configure/compile time difference --- src/CMakeLists.txt | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b6d57485f..bd81a431f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -40,12 +40,6 @@ IF (GIT_FOUND AND IS_GIT_PROJECT) # Apparently custom commands need to be defined where the output is used. # If this in the main CMakeLists.txt it does not work. - EXECUTE_PROCESS(COMMAND ${GIT_EXECUTABLE} log -1 --format=%s - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} - OUTPUT_VARIABLE GIT_SUBJECT_RAW - OUTPUT_STRIP_TRAILING_WHITESPACE - ) - STRING(REPLACE "\"" "\\\"" GIT_SUBJECT "${GIT_SUBJECT_RAW}") ADD_CUSTOM_COMMAND( OUTPUT ${GITREV_TMP} COMMAND ${CMAKE_COMMAND} -E echo_append "#define GIT_BRANCH_RAW " > ${GITREV_TMP} @@ -57,7 +51,9 @@ IF (GIT_FOUND AND IS_GIT_PROJECT) COMMAND ${CMAKE_COMMAND} -E echo_append "#define GIT_COMMIT_LAST_CHANGED_RAW " >> ${GITREV_TMP} COMMAND ${GIT_EXECUTABLE} log -1 --format=%ad >> ${GITREV_TMP} COMMAND ${CMAKE_COMMAND} -E echo >> ${GITREV_TMP} - COMMAND ${CMAKE_COMMAND} -E echo "#define GIT_COMMIT_SUBJECT_RAW \"${GIT_SUBJECT}\"" >> ${GITREV_TMP} + COMMAND ${CMAKE_COMMAND} -E echo_append "#define GIT_COMMIT_SUBJECT_RAW \"" >> ${GITREV_TMP} + COMMAND ${GIT_EXECUTABLE} log -1 --format=%s | sed -E "s/\"/\\\"/g" | tr -d '\n' >> ${GITREV_TMP} + COMMAND ${CMAKE_COMMAND} -E echo_append "\"" >> ${GITREV_TMP} COMMAND ${CMAKE_COMMAND} -E copy_if_different ${GITREV_TMP} ${GITREV_FILE} COMMAND ${CMAKE_COMMAND} -E remove ${GITREV_TMP} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} From 3a8e49254ec50737418d2f761b9b7a78b639dccc Mon Sep 17 00:00:00 2001 From: Dan Ibanez Date: Wed, 17 Jan 2018 12:03:03 -0700 Subject: [PATCH 4/5] Fix escape of newline --- src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index bd81a431f..fe08da99d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -52,7 +52,7 @@ IF (GIT_FOUND AND IS_GIT_PROJECT) COMMAND ${GIT_EXECUTABLE} log -1 --format=%ad >> ${GITREV_TMP} COMMAND ${CMAKE_COMMAND} -E echo >> ${GITREV_TMP} COMMAND ${CMAKE_COMMAND} -E echo_append "#define GIT_COMMIT_SUBJECT_RAW \"" >> ${GITREV_TMP} - COMMAND ${GIT_EXECUTABLE} log -1 --format=%s | sed -E "s/\"/\\\"/g" | tr -d '\n' >> ${GITREV_TMP} + COMMAND ${GIT_EXECUTABLE} log -1 --format=%s | sed -E "s/\"/\\\"/g" | tr -d '\\n' >> ${GITREV_TMP} COMMAND ${CMAKE_COMMAND} -E echo_append "\"" >> ${GITREV_TMP} COMMAND ${CMAKE_COMMAND} -E copy_if_different ${GITREV_TMP} ${GITREV_FILE} COMMAND ${CMAKE_COMMAND} -E remove ${GITREV_TMP} From aa33d895bbd7806d4efd0b93b351b7f71039d23c Mon Sep 17 00:00:00 2001 From: Dan Ibanez Date: Thu, 18 Jan 2018 08:59:08 -0700 Subject: [PATCH 5/5] more escape for CMake "also "quotes"" --- src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index fe08da99d..b317647df 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -52,7 +52,7 @@ IF (GIT_FOUND AND IS_GIT_PROJECT) COMMAND ${GIT_EXECUTABLE} log -1 --format=%ad >> ${GITREV_TMP} COMMAND ${CMAKE_COMMAND} -E echo >> ${GITREV_TMP} COMMAND ${CMAKE_COMMAND} -E echo_append "#define GIT_COMMIT_SUBJECT_RAW \"" >> ${GITREV_TMP} - COMMAND ${GIT_EXECUTABLE} log -1 --format=%s | sed -E "s/\"/\\\"/g" | tr -d '\\n' >> ${GITREV_TMP} + COMMAND ${GIT_EXECUTABLE} log -1 --format=%s | sed -E "s/\"/\\\\\"/g" | tr -d '\\n' >> ${GITREV_TMP} COMMAND ${CMAKE_COMMAND} -E echo_append "\"" >> ${GITREV_TMP} COMMAND ${CMAKE_COMMAND} -E copy_if_different ${GITREV_TMP} ${GITREV_FILE} COMMAND ${CMAKE_COMMAND} -E remove ${GITREV_TMP}