Skip to content

Commit cd690e8

Browse files
committed
[3.10] pythongh-114099 - Add iOS testbed, plus Makefile target to invoke it. (pythongh-115930)
1 parent b705c03 commit cd690e8

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
@@ -1254,6 +1254,42 @@ testuniversal: @DEF_MAKE_RULE@ platform
12541254
$(RUNSHARED) /usr/libexec/oah/translate \
12551255
./$(BUILDPYTHON) -E -m test -j 0 -u all $(TESTOPTS)
12561256

1257+
# Run the test suite on the iOS simulator. Must be run on a macOS machine with
1258+
# a full Xcode install that has an iPhone SE (3rd edition) simulator available.
1259+
# This must be run *after* a `make install` has completed the build. The
1260+
# `--with-framework-name` argument *cannot* be used when configuring the build.
1261+
XCFOLDER=iOSTestbed.$(MULTIARCH).$(shell date +%s)
1262+
XCRESULT=$(XCFOLDER)/$(MULTIARCH).xcresult
1263+
.PHONY: testios
1264+
testios:
1265+
@if test "$(MACHDEP)" != "ios"; then \
1266+
echo "Cannot run the iOS testbed for a non-iOS build."; \
1267+
exit 1;\
1268+
fi
1269+
@if test "$(findstring -iphonesimulator,$(MULTIARCH))" != "-iphonesimulator"; then \
1270+
echo "Cannot run the iOS testbed for non-simulator builds."; \
1271+
exit 1;\
1272+
fi
1273+
@if test $(PYTHONFRAMEWORK) != "Python"; then \
1274+
echo "Cannot run the iOS testbed with a non-default framework name."; \
1275+
exit 1;\
1276+
fi
1277+
@if ! test -d $(PYTHONFRAMEWORKPREFIX); then \
1278+
echo "Cannot find a finalized iOS Python.framework. Have you run 'make install' to finalize the framework build?"; \
1279+
exit 1;\
1280+
fi
1281+
# Copy the testbed project into the build folder
1282+
cp -r $(srcdir)/iOS/testbed $(XCFOLDER)
1283+
# Copy the framework from the install location to the testbed project.
1284+
cp -r $(PYTHONFRAMEWORKPREFIX)/* $(XCFOLDER)/Python.xcframework/ios-arm64_x86_64-simulator
1285+
# Run the test suite for the Xcode project, targeting the iOS simulator.
1286+
# If the suite fails, extract and print the console output, then re-raise the failure
1287+
if ! xcodebuild test -project $(XCFOLDER)/iOSTestbed.xcodeproj -scheme "iOSTestbed" -destination "platform=iOS Simulator,name=iPhone SE (3rd Generation)" -resultBundlePath $(XCRESULT) ; then \
1288+
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'])"); \
1289+
echo ; \
1290+
exit 1; \
1291+
fi
1292+
12571293
# Like testall, but with only one pass and without multiple processes.
12581294
# Run an optional script to include information about the build environment.
12591295
buildbottest: build_all platform
@@ -1878,7 +1914,7 @@ frameworkinstallextras:
18781914
# subdirectory. The install has put these folders in the same folder as
18791915
# Python.framework; Move the headers to their final framework-compatible home.
18801916
.PHONY: frameworkinstallmobileheaders
1881-
frameworkinstallmobileheaders:
1917+
frameworkinstallmobileheaders: frameworkinstallunversionedstructure inclinstall
18821918
if test -d $(DESTDIR)$(PYTHONFRAMEWORKINSTALLDIR)/Headers; then \
18831919
echo "Removing old framework headers"; \
18841920
rm -rf $(DESTDIR)$(PYTHONFRAMEWORKINSTALLDIR)/Headers; \
@@ -1986,6 +2022,10 @@ clean-retain-profile: pycremoval
19862022
-find build -type f -a ! -name '*.gc??' -exec rm -f {} ';'
19872023
-rm -f Include/pydtrace_probes.h
19882024
-rm -f profile-gen-stamp
2025+
-rm -rf iOS/testbed/Python.xcframework/ios-*/bin
2026+
-rm -rf iOS/testbed/Python.xcframework/ios-*/lib
2027+
-rm -rf iOS/testbed/Python.xcframework/ios-*/include
2028+
-rm -rf iOS/testbed/Python.xcframework/ios-*/Python.framework
19892029

19902030
profile-removal:
19912031
find . -name '*.gc??' -exec rm -f {} ';'
@@ -2007,6 +2047,8 @@ clobber: clean
20072047
config.cache config.log pyconfig.h Modules/config.c
20082048
-rm -rf build platform
20092049
-rm -rf $(PYTHONFRAMEWORKDIR)
2050+
-rm -rf iOS/Frameworks
2051+
-rm -rf iOSTestbed.*
20102052
-rm -f python-config.py python-config
20112053

20122054
# 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
@@ -3153,6 +3153,52 @@ fi
31533153
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: \"$MACHDEP\"" >&5
31543154
$as_echo "\"$MACHDEP\"" >&6; }
31553155

3156+
# On cross-compile builds, configure will look for a host-specific compiler by
3157+
# prepending the user-provided host triple to the required binary name.
3158+
#
3159+
# On iOS, this results in binaries like "arm64-apple-ios12.0-simulator-gcc",
3160+
# which isn't a binary that exists, and isn't very convenient, as it contains the
3161+
# iOS version. As the default cross-compiler name won't exist, configure falls
3162+
# back to gcc, which *definitely* won't work. We're providing wrapper scripts for
3163+
# these tools; the binary names of these scripts are better defaults than "gcc".
3164+
# This only requires that the user put the platform scripts folder (e.g.,
3165+
# "iOS/Resources/bin") in their path, rather than defining platform-specific
3166+
# names/paths for AR, CC, CPP, and CXX explicitly; and if the user forgets to
3167+
# either put the platform scripts folder in the path, or specify CC etc,
3168+
# configure will fail.
3169+
if test -z "$AR"; then
3170+
case "$host" in
3171+
aarch64-apple-ios*-simulator) AR=arm64-apple-ios-simulator-ar ;;
3172+
aarch64-apple-ios*) AR=arm64-apple-ios-ar ;;
3173+
x86_64-apple-ios*-simulator) AR=x86_64-apple-ios-simulator-ar ;;
3174+
*)
3175+
esac
3176+
fi
3177+
if test -z "$CC"; then
3178+
case "$host" in
3179+
aarch64-apple-ios*-simulator) CC=arm64-apple-ios-simulator-clang ;;
3180+
aarch64-apple-ios*) CC=arm64-apple-ios-clang ;;
3181+
x86_64-apple-ios*-simulator) CC=x86_64-apple-ios-simulator-clang ;;
3182+
*)
3183+
esac
3184+
fi
3185+
if test -z "$CPP"; then
3186+
case "$host" in
3187+
aarch64-apple-ios*-simulator) CPP=arm64-apple-ios-simulator-cpp ;;
3188+
aarch64-apple-ios*) CPP=arm64-apple-ios-cpp ;;
3189+
x86_64-apple-ios*-simulator) CPP=x86_64-apple-ios-simulator-cpp ;;
3190+
*)
3191+
esac
3192+
fi
3193+
if test -z "$CXX"; then
3194+
case "$host" in
3195+
aarch64-apple-ios*-simulator) CXX=arm64-apple-ios-simulator-clang ;;
3196+
aarch64-apple-ios*) CXX=arm64-apple-ios-clang ;;
3197+
x86_64-apple-ios*-simulator) CXX=x86_64-apple-ios-simulator-clang ;;
3198+
*)
3199+
esac
3200+
fi
3201+
31563202
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for --enable-universalsdk" >&5
31573203
$as_echo_n "checking for --enable-universalsdk... " >&6; }
31583204
# Check whether --enable-universalsdk was given.
@@ -3264,37 +3310,38 @@ if test "${enable_framework+set}" = set; then :
32643310
enableval=$enable_framework;
32653311
case $enableval in
32663312
yes)
3267-
if test "$ac_sys_system" = "iOS"; then
3268-
as_fn_error $? "iOS builds must provide an explicit path for --enable-framework" "$LINENO" 5
3269-
fi
3270-
3271-
enableval=/Library/Frameworks
3313+
case $ac_sys_system in
3314+
Darwin) enableval=/Library/Frameworks ;;
3315+
iOS) enableval=iOS/Frameworks/\$\(MULTIARCH\) ;;
3316+
*) as_fn_error $? "Unknown platform for framework build" "$LINENO" 5
3317+
esac
32723318
esac
3319+
32733320
case $enableval in
32743321
no)
3275-
if test "$ac_sys_system" = "iOS"; then
3276-
as_fn_error $? "iOS builds must use --enable-framework=<install path>" "$LINENO" 5
3277-
fi
3322+
case $ac_sys_system in
3323+
iOS) as_fn_error $? "iOS builds must use --enable-framework" "$LINENO" 5 ;;
3324+
*)
3325+
PYTHONFRAMEWORK=
3326+
PYTHONFRAMEWORKDIR=no-framework
3327+
PYTHONFRAMEWORKPREFIX=
3328+
PYTHONFRAMEWORKINSTALLDIR=
3329+
PYTHONFRAMEWORKINSTALLNAMEPREFIX=
3330+
RESSRCDIR=
3331+
FRAMEWORKINSTALLFIRST=
3332+
FRAMEWORKINSTALLLAST=
3333+
FRAMEWORKALTINSTALLFIRST=
3334+
FRAMEWORKALTINSTALLLAST=
3335+
FRAMEWORKPYTHONW=
3336+
INSTALLTARGETS="commoninstall bininstall maninstall"
32783337

3279-
PYTHONFRAMEWORK=
3280-
PYTHONFRAMEWORKDIR=no-framework
3281-
PYTHONFRAMEWORKPREFIX=
3282-
PYTHONFRAMEWORKINSTALLDIR=
3283-
PYTHONFRAMEWORKINSTALLNAMEPREFIX=
3284-
RESSRCDIR=
3285-
FRAMEWORKINSTALLFIRST=
3286-
FRAMEWORKINSTALLLAST=
3287-
FRAMEWORKALTINSTALLFIRST=
3288-
FRAMEWORKALTINSTALLLAST=
3289-
FRAMEWORKPYTHONW=
3290-
INSTALLTARGETS="commoninstall bininstall maninstall"
3291-
3292-
if test "x${prefix}" = "xNONE"; then
3293-
FRAMEWORKUNIXTOOLSPREFIX="${ac_default_prefix}"
3294-
else
3295-
FRAMEWORKUNIXTOOLSPREFIX="${prefix}"
3296-
fi
3297-
enable_framework=
3338+
if test "x${prefix}" = "xNONE"; then
3339+
FRAMEWORKUNIXTOOLSPREFIX="${ac_default_prefix}"
3340+
else
3341+
FRAMEWORKUNIXTOOLSPREFIX="${prefix}"
3342+
fi
3343+
enable_framework=
3344+
esac
32983345
;;
32993346
*)
33003347
PYTHONFRAMEWORKPREFIX="${enableval}"
@@ -3389,29 +3436,28 @@ if test "${enable_framework+set}" = set; then :
33893436

33903437
else
33913438

3392-
if test "$ac_sys_system" = "iOS"; then
3393-
as_fn_error $? "iOS builds must use --enable-framework=<install path>" "$LINENO" 5
3394-
fi
3395-
3396-
PYTHONFRAMEWORK=
3397-
PYTHONFRAMEWORKDIR=no-framework
3398-
PYTHONFRAMEWORKPREFIX=
3399-
PYTHONFRAMEWORKINSTALLDIR=
3400-
PYTHONFRAMEWORKINSTALLNAMEPREFIX=
3401-
RESSRCDIR=
3402-
FRAMEWORKINSTALLFIRST=
3403-
FRAMEWORKINSTALLLAST=
3404-
FRAMEWORKALTINSTALLFIRST=
3405-
FRAMEWORKALTINSTALLLAST=
3406-
FRAMEWORKPYTHONW=
3407-
INSTALLTARGETS="commoninstall bininstall maninstall"
3408-
if test "x${prefix}" = "xNONE" ; then
3409-
FRAMEWORKUNIXTOOLSPREFIX="${ac_default_prefix}"
3410-
else
3411-
FRAMEWORKUNIXTOOLSPREFIX="${prefix}"
3412-
fi
3413-
enable_framework=
3414-
3439+
case $ac_sys_system in
3440+
iOS) as_fn_error $? "iOS builds must use --enable-framework" "$LINENO" 5 ;;
3441+
*)
3442+
PYTHONFRAMEWORK=
3443+
PYTHONFRAMEWORKDIR=no-framework
3444+
PYTHONFRAMEWORKPREFIX=
3445+
PYTHONFRAMEWORKINSTALLDIR=
3446+
PYTHONFRAMEWORKINSTALLNAMEPREFIX=
3447+
RESSRCDIR=
3448+
FRAMEWORKINSTALLFIRST=
3449+
FRAMEWORKINSTALLLAST=
3450+
FRAMEWORKALTINSTALLFIRST=
3451+
FRAMEWORKALTINSTALLLAST=
3452+
FRAMEWORKPYTHONW=
3453+
INSTALLTARGETS="commoninstall bininstall maninstall"
3454+
if test "x${prefix}" = "xNONE" ; then
3455+
FRAMEWORKUNIXTOOLSPREFIX="${ac_default_prefix}"
3456+
else
3457+
FRAMEWORKUNIXTOOLSPREFIX="${prefix}"
3458+
fi
3459+
enable_framework=
3460+
esac
34153461

34163462
fi
34173463

@@ -9993,8 +10039,8 @@ then
999310039
fi
999410040
;;
999510041
iOS/*)
9996-
LDSHARED='$(CC) -dynamiclib -F . -framework Python'
9997-
LDCXXSHARED='$(CXX) -dynamiclib -F . -framework Python'
10042+
LDSHARED='$(CC) -dynamiclib -F . -framework $(PYTHONFRAMEWORK)'
10043+
LDCXXSHARED='$(CXX) -dynamiclib -F . -framework $(PYTHONFRAMEWORK)'
999810044
BLDSHARED="$LDSHARED"
999910045
;;
1000010046
Linux*|GNU*|QNX*|VxWorks*)

0 commit comments

Comments
 (0)