-
Notifications
You must be signed in to change notification settings - Fork 331
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Preprocessor to make select constructs public (#3880)
This PR allows the Paywalls Tester app to access some items internal to purchases-ios by temporarily marking them public during complication. Items that need to be public have been annotated with `\\@PublicForExternalTesting`. The Paywalls Tester project runs a script, Preprocessor.sh, as a pre-action to add `public` to all classes/structs/enums/functions/inits that have been annotated. After compilation it runs a second script, Postprocessor.sh, as a post-action to undo these changes so that they don't accidentally get checked in. The first script is run as a scheme pre-action rather than as a run script build phase, because when run as a build phase the changes to the files aren't picked up until the next compilation attempt. <img width="669" alt="image" src="https://github.com/RevenueCat/purchases-ios/assets/109382862/0b0bacdb-79de-441d-8d61-2a5dd03b1b53"> It also changes the archive step to be built with a release configuration, and removes the use of `@testable import` for debug builds. resolves PWL-459
- Loading branch information
Showing
15 changed files
with
211 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#!/bin/sh | ||
|
||
# Preprocessor.sh | ||
# PaywallsTester | ||
# | ||
# Created by James Borthwick on 2024-05-08. | ||
# | ||
|
||
# Intended to be run via the scheme's post-actions build phase | ||
# | ||
# This script undoes the changes made by "Preprocessor.sh" so that they don't | ||
# end up accidentally checked in. | ||
|
||
|
||
echo "Starting undo process." | ||
|
||
find_dir() { | ||
local dir="$1" | ||
local target_dir="$2" | ||
while [[ "$dir" != "/" ]]; do | ||
if [[ -e "$dir/$target_dir" ]]; then | ||
echo "$dir/$target_dir" | ||
return 0 | ||
fi | ||
dir=$(dirname "$dir") # go up one level | ||
done | ||
return 1 # Target directory not found | ||
} | ||
|
||
base_directory=$(find_dir "${PROJECT_DIR}" "RevenueCatUI") | ||
|
||
if [[ -z "$base_directory" ]]; then | ||
echo "Error: RevenueCatUI not found in the current directory or any parent directory." | ||
exit 1 | ||
fi | ||
|
||
echo "Starting at: $base_directory" | ||
|
||
# debug log | ||
log_file="undo_log.txt" | ||
echo "Starting log at $(date)" > "$log_file" | ||
|
||
# Find all .orig files and restore them | ||
find "$base_directory" -type f -name "*.swift.orig" | while read -r backup_file; do | ||
original_file="${backup_file%.orig}" | ||
cp "$backup_file" "$original_file" | ||
rm -f "$backup_file" | ||
|
||
echo "Restored: $original_file" | tee -a "$log_file" | ||
done | ||
|
||
echo "Undo process completed." | tee -a "$log_file" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#!/bin/sh | ||
|
||
# Preprocessor.sh | ||
# PaywallsTester | ||
# | ||
# Created by James Borthwick on 2024-05-08. | ||
# | ||
|
||
# Intended to be run via the scheme's pre-actions build phase | ||
# | ||
# This script searches up from ${PROJECT_DIR} to locate the RevenueCatUI directory. | ||
# Once found, it searches through all `.swift` files starting from that base directory. | ||
# It finds occurrences of `//@PublicForExternalTesting` and modifies the subsequent class, struct, | ||
# func, init, and enum declaration to make it public. | ||
|
||
find_dir() { | ||
local dir="$1" | ||
local target_dir="$2" | ||
while [[ "$dir" != "/" ]]; do | ||
if [[ -e "$dir/$target_dir" ]]; then | ||
echo "$dir/$target_dir" | ||
return 0 | ||
fi | ||
dir=$(dirname "$dir") # go up one level | ||
done | ||
return 1 # Target directory not found | ||
} | ||
|
||
echo "Starting script to make items annotated with \`\/\/ @PublicForExternalTesting\` public." | ||
|
||
base_directory=$(find_dir "${PROJECT_DIR}" "RevenueCatUI") | ||
|
||
if [[ -z "$base_directory" ]]; then | ||
echo "Error: RevenueCatUI not found in the current directory or any parent directory." | ||
exit 1 | ||
fi | ||
|
||
echo "Starting at: $base_directory" | ||
|
||
# debug log | ||
log_file="preprocess_log.txt" | ||
echo "Starting log at $(date)" > "$log_file" | ||
|
||
# Find all .swift files recursively from the base directory | ||
find "$base_directory" -type f -name "*.swift" | while read -r file; do | ||
|
||
if grep -q '// @PublicForExternalTesting' "$file"; then | ||
# Backup original file | ||
backup_file="${file}.orig" | ||
cp "$file" "$original_file" | ||
|
||
# Find //@PublicForExternalTesting and replace it with public before declarations | ||
sed -i.orig -E \ | ||
'/\/\/ @PublicForExternalTesting[[:space:]]*$/{ | ||
N | ||
s/\/\/ @PublicForExternalTesting[[:space:]]*\n[[:space:]]*(static[[:space:]]+)?(struct|class|final[[:space:]]+class|enum|init|func)/public \1\2/ | ||
}' "$file" | ||
|
||
# Log changes made to the file | ||
diff_output=$(diff "$backup_file" "$file") | ||
if [[ -n "$diff_output" ]]; then | ||
echo "Changes made in file: $file" | tee -a "$log_file" | ||
echo "$diff_output" | tee -a "$log_file" | ||
fi | ||
|
||
fi | ||
done | ||
|
||
echo "Processing completed." | tee -a "$log_file" |