Skip to content

Commit fd5a4aa

Browse files
committed
[3.9] pythongh-114099 - Add iOS testbed, plus Makefile target to invoke it. (pythongh-115930)
1 parent 00a8a24 commit fd5a4aa

File tree

20 files changed

+1188
-122
lines changed

20 files changed

+1188
-122
lines changed

.gitignore

+10
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,17 @@ Lib/test/data/*
6161
!Lib/test/data/README
6262
/Makefile
6363
/Makefile.pre
64+
iOSTestbed.*
65+
iOS/Frameworks/
6466
iOS/Resources/Info.plist
67+
iOS/testbed/build
68+
iOS/testbed/Python.xcframework/ios-*/bin
69+
iOS/testbed/Python.xcframework/ios-*/include
70+
iOS/testbed/Python.xcframework/ios-*/lib
71+
iOS/testbed/Python.xcframework/ios-*/Python.framework
72+
iOS/testbed/iOSTestbed.xcodeproj/project.xcworkspace
73+
iOS/testbed/iOSTestbed.xcodeproj/xcuserdata
74+
iOS/testbed/iOSTestbed.xcodeproj/xcshareddata
6575
Mac/Makefile
6676
Mac/PythonLauncher/Info.plist
6777
Mac/PythonLauncher/Makefile

Makefile.pre.in

+43-1
Original file line numberDiff line numberDiff line change
@@ -1239,6 +1239,42 @@ testuniversal: @DEF_MAKE_RULE@ platform
12391239
$(RUNSHARED) /usr/libexec/oah/translate \
12401240
./$(BUILDPYTHON) -E -m test -j 0 -u all $(TESTOPTS)
12411241

1242+
# Run the test suite on the iOS simulator. Must be run on a macOS machine with
1243+
# a full Xcode install that has an iPhone SE (3rd edition) simulator available.
1244+
# This must be run *after* a `make install` has completed the build. The
1245+
# `--with-framework-name` argument *cannot* be used when configuring the build.
1246+
XCFOLDER=iOSTestbed.$(MULTIARCH).$(shell date +%s)
1247+
XCRESULT=$(XCFOLDER)/$(MULTIARCH).xcresult
1248+
.PHONY: testios
1249+
testios:
1250+
@if test "$(MACHDEP)" != "ios"; then \
1251+
echo "Cannot run the iOS testbed for a non-iOS build."; \
1252+
exit 1;\
1253+
fi
1254+
@if test "$(findstring -iphonesimulator,$(MULTIARCH))" != "-iphonesimulator"; then \
1255+
echo "Cannot run the iOS testbed for non-simulator builds."; \
1256+
exit 1;\
1257+
fi
1258+
@if test $(PYTHONFRAMEWORK) != "Python"; then \
1259+
echo "Cannot run the iOS testbed with a non-default framework name."; \
1260+
exit 1;\
1261+
fi
1262+
@if ! test -d $(PYTHONFRAMEWORKPREFIX); then \
1263+
echo "Cannot find a finalized iOS Python.framework. Have you run 'make install' to finalize the framework build?"; \
1264+
exit 1;\
1265+
fi
1266+
# Copy the testbed project into the build folder
1267+
cp -r $(srcdir)/iOS/testbed $(XCFOLDER)
1268+
# Copy the framework from the install location to the testbed project.
1269+
cp -r $(PYTHONFRAMEWORKPREFIX)/* $(XCFOLDER)/Python.xcframework/ios-arm64_x86_64-simulator
1270+
# Run the test suite for the Xcode project, targeting the iOS simulator.
1271+
# If the suite fails, extract and print the console output, then re-raise the failure
1272+
if ! xcodebuild test -project $(XCFOLDER)/iOSTestbed.xcodeproj -scheme "iOSTestbed" -destination "platform=iOS Simulator,name=iPhone SE (3rd Generation)" -resultBundlePath $(XCRESULT) ; then \
1273+
xcrun xcresulttool get --path $(XCRESULT) --id $$(xcrun xcresulttool get --path $(XCRESULT) --format json | $(PYTHON_FOR_BUILD) -c "import sys, json; result = json.load(sys.stdin); print(result['actions']['_values'][0]['actionResult']['logRef']['id']['_value'])"); \
1274+
echo ; \
1275+
exit 1; \
1276+
fi
1277+
12421278
# Like testall, but with only one pass and without multiple processes.
12431279
# Run an optional script to include information about the build environment.
12441280
buildbottest: build_all platform
@@ -1825,7 +1861,7 @@ frameworkinstallextras:
18251861
# subdirectory. The install has put these folders in the same folder as
18261862
# Python.framework; Move the headers to their final framework-compatible home.
18271863
.PHONY: frameworkinstallmobileheaders
1828-
frameworkinstallmobileheaders:
1864+
frameworkinstallmobileheaders: frameworkinstallunversionedstructure inclinstall
18291865
if test -d $(DESTDIR)$(PYTHONFRAMEWORKINSTALLDIR)/Headers; then \
18301866
echo "Removing old framework headers"; \
18311867
rm -rf $(DESTDIR)$(PYTHONFRAMEWORKINSTALLDIR)/Headers; \
@@ -1934,6 +1970,10 @@ clean-retain-profile: pycremoval
19341970
-find build -type f -a ! -name '*.gc??' -exec rm -f {} ';'
19351971
-rm -f Include/pydtrace_probes.h
19361972
-rm -f profile-gen-stamp
1973+
-rm -rf iOS/testbed/Python.xcframework/ios-*/bin
1974+
-rm -rf iOS/testbed/Python.xcframework/ios-*/lib
1975+
-rm -rf iOS/testbed/Python.xcframework/ios-*/include
1976+
-rm -rf iOS/testbed/Python.xcframework/ios-*/Python.framework
19371977

19381978
profile-removal:
19391979
find . -name '*.gc??' -exec rm -f {} ';'
@@ -1955,6 +1995,8 @@ clobber: clean
19551995
config.cache config.log pyconfig.h Modules/config.c
19561996
-rm -rf build platform
19571997
-rm -rf $(PYTHONFRAMEWORKDIR)
1998+
-rm -rf iOS/Frameworks
1999+
-rm -rf iOSTestbed.*
19582000
-rm -f python-config.py python-config
19592001

19602002
# Make things extra clean, before making a distribution:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
A testbed project was added to run the test suite on iOS.

configure

+98-52
Original file line numberDiff line numberDiff line change
@@ -3125,6 +3125,52 @@ fi
31253125
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: \"$MACHDEP\"" >&5
31263126
$as_echo "\"$MACHDEP\"" >&6; }
31273127

3128+
# On cross-compile builds, configure will look for a host-specific compiler by
3129+
# prepending the user-provided host triple to the required binary name.
3130+
#
3131+
# On iOS, this results in binaries like "arm64-apple-ios12.0-simulator-gcc",
3132+
# which isn't a binary that exists, and isn't very convenient, as it contains the
3133+
# iOS version. As the default cross-compiler name won't exist, configure falls
3134+
# back to gcc, which *definitely* won't work. We're providing wrapper scripts for
3135+
# these tools; the binary names of these scripts are better defaults than "gcc".
3136+
# This only requires that the user put the platform scripts folder (e.g.,
3137+
# "iOS/Resources/bin") in their path, rather than defining platform-specific
3138+
# names/paths for AR, CC, CPP, and CXX explicitly; and if the user forgets to
3139+
# either put the platform scripts folder in the path, or specify CC etc,
3140+
# configure will fail.
3141+
if test -z "$AR"; then
3142+
case "$host" in
3143+
aarch64-apple-ios*-simulator) AR=arm64-apple-ios-simulator-ar ;;
3144+
aarch64-apple-ios*) AR=arm64-apple-ios-ar ;;
3145+
x86_64-apple-ios*-simulator) AR=x86_64-apple-ios-simulator-ar ;;
3146+
*)
3147+
esac
3148+
fi
3149+
if test -z "$CC"; then
3150+
case "$host" in
3151+
aarch64-apple-ios*-simulator) CC=arm64-apple-ios-simulator-clang ;;
3152+
aarch64-apple-ios*) CC=arm64-apple-ios-clang ;;
3153+
x86_64-apple-ios*-simulator) CC=x86_64-apple-ios-simulator-clang ;;
3154+
*)
3155+
esac
3156+
fi
3157+
if test -z "$CPP"; then
3158+
case "$host" in
3159+
aarch64-apple-ios*-simulator) CPP=arm64-apple-ios-simulator-cpp ;;
3160+
aarch64-apple-ios*) CPP=arm64-apple-ios-cpp ;;
3161+
x86_64-apple-ios*-simulator) CPP=x86_64-apple-ios-simulator-cpp ;;
3162+
*)
3163+
esac
3164+
fi
3165+
if test -z "$CXX"; then
3166+
case "$host" in
3167+
aarch64-apple-ios*-simulator) CXX=arm64-apple-ios-simulator-clang ;;
3168+
aarch64-apple-ios*) CXX=arm64-apple-ios-clang ;;
3169+
x86_64-apple-ios*-simulator) CXX=x86_64-apple-ios-simulator-clang ;;
3170+
*)
3171+
esac
3172+
fi
3173+
31283174
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for --enable-universalsdk" >&5
31293175
$as_echo_n "checking for --enable-universalsdk... " >&6; }
31303176
# Check whether --enable-universalsdk was given.
@@ -3236,37 +3282,38 @@ if test "${enable_framework+set}" = set; then :
32363282
enableval=$enable_framework;
32373283
case $enableval in
32383284
yes)
3239-
if test "$ac_sys_system" = "iOS"; then
3240-
as_fn_error $? "iOS builds must provide an explicit path for --enable-framework" "$LINENO" 5
3241-
fi
3242-
3243-
enableval=/Library/Frameworks
3285+
case $ac_sys_system in
3286+
Darwin) enableval=/Library/Frameworks ;;
3287+
iOS) enableval=iOS/Frameworks/\$\(MULTIARCH\) ;;
3288+
*) as_fn_error $? "Unknown platform for framework build" "$LINENO" 5
3289+
esac
32443290
esac
3291+
32453292
case $enableval in
32463293
no)
3247-
if test "$ac_sys_system" = "iOS"; then
3248-
as_fn_error $? "iOS builds must use --enable-framework=<install path>" "$LINENO" 5
3249-
fi
3294+
case $ac_sys_system in
3295+
iOS) as_fn_error $? "iOS builds must use --enable-framework" "$LINENO" 5 ;;
3296+
*)
3297+
PYTHONFRAMEWORK=
3298+
PYTHONFRAMEWORKDIR=no-framework
3299+
PYTHONFRAMEWORKPREFIX=
3300+
PYTHONFRAMEWORKINSTALLDIR=
3301+
PYTHONFRAMEWORKINSTALLNAMEPREFIX=
3302+
RESSRCDIR=
3303+
FRAMEWORKINSTALLFIRST=
3304+
FRAMEWORKINSTALLLAST=
3305+
FRAMEWORKALTINSTALLFIRST=
3306+
FRAMEWORKALTINSTALLLAST=
3307+
FRAMEWORKPYTHONW=
3308+
INSTALLTARGETS="commoninstall bininstall maninstall"
32503309

3251-
PYTHONFRAMEWORK=
3252-
PYTHONFRAMEWORKDIR=no-framework
3253-
PYTHONFRAMEWORKPREFIX=
3254-
PYTHONFRAMEWORKINSTALLDIR=
3255-
PYTHONFRAMEWORKINSTALLNAMEPREFIX=
3256-
RESSRCDIR=
3257-
FRAMEWORKINSTALLFIRST=
3258-
FRAMEWORKINSTALLLAST=
3259-
FRAMEWORKALTINSTALLFIRST=
3260-
FRAMEWORKALTINSTALLLAST=
3261-
FRAMEWORKPYTHONW=
3262-
INSTALLTARGETS="commoninstall bininstall maninstall"
3263-
3264-
if test "x${prefix}" = "xNONE"; then
3265-
FRAMEWORKUNIXTOOLSPREFIX="${ac_default_prefix}"
3266-
else
3267-
FRAMEWORKUNIXTOOLSPREFIX="${prefix}"
3268-
fi
3269-
enable_framework=
3310+
if test "x${prefix}" = "xNONE"; then
3311+
FRAMEWORKUNIXTOOLSPREFIX="${ac_default_prefix}"
3312+
else
3313+
FRAMEWORKUNIXTOOLSPREFIX="${prefix}"
3314+
fi
3315+
enable_framework=
3316+
esac
32703317
;;
32713318
*)
32723319
PYTHONFRAMEWORKPREFIX="${enableval}"
@@ -3361,29 +3408,28 @@ if test "${enable_framework+set}" = set; then :
33613408

33623409
else
33633410

3364-
if test "$ac_sys_system" = "iOS"; then
3365-
as_fn_error $? "iOS builds must use --enable-framework=<install path>" "$LINENO" 5
3366-
fi
3367-
3368-
PYTHONFRAMEWORK=
3369-
PYTHONFRAMEWORKDIR=no-framework
3370-
PYTHONFRAMEWORKPREFIX=
3371-
PYTHONFRAMEWORKINSTALLDIR=
3372-
PYTHONFRAMEWORKINSTALLNAMEPREFIX=
3373-
RESSRCDIR=
3374-
FRAMEWORKINSTALLFIRST=
3375-
FRAMEWORKINSTALLLAST=
3376-
FRAMEWORKALTINSTALLFIRST=
3377-
FRAMEWORKALTINSTALLLAST=
3378-
FRAMEWORKPYTHONW=
3379-
INSTALLTARGETS="commoninstall bininstall maninstall"
3380-
if test "x${prefix}" = "xNONE" ; then
3381-
FRAMEWORKUNIXTOOLSPREFIX="${ac_default_prefix}"
3382-
else
3383-
FRAMEWORKUNIXTOOLSPREFIX="${prefix}"
3384-
fi
3385-
enable_framework=
3386-
3411+
case $ac_sys_system in
3412+
iOS) as_fn_error $? "iOS builds must use --enable-framework" "$LINENO" 5 ;;
3413+
*)
3414+
PYTHONFRAMEWORK=
3415+
PYTHONFRAMEWORKDIR=no-framework
3416+
PYTHONFRAMEWORKPREFIX=
3417+
PYTHONFRAMEWORKINSTALLDIR=
3418+
PYTHONFRAMEWORKINSTALLNAMEPREFIX=
3419+
RESSRCDIR=
3420+
FRAMEWORKINSTALLFIRST=
3421+
FRAMEWORKINSTALLLAST=
3422+
FRAMEWORKALTINSTALLFIRST=
3423+
FRAMEWORKALTINSTALLLAST=
3424+
FRAMEWORKPYTHONW=
3425+
INSTALLTARGETS="commoninstall bininstall maninstall"
3426+
if test "x${prefix}" = "xNONE" ; then
3427+
FRAMEWORKUNIXTOOLSPREFIX="${ac_default_prefix}"
3428+
else
3429+
FRAMEWORKUNIXTOOLSPREFIX="${prefix}"
3430+
fi
3431+
enable_framework=
3432+
esac
33873433

33883434
fi
33893435

@@ -9780,8 +9826,8 @@ then
97809826
fi
97819827
;;
97829828
iOS/*)
9783-
LDSHARED='$(CC) -dynamiclib -F . -framework Python'
9784-
LDCXXSHARED='$(CXX) -dynamiclib -F . -framework Python'
9829+
LDSHARED='$(CC) -dynamiclib -F . -framework $(PYTHONFRAMEWORK)'
9830+
LDCXXSHARED='$(CXX) -dynamiclib -F . -framework $(PYTHONFRAMEWORK)'
97859831
BLDSHARED="$LDSHARED"
97869832
;;
97879833
Linux*|GNU*|QNX*|VxWorks*)

0 commit comments

Comments
 (0)