Skip to content

Commit

Permalink
bpo-23404: make touch becomes make regen-all
Browse files Browse the repository at this point in the history
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-importlib: Python/importlib_external.h and Python/importlib.h
  - regen-opcode: Include/opcode.h
  - regen-opcode-targets: Python/opcode_targets.h
  - regen-typeslots: Objects/typeslots.inc

* Rename PYTHON_FOR_GEN to PYTHON_FOR_REGEN
* 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

Note: $(PYTHON_FOR_REGEN) is no more used nor needed by "make"
default target building Python.
  • Loading branch information
vstinner committed May 3, 2017
1 parent 0360a9d commit 12ad6d2
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 263 deletions.
17 changes: 0 additions & 17 deletions .hgtouch

This file was deleted.

4 changes: 0 additions & 4 deletions Mac/BuildScript/build-installer.py
Expand Up @@ -1142,10 +1142,6 @@ def buildPython():
shellQuote(WORKDIR)[1:-1],
shellQuote(WORKDIR)[1:-1]))

# bpo-29550: avoid using make touch until it is fixed for git
# print("Running make touch")
# runCommand("make touch")

print("Running make")
runCommand("make")

Expand Down
153 changes: 72 additions & 81 deletions Makefile.pre.in
Expand Up @@ -229,7 +229,7 @@ LIBOBJS= @LIBOBJS@
PYTHON= python$(EXE)
BUILDPYTHON= python$(BUILDEXE)

PYTHON_FOR_GEN=@PYTHON_FOR_GEN@
PYTHON_FOR_REGEN=@PYTHON_FOR_REGEN@
PYTHON_FOR_BUILD=@PYTHON_FOR_BUILD@
_PYTHON_HOST_PLATFORM=@_PYTHON_HOST_PLATFORM@
BUILD_GNU_TYPE= @build@
Expand Down Expand Up @@ -273,11 +273,6 @@ IO_OBJS= \
Modules/_io/stringio.o

##########################################################################
# Grammar
GRAMMAR_H= Include/graminit.h
GRAMMAR_C= Python/graminit.c
GRAMMAR_INPUT= $(srcdir)/Grammar/Grammar


LIBFFI_INCLUDEDIR= @LIBFFI_INCLUDEDIR@

Expand Down Expand Up @@ -316,38 +311,9 @@ PARSER_HEADERS= \

PGENOBJS= $(POBJS) $(PGOBJS)

##########################################################################
# opcode.h generation
OPCODE_H_DIR= $(srcdir)/Include
OPCODE_H_SCRIPT= $(srcdir)/Tools/scripts/generate_opcode_h.py
OPCODE_H= $(OPCODE_H_DIR)/opcode.h
OPCODE_H_GEN= $(PYTHON_FOR_GEN) $(OPCODE_H_SCRIPT) $(srcdir)/Lib/opcode.py $(OPCODE_H)

##########################################################################
# 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
# Note that a build now requires Python to exist before the build starts.
# Use "hg touch" to fix up screwed up file mtimes in a checkout.
ASDLGEN= $(PYTHON_FOR_GEN) $(srcdir)/Parser/asdl_c.py

##########################################################################
# Python

OPCODETARGETS_H= \
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 \
Expand Down Expand Up @@ -548,11 +514,8 @@ coverage-lcov:
@echo "lcov report at $(COVERAGE_REPORT)/index.html"
@echo

coverage-report:
@ # force rebuilding of parser and importlib
@touch $(GRAMMAR_INPUT)
@touch $(srcdir)/Lib/importlib/_bootstrap.py
@touch $(srcdir)/Lib/importlib/_bootstrap_external.py
# Force regeneration of parser and importlib
coverage-report: regen-grammar regen-importlib
@ # build with coverage info
$(MAKE) coverage
@ # run tests, ignore failures
Expand Down Expand Up @@ -724,14 +687,24 @@ Programs/_freeze_importlib.o: Programs/_freeze_importlib.c Makefile
Programs/_freeze_importlib: Programs/_freeze_importlib.o $(LIBRARY_OBJS_OMIT_FROZEN)
$(LINKCC) $(PY_LDFLAGS) -o $@ Programs/_freeze_importlib.o $(LIBRARY_OBJS_OMIT_FROZEN) $(LIBS) $(MODLIBS) $(SYSLIBS) $(LDLAST)

Python/importlib_external.h: @GENERATED_COMMENT@ $(srcdir)/Lib/importlib/_bootstrap_external.py Programs/_freeze_importlib Python/marshal.c
.PHONY: regen-importlib
regen-importlib: Programs/_freeze_importlib
# Regenerate Python/importlib_external.h
# from Lib/importlib/_bootstrap_external.py using _freeze_importlib
./Programs/_freeze_importlib \
$(srcdir)/Lib/importlib/_bootstrap_external.py Python/importlib_external.h

Python/importlib.h: @GENERATED_COMMENT@ $(srcdir)/Lib/importlib/_bootstrap.py Programs/_freeze_importlib Python/marshal.c
$(srcdir)/Lib/importlib/_bootstrap_external.py \
$(srcdir)/Python/importlib_external.h
# Regenerate Python/importlib.h from Lib/importlib/_bootstrap.py
# using _freeze_importlib
./Programs/_freeze_importlib \
$(srcdir)/Lib/importlib/_bootstrap.py Python/importlib.h
$(srcdir)/Lib/importlib/_bootstrap.py \
$(srcdir)/Python/importlib.h


############################################################################
# Regenerate all generated files

regen-all: regen-opcode regen-opcode-targets regen-typeslots regen-grammar regen-ast regen-importlib

############################################################################
# Special rules for object files
Expand Down Expand Up @@ -790,15 +763,18 @@ Python/sysmodule.o: $(srcdir)/Python/sysmodule.c Makefile

$(IO_OBJS): $(IO_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) $(PY_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
Expand All @@ -810,18 +786,28 @@ Parser/printgrammar.o: $(srcdir)/Parser/printgrammar.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_H) $(AST_ASDL) $(ASDLGEN_FILES)
$(MKDIR_P) $(AST_C_DIR)
$(ASDLGEN) -c $(AST_C_DIR) $(AST_ASDL)

$(OPCODE_H): $(srcdir)/Lib/opcode.py $(OPCODE_H_SCRIPT)
$(OPCODE_H_GEN)

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

.PHONY: regen-opcode
regen-opcode:
# Regenerate Include/opcode.h from Lib/opcode.py
# using Tools/scripts/generate_opcode_h.py
$(PYTHON_FOR_REGEN) $(srcdir)/Tools/scripts/generate_opcode_h.py \
$(srcdir)/Lib/opcode.py \
$(srcdir)/Include/opcode.h

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_CORE_CFLAGS) -DPLATFORM='"$(MACHDEP)"' -o $@ $(srcdir)/Python/getplatform.c
Expand Down Expand Up @@ -871,12 +857,16 @@ Objects/odictobject.o: $(srcdir)/Objects/dict-common.h
Objects/dictobject.o: $(srcdir)/Objects/stringlib/eq.h $(srcdir)/Objects/dict-common.h
Objects/setobject.o: $(srcdir)/Objects/stringlib/eq.h

$(OPCODETARGETS_H): $(OPCODETARGETGEN_FILES)
$(PYTHON_FOR_GEN) $(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) $(srcdir)/Python/ceval_gil.h
Python/ceval.o: $(srcdir)/Python/opcode_targets.h $(srcdir)/Python/ceval_gil.h

Python/frozen.o: Python/importlib.h Python/importlib_external.h
Python/frozen.o: $(srcdir)/Python/importlib.h $(srcdir)/Python/importlib_external.h

# Generate DTrace probe macros, then rename them (PYTHON_ -> PyDTrace_) to
# follow our naming conventions. dtrace(1) uses the output filename to generate
Expand All @@ -891,8 +881,14 @@ Python/pydtrace.o: $(srcdir)/Include/pydtrace.d $(DTRACE_DEPS)
$(DTRACE) $(DFLAGS) -o $@ -G -s $< $(DTRACE_DEPS)

Objects/typeobject.o: Objects/typeslots.inc
Objects/typeslots.inc: $(srcdir)/Include/typeslots.h $(srcdir)/Objects/typeslots.py
$(PYTHON_FOR_GEN) $(srcdir)/Objects/typeslots.py < $(srcdir)/Include/typeslots.h Objects/typeslots.inc

.PHONY: regen-typeslots
regen-typeslots:
# Regenerate Objects/typeslots.inc from Include/typeslotsh
# using Objects/typeslots.py
$(PYTHON_FOR_REGEN) $(srcdir)/Objects/typeslots.py \
< $(srcdir)/Include/typeslots.h \
$(srcdir)/Objects/typeslots.inc

############################################################################
# Header files
Expand Down Expand Up @@ -945,7 +941,7 @@ PYTHON_HEADERS= \
$(srcdir)/Include/node.h \
$(srcdir)/Include/object.h \
$(srcdir)/Include/objimpl.h \
$(OPCODE_H) \
$(srcdir)/Include/opcode.h \
$(srcdir)/Include/osdefs.h \
$(srcdir)/Include/osmodule.h \
$(srcdir)/Include/patchlevel.h \
Expand Down Expand Up @@ -988,7 +984,7 @@ PYTHON_HEADERS= \
$(srcdir)/Include/weakrefobject.h \
pyconfig.h \
$(PARSER_HEADERS) \
$(AST_H) \
$(srcdir)/Include/Python-ast.h \
$(DTRACE_HEADERS)

$(LIBRARY_OBJS) $(MODOBJS) Programs/python.o: $(PYTHON_HEADERS)
Expand Down Expand Up @@ -1555,9 +1551,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 -Wall)
# Regenerate pyconfig.h.in from configure.ac using autoheader
(cd $(srcdir); autoheader -Wall)

# Create a tags file for vi
Expand All @@ -1574,14 +1573,6 @@ TAGS::
etags Include/*.h; \
for i in $(SRCDIRS); do etags -a $$i/*.[ch]; done

# This fixes up the mtimes of checked-in generated files, assuming that they
# only *appear* to be outdated because of checkout order.
# This is run while preparing a source release tarball, and can be run manually
# to avoid bootstrap issues.
touch:
cd $(srcdir); \
hg --config extensions.touch=Tools/hg/hgtouch.py touch -v

# Sanitation targets -- clean leaves libraries, executables and tags
# files, which clobber removes as well
pycremoval:
Expand Down Expand Up @@ -1699,7 +1690,7 @@ 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: frameworkaltinstallunixtools recheck clean clobber distclean
.PHONY: smelly funny patchcheck touch altmaninstall commoninstall
.PHONY: gdbhooks

Expand Down
4 changes: 4 additions & 0 deletions Misc/NEWS
Expand Up @@ -1023,6 +1023,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-29643: Fix ``--enable-optimization`` didn't work.

- bpo-27593: sys.version and the platform module python_build(),
Expand Down

0 comments on commit 12ad6d2

Please sign in to comment.