]> granicus.if.org Git - python/commitdiff
bpo-23404: make touch becomes make regen-all (#1466)
authorVictor Stinner <victor.stinner@gmail.com>
Fri, 5 May 2017 01:14:23 +0000 (03:14 +0200)
committerGitHub <noreply@github.com>
Fri, 5 May 2017 01:14:23 +0000 (03:14 +0200)
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

Mac/BuildScript/build-installer.py
Makefile.pre.in
Misc/NEWS
configure
configure.ac

index 0951e5feaac5813933196b904982de7cf971f805..e8272e7e439b490b24f3b85746721c4abd7a1a27 100755 (executable)
@@ -1168,9 +1168,6 @@ def buildPython():
         shellQuote(WORKDIR)[1:-1],
         shellQuote(WORKDIR)[1:-1]))
 
-    print("Running make touch")
-    runCommand("make touch")
-
     print("Running make")
     runCommand("make")
 
index 7d94d4109e73320c6e50e2057853e1a264e6ee59..32d8613b89b5056247e20067a470e4def0d6fe05 100644 (file)
@@ -199,6 +199,7 @@ UNICODE_OBJS=   @UNICODE_OBJS@
 PYTHON=                python$(EXE)
 BUILDPYTHON=   python$(BUILDEXE)
 
+PYTHON_FOR_REGEN=@PYTHON_FOR_REGEN@
 PYTHON_FOR_BUILD=@PYTHON_FOR_BUILD@
 _PYTHON_HOST_PLATFORM=@_PYTHON_HOST_PLATFORM@
 HOST_GNU_TYPE=  @host@
@@ -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@
 
@@ -297,29 +293,6 @@ PGENSRCS=  $(PSRCS) $(PGSRCS)
 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/_warnings.o \
                Python/Python-ast.o \
@@ -493,9 +466,8 @@ coverage-lcov:
        @echo "lcov report at $(COVERAGE_REPORT)/index.html"
        @echo
 
-coverage-report:
-       : # force rebuilding of parser
-       @touch $(GRAMMAR_INPUT)
+# Force regeneration of parser
+coverage-report: regen-grammar
        : # build with coverage info
        $(MAKE) coverage
        : # run tests, ignore failures
@@ -644,6 +616,12 @@ Modules/Setup: $(srcdir)/Modules/Setup.dist
                echo "-----------------------------------------------"; \
        fi
 
+
+############################################################################
+# Regenerate all generated files
+
+regen-all: regen-opcode-targets regen-grammar regen-ast
+
 ############################################################################
 # Special rules for object files
 
@@ -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
 
-$(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)
                $(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 \
                                $(srcdir)/Include/token.h \
                                $(srcdir)/Include/grammar.h
@@ -695,15 +676,20 @@ Parser/tokenizer_pgen.o:  $(srcdir)/Parser/tokenizer.c
 
 Parser/pgenmain.o:     $(srcdir)/Include/parsetok.h
 
-$(AST_H): $(AST_ASDL) $(ASDLGEN_FILES)
-       $(MKDIR_P) $(AST_H_DIR)
-       $(ASDLGEN) -h $(AST_H_DIR) $(AST_ASDL)
-
-$(AST_C): $(AST_ASDL) $(ASDLGEN_FILES)
-       $(MKDIR_P) $(AST_C_DIR)
-       $(ASDLGEN) -c $(AST_C_DIR) $(AST_ASDL)
-
-Python/compile.o Python/symtable.o Python/ast.o: $(GRAMMAR_H) $(AST_H)
+.PHONY=regen-ast
+regen-ast:
+       # Regenerate Include/Python-ast.h using Parser/asdl_c.py -h
+       $(MKDIR_P) $(srcdir)/Include
+       $(PYTHON_FOR_REGEN) $(srcdir)/Parser/asdl_c.py \
+               -h $(srcdir)/Include \
+               $(srcdir)/Parser/Python.asdl
+       # Regenerate Python/Python-ast.c using Parser/asdl_c.py -c
+       $(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
                $(CC) -c $(PY_CFLAGS) -DPLATFORM='"$(MACHDEP)"' -o $@ $(srcdir)/Python/getplatform.c
@@ -738,10 +724,14 @@ Objects/bytearrayobject.o: $(srcdir)/Objects/bytearrayobject.c \
 Objects/stringobject.o: $(srcdir)/Objects/stringobject.c \
                                $(STRINGLIB_HEADERS)
 
-$(OPCODETARGETS_H): $(OPCODETARGETGEN_FILES)
-       $(OPCODETARGETGEN) $(OPCODETARGETS_H)
+.PHONY: regen-opcode-targets
+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 \
                                $(STRINGLIB_HEADERS)
@@ -836,7 +826,7 @@ PYTHON_HEADERS= \
                Include/weakrefobject.h \
                pyconfig.h \
                $(PARSER_HEADERS) \
-               $(AST_H)
+               $(srcdir)/Include/Python-ast.h
 
 $(LIBRARY_OBJS) $(MODOBJS) Modules/python.o: $(PYTHON_HEADERS)
 
@@ -1356,9 +1346,12 @@ recheck:
        $(SHELL) config.status --recheck
        $(SHELL) config.status
 
-# Rebuild the configure script from configure.ac; also rebuild pyconfig.h.in
+# Regenerate configure and pyconfig.h.in
+.PHONY: autoconf
 autoconf:
+       # Regenerate the configure script from configure.ac using autoconf
        (cd $(srcdir); autoconf)
+       # Regenerate pyconfig.h.in from configure.ac using autoheader
        (cd $(srcdir); autoheader)
 
 # Create a tags file for vi
@@ -1375,11 +1368,6 @@ TAGS::
        etags Include/*.h; \
        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
 # files, which clobber removes as well
 pycremoval:
@@ -1476,8 +1464,8 @@ Python/thread.o: @THREADHEADERS@
 .PHONY: maninstall libinstall inclinstall libainstall sharedinstall
 .PHONY: frameworkinstall frameworkinstallframework frameworkinstallstructure
 .PHONY: frameworkinstallmaclib frameworkinstallapps frameworkinstallunixtools
-.PHONY: frameworkaltinstallunixtools recheck autoconf clean clobber distclean
-.PHONY: smelly funny patchcheck touch altmaninstall commoninstall
+.PHONY: frameworkaltinstallunixtools recheck clean clobber distclean
+.PHONY: smelly funny patchcheck altmaninstall commoninstall
 .PHONY: gdbhooks
 
 # IF YOU PUT ANYTHING HERE IT WILL GO AWAY
index 47a00a604278a23da11edd52aca61f6595a1b8b2..d8ca14a94c7afa10e3ce0d6bde0813332feab133 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -134,6 +134,10 @@ Documentation
 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(),
   python_branch(), and python_revision() functions now use
   git information rather than hg when building from a repo.
index 8c917351247121487a0dc591c17db1bc43a83081..6123e21109c78964fd943ef98bad97ac429d1e19 100755 (executable)
--- a/configure
+++ b/configure
@@ -740,8 +740,8 @@ UNIVERSALSDK
 CONFIG_ARGS
 SOVERSION
 VERSION
-GENERATED_COMMENT
 PYTHON_FOR_BUILD
+PYTHON_FOR_REGEN
 host_os
 host_vendor
 host_cpu
@@ -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
 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
     { $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; }
@@ -2918,20 +2963,16 @@ $as_echo_n "checking for python interpreter for cross build... " >&6; }
        fi
         { $as_echo "$as_me:${as_lineno-$LINENO}: result: $interp" >&5
 $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
-    # Used to comment out stuff for rebuilding generated files
-    GENERATED_COMMENT='#'
 elif test "$cross_compiling" = maybe; then
     as_fn_error $? "Cross compiling required --host=HOST-TUPLE and --build=ARCH" "$LINENO" 5
 else
     PYTHON_FOR_BUILD='./$(BUILDPYTHON) -E'
-    GENERATED_COMMENT=''
 fi
 
 
 
-
 if test "$prefix" != "/"; then
     prefix=`echo "$prefix" | sed -e 's/\/$//g'`
 fi
index aa74259ef58c8e8b79cb41b78cd5b4ecad2a0276..780f2758c839e3092e6ca90e150cedb5727d6c78 100644 (file)
@@ -19,6 +19,9 @@ AC_SUBST(host)
 # pybuilddir.txt will be created by --generate-posix-vars in the Makefile
 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
     AC_MSG_CHECKING([for python interpreter for cross build])
     if test -z "$PYTHON_FOR_BUILD"; then
@@ -35,16 +38,12 @@ if test "$cross_compiling" = yes; then
         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
     fi
-    # Used to comment out stuff for rebuilding generated files
-    GENERATED_COMMENT='#'
 elif test "$cross_compiling" = maybe; then
     AC_MSG_ERROR([Cross compiling required --host=HOST-TUPLE and --build=ARCH])
 else
     PYTHON_FOR_BUILD='./$(BUILDPYTHON) -E'
-    GENERATED_COMMENT=''
 fi
 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 it does, we get path names containing '//' which is both ugly and