Git fork

Makefile: extract script to massage Python scripts

Extract a script that massages Python scripts. This provides a couple of
benefits:

- The build logic is deduplicated across Make, CMake and Meson.

- CMake learns to rewrite scripts as-needed at build time instead of
only writing them at configure time.

Furthermore, we will use this script when introducing Meson to
deduplicate the logic across build systems.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Patrick Steinhardt and committed by
Junio C Hamano
b7835b94 eb98cb83

+33 -10
+2 -6
Makefile
··· 2635 2635 $(SCRIPT_PYTHON_GEN): GIT-BUILD-OPTIONS 2636 2636 2637 2637 ifndef NO_PYTHON 2638 - $(SCRIPT_PYTHON_GEN): GIT-CFLAGS GIT-PREFIX GIT-PYTHON-VARS 2638 + $(SCRIPT_PYTHON_GEN): generate-python.sh 2639 2639 $(SCRIPT_PYTHON_GEN): % : %.py 2640 - $(QUIET_GEN) \ 2641 - sed -e '1s|#!.*python|#!$(PYTHON_PATH_SQ)|' \ 2642 - $< >$@+ && \ 2643 - chmod +x $@+ && \ 2644 - mv $@+ $@ 2640 + $(QUIET_GEN)$(SHELL_PATH) generate-python.sh ./GIT-BUILD-OPTIONS "$<" "$@" 2645 2641 else # NO_PYTHON 2646 2642 $(SCRIPT_PYTHON_GEN): % : unimplemented.sh 2647 2643 $(QUIET_GEN) \
+11 -4
contrib/buildsystems/CMakeLists.txt
··· 899 899 endforeach() 900 900 add_custom_target(perl-gen ALL DEPENDS ${perl_gen}) 901 901 902 - #python script 903 - file(STRINGS ${CMAKE_SOURCE_DIR}/git-p4.py content NEWLINE_CONSUME) 904 - string(REPLACE "#!/usr/bin/env python" "#!/usr/bin/python" content "${content}") 905 - file(WRITE ${CMAKE_BINARY_DIR}/git-p4 ${content}) 902 + # Python script 903 + add_custom_command(OUTPUT "${CMAKE_BINARY_DIR}/git-p4" 904 + COMMAND "${SH_EXE}" "${CMAKE_SOURCE_DIR}/generate-python.sh" 905 + "${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS" 906 + "${CMAKE_SOURCE_DIR}/git-p4.py" 907 + "${CMAKE_BINARY_DIR}/git-p4" 908 + DEPENDS "${CMAKE_SOURCE_DIR}/generate-python.sh" 909 + "${CMAKE_SOURCE_DIR}/git-p4.py" 910 + "${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS" 911 + VERBATIM) 912 + add_custom_target(python-gen ALL DEPENDS "${CMAKE_BINARY_DIR}/git-p4") 906 913 907 914 #templates 908 915 file(GLOB templates "${CMAKE_SOURCE_DIR}/templates/*")
+20
generate-python.sh
··· 1 + #!/bin/sh 2 + 3 + set -e 4 + 5 + if test $# -ne 3 6 + then 7 + echo >&2 "USAGE: $0 <GIT_BUILD_OPTIONS> <INPUT> <OUTPUT>" 8 + exit 1 9 + fi 10 + 11 + GIT_BUILD_OPTIONS="$1" 12 + INPUT="$2" 13 + OUTPUT="$3" 14 + 15 + . "$GIT_BUILD_OPTIONS" 16 + 17 + sed -e "1s|#!.*python|#!$PYTHON_PATH|" \ 18 + "$INPUT" >"$OUTPUT+" 19 + chmod a+x "$OUTPUT+" 20 + mv "$OUTPUT+" "$OUTPUT"