Commit 8a19eb24 authored by Victor Stinner's avatar Victor Stinner Committed by GitHub

bpo-23404: make touch becomes make regen-all (#1466)

Don't rebuild generated files based on file modification time
anymore, the action is now explicit. Replace "make touch"
with "make regen-all".

Changes:

* Remove "make touch", Tools/hg/hgtouch.py and .hgtouch
* Add a new "make regen-all" command to rebuild all generated files
* Add subcommands to only generate specific files:

  - regen-ast: Include/Python-ast.h and Python/Python-ast.c
  - regen-grammar: Include/graminit.h and Python/graminit.c
  - regen-opcode-targets: Python/opcode_targets.h

* Add PYTHON_FOR_REGEN variable
* pgen is now only built by by "make regen-grammar"
* Add $(srcdir)/ prefix to paths to source files to handle correctly
  compilation outside the source directory
parent e81e355a
...@@ -1168,9 +1168,6 @@ def buildPython(): ...@@ -1168,9 +1168,6 @@ def buildPython():
shellQuote(WORKDIR)[1:-1], shellQuote(WORKDIR)[1:-1],
shellQuote(WORKDIR)[1:-1])) shellQuote(WORKDIR)[1:-1]))
print("Running make touch")
runCommand("make touch")
print("Running make") print("Running make")
runCommand("make") runCommand("make")
......
...@@ -199,6 +199,7 @@ UNICODE_OBJS= @UNICODE_OBJS@ ...@@ -199,6 +199,7 @@ UNICODE_OBJS= @UNICODE_OBJS@
PYTHON= python$(EXE) PYTHON= python$(EXE)
BUILDPYTHON= python$(BUILDEXE) BUILDPYTHON= python$(BUILDEXE)
PYTHON_FOR_REGEN=@PYTHON_FOR_REGEN@
PYTHON_FOR_BUILD=@PYTHON_FOR_BUILD@ PYTHON_FOR_BUILD=@PYTHON_FOR_BUILD@
_PYTHON_HOST_PLATFORM=@_PYTHON_HOST_PLATFORM@ _PYTHON_HOST_PLATFORM=@_PYTHON_HOST_PLATFORM@
HOST_GNU_TYPE= @host@ HOST_GNU_TYPE= @host@
...@@ -233,11 +234,6 @@ SIGNAL_OBJS= @SIGNAL_OBJS@ ...@@ -233,11 +234,6 @@ SIGNAL_OBJS= @SIGNAL_OBJS@
########################################################################## ##########################################################################
# Grammar
GRAMMAR_H= Include/graminit.h
GRAMMAR_C= Python/graminit.c
GRAMMAR_INPUT= $(srcdir)/Grammar/Grammar
LIBFFI_INCLUDEDIR= @LIBFFI_INCLUDEDIR@ LIBFFI_INCLUDEDIR= @LIBFFI_INCLUDEDIR@
...@@ -297,29 +293,6 @@ PGENSRCS= $(PSRCS) $(PGSRCS) ...@@ -297,29 +293,6 @@ PGENSRCS= $(PSRCS) $(PGSRCS)
PGENOBJS= $(POBJS) $(PGOBJS) PGENOBJS= $(POBJS) $(PGOBJS)
########################################################################## ##########################################################################
# AST
AST_H_DIR= Include
AST_H= $(AST_H_DIR)/Python-ast.h
AST_C_DIR= Python
AST_C= $(AST_C_DIR)/Python-ast.c
AST_ASDL= $(srcdir)/Parser/Python.asdl
ASDLGEN_FILES= $(srcdir)/Parser/asdl.py $(srcdir)/Parser/asdl_c.py
# XXX Note that a build now requires Python exist before the build starts
ASDLGEN= $(srcdir)/Parser/asdl_c.py
##########################################################################
# Python
OPCODETARGETS_H= \
$(srcdir)/Python/opcode_targets.h
OPCODETARGETGEN= \
$(srcdir)/Python/makeopcodetargets.py
OPCODETARGETGEN_FILES= \
$(OPCODETARGETGEN) $(srcdir)/Lib/opcode.py
PYTHON_OBJS= \ PYTHON_OBJS= \
Python/_warnings.o \ Python/_warnings.o \
Python/Python-ast.o \ Python/Python-ast.o \
...@@ -493,9 +466,8 @@ coverage-lcov: ...@@ -493,9 +466,8 @@ coverage-lcov:
@echo "lcov report at $(COVERAGE_REPORT)/index.html" @echo "lcov report at $(COVERAGE_REPORT)/index.html"
@echo @echo
coverage-report: # Force regeneration of parser
: # force rebuilding of parser coverage-report: regen-grammar
@touch $(GRAMMAR_INPUT)
: # build with coverage info : # build with coverage info
$(MAKE) coverage $(MAKE) coverage
: # run tests, ignore failures : # run tests, ignore failures
...@@ -644,6 +616,12 @@ Modules/Setup: $(srcdir)/Modules/Setup.dist ...@@ -644,6 +616,12 @@ Modules/Setup: $(srcdir)/Modules/Setup.dist
echo "-----------------------------------------------"; \ echo "-----------------------------------------------"; \
fi fi
############################################################################
# Regenerate all generated files
regen-all: regen-opcode-targets regen-grammar regen-ast
############################################################################ ############################################################################
# Special rules for object files # Special rules for object files
...@@ -677,15 +655,18 @@ Modules/grpmodule.o: $(srcdir)/Modules/grpmodule.c $(srcdir)/Modules/posixmodule ...@@ -677,15 +655,18 @@ Modules/grpmodule.o: $(srcdir)/Modules/grpmodule.c $(srcdir)/Modules/posixmodule
Modules/pwdmodule.o: $(srcdir)/Modules/pwdmodule.c $(srcdir)/Modules/posixmodule.h Modules/pwdmodule.o: $(srcdir)/Modules/pwdmodule.c $(srcdir)/Modules/posixmodule.h
$(GRAMMAR_H): @GENERATED_COMMENT@ $(GRAMMAR_INPUT) $(PGEN)
@$(MKDIR_P) Include
$(PGEN) $(GRAMMAR_INPUT) $(GRAMMAR_H) $(GRAMMAR_C)
$(GRAMMAR_C): @GENERATED_COMMENT@ $(GRAMMAR_H)
touch $(GRAMMAR_C)
$(PGEN): $(PGENOBJS) $(PGEN): $(PGENOBJS)
$(CC) $(OPT) $(LDFLAGS) $(PGENOBJS) $(LIBS) -o $(PGEN) $(CC) $(OPT) $(LDFLAGS) $(PGENOBJS) $(LIBS) -o $(PGEN)
.PHONY: regen-grammar
regen-grammar: $(PGEN)
# Regenerate Include/graminit.h and Python/graminit.c
# from Grammar/Grammar using pgen
@$(MKDIR_P) Include
$(PGEN) $(srcdir)/Grammar/Grammar \
$(srcdir)/Include/graminit.h \
$(srcdir)/Python/graminit.c
Parser/grammar.o: $(srcdir)/Parser/grammar.c \ Parser/grammar.o: $(srcdir)/Parser/grammar.c \
$(srcdir)/Include/token.h \ $(srcdir)/Include/token.h \
$(srcdir)/Include/grammar.h $(srcdir)/Include/grammar.h
...@@ -695,15 +676,20 @@ Parser/tokenizer_pgen.o: $(srcdir)/Parser/tokenizer.c ...@@ -695,15 +676,20 @@ Parser/tokenizer_pgen.o: $(srcdir)/Parser/tokenizer.c
Parser/pgenmain.o: $(srcdir)/Include/parsetok.h Parser/pgenmain.o: $(srcdir)/Include/parsetok.h
$(AST_H): $(AST_ASDL) $(ASDLGEN_FILES) .PHONY=regen-ast
$(MKDIR_P) $(AST_H_DIR) regen-ast:
$(ASDLGEN) -h $(AST_H_DIR) $(AST_ASDL) # Regenerate Include/Python-ast.h using Parser/asdl_c.py -h
$(MKDIR_P) $(srcdir)/Include
$(AST_C): $(AST_ASDL) $(ASDLGEN_FILES) $(PYTHON_FOR_REGEN) $(srcdir)/Parser/asdl_c.py \
$(MKDIR_P) $(AST_C_DIR) -h $(srcdir)/Include \
$(ASDLGEN) -c $(AST_C_DIR) $(AST_ASDL) $(srcdir)/Parser/Python.asdl
# Regenerate Python/Python-ast.c using Parser/asdl_c.py -c
Python/compile.o Python/symtable.o Python/ast.o: $(GRAMMAR_H) $(AST_H) $(MKDIR_P) $(srcdir)/Python
$(PYTHON_FOR_REGEN) $(srcdir)/Parser/asdl_c.py \
-c $(srcdir)/Python \
$(srcdir)/Parser/Python.asdl
Python/compile.o Python/symtable.o Python/ast.o: $(srcdir)/Include/graminit.h $(srcdir)/Include/Python-ast.h
Python/getplatform.o: $(srcdir)/Python/getplatform.c Python/getplatform.o: $(srcdir)/Python/getplatform.c
$(CC) -c $(PY_CFLAGS) -DPLATFORM='"$(MACHDEP)"' -o $@ $(srcdir)/Python/getplatform.c $(CC) -c $(PY_CFLAGS) -DPLATFORM='"$(MACHDEP)"' -o $@ $(srcdir)/Python/getplatform.c
...@@ -738,10 +724,14 @@ Objects/bytearrayobject.o: $(srcdir)/Objects/bytearrayobject.c \ ...@@ -738,10 +724,14 @@ Objects/bytearrayobject.o: $(srcdir)/Objects/bytearrayobject.c \
Objects/stringobject.o: $(srcdir)/Objects/stringobject.c \ Objects/stringobject.o: $(srcdir)/Objects/stringobject.c \
$(STRINGLIB_HEADERS) $(STRINGLIB_HEADERS)
$(OPCODETARGETS_H): $(OPCODETARGETGEN_FILES) .PHONY: regen-opcode-targets
$(OPCODETARGETGEN) $(OPCODETARGETS_H) regen-opcode-targets:
# Regenerate Python/opcode_targets.h from Lib/opcode.py
# using Python/makeopcodetargets.py
$(PYTHON_FOR_REGEN) $(srcdir)/Python/makeopcodetargets.py \
$(srcdir)/Python/opcode_targets.h
Python/ceval.o: $(OPCODETARGETS_H) Python/ceval.o: $(srcdir)/Python/opcode_targets.h
Python/formatter_unicode.o: $(srcdir)/Python/formatter_unicode.c \ Python/formatter_unicode.o: $(srcdir)/Python/formatter_unicode.c \
$(STRINGLIB_HEADERS) $(STRINGLIB_HEADERS)
...@@ -836,7 +826,7 @@ PYTHON_HEADERS= \ ...@@ -836,7 +826,7 @@ PYTHON_HEADERS= \
Include/weakrefobject.h \ Include/weakrefobject.h \
pyconfig.h \ pyconfig.h \
$(PARSER_HEADERS) \ $(PARSER_HEADERS) \
$(AST_H) $(srcdir)/Include/Python-ast.h
$(LIBRARY_OBJS) $(MODOBJS) Modules/python.o: $(PYTHON_HEADERS) $(LIBRARY_OBJS) $(MODOBJS) Modules/python.o: $(PYTHON_HEADERS)
...@@ -1356,9 +1346,12 @@ recheck: ...@@ -1356,9 +1346,12 @@ recheck:
$(SHELL) config.status --recheck $(SHELL) config.status --recheck
$(SHELL) config.status $(SHELL) config.status
# Rebuild the configure script from configure.ac; also rebuild pyconfig.h.in # Regenerate configure and pyconfig.h.in
.PHONY: autoconf
autoconf: autoconf:
# Regenerate the configure script from configure.ac using autoconf
(cd $(srcdir); autoconf) (cd $(srcdir); autoconf)
# Regenerate pyconfig.h.in from configure.ac using autoheader
(cd $(srcdir); autoheader) (cd $(srcdir); autoheader)
# Create a tags file for vi # Create a tags file for vi
...@@ -1375,11 +1368,6 @@ TAGS:: ...@@ -1375,11 +1368,6 @@ TAGS::
etags Include/*.h; \ etags Include/*.h; \
for i in $(SRCDIRS); do etags -a $$i/*.[ch]; done for i in $(SRCDIRS); do etags -a $$i/*.[ch]; done
# Touch generated files
touch:
cd $(srcdir); \
touch Include/Python-ast.h Python/Python-ast.c
# Sanitation targets -- clean leaves libraries, executables and tags # Sanitation targets -- clean leaves libraries, executables and tags
# files, which clobber removes as well # files, which clobber removes as well
pycremoval: pycremoval:
...@@ -1476,8 +1464,8 @@ Python/thread.o: @THREADHEADERS@ ...@@ -1476,8 +1464,8 @@ Python/thread.o: @THREADHEADERS@
.PHONY: maninstall libinstall inclinstall libainstall sharedinstall .PHONY: maninstall libinstall inclinstall libainstall sharedinstall
.PHONY: frameworkinstall frameworkinstallframework frameworkinstallstructure .PHONY: frameworkinstall frameworkinstallframework frameworkinstallstructure
.PHONY: frameworkinstallmaclib frameworkinstallapps frameworkinstallunixtools .PHONY: frameworkinstallmaclib frameworkinstallapps frameworkinstallunixtools
.PHONY: frameworkaltinstallunixtools recheck autoconf clean clobber distclean .PHONY: frameworkaltinstallunixtools recheck clean clobber distclean
.PHONY: smelly funny patchcheck touch altmaninstall commoninstall .PHONY: smelly funny patchcheck altmaninstall commoninstall
.PHONY: gdbhooks .PHONY: gdbhooks
# IF YOU PUT ANYTHING HERE IT WILL GO AWAY # IF YOU PUT ANYTHING HERE IT WILL GO AWAY
...@@ -134,6 +134,10 @@ Documentation ...@@ -134,6 +134,10 @@ Documentation
Build Build
----- -----
- bpo-23404: Don't regenerate generated files based on file modification time
anymore: the action is now explicit. Replace ``make touch`` with
``make regen-all``.
- bpo-27593: sys.version and the platform module python_build(), - bpo-27593: sys.version and the platform module python_build(),
python_branch(), and python_revision() functions now use python_branch(), and python_revision() functions now use
git information rather than hg when building from a repo. git information rather than hg when building from a repo.
......
...@@ -740,8 +740,8 @@ UNIVERSALSDK ...@@ -740,8 +740,8 @@ UNIVERSALSDK
CONFIG_ARGS CONFIG_ARGS
SOVERSION SOVERSION
VERSION VERSION
GENERATED_COMMENT
PYTHON_FOR_BUILD PYTHON_FOR_BUILD
PYTHON_FOR_REGEN
host_os host_os
host_vendor host_vendor
host_cpu host_cpu
...@@ -2902,6 +2902,51 @@ case $host_os in *\ *) host_os=`echo "$host_os" | sed 's/ /-/g'`;; esac ...@@ -2902,6 +2902,51 @@ case $host_os in *\ *) host_os=`echo "$host_os" | sed 's/ /-/g'`;; esac
# pybuilddir.txt will be created by --generate-posix-vars in the Makefile # pybuilddir.txt will be created by --generate-posix-vars in the Makefile
rm -f pybuilddir.txt rm -f pybuilddir.txt
for ac_prog in python$PACKAGE_VERSION python3 python
do
# Extract the first word of "$ac_prog", so it can be a program name with args.
set dummy $ac_prog; ac_word=$2
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
$as_echo_n "checking for $ac_word... " >&6; }
if ${ac_cv_prog_PYTHON_FOR_REGEN+:} false; then :
$as_echo_n "(cached) " >&6
else
if test -n "$PYTHON_FOR_REGEN"; then
ac_cv_prog_PYTHON_FOR_REGEN="$PYTHON_FOR_REGEN" # Let the user override the test.
else
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
IFS=$as_save_IFS
test -z "$as_dir" && as_dir=.
for ac_exec_ext in '' $ac_executable_extensions; do
if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
ac_cv_prog_PYTHON_FOR_REGEN="$ac_prog"
$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
break 2
fi
done
done
IFS=$as_save_IFS
fi
fi
PYTHON_FOR_REGEN=$ac_cv_prog_PYTHON_FOR_REGEN
if test -n "$PYTHON_FOR_REGEN"; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $PYTHON_FOR_REGEN" >&5
$as_echo "$PYTHON_FOR_REGEN" >&6; }
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
fi
test -n "$PYTHON_FOR_REGEN" && break
done
test -n "$PYTHON_FOR_REGEN" || PYTHON_FOR_REGEN="python3"
if test "$cross_compiling" = yes; then if test "$cross_compiling" = yes; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for python interpreter for cross build" >&5 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for python interpreter for cross build" >&5
$as_echo_n "checking for python interpreter for cross build... " >&6; } $as_echo_n "checking for python interpreter for cross build... " >&6; }
...@@ -2918,20 +2963,16 @@ $as_echo_n "checking for python interpreter for cross build... " >&6; } ...@@ -2918,20 +2963,16 @@ $as_echo_n "checking for python interpreter for cross build... " >&6; }
fi fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $interp" >&5 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $interp" >&5
$as_echo "$interp" >&6; } $as_echo "$interp" >&6; }
PYTHON_FOR_BUILD='_PYTHON_PROJECT_BASE=$(abs_builddir) _PYTHON_HOST_PLATFORM=$(_PYTHON_HOST_PLATFORM) PYTHONPATH=$(shell test -f pybuilddir.txt && echo $(abs_builddir)/`cat pybuilddir.txt`:)$(srcdir)/Lib:$(srcdir)/Lib/$(PLATDIR) '$interp PYTHON_FOR_BUILD='_PYTHON_PROJECT_BASE=$(abs_builddir) _PYTHON_HOST_PLATFORM=$(_PYTHON_HOST_PLATFORM) PYTHONPATH=$(shell test -f pybuilddir.txt && echo $(abs_builddir)/`cat pybuilddir.txt`:)$(srcdir)/Lib _PYTHON_SYSCONFIGDATA_NAME=_sysconfigdata_$(ABIFLAGS)_$(MACHDEP)_$(MULTIARCH) '$interp
fi fi
# Used to comment out stuff for rebuilding generated files
GENERATED_COMMENT='#'
elif test "$cross_compiling" = maybe; then elif test "$cross_compiling" = maybe; then
as_fn_error $? "Cross compiling required --host=HOST-TUPLE and --build=ARCH" "$LINENO" 5 as_fn_error $? "Cross compiling required --host=HOST-TUPLE and --build=ARCH" "$LINENO" 5
else else
PYTHON_FOR_BUILD='./$(BUILDPYTHON) -E' PYTHON_FOR_BUILD='./$(BUILDPYTHON) -E'
GENERATED_COMMENT=''
fi fi
if test "$prefix" != "/"; then if test "$prefix" != "/"; then
prefix=`echo "$prefix" | sed -e 's/\/$//g'` prefix=`echo "$prefix" | sed -e 's/\/$//g'`
fi fi
......
...@@ -19,6 +19,9 @@ AC_SUBST(host) ...@@ -19,6 +19,9 @@ AC_SUBST(host)
# pybuilddir.txt will be created by --generate-posix-vars in the Makefile # pybuilddir.txt will be created by --generate-posix-vars in the Makefile
rm -f pybuilddir.txt rm -f pybuilddir.txt
AC_CHECK_PROGS(PYTHON_FOR_REGEN, python$PACKAGE_VERSION python3 python, python3)
AC_SUBST(PYTHON_FOR_REGEN)
if test "$cross_compiling" = yes; then if test "$cross_compiling" = yes; then
AC_MSG_CHECKING([for python interpreter for cross build]) AC_MSG_CHECKING([for python interpreter for cross build])
if test -z "$PYTHON_FOR_BUILD"; then if test -z "$PYTHON_FOR_BUILD"; then
...@@ -35,16 +38,12 @@ if test "$cross_compiling" = yes; then ...@@ -35,16 +38,12 @@ if test "$cross_compiling" = yes; then
AC_MSG_RESULT($interp) AC_MSG_RESULT($interp)
PYTHON_FOR_BUILD='_PYTHON_PROJECT_BASE=$(abs_builddir) _PYTHON_HOST_PLATFORM=$(_PYTHON_HOST_PLATFORM) PYTHONPATH=$(shell test -f pybuilddir.txt && echo $(abs_builddir)/`cat pybuilddir.txt`:)$(srcdir)/Lib:$(srcdir)/Lib/$(PLATDIR) '$interp PYTHON_FOR_BUILD='_PYTHON_PROJECT_BASE=$(abs_builddir) _PYTHON_HOST_PLATFORM=$(_PYTHON_HOST_PLATFORM) PYTHONPATH=$(shell test -f pybuilddir.txt && echo $(abs_builddir)/`cat pybuilddir.txt`:)$(srcdir)/Lib:$(srcdir)/Lib/$(PLATDIR) '$interp
fi fi
# Used to comment out stuff for rebuilding generated files
GENERATED_COMMENT='#'
elif test "$cross_compiling" = maybe; then elif test "$cross_compiling" = maybe; then
AC_MSG_ERROR([Cross compiling required --host=HOST-TUPLE and --build=ARCH]) AC_MSG_ERROR([Cross compiling required --host=HOST-TUPLE and --build=ARCH])
else else
PYTHON_FOR_BUILD='./$(BUILDPYTHON) -E' PYTHON_FOR_BUILD='./$(BUILDPYTHON) -E'
GENERATED_COMMENT=''
fi fi
AC_SUBST(PYTHON_FOR_BUILD) AC_SUBST(PYTHON_FOR_BUILD)
AC_SUBST(GENERATED_COMMENT)
dnl Ensure that if prefix is specified, it does not end in a slash. If dnl Ensure that if prefix is specified, it does not end in a slash. If
dnl it does, we get path names containing '//' which is both ugly and dnl it does, we get path names containing '//' which is both ugly and
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment