8000 [3.11] gh-120522: Apply App Store compliance patch during installatio… · freakboy3742/cpython@6fa5b37 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6fa5b37

Browse files
[3.11] pythongh-120522: Apply App Store compliance patch during installation (pythonGH-121947) (python#122105)
pythongh-120522: Apply App Store compliance patch during installation (pythonGH-121947) Adds a --with-app-store-compliance configuration option that patches out code known to be an issue with App Store review processes. This option is applied automatically on iOS, and optionally on macOS. (cherry picked from commit 728432c) Co-authored-by: Russell Keith-Magee <russell@keith-magee.com>
1 parent fc47e0c commit 6fa5b37

File tree

9 files changed

+183
-7
lines changed

9 files changed

+183
-7
lines changed

Doc/library/urllib.parse.rst

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,19 @@ 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 and iOS App Stores.
34+
Handling for the ``itms-services`` scheme is always removed on iOS; on
35+
macOS, it *may* be removed if CPython has been built with the
36+
:option:`--with-app-store-compliance` option.
37+
3038
The :mod:`urllib.parse` module defines functions that fall into two broad
3139
categories: URL parsing and URL quoting. These are covered in detail in
3240
the following sections.

Doc/using/configure.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,17 @@ See :source:`Mac/README.rst`.
562562
Specify the name for the python framework on macOS only valid when
563563
:option:`--enable-framework` is set (default: ``Python``).
564564

565+
.. option:: --with-app-store-compliance
566+
.. option:: --with-app-store-compliance=PATCH-FILE
567+
568+
The Python standard library contains strings that are known to trigger
569+
automated inspection tool errors when submitted for distribution by
570+
the macOS and iOS App Stores. If enabled, this option will apply the list of
571+
patches that are known to correct app store compliance. A custom patch
572+
file can also be specified. This option is disabled by default.
573+
574+
.. versionadded:: 3.13
575+
565576
iOS Options
566577
-----------
567578

Doc/using/ios.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,3 +323,21 @@ modules in your app, some additional steps will be required:
323323

324324
* If you're using a separate folder for third-party packages, ensure that folder
325325
is included as part of the ``PYTHONPATH`` configuration in step 10.
326+
327+
App Store Compliance
328+
====================
329+
330+
The only mechanism for distributing apps to third-party iOS devices is to
331+
submit the app to the iOS App Store; apps submitted for distribution must pass
332+
Apple's app review process. This process includes a set of automated validation
333+
rules that inspect the submitted application bundle for problematic code.
334+
335+
The Python standard library contains some code that is known to violate these
336+
automated rules. While these violations appear to be false positives, Apple's
337+
review rules cannot be challenged; so, it is necessary to modify the Python
338+
standard library for an app to pass App Store review.
339+
340+
The Python source tree contains
341+
:source:`a patch file <Mac/Resources/app-store-compliance.patch>` that will remove
342+
all code that is known to cause issues with the App Store review process. This
343+
patch is applied automatically when building for iOS.

Doc/using/mac.rst

Lines changed: 22 additions & 0 deletions
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

Mac/Resources/app-store-compliance.patch

Whitespace-only changes.

Makefile.pre.in

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,9 @@ EXPORTSFROM= @EXPORTSFROM@
175175
EXE= @EXEEXT@
176176
BUILDEXE= @BUILDEXEEXT@
177177

178+
# Name of the patch file to apply for app store compliance
179+
APP_STORE_COMPLIANCE_PATCH=@APP_STORE_COMPLIANCE_PATCH@
180+
178181
# Short name and location for Mac OS X Python framework
179182
UNIVERSALSDK=@UNIVERSALSDK@
180183
PYTHONFRAMEWORK= @PYTHONFRAMEWORK@
@@ -595,7 +598,7 @@ LIBEXPAT_HEADERS= \
595598

596599
# Default target
597600
all: @DEF_MAKE_ALL_RULE@
598-
build_all: check-clean-src $(BUILDPYTHON) platform oldsharedmods sharedmods \
601+
build_all: check-clean-src check-app-store-compliance $(BUILDPYTHON) platform oldsharedmods sharedmods \
599602
gdbhooks Programs/_testembed python-config
600603
build_wasm: check-clean-src $(BUILDPYTHON) platform oldsharedmods python-config
601604

@@ -614,6 +617,16 @@ check-clean-src:
614617
exit 1; \
615618
fi
616619

620+
# Check that the app store compliance patch can be applied (if configured).
621+
# This is checked as a dry-run against the original library sources;
622+
# the patch will be actually applied during the install phase.
623+
.PHONY: check-app-store-compliance
624+
check-app-store-compliance:
625+
@if [ "$(APP_STORE_COMPLIANCE_PATCH)" != "" ]; then \
626+
patch --dry-run --quiet --force --strip 1 --directory "$(abs_srcdir)" --input "$(abs_srcdir)/$(APP_STORE_COMPLIANCE_PATCH)"; \
627+
echo "App store compliance patch can be applied."; \
628+
fi
629+
617630
# Profile generation build must start from a clean tree.
618631
profile-clean-stamp:
619632
$(MAKE) clean
@@ -2216,7 +2229,16 @@ libinstall: all $(srcdir)/Modules/xxmodule.c
22162229
$(INSTALL_DATA) $(srcdir)/Modules/xxmodule.c \
22172230
$(DESTDIR)$(LIBDEST)/distutils/tests ; \
22182231
fi
2219-
-PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
2232+
@ # If app store compliance has been configured, apply the patch to the
2233+
@ # installed library code. The patch has been previously validated against
2234+
@ # the original source tree, so we can ignore any errors that are raised
2235+
@ # due to files that are missing because of --disable-test-modules etc.
2236+
@if [ "$(APP_STORE_COMPLIANCE_PATCH)" != "" ]; then \
2237+
echo "Applying app store compliance patch"; \
2238+
patch --force --reject-file "$(abs_builddir)/app-store-compliance.rej" --strip 2 --directory "$(DESTDIR)$(LIBDEST)" --input "$(abs_srcdir)/$(APP_STORE_COMPLIANCE_PATCH)" || true ; \
2239+
fi
2240+
@ # Build PYC files for the 3 optimization levels (0, 1, 2)
2241+
-PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
22202242
$(PYTHON_FOR_BUILD) -Wi $(DESTDIR)$(LIBDEST)/compileall.py \
22212243
-j0 -d $(LIBDEST) -f \
22222244
-x 'bad_coding|badsyntax|site-packages|lib2to3/tests/data' \
Lines changed: 2 additions & 0 deletions
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
2+
issues with macOS/iOS App Store review processes.

configure

Lines changed: 56 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

configure.ac

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,47 @@ AC_SUBST([INSTALLTARGETS])
689689

690690
AC_DEFINE_UNQUOTED(_PYTHONFRAMEWORK, "${PYTHONFRAMEWORK}", [framework name])
691691

692+
dnl quadrigraphs "@<:@" and "@:>@" produce "[" and "]" in the output
693+
AC_MSG_CHECKING([for --with-app-store-compliance])
694+
AC_ARG_WITH(
695+
[app_store_compliance],
696+
[AS_HELP_STRING(
697+
[--with-app-store-compliance=@<:@PATCH-FILE@:>@],
698+
[Enable any patches required for compiliance with app stores.
699+
Optional PATCH-FILE specifies the custom patch to apply.]
700+
)],[
701+
case "$withval" in
702+
yes)
703+
case $ac_sys_system in
704+
Darwin|iOS)
705+
# iOS is able to share the macOS patch
706+
APP_STORE_COMPLIANCE_PATCH="Mac/Resources/app-store-compliance.patch"
707+
;;
708+
*) AC_MSG_ERROR([no default app store compliance patch available for $ac_sys_system]) ;;
709+
esac
710+
AC_MSG_RESULT([applying default app store compliance patch])
711+
;;
712+
*)
713+
APP_STORE_COMPLIANCE_PATCH="${withval}"
714+
AC_MSG_RESULT([applying custom app store compliance patch])
715+
;;
716+
esac
717+
],[
718+
case $ac_sys_system in
719+
iOS)
720+
# Always apply the compliance patch on iOS; we can use the macOS patch
721+
APP_STORE_COMPLIANCE_PATCH="Mac/Resources/app-store-compliance.patch"
722+
AC_MSG_RESULT([applying default app store compliance patch])
723+
;;
724+
*)
725+
# No default app compliance patching on any other platform
726+
APP_STORE_COMPLIANCE_PATCH=
727+
AC_MSG_RESULT([not patching for app store compliance])
728+
;;
729+
esac
730+
])
731+
AC_SUBST([APP_STORE_COMPLIANCE_PATCH])
732+
692733
AC_SUBST([_PYTHON_HOST_PLATFORM])
693734
if test "$cross_compiling" = yes; then
694735
case "$host" in

0 commit comments

Comments
 (0)
0