Skip to content

Commit 8a19eb2

Browse files
authored
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
1 parent e81e355 commit 8a19eb2

File tree

5 files changed

+100
-71
lines changed

5 files changed

+100
-71
lines changed

‎Mac/BuildScript/build-installer.py‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,9 +1168,6 @@ def buildPython():
11681168
shellQuote(WORKDIR)[1:-1],
11691169
shellQuote(WORKDIR)[1:-1]))
11701170

1171-
print("Running make touch")
1172-
runCommand("make touch")
1173-
11741171
print("Running make")
11751172
runCommand("make")
11761173

‎Makefile.pre.in‎

Lines changed: 46 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ UNICODE_OBJS= @UNICODE_OBJS@
199199
PYTHON= python$(EXE)
200200
BUILDPYTHON= python$(BUILDEXE)
201201

202+
PYTHON_FOR_REGEN=@PYTHON_FOR_REGEN@
202203
PYTHON_FOR_BUILD=@PYTHON_FOR_BUILD@
203204
_PYTHON_HOST_PLATFORM=@_PYTHON_HOST_PLATFORM@
204205
HOST_GNU_TYPE= @host@
@@ -233,11 +234,6 @@ SIGNAL_OBJS= @SIGNAL_OBJS@
233234

234235

235236
##########################################################################
236-
# Grammar
237-
GRAMMAR_H= Include/graminit.h
238-
GRAMMAR_C= Python/graminit.c
239-
GRAMMAR_INPUT= $(srcdir)/Grammar/Grammar
240-
241237

242238
LIBFFI_INCLUDEDIR= @LIBFFI_INCLUDEDIR@
243239

@@ -297,29 +293,6 @@ PGENSRCS= $(PSRCS) $(PGSRCS)
297293
PGENOBJS= $(POBJS) $(PGOBJS)
298294

299295
##########################################################################
300-
# AST
301-
AST_H_DIR= Include
302-
AST_H= $(AST_H_DIR)/Python-ast.h
303-
AST_C_DIR= Python
304-
AST_C= $(AST_C_DIR)/Python-ast.c
305-
AST_ASDL= $(srcdir)/Parser/Python.asdl
306-
307-
ASDLGEN_FILES= $(srcdir)/Parser/asdl.py $(srcdir)/Parser/asdl_c.py
308-
# XXX Note that a build now requires Python exist before the build starts
309-
ASDLGEN= $(srcdir)/Parser/asdl_c.py
310-
311-
##########################################################################
312-
# Python
313-
314-
OPCODETARGETS_H= \
315-
$(srcdir)/Python/opcode_targets.h
316-
317-
OPCODETARGETGEN= \
318-
$(srcdir)/Python/makeopcodetargets.py
319-
320-
OPCODETARGETGEN_FILES= \
321-
$(OPCODETARGETGEN) $(srcdir)/Lib/opcode.py
322-
323296
PYTHON_OBJS= \
324297
Python/_warnings.o \
325298
Python/Python-ast.o \
@@ -493,9 +466,8 @@ coverage-lcov:
493466
@echo "lcov report at $(COVERAGE_REPORT)/index.html"
494467
@echo
495468

496-
coverage-report:
497-
: # force rebuilding of parser
498-
@touch $(GRAMMAR_INPUT)
469+
# Force regeneration of parser
470+
coverage-report: regen-grammar
499471
: # build with coverage info
500472
$(MAKE) coverage
501473
: # run tests, ignore failures
@@ -644,6 +616,12 @@ Modules/Setup: $(srcdir)/Modules/Setup.dist
644616
echo "-----------------------------------------------"; \
645617
fi
646618

619+
620+
############################################################################
621+
# Regenerate all generated files
622+
623+
regen-all: regen-opcode-targets regen-grammar regen-ast
624+
647625
############################################################################
648626
# Special rules for object files
649627

@@ -677,15 +655,18 @@ Modules/grpmodule.o: $(srcdir)/Modules/grpmodule.c $(srcdir)/Modules/posixmodule
677655

678656
Modules/pwdmodule.o: $(srcdir)/Modules/pwdmodule.c $(srcdir)/Modules/posixmodule.h
679657

680-
$(GRAMMAR_H): @GENERATED_COMMENT@ $(GRAMMAR_INPUT) $(PGEN)
681-
@$(MKDIR_P) Include
682-
$(PGEN) $(GRAMMAR_INPUT) $(GRAMMAR_H) $(GRAMMAR_C)
683-
$(GRAMMAR_C): @GENERATED_COMMENT@ $(GRAMMAR_H)
684-
touch $(GRAMMAR_C)
685-
686658
$(PGEN): $(PGENOBJS)
687659
$(CC) $(OPT) $(LDFLAGS) $(PGENOBJS) $(LIBS) -o $(PGEN)
688660

661+
.PHONY: regen-grammar
662+
regen-grammar: $(PGEN)
663+
# Regenerate Include/graminit.h and Python/graminit.c
664+
# from Grammar/Grammar using pgen
665+
@$(MKDIR_P) Include
666+
$(PGEN) $(srcdir)/Grammar/Grammar \
667+
$(srcdir)/Include/graminit.h \
668+
$(srcdir)/Python/graminit.c
669+
689670
Parser/grammar.o: $(srcdir)/Parser/grammar.c \
690671
$(srcdir)/Include/token.h \
691672
$(srcdir)/Include/grammar.h
@@ -695,15 +676,20 @@ Parser/tokenizer_pgen.o: $(srcdir)/Parser/tokenizer.c
695676

696677
Parser/pgenmain.o: $(srcdir)/Include/parsetok.h
697678

698-
$(AST_H): $(AST_ASDL) $(ASDLGEN_FILES)
699-
$(MKDIR_P) $(AST_H_DIR)
700-
$(ASDLGEN) -h $(AST_H_DIR) $(AST_ASDL)
701-
702-
$(AST_C): $(AST_ASDL) $(ASDLGEN_FILES)
703-
$(MKDIR_P) $(AST_C_DIR)
704-
$(ASDLGEN) -c $(AST_C_DIR) $(AST_ASDL)
705-
706-
Python/compile.o Python/symtable.o Python/ast.o: $(GRAMMAR_H) $(AST_H)
679+
.PHONY=regen-ast
680+
regen-ast:
681+
# Regenerate Include/Python-ast.h using Parser/asdl_c.py -h
682+
$(MKDIR_P) $(srcdir)/Include
683+
$(PYTHON_FOR_REGEN) $(srcdir)/Parser/asdl_c.py \
684+
-h $(srcdir)/Include \
685+
$(srcdir)/Parser/Python.asdl
686+
# Regenerate Python/Python-ast.c using Parser/asdl_c.py -c
687+
$(MKDIR_P) $(srcdir)/Python
688+
$(PYTHON_FOR_REGEN) $(srcdir)/Parser/asdl_c.py \
689+
-c $(srcdir)/Python \
690+
$(srcdir)/Parser/Python.asdl
691+
692+
Python/compile.o Python/symtable.o Python/ast.o: $(srcdir)/Include/graminit.h $(srcdir)/Include/Python-ast.h
707693

708694
Python/getplatform.o: $(srcdir)/Python/getplatform.c
709695
$(CC) -c $(PY_CFLAGS) -DPLATFORM='"$(MACHDEP)"' -o $@ $(srcdir)/Python/getplatform.c
@@ -738,10 +724,14 @@ Objects/bytearrayobject.o: $(srcdir)/Objects/bytearrayobject.c \
738724
Objects/stringobject.o: $(srcdir)/Objects/stringobject.c \
739725
$(STRINGLIB_HEADERS)
740726

741-
$(OPCODETARGETS_H): $(OPCODETARGETGEN_FILES)
742-
$(OPCODETARGETGEN) $(OPCODETARGETS_H)
727+
.PHONY: regen-opcode-targets
728+
regen-opcode-targets:
729+
# Regenerate Python/opcode_targets.h from Lib/opcode.py
730+
# using Python/makeopcodetargets.py
731+
$(PYTHON_FOR_REGEN) $(srcdir)/Python/makeopcodetargets.py \
732+
$(srcdir)/Python/opcode_targets.h
743733

744-
Python/ceval.o: $(OPCODETARGETS_H)
734+
Python/ceval.o: $(srcdir)/Python/opcode_targets.h
745735

746736
Python/formatter_unicode.o: $(srcdir)/Python/formatter_unicode.c \
747737
$(STRINGLIB_HEADERS)
@@ -836,7 +826,7 @@ PYTHON_HEADERS= \
836826
Include/weakrefobject.h \
837827
pyconfig.h \
838828
$(PARSER_HEADERS) \
839-
$(AST_H)
829+
$(srcdir)/Include/Python-ast.h
840830

841831
$(LIBRARY_OBJS) $(MODOBJS) Modules/python.o: $(PYTHON_HEADERS)
842832

@@ -1356,9 +1346,12 @@ recheck:
13561346
$(SHELL) config.status --recheck
13571347
$(SHELL) config.status
13581348

1359-
# Rebuild the configure script from configure.ac; also rebuild pyconfig.h.in
1349+
# Regenerate configure and pyconfig.h.in
1350+
.PHONY: autoconf
13601351
autoconf:
1352+
# Regenerate the configure script from configure.ac using autoconf
13611353
(cd $(srcdir); autoconf)
1354+
# Regenerate pyconfig.h.in from configure.ac using autoheader
13621355
(cd $(srcdir); autoheader)
13631356

13641357
# Create a tags file for vi
@@ -1375,11 +1368,6 @@ TAGS::
13751368
etags Include/*.h; \
13761369
for i in $(SRCDIRS); do etags -a $$i/*.[ch]; done
13771370

1378-
# Touch generated files
1379-
touch:
1380-
cd $(srcdir); \
1381-
touch Include/Python-ast.h Python/Python-ast.c
1382-
13831371
# Sanitation targets -- clean leaves libraries, executables and tags
13841372
# files, which clobber removes as well
13851373
pycremoval:
@@ -1476,8 +1464,8 @@ Python/thread.o: @THREADHEADERS@
14761464
.PHONY: maninstall libinstall inclinstall libainstall sharedinstall
14771465
.PHONY: frameworkinstall frameworkinstallframework frameworkinstallstructure
14781466
.PHONY: frameworkinstallmaclib frameworkinstallapps frameworkinstallunixtools
1479-
.PHONY: frameworkaltinstallunixtools recheck autoconf clean clobber distclean
1480-
.PHONY: smelly funny patchcheck touch altmaninstall commoninstall
1467+
.PHONY: frameworkaltinstallunixtools recheck clean clobber distclean
1468+
.PHONY: smelly funny patchcheck altmaninstall commoninstall
14811469
.PHONY: gdbhooks
14821470

14831471
# IF YOU PUT ANYTHING HERE IT WILL GO AWAY

‎Misc/NEWS‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ Documentation
134134
Build
135135
-----
136136

137+
- bpo-23404: Don't regenerate generated files based on file modification time
138+
anymore: the action is now explicit. Replace ``make touch`` with
139+
``make regen-all``.
140+
137141
- bpo-27593: sys.version and the platform module python_build(),
138142
python_branch(), and python_revision() functions now use
139143
git information rather than hg when building from a repo.

‎configure‎

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -740,8 +740,8 @@ UNIVERSALSDK
740740
CONFIG_ARGS
741741
SOVERSION
742742
VERSION
743-
GENERATED_COMMENT
744743
PYTHON_FOR_BUILD
744+
PYTHON_FOR_REGEN
745745
host_os
746746
host_vendor
747747
host_cpu
@@ -2902,6 +2902,51 @@ case $host_os in *\ *) host_os=`echo "$host_os" | sed 's/ /-/g'`;; esac
29022902
# pybuilddir.txt will be created by --generate-posix-vars in the Makefile
29032903
rm -f pybuilddir.txt
29042904
2905+
for ac_prog in python$PACKAGE_VERSION python3 python
2906+
do
2907+
# Extract the first word of "$ac_prog", so it can be a program name with args.
2908+
set dummy $ac_prog; ac_word=$2
2909+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
2910+
$as_echo_n "checking for $ac_word... " >&6; }
2911+
if ${ac_cv_prog_PYTHON_FOR_REGEN+:} false; then :
2912+
$as_echo_n "(cached) " >&6
2913+
else
2914+
if test -n "$PYTHON_FOR_REGEN"; then
2915+
ac_cv_prog_PYTHON_FOR_REGEN="$PYTHON_FOR_REGEN" # Let the user override the test.
2916+
else
2917+
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
2918+
for as_dir in $PATH
2919+
do
2920+
IFS=$as_save_IFS
2921+
test -z "$as_dir" && as_dir=.
2922+
for ac_exec_ext in '' $ac_executable_extensions; do
2923+
if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
2924+
ac_cv_prog_PYTHON_FOR_REGEN="$ac_prog"
2925+
$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
2926+
break 2
2927+
fi
2928+
done
2929+
done
2930+
IFS=$as_save_IFS
2931+
2932+
fi
2933+
fi
2934+
PYTHON_FOR_REGEN=$ac_cv_prog_PYTHON_FOR_REGEN
2935+
if test -n "$PYTHON_FOR_REGEN"; then
2936+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $PYTHON_FOR_REGEN" >&5
2937+
$as_echo "$PYTHON_FOR_REGEN" >&6; }
2938+
else
2939+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
2940+
$as_echo "no" >&6; }
2941+
fi
2942+
2943+
2944+
test -n "$PYTHON_FOR_REGEN" && break
2945+
done
2946+
test -n "$PYTHON_FOR_REGEN" || PYTHON_FOR_REGEN="python3"
2947+
2948+
2949+
29052950
if test "$cross_compiling" = yes; then
29062951
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for python interpreter for cross build" >&5
29072952
$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; }
29182963
fi
29192964
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $interp" >&5
29202965
$as_echo "$interp" >&6; }
2921-
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
2966+
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
29222967
fi
2923-
# Used to comment out stuff for rebuilding generated files
2924-
GENERATED_COMMENT='#'
29252968
elif test "$cross_compiling" = maybe; then
29262969
as_fn_error $? "Cross compiling required --host=HOST-TUPLE and --build=ARCH" "$LINENO" 5
29272970
else
29282971
PYTHON_FOR_BUILD='./$(BUILDPYTHON) -E'
2929-
GENERATED_COMMENT=''
29302972
fi
29312973
29322974
29332975
2934-
29352976
if test "$prefix" != "/"; then
29362977
prefix=`echo "$prefix" | sed -e 's/\/$//g'`
29372978
fi

‎configure.ac‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ AC_SUBST(host)
1919
# pybuilddir.txt will be created by --generate-posix-vars in the Makefile
2020
rm -f pybuilddir.txt
2121

22+
AC_CHECK_PROGS(PYTHON_FOR_REGEN, python$PACKAGE_VERSION python3 python, python3)
23+
AC_SUBST(PYTHON_FOR_REGEN)
24+
2225
if test "$cross_compiling" = yes; then
2326
AC_MSG_CHECKING([for python interpreter for cross build])
2427
if test -z "$PYTHON_FOR_BUILD"; then
@@ -35,16 +38,12 @@ if test "$cross_compiling" = yes; then
3538
AC_MSG_RESULT($interp)
3639
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
3740
fi
38-
# Used to comment out stuff for rebuilding generated files
39-
GENERATED_COMMENT='#'
4041
elif test "$cross_compiling" = maybe; then
4142
AC_MSG_ERROR([Cross compiling required --host=HOST-TUPLE and --build=ARCH])
4243
else
4344
PYTHON_FOR_BUILD='./$(BUILDPYTHON) -E'
44-
GENERATED_COMMENT=''
4545
fi
4646
AC_SUBST(PYTHON_FOR_BUILD)
47-
AC_SUBST(GENERATED_COMMENT)
4847

4948
dnl Ensure that if prefix is specified, it does not end in a slash. If
5049
dnl it does, we get path names containing '//' which is both ugly and

0 commit comments

Comments
 (0)