Skip to content

Commit 8a21d05

Browse files
freakboy3742nineteendoncoghlanerlend-aasland
committed
[3.12] pythongh-120522: Add a --with-app-store-compliance configure option to patch out problematic code (pythonGH-120984)
* Add --app-store-compliance configuration option. * Added blurb. * Correct tab-vs-spaces formatting issue. * Correct source file name in docs. Co-authored-by: Nice Zombies <[email protected]> * Correct source code reference in Mac docs Co-authored-by: Nice Zombies <[email protected]> * Only apply the patch forward, and ensure the working directory is correct. * Make patching reslient to multiple builds. * Documentation fixes found during review Co-authored-by: Alyssa Coghlan <[email protected]> * Documentation and configure.ac syntax improvements Co-authored-by: Erlend E. Aasland <[email protected]> * Regenerate configure script. * Silence the patch echo output. --------- (cherry picked from commit 48cd104) Co-authored-by: Russell Keith-Magee <[email protected]> Co-authored-by: Nice Zombies <[email protected]> Co-authored-by: Alyssa Coghlan <[email protected]> Co-authored-by: Erlend E. Aasland <[email protected]>
1 parent d474772 commit 8a21d05

File tree

8 files changed

+202
-2
lines changed

8 files changed

+202
-2
lines changed

Doc/library/urllib.parse.rst

+8-1
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,18 @@ to an absolute URL given a "base URL."
2222

2323
The module has been designed to match the internet RFC on Relative Uniform
2424
Resource Locators. It supports the following URL schemes: ``file``, ``ftp``,
25-
``gopher``, ``hdl``, ``http``, ``https``, ``imap``, ``mailto``, ``mms``,
25+
``gopher``, ``hdl``, ``http``, ``https``, ``imap``, ``itms-services``, ``mailto``, ``mms``,
2626
``news``, ``nntp``, ``prospero``, ``rsync``, ``rtsp``, ``rtsps``, ``rtspu``,
2727
``sftp``, ``shttp``, ``sip``, ``sips``, ``snews``, ``svn``, ``svn+ssh``,
2828
``telnet``, ``wais``, ``ws``, ``wss``.
2929

30+
.. impl-detail::
31+
32+
The inclusion of the ``itms-services`` URL scheme can prevent an app from
33+
passing Apple's App Store review process for the macOS App Stores. Handling
34+
for the ``itms-services`` scheme *may* be removed if CPython has been built
35+
with the :option:`--with-app-store-compliance` option.
36+
3037
The :mod:`urllib.parse` module defines functions that fall into two broad
3138
categories: URL parsing and URL quoting. These are covered in detail in
3239
the following sections.

Doc/using/configure.rst

+11
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,17 @@ See ``Mac/README.rst``.
673673
Specify the name for the python framework on macOS only valid when
674674
:option:`--enable-framework` is set (default: ``Python``).
675675

676+
.. option:: --with-app-store-compliance
677+
.. option:: --with-app-store-compliance=PATCH-FILE
678+
679+
The Python standard library contains strings that are known to trigger
680+
automated inspection tool errors when submitted for distribution by
681+
the macOS App Store. If enabled, this option will apply the list of
682+
patches that are known to correct app store compliance. A custom patch
683+
file can also be specified. This option is disabled by default.
684+
685+
.. versionadded:: 3.12
686+
676687

677688
Cross Compiling Options
678689
-----------------------

Doc/using/mac.rst

+22
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,28 @@ distributable application:
188188
* `PyInstaller <https://pyinstaller.org/>`__: A cross-platform packaging tool that creates
189189
a single file or folder as a distributable artifact.
190190

191+
App Store Compliance
192+
--------------------
193+
194+
Apps submitted for distribution through the macOS App Store must pass Apple's
195+
app review process. This process includes a set of automated validation rules
196+
that inspect the submitted application bundle for problematic code.
197+
198+
The Python standard library contains some code that is known to violate these
199+
automated rules. While these violations appear to be false positives, Apple's
200+
review rules cannot be challenged. Therefore, it is necessary to modify the
201+
Python standard library for an app to pass App Store review.
202+
203+
The Python source tree contains
204+
:source:`a patch file <Mac/Resources/app-store-compliance.patch>` that will remove
205+
all code that is known to cause issues with the App Store review process. This
206+
patch is applied automatically when CPython is configured with the
207+
:option:`--with-app-store-compliance` option.
208+
209+
This patch is not normally required to use CPython on a Mac; nor is it required
210+
if you are distributing an app *outside* the macOS App Store. It is *only*
211+
required if you are using the macOS App Store as a distribution channel.
212+
191213
Other Resources
192214
===============
193215

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
diff --git a/Lib/test/test_urlparse.py b/Lib/test/test_urlparse.py
2+
index d6c83a75c1c..19ed4e01091 100644
3+
--- a/Lib/test/test_urlparse.py
4+
+++ b/Lib/test/test_urlparse.py
5+
@@ -237,11 +237,6 @@ def test_roundtrips(self):
6+
'','',''),
7+
('git+ssh', '[email protected]','/user/project.git',
8+
'', '')),
9+
- ('itms-services://?action=download-manifest&url=https://example.com/app',
10+
- ('itms-services', '', '', '',
11+
- 'action=download-manifest&url=https://example.com/app', ''),
12+
- ('itms-services', '', '',
13+
- 'action=download-manifest&url=https://example.com/app', '')),
14+
('+scheme:path/to/file',
15+
('', '', '+scheme:path/to/file', '', '', ''),
16+
('', '', '+scheme:path/to/file', '', '')),
17+
diff --git a/Lib/urllib/parse.py b/Lib/urllib/parse.py
18+
index 8f724f907d4..148caf742c9 100644
19+
--- a/Lib/urllib/parse.py
20+
+++ b/Lib/urllib/parse.py
21+
@@ -59,7 +59,7 @@
22+
'imap', 'wais', 'file', 'mms', 'https', 'shttp',
23+
'snews', 'prospero', 'rtsp', 'rtsps', 'rtspu', 'rsync',
24+
'svn', 'svn+ssh', 'sftp', 'nfs', 'git', 'git+ssh',
25+
- 'ws', 'wss', 'itms-services']
26+
+ 'ws', 'wss']
27+
28+
uses_params = ['', 'ftp', 'hdl', 'prospero', 'http', 'imap',
29+
'https', 'shttp', 'rtsp', 'rtsps', 'rtspu', 'sip',

Makefile.pre.in

+16-1
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,9 @@ EXPORTSFROM= @EXPORTSFROM@
178178
EXE= @EXEEXT@
179179
BUILDEXE= @BUILDEXEEXT@
180180

181+
# Name of the patch file to apply for app store compliance
182+
APP_STORE_COMPLIANCE_PATCH=@APP_STORE_COMPLIANCE_PATCH@
183+
181184
# Short name and location for Mac OS X Python framework
182185
UNIVERSALSDK=@UNIVERSALSDK@
183186
PYTHONFRAMEWORK= @PYTHONFRAMEWORK@
@@ -614,7 +617,7 @@ all: @DEF_MAKE_ALL_RULE@
614617
.PHONY: all
615618

616619
.PHONY: build_all
617-
build_all: check-clean-src $(BUILDPYTHON) platform sharedmods \
620+
build_all: check-clean-src @APP_STORE_COMPLIANCE_PATCH_TARGET@ $(BUILDPYTHON) platform sharedmods \
618621
gdbhooks Programs/_testembed scripts checksharedmods rundsymutil
619622

620623
.PHONY: build_wasm
@@ -848,6 +851,18 @@ SRC_GDB_HOOKS=$(srcdir)/Tools/gdb/libpython.py
848851
$(BUILDPYTHON)-gdb.py: $(SRC_GDB_HOOKS)
849852
$(INSTALL_DATA) $(SRC_GDB_HOOKS) $(BUILDPYTHON)-gdb.py
850853

854+
# Compliance with app stores (such as iOS and macOS) sometimes requires making
855+
# modifications to the Python standard library. If enabled, apply the patch of
856+
# known modifications to the source tree before building. The patch will be
857+
# applied in a dry-run mode (validating, but not applying the patch) on builds
858+
# that *have* a compliance patch, but where compliance has not been enabled.
859+
build/app-store-compliant:
860+
patch @APP_STORE_COMPLIANCE_PATCH_FLAGS@ --forward --strip=1 --directory="$(srcdir)" --input "$(APP_STORE_COMPLIANCE_PATCH)"
861+
@if test "@APP_STORE_COMPLIANCE_PATCH_FLAGS@" == ""; then \
862+
mkdir -p build ; \
863+
echo "$(APP_STORE_COMPLIANCE_PATCH)" > build/app-store-compliant ; \
864+
fi
865+
851866
# This rule is here for OPENSTEP/Rhapsody/MacOSX. It builds a temporary
852867
# minimal framework (not including the Lib directory and such) in the current
853868
# directory.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Added a :option:`--with-app-store-compliance` option to patch out known issues
2+
with macOS/iOS App Store review processes.

configure

+64
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

configure.ac

+50
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,56 @@ then
598598
fi
599599
AC_MSG_RESULT(["$MACHDEP"])
600600

601+
dnl quadrigraphs "@<:@" and "@:>@" produce "[" and "]" in the output
602+
AC_MSG_CHECKING([for --with-app-store-compliance])
603+
AC_ARG_WITH(
604+
[app_store_compliance],
605+
[AS_HELP_STRING(
606+
[--with-app-store-compliance=@<:@PATCH-FILE@:>@],
607+
[Enable any patches required for compiliance with app stores.
608+
Optional PATCH-FILE specifies the custom patch to apply.]
609+
)],[
610+
case "$withval" in
611+
yes)
612+
case $ac_sys_system in
613+
Darwin)
614+
APP_STORE_COMPLIANCE_PATCH="Mac/Resources/app-store-compliance.patch"
615+
APP_STORE_COMPLIANCE_PATCH_TARGET="build/app-store-compliant"
616+
APP_STORE_COMPLIANCE_PATCH_FLAGS=
617+
;;
618+
*) AC_MSG_ERROR([no default app store compliance patch available for $ac_sys_system]) ;;
619+
esac
620+
AC_MSG_RESULT([applying default app store compliance patch])
621+
;;
622+
*)
623+
APP_STORE_COMPLIANCE_PATCH="${withval}"
624+
APP_STORE_COMPLIANCE_PATCH_TARGET="build/app-store-compliant"
625+
APP_STORE_COMPLIANCE_PATCH_FLAGS=
626+
AC_MSG_RESULT([applying custom app store compliance patch])
627+
;;
628+
esac
629+
],[
630+
case $ac_sys_system in
631+
Darwin)
632+
# Always *check* the compliance patch on macOS
633+
APP_STORE_COMPLIANCE_PATCH="Mac/Resources/app-store-compliance.patch"
634+
APP_STORE_COMPLIANCE_PATCH_TARGET="build/app-store-compliant"
635+
APP_STORE_COMPLIANCE_PATCH_FLAGS="--dry-run"
636+
AC_MSG_RESULT([checking (not applying) default app store compliance patch])
637+
;;
638+
*)
639+
# No app compliance patching on any other platform
640+
APP_STORE_COMPLIANCE_PATCH=
641+
APP_STORE_COMPLIANCE_PATCH_TARGET=
642+
APP_STORE_COMPLIANCE_PATCH_FLAGS=
643+
AC_MSG_RESULT([not patching for app store compliance])
644+
;;
645+
esac
646+
])
647+
AC_SUBST([APP_STORE_COMPLIANCE_PATCH])
648+
AC_SUBST([APP_STORE_COMPLIANCE_PATCH_TARGET])
649+
AC_SUBST([APP_STORE_COMPLIANCE_PATCH_FLAGS])
650+
601651
AC_SUBST([_PYTHON_HOST_PLATFORM])
602652
if test "$cross_compiling" = yes; then
603653
case "$host" in

0 commit comments

Comments
 (0)