Skip to content

Commit bb40451

Browse files
committed
Add automation to strip Wormholy from non-Debug builds
1 parent 26688b4 commit bb40451

File tree

3 files changed

+89
-0
lines changed

3 files changed

+89
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash -eu
2+
3+
# Checks if the SwiftPM setup includes Wormholy during a build that is not Debug.
4+
#
5+
# If that's the case, it fails the build, because we don't want the library in non Debug builds.
6+
#
7+
# See counterpart method remove_wormholy_dependency_from_package_swift in fastlane/Fastfile.
8+
9+
MODULES_PATH="${SRCROOT}/../Modules"
10+
PACKAGE_PATH="${MODULES_PATH}/Package.swift"
11+
# Note: when/if we'll remove the workspace, this will change to ${MODULES_PATH}/Package.resolved
12+
PACKAGE_RESOLVED_PATH="${SRCROOT}/../WooCommerce.xcworkspace/xcshareddata/swiftpm/Package.resolved"
13+
14+
if [ "${CONFIGURATION}" == "Debug" ]; then
15+
echo "info: Running in Debug build configuration. Skipping Wormholy check."
16+
exit 0
17+
else
18+
echo "info: Running with a build configuration that is not Debug (${CONFIGURATION}). Checking Wormholy is not part of the SwiftPM setup..."
19+
fi
20+
21+
EXPLANATION="You are likely running a distribution build from Xcode, which cannot strip Wormholy. Please build for distribution using Fastlane (\`bundle exec fastlane build_for_app_store_connect\` or \`bundle exec fastlane build_for_prototype_build\`)."
22+
23+
if grep --quiet "Wormholy" "${PACKAGE_PATH}"; then
24+
echo "error: Wormholy reference found in Package.swift. $EXPLANATION"
25+
exit 1
26+
fi
27+
28+
# This is not necessary from the build point of view, because Package.swift is the source of truth.
29+
# But checking it ensures that the packages were resolved before starting the build.
30+
31+
if grep --quiet "Wormholy" "${PACKAGE_RESOLVED_PATH}"; then
32+
echo "error: Wormholy reference found in Package.resolved. $EXPLANATION"
33+
exit 1
34+
fi
35+
36+
echo "info: Wormholy not found in SwiftPM setup. Proceeding with the build..."

WooCommerce/WooCommerce.xcodeproj/project.pbxproj

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14479,6 +14479,7 @@
1447914479
isa = PBXNativeTarget;
1448014480
buildConfigurationList = B56DB3E62049BFAA00D4AA8E /* Build configuration list for PBXNativeTarget "WooCommerce" */;
1448114481
buildPhases = (
14482+
3F4278632E0BD6B700B11B9E /* Prevent Wormholy in non-Debug builds */,
1448214483
57CCFFD4249D2A5700825FCF /* SwiftLint */,
1448314484
3F50FE4528CAEE9F00C89201 /* Enforce AppLocalizedString usages */,
1448414485
B56DB3C22049BFAA00D4AA8E /* Sources */,
@@ -15056,6 +15057,25 @@
1505615057
/* End PBXResourcesBuildPhase section */
1505715058

1505815059
/* Begin PBXShellScriptBuildPhase section */
15060+
3F4278632E0BD6B700B11B9E /* Prevent Wormholy in non-Debug builds */ = {
15061+
isa = PBXShellScriptBuildPhase;
15062+
alwaysOutOfDate = 1;
15063+
buildActionMask = 2147483647;
15064+
files = (
15065+
);
15066+
inputFileListPaths = (
15067+
);
15068+
inputPaths = (
15069+
);
15070+
name = "Prevent Wormholy in non-Debug builds";
15071+
outputFileListPaths = (
15072+
);
15073+
outputPaths = (
15074+
);
15075+
runOnlyForDeploymentPostprocessing = 0;
15076+
shellPath = /bin/sh;
15077+
shellScript = "${SRCROOT}/../Scripts/build-phases/fail-non-debug-build-if-wormholy-present.sh\n";
15078+
};
1505915079
3F50FE4528CAEE9F00C89201 /* Enforce AppLocalizedString usages */ = {
1506015080
isa = PBXShellScriptBuildPhase;
1506115081
alwaysOutOfDate = 1;

fastlane/Fastfile

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,8 @@ platform :ios do
720720
lane :build_for_app_store_connect do |fetch_code_signing: true|
721721
update_certs_and_profiles_app_store if fetch_code_signing
722722

723+
remove_wormholy_dependency_from_package_swift
724+
723725
gym(
724726
scheme: 'WooCommerce',
725727
workspace: WORKSPACE_PATH,
@@ -784,6 +786,8 @@ platform :ios do
784786
lane :build_for_prototype_build do |fetch_code_signing: true|
785787
update_certs_and_profiles_enterprise if fetch_code_signing
786788

789+
remove_wormholy_dependency_from_package_swift
790+
787791
build_number = ENV.fetch('BUILDKITE_BUILD_NUMBER', '0')
788792
pr_or_branch = pull_request_number&.then { |num| "PR ##{num}" } || ENV.fetch('BUILDKITE_BRANCH', nil)
789793

@@ -1555,3 +1559,32 @@ def report_milestone_error(error_title:)
15551559

15561560
buildkite_annotate(style: 'warning', context: 'error-with-milestone', message: error_message) if is_ci
15571561
end
1562+
1563+
# Removes all Wormholy entries from a given `Package.swift`
1564+
#
1565+
# Wormholy is a library we only need in Debug builds.
1566+
# We don't want to bloat other builds with it, despite how small it might be.
1567+
#
1568+
# Thanks to all our Swift dependencies being declared in `Modules/Package.swift`, removing Wormholy from the file safely removes if from Xcode.
1569+
# No need to edit the Xcode project.
1570+
#
1571+
# See counterpart build phase script fail-non-debug-build-if-wormholy-present.sh
1572+
def remove_wormholy_dependency_from_package_swift(
1573+
package_path: File.join(PROJECT_ROOT_FOLDER, 'Modules', 'Package.swift')
1574+
)
1575+
content = File.read(package_path)
1576+
1577+
# Remove any line containing Wormholy.
1578+
#
1579+
# This relies on Package.swift being straightforward in how it defines dependencies.
1580+
# Given the code is only for usage in this repo at this time, it seems safe to do.
1581+
#
1582+
# This also assumes no other dependency, target, etc. includes "Wormholy" in its name.
1583+
# That also seem safe.
1584+
cleaned_content = content.lines.reject do |line|
1585+
line.include? 'Wormholy'
1586+
end.join
1587+
1588+
File.write(package_path, cleaned_content)
1589+
UI.success("Stripped Wormholy from #{package_path}")
1590+
end

0 commit comments

Comments
 (0)