Skip to content

Commit fd0d593

Browse files
author
Xavier de Gaye
committed
Issue #26662: Set PYTHON_FOR_GEN in configure
as the Python program to be used for file generation during the build.
1 parent 254da19 commit fd0d593

File tree

5 files changed

+108
-164
lines changed

5 files changed

+108
-164
lines changed

Makefile.pre.in

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ PYTHON= python$(EXE)
222222
BUILDPYTHON= python$(BUILDEXE)
223223

224224
cross_compiling=@cross_compiling@
225+
PYTHON_FOR_GEN=@PYTHON_FOR_GEN@
225226
PYTHON_FOR_BUILD=@PYTHON_FOR_BUILD@
226227
_PYTHON_HOST_PLATFORM=@_PYTHON_HOST_PLATFORM@
227228
BUILD_GNU_TYPE= @build@
@@ -339,7 +340,7 @@ PGENOBJS= $(POBJS) $(PGOBJS)
339340
OPCODE_H_DIR= $(srcdir)/Include
340341
OPCODE_H_SCRIPT= $(srcdir)/Tools/scripts/generate_opcode_h.py
341342
OPCODE_H= $(OPCODE_H_DIR)/opcode.h
342-
OPCODE_H_GEN= @OPCODEHGEN@ $(OPCODE_H_SCRIPT) $(srcdir)/Lib/opcode.py $(OPCODE_H)
343+
OPCODE_H_GEN= $(PYTHON_FOR_GEN) $(OPCODE_H_SCRIPT) $(srcdir)/Lib/opcode.py $(OPCODE_H)
343344
#
344345
##########################################################################
345346
# AST
@@ -352,7 +353,7 @@ AST_ASDL= $(srcdir)/Parser/Python.asdl
352353
ASDLGEN_FILES= $(srcdir)/Parser/asdl.py $(srcdir)/Parser/asdl_c.py
353354
# Note that a build now requires Python to exist before the build starts.
354355
# Use "hg touch" to fix up screwed up file mtimes in a checkout.
355-
ASDLGEN= @ASDLGEN@ $(srcdir)/Parser/asdl_c.py
356+
ASDLGEN= $(PYTHON_FOR_GEN) $(srcdir)/Parser/asdl_c.py
356357

357358
##########################################################################
358359
# Python
@@ -880,15 +881,15 @@ Objects/dictobject.o: $(srcdir)/Objects/stringlib/eq.h
880881
Objects/setobject.o: $(srcdir)/Objects/stringlib/eq.h
881882

882883
$(OPCODETARGETS_H): $(OPCODETARGETGEN_FILES)
883-
$(OPCODETARGETGEN) $(OPCODETARGETS_H)
884+
$(PYTHON_FOR_GEN) $(OPCODETARGETGEN) $(OPCODETARGETS_H)
884885

885886
Python/ceval.o: $(OPCODETARGETS_H) $(srcdir)/Python/ceval_gil.h
886887

887888
Python/frozen.o: Python/importlib.h Python/importlib_external.h
888889

889890
Objects/typeobject.o: Objects/typeslots.inc
890891
Objects/typeslots.inc: $(srcdir)/Include/typeslots.h $(srcdir)/Objects/typeslots.py
891-
$(PYTHON) $(srcdir)/Objects/typeslots.py < $(srcdir)/Include/typeslots.h > Objects/typeslots.inc
892+
$(PYTHON_FOR_GEN) $(srcdir)/Objects/typeslots.py < $(srcdir)/Include/typeslots.h Objects/typeslots.inc
892893

893894
############################################################################
894895
# Header files

Misc/NEWS

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,12 @@ Windows
142142

143143
- Issue #27309: Enabled proper Windows styles in python[w].exe manifest.
144144

145+
Build
146+
-----
147+
148+
- Issue #26662: Set PYTHON_FOR_GEN in configure as the Python program to be
149+
used for file generation during the build.
150+
145151
What's New in Python 3.5.2?
146152
===========================
147153

Objects/typeslots.py

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,43 @@
11
#!/usr/bin/python
2-
# Usage: typeslots.py < Include/typeslots.h > typeslots.inc
2+
# Usage: typeslots.py < Include/typeslots.h typeslots.inc
33

44
import sys, re
55

6-
print("/* Generated by typeslots.py */")
7-
res = {}
8-
for line in sys.stdin:
9-
m = re.match("#define Py_([a-z_]+) ([0-9]+)", line)
10-
if not m:
11-
continue
12-
member = m.group(1)
13-
if member.startswith("tp_"):
14-
member = "ht_type."+member
15-
elif member.startswith("am_"):
16-
member = "as_async."+member
17-
elif member.startswith("nb_"):
18-
member = "as_number."+member
19-
elif member.startswith("mp_"):
20-
member = "as_mapping."+member
21-
elif member.startswith("sq_"):
22-
member = "as_sequence."+member
23-
elif member.startswith("bf_"):
24-
member = "as_buffer."+member
25-
res[int(m.group(2))] = member
6+
def generate_typeslots(out=sys.stdout):
7+
out.write("/* Generated by typeslots.py */\n")
8+
res = {}
9+
for line in sys.stdin:
10+
m = re.match("#define Py_([a-z_]+) ([0-9]+)", line)
11+
if not m:
12+
continue
13+
member = m.group(1)
14+
if member.startswith("tp_"):
15+
member = "ht_type."+member
16+
elif member.startswith("am_"):
17+
member = "as_async."+member
18+
elif member.startswith("nb_"):
19+
member = "as_number."+member
20+
elif member.startswith("mp_"):
21+
member = "as_mapping."+member
22+
elif member.startswith("sq_"):
23+
member = "as_sequence."+member
24+
elif member.startswith("bf_"):
25+
member = "as_buffer."+member
26+
res[int(m.group(2))] = member
2627

27-
M = max(res.keys())+1
28-
for i in range(1,M):
29-
if i in res:
30-
print("offsetof(PyHeapTypeObject, %s)," % res[i])
28+
M = max(res.keys())+1
29+
for i in range(1,M):
30+
if i in res:
31+
out.write("offsetof(PyHeapTypeObject, %s),\n" % res[i])
32+
else:
33+
out.write("0,\n")
34+
35+
def main():
36+
if len(sys.argv) == 2:
37+
with open(sys.argv[1], "w") as f:
38+
generate_typeslots(f)
3139
else:
32-
print("0,")
40+
generate_typeslots()
41+
42+
if __name__ == "__main__":
43+
main()

configure

Lines changed: 52 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -680,9 +680,6 @@ MKDIR_P
680680
INSTALL_DATA
681681
INSTALL_SCRIPT
682682
INSTALL_PROGRAM
683-
OPCODEHGEN
684-
PYTHON
685-
ASDLGEN
686683
ac_ct_READELF
687684
READELF
688685
ARFLAGS
@@ -743,6 +740,7 @@ CONFIG_ARGS
743740
SOVERSION
744741
VERSION
745742
PYTHON_FOR_BUILD
743+
PYTHON_FOR_GEN
746744
host_os
747745
host_vendor
748746
host_cpu
@@ -776,7 +774,6 @@ infodir
776774
docdir
777775
oldincludedir
778776
includedir
779-
runstatedir
780777
localstatedir
781778
sharedstatedir
782779
sysconfdir
@@ -887,7 +884,6 @@ datadir='${datarootdir}'
887884
sysconfdir='${prefix}/etc'
888885
sharedstatedir='${prefix}/com'
889886
localstatedir='${prefix}/var'
890-
runstatedir='${localstatedir}/run'
891887
includedir='${prefix}/include'
892888
oldincludedir='/usr/include'
893889
docdir='${datarootdir}/doc/${PACKAGE_TARNAME}'
@@ -1140,15 +1136,6 @@ do
11401136
| -silent | --silent | --silen | --sile | --sil)
11411137
silent=yes ;;
11421138

1143-
-runstatedir | --runstatedir | --runstatedi | --runstated \
1144-
| --runstate | --runstat | --runsta | --runst | --runs \
1145-
| --run | --ru | --r)
1146-
ac_prev=runstatedir ;;
1147-
-runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \
1148-
| --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \
1149-
| --run=* | --ru=* | --r=*)
1150-
runstatedir=$ac_optarg ;;
1151-
11521139
-sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
11531140
ac_prev=sbindir ;;
11541141
-sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
@@ -1286,7 +1273,7 @@ fi
12861273
for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \
12871274
datadir sysconfdir sharedstatedir localstatedir includedir \
12881275
oldincludedir docdir infodir htmldir dvidir pdfdir psdir \
1289-
libdir localedir mandir runstatedir
1276+
libdir localedir mandir
12901277
do
12911278
eval ac_val=\$$ac_var
12921279
# Remove trailing slashes.
@@ -1439,7 +1426,6 @@ Fine tuning of the installation directories:
14391426
--sysconfdir=DIR read-only single-machine data [PREFIX/etc]
14401427
--sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com]
14411428
--localstatedir=DIR modifiable single-machine data [PREFIX/var]
1442-
--runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run]
14431429
--libdir=DIR object code libraries [EPREFIX/lib]
14441430
--includedir=DIR C header files [PREFIX/include]
14451431
--oldincludedir=DIR C header files for non-gcc [/usr/include]
@@ -2995,6 +2981,56 @@ case $host_os in *\ *) host_os=`echo "$host_os" | sed 's/ /-/g'`;; esac
29952981
# pybuilddir.txt will be created by --generate-posix-vars in the Makefile
29962982
rm -f pybuilddir.txt
29972983

2984+
for ac_prog in python$PACKAGE_VERSION python3 python
2985+
do
2986+
# Extract the first word of "$ac_prog", so it can be a program name with args.
2987+
set dummy $ac_prog; ac_word=$2
2988+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
2989+
$as_echo_n "checking for $ac_word... " >&6; }
2990+
if ${ac_cv_prog_PYTHON_FOR_GEN+:} false; then :
2991+
$as_echo_n "(cached) " >&6
2992+
else
2993+
if test -n "$PYTHON_FOR_GEN"; then
2994+
ac_cv_prog_PYTHON_FOR_GEN="$PYTHON_FOR_GEN" # Let the user override the test.
2995+
else
2996+
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
2997+
for as_dir in $PATH
2998+
do
2999+
IFS=$as_save_IFS
3000+
test -z "$as_dir" && as_dir=.
3001+
for ac_exec_ext in '' $ac_executable_extensions; do
3002+
if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
3003+
ac_cv_prog_PYTHON_FOR_GEN="$ac_prog"
3004+
$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
3005+
break 2
3006+
fi
3007+
done
3008+
done
3009+
IFS=$as_save_IFS
3010+
3011+
fi
3012+
fi
3013+
PYTHON_FOR_GEN=$ac_cv_prog_PYTHON_FOR_GEN
3014+
if test -n "$PYTHON_FOR_GEN"; then
3015+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $PYTHON_FOR_GEN" >&5
3016+
$as_echo "$PYTHON_FOR_GEN" >&6; }
3017+
else
3018+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
3019+
$as_echo "no" >&6; }
3020+
fi
3021+
3022+
3023+
test -n "$PYTHON_FOR_GEN" && break
3024+
done
3025+
test -n "$PYTHON_FOR_GEN" || PYTHON_FOR_GEN="not-found"
3026+
3027+
if test "$PYTHON_FOR_GEN" = not-found; then
3028+
PYTHON_FOR_GEN='@echo "Cannot generate $@, python not found !" && \
3029+
echo "To skip re-generation of $@ run <make touch> or <make -t $@>." && \
3030+
echo "Otherwise, set python in PATH and run configure or run <make PYTHON_FOR_GEN=python>." && false &&'
3031+
fi
3032+
3033+
29983034
if test "$cross_compiling" = yes; then
29993035
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for python interpreter for cross build" >&5
30003036
$as_echo_n "checking for python interpreter for cross build... " >&6; }
@@ -6295,107 +6331,6 @@ fi
62956331

62966332

62976333

6298-
for ac_prog in python$PACKAGE_VERSION python3 python
6299-
do
6300-
# Extract the first word of "$ac_prog", so it can be a program name with args.
6301-
set dummy $ac_prog; ac_word=$2
6302-
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
6303-
$as_echo_n "checking for $ac_word... " >&6; }
6304-
if ${ac_cv_prog_PYTHON+:} false; then :
6305-
$as_echo_n "(cached) " >&6
6306-
else
6307-
if test -n "$PYTHON"; then
6308-
ac_cv_prog_PYTHON="$PYTHON" # Let the user override the test.
6309-
else
6310-
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
6311-
for as_dir in $PATH
6312-
do
6313-
IFS=$as_save_IFS
6314-
test -z "$as_dir" && as_dir=.
6315-
for ac_exec_ext in '' $ac_executable_extensions; do
6316-
if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
6317-
ac_cv_prog_PYTHON="$ac_prog"
6318-
$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
6319-
break 2
6320-
fi
6321-
done
6322-
done
6323-
IFS=$as_save_IFS
6324-
6325-
fi
6326-
fi
6327-
PYTHON=$ac_cv_prog_PYTHON
6328-
if test -n "$PYTHON"; then
6329-
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $PYTHON" >&5
6330-
$as_echo "$PYTHON" >&6; }
6331-
else
6332-
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
6333-
$as_echo "no" >&6; }
6334-
fi
6335-
6336-
6337-
test -n "$PYTHON" && break
6338-
done
6339-
test -n "$PYTHON" || PYTHON="not-found"
6340-
6341-
if test "$PYTHON" = not-found; then
6342-
ASDLGEN="@echo python: $PYTHON! cannot run \$(srcdir)/Parser/asdl_c.py #"
6343-
else
6344-
ASDLGEN="$PYTHON"
6345-
fi
6346-
6347-
6348-
for ac_prog in python$PACKAGE_VERSION python3 python
6349-
do
6350-
# Extract the first word of "$ac_prog", so it can be a program name with args.
6351-
set dummy $ac_prog; ac_word=$2
6352-
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
6353-
$as_echo_n "checking for $ac_word... " >&6; }
6354-
if ${ac_cv_prog_PYTHON+:} false; then :
6355-
$as_echo_n "(cached) " >&6
6356-
else
6357-
if test -n "$PYTHON"; then
6358-
ac_cv_prog_PYTHON="$PYTHON" # Let the user override the test.
6359-
else
6360-
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
6361-
for as_dir in $PATH
6362-
do
6363-
IFS=$as_save_IFS
6364-
test -z "$as_dir" && as_dir=.
6365-
for ac_exec_ext in '' $ac_executable_extensions; do
6366-
if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
6367-
ac_cv_prog_PYTHON="$ac_prog"
6368-
$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
6369-
break 2
6370-
fi
6371-
done
6372-
done
6373-
IFS=$as_save_IFS
6374-
6375-
fi
6376-
fi
6377-
PYTHON=$ac_cv_prog_PYTHON
6378-
if test -n "$PYTHON"; then
6379-
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $PYTHON" >&5
6380-
$as_echo "$PYTHON" >&6; }
6381-
else
6382-
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
6383-
$as_echo "no" >&6; }
6384-
fi
6385-
6386-
6387-
test -n "$PYTHON" && break
6388-
done
6389-
test -n "$PYTHON" || PYTHON="not-found"
6390-
6391-
if test "$PYTHON" = not-found; then
6392-
OPCODEHGEN="@echo python: $PYTHON! cannot run Tools/scripts/generate_opcode_h.py"
6393-
else
6394-
OPCODEHGEN="$PYTHON"
6395-
fi
6396-
6397-
6398-
63996334
case $MACHDEP in
64006335
bsdos*|hp*|HP*)
64016336
# install -d does not work on BSDI or HP-UX

configure.ac

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ AC_SUBST(host)
5757
# pybuilddir.txt will be created by --generate-posix-vars in the Makefile
5858
rm -f pybuilddir.txt
5959

60+
AC_CHECK_PROGS(PYTHON_FOR_GEN, python$PACKAGE_VERSION python3 python, not-found)
61+
if test "$PYTHON_FOR_GEN" = not-found; then
62+
PYTHON_FOR_GEN='@echo "Cannot generate $@, python not found !" && \
63+
echo "To skip re-generation of $@ run <make touch> or <make -t $@>." && \
64+
echo "Otherwise, set python in PATH and run configure or run <make PYTHON_FOR_GEN=python>." && false &&'
65+
fi
66+
AC_SUBST(PYTHON_FOR_GEN)
67+
6068
if test "$cross_compiling" = yes; then
6169
AC_MSG_CHECKING([for python interpreter for cross build])
6270
if test -z "$PYTHON_FOR_BUILD"; then
@@ -1178,23 +1186,6 @@ if test "$cross_compiling" = yes; then
11781186
fi
11791187
AC_SUBST(READELF)
11801188

1181-
AC_SUBST(ASDLGEN)
1182-
AC_CHECK_PROGS(PYTHON, python$PACKAGE_VERSION python3 python, not-found)
1183-
if test "$PYTHON" = not-found; then
1184-
ASDLGEN="@echo python: $PYTHON! cannot run \$(srcdir)/Parser/asdl_c.py #"
1185-
else
1186-
ASDLGEN="$PYTHON"
1187-
fi
1188-
1189-
AC_SUBST(OPCODEHGEN)
1190-
AC_CHECK_PROGS(PYTHON, python$PACKAGE_VERSION python3 python, not-found)
1191-
if test "$PYTHON" = not-found; then
1192-
OPCODEHGEN="@echo python: $PYTHON! cannot run Tools/scripts/generate_opcode_h.py"
1193-
else
1194-
OPCODEHGEN="$PYTHON"
1195-
fi
1196-
1197-
11981189

11991190
case $MACHDEP in
12001191
bsdos*|hp*|HP*)

0 commit comments

Comments
 (0)