From d81f4661171bcf16053c600302fc862bb0b6b3e4 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Tue, 18 Jul 2023 17:15:59 +1000 Subject: [PATCH 1/3] Add build phase to prevent nested frameworks --- Scripts/BuildPhases/LintNestedFrameworks.sh | 27 +++++++++++++ WordPress/WordPress.xcodeproj/project.pbxproj | 39 +++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100755 Scripts/BuildPhases/LintNestedFrameworks.sh diff --git a/Scripts/BuildPhases/LintNestedFrameworks.sh b/Scripts/BuildPhases/LintNestedFrameworks.sh new file mode 100755 index 000000000000..cbb5137f72df --- /dev/null +++ b/Scripts/BuildPhases/LintNestedFrameworks.sh @@ -0,0 +1,27 @@ +#!/bin/sh -eu + +set pipefail + +# Nested frameworks (i.e. having a Frameworks/ folder inside *.app/Frameworks/.framework) is invalid and will make the build be rejected during TestFlight validation. +# +# See also https://github.com/woocommerce/woocommerce-ios/pull/4226 + +# This script is intended to be used as a Build Phase on the main app target, as the very last build phase (and especially after the "Embed Frameworks" phase) + +NESTED_FMKS_DIRS=$(find "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" -name Frameworks -depth 2) +if [ -z "$NESTED_FMKS_DIRS" ]; then + echo "✅ No nested framework found, you're good to go!" +else + echo "❌ Found nested \`Frameworks\` folder inside frameworks of final bundle." + for fmk_dir in $NESTED_FMKS_DIRS; do + # Extract the name of the parent framework containing the nested ones + parent_fmk=$(basename $(dirname $fmk_dir) .framework) + # Extract the list of frameworks nested inside that parent framework. In the next command: + # * `-depth 1` is to avoid logging cases of "C nested in B itself nested in A" (2+ levels of nesting), since C nested in B will already be logged when looping on fmk_dir=B, so no need to log it during fmk_dir=A too. + # * The `sed` command removes the leading `./` in the paths returned by `find`, then quote the results in backticks for nicer formatting in final message. + # * The `tr` command joins all the lines (= found frameworks) with a `,`. Note that this will result in an extra comma at the end of the list too, but we'll get rid of that in the final message using ${nested_fmks%,} bash substitution. + nested_fmks=$(cd "${fmk_dir}" && find . -name '*.framework' -depth 1 | sed "s:^./\(.*\)$:\`\1\`:" | tr '\n' ',') + echo "error: Found nested frameworks in ${fmk_dir} -- Such a configuration is invalid and will be rejected by TestFlight. Please fix by choosing 'Do Not Embed' for the nested framework(s) ${nested_fmks%,} within the \`${parent_fmk}\` Xcode project which links to them. You might need to use Xcode 12.5 to fix this, due to an Xcode 12.4 bug – see paNNhX-ee-p2" + done + exit 1 +fi diff --git a/WordPress/WordPress.xcodeproj/project.pbxproj b/WordPress/WordPress.xcodeproj/project.pbxproj index da744d7caef0..b395c72c66fd 100644 --- a/WordPress/WordPress.xcodeproj/project.pbxproj +++ b/WordPress/WordPress.xcodeproj/project.pbxproj @@ -18311,6 +18311,7 @@ 37399571B0D91BBEAE911024 /* [CP] Embed Pods Frameworks */, 920B9A6DAD47189622A86A9C /* [CP] Copy Pods Resources */, E1C5456F219F10E000896227 /* Copy Gutenberg JS */, + 3FF795712A6671DB00F27B17 /* Lint against nested frameworks */, ); buildRules = ( ); @@ -18607,6 +18608,7 @@ FABB264A2602FC2C00C8785C /* [CP] Embed Pods Frameworks */, FABB264B2602FC2C00C8785C /* [CP] Copy Pods Resources */, FABB264C2602FC2C00C8785C /* Copy Gutenberg JS */, + 3FF795732A66730200F27B17 /* Lint against nested frameworks */, ); buildRules = ( ); @@ -20120,6 +20122,43 @@ shellPath = /bin/sh; shellScript = "$SRCROOT/../Scripts/BuildPhases/GenerateCredentials.sh\n"; }; + 3FF795712A6671DB00F27B17 /* Lint against nested frameworks */ = { + isa = PBXShellScriptBuildPhase; + alwaysOutOfDate = 1; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + ); + name = "Lint against nested frameworks"; + outputFileListPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"$SRCROOT/../Scripts/BuildPhases/LintNestedFrameworks.sh\"\n"; + }; + 3FF795732A66730200F27B17 /* Lint against nested frameworks */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + ); + name = "Lint against nested frameworks"; + outputFileListPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"$SRCROOT/../Scripts/BuildPhases/LintNestedFrameworks.sh\"\n"; + }; 49AE9271B82C7D67430387FA /* [CP] Embed Pods Frameworks */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; From f8759684b0aa10c0ef389e16e40e3551e23a6bb2 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Wed, 19 Jul 2023 10:27:16 +1000 Subject: [PATCH 2/3] Remove outdated Xcode 12.5 mention from nested frameworks linter --- Scripts/BuildPhases/LintNestedFrameworks.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Scripts/BuildPhases/LintNestedFrameworks.sh b/Scripts/BuildPhases/LintNestedFrameworks.sh index cbb5137f72df..c0a1dfdb3af6 100755 --- a/Scripts/BuildPhases/LintNestedFrameworks.sh +++ b/Scripts/BuildPhases/LintNestedFrameworks.sh @@ -21,7 +21,7 @@ else # * The `sed` command removes the leading `./` in the paths returned by `find`, then quote the results in backticks for nicer formatting in final message. # * The `tr` command joins all the lines (= found frameworks) with a `,`. Note that this will result in an extra comma at the end of the list too, but we'll get rid of that in the final message using ${nested_fmks%,} bash substitution. nested_fmks=$(cd "${fmk_dir}" && find . -name '*.framework' -depth 1 | sed "s:^./\(.*\)$:\`\1\`:" | tr '\n' ',') - echo "error: Found nested frameworks in ${fmk_dir} -- Such a configuration is invalid and will be rejected by TestFlight. Please fix by choosing 'Do Not Embed' for the nested framework(s) ${nested_fmks%,} within the \`${parent_fmk}\` Xcode project which links to them. You might need to use Xcode 12.5 to fix this, due to an Xcode 12.4 bug – see paNNhX-ee-p2" + echo "error: Found nested frameworks in ${fmk_dir} -- Such a configuration is invalid and will be rejected by TestFlight. Please fix by choosing 'Do Not Embed' for the nested framework(s) ${nested_fmks%,} within the \`${parent_fmk}\` Xcode project which links to them." done exit 1 fi From 723f8ed0354db6291fac1834c5f8e9eca8161630 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Thu, 20 Jul 2023 09:47:37 +1000 Subject: [PATCH 3/3] Reintroduce link to internal doc with "Do Not Embed" explanation Co-authored-by: Olivier Halligon --- Scripts/BuildPhases/LintNestedFrameworks.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Scripts/BuildPhases/LintNestedFrameworks.sh b/Scripts/BuildPhases/LintNestedFrameworks.sh index c0a1dfdb3af6..e7a42541664b 100755 --- a/Scripts/BuildPhases/LintNestedFrameworks.sh +++ b/Scripts/BuildPhases/LintNestedFrameworks.sh @@ -21,7 +21,7 @@ else # * The `sed` command removes the leading `./` in the paths returned by `find`, then quote the results in backticks for nicer formatting in final message. # * The `tr` command joins all the lines (= found frameworks) with a `,`. Note that this will result in an extra comma at the end of the list too, but we'll get rid of that in the final message using ${nested_fmks%,} bash substitution. nested_fmks=$(cd "${fmk_dir}" && find . -name '*.framework' -depth 1 | sed "s:^./\(.*\)$:\`\1\`:" | tr '\n' ',') - echo "error: Found nested frameworks in ${fmk_dir} -- Such a configuration is invalid and will be rejected by TestFlight. Please fix by choosing 'Do Not Embed' for the nested framework(s) ${nested_fmks%,} within the \`${parent_fmk}\` Xcode project which links to them." + echo "error: Found nested frameworks in ${fmk_dir} -- Such a configuration is invalid and will be rejected by TestFlight. Please fix by choosing 'Do Not Embed' for the nested framework(s) ${nested_fmks%,} within the \`${parent_fmk}\` Xcode project which links to them. See paNNhX-ee-p2." done exit 1 fi