Skip to content

Commit 5510d30

Browse files
committed
Update package scripts
1 parent 7fd31c1 commit 5510d30

19 files changed

+1286
-552
lines changed

scripts/build.sh

Lines changed: 91 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,101 @@
11
#!/bin/bash
22

3-
# Documentation:
4-
# This script builds a <TARGET> for all provided <PLATFORMS>.
5-
# This script targets iOS, macOS, tvOS, watchOS, and xrOS by default.
6-
# You can pass in a list of <PLATFORMS> if you want to customize the build.
7-
8-
# Usage:
9-
# build.sh <TARGET> [<PLATFORMS> default:iOS macOS tvOS watchOS xrOS]
10-
# e.g. `bash scripts/build.sh MyTarget iOS macOS`
11-
123
# Exit immediately if a command exits with a non-zero status
134
set -e
145

15-
# Verify that all required arguments are provided
16-
if [ $# -eq 0 ]; then
17-
echo "Error: This script requires at least one argument"
18-
echo "Usage: $0 <TARGET> [<PLATFORMS> default:iOS macOS tvOS watchOS xrOS]"
19-
echo "For instance: $0 MyTarget iOS macOS"
6+
# Function to display usage information
7+
show_usage() {
8+
echo
9+
echo "This script builds a <TARGET> for all provided <PLATFORMS>."
10+
11+
echo
12+
echo "Usage: $0 [TARGET] [-p|--platforms <PLATFORM1> <PLATFORM2> ...]"
13+
echo " [TARGET] Optional. The target to build (defaults to package name)"
14+
echo " -p, --platforms Optional. List of platforms (default: iOS macOS tvOS watchOS xrOS)"
15+
16+
echo
17+
echo "Examples:"
18+
echo " $0"
19+
echo " $0 MyTarget"
20+
echo " $0 -p iOS macOS"
21+
echo " $0 MyTarget -p iOS macOS"
22+
echo " $0 MyTarget --platforms iOS macOS tvOS watchOS xrOS"
23+
echo
24+
}
25+
26+
# Function to display error message, show usage, and exit
27+
show_error_and_exit() {
28+
echo
29+
local error_message="$1"
30+
echo "Error: $error_message"
31+
show_usage
2032
exit 1
21-
fi
33+
}
2234

2335
# Define argument variables
24-
TARGET=$1
36+
TARGET=""
37+
PLATFORMS="iOS macOS tvOS watchOS xrOS" # Default platforms
2538

26-
# Remove TARGET from arguments list
27-
shift
39+
# Parse command line arguments
40+
while [[ $# -gt 0 ]]; do
41+
case $1 in
42+
-p|--platforms)
43+
shift # Remove --platforms from arguments
44+
PLATFORMS="" # Clear default platforms
45+
46+
# Collect all platform arguments until we hit another flag or run out of args
47+
while [[ $# -gt 0 && ! "$1" =~ ^- ]]; do
48+
PLATFORMS="$PLATFORMS $1"
49+
shift
50+
done
51+
52+
# Remove leading space and check if we got any platforms
53+
PLATFORMS=$(echo "$PLATFORMS" | sed 's/^ *//')
54+
if [ -z "$PLATFORMS" ]; then
55+
show_error_and_exit "--platforms requires at least one platform"
56+
fi
57+
;;
58+
-h|--help)
59+
show_usage; exit 0 ;;
60+
-*)
61+
show_error_and_exit "Unknown option $1" ;;
62+
*)
63+
if [ -z "$TARGET" ]; then
64+
TARGET="$1"
65+
else
66+
show_error_and_exit "Unexpected argument '$1'"
67+
fi
68+
shift
69+
;;
70+
esac
71+
done
2872

29-
# Define platforms variable
30-
if [ $# -eq 0 ]; then
31-
set -- iOS macOS tvOS watchOS xrOS
73+
# If no TARGET was provided, try to get package name
74+
if [ -z "$TARGET" ]; then
75+
# Use the script folder to refer to other scripts
76+
FOLDER="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
77+
SCRIPT_PACKAGE_NAME="$FOLDER/package_name.sh"
78+
79+
# Check if package_name.sh exists
80+
if [ -f "$SCRIPT_PACKAGE_NAME" ]; then
81+
echo "No target provided, attempting to get package name..."
82+
if TARGET=$("$SCRIPT_PACKAGE_NAME"); then
83+
echo "Using package name: $TARGET"
84+
else
85+
echo ""
86+
read -p "Failed to get package name. Please enter the target to build: " TARGET
87+
if [ -z "$TARGET" ]; then
88+
show_error_and_exit "TARGET is required"
89+
fi
90+
fi
91+
else
92+
echo ""
93+
read -p "Please enter the target to build: " TARGET
94+
if [ -z "$TARGET" ]; then
95+
show_error_and_exit "TARGET is required"
96+
fi
97+
fi
3298
fi
33-
PLATFORMS=$@
3499

35100
# A function that builds $TARGET for a specific platform
36101
build_platform() {
@@ -41,18 +106,16 @@ build_platform() {
41106
# Build $TARGET for the $PLATFORM
42107
echo "Building $TARGET for $PLATFORM..."
43108
if ! xcodebuild -scheme $TARGET -derivedDataPath .build -destination generic/platform=$PLATFORM; then
44-
echo "Failed to build $TARGET for $PLATFORM"
45-
return 1
109+
echo "Failed to build $TARGET for $PLATFORM" ; return 1
46110
fi
47111

48112
# Complete successfully
49113
echo "Successfully built $TARGET for $PLATFORM"
50114
}
51115

52116
# Start script
53-
echo ""
117+
echo
54118
echo "Building $TARGET for [$PLATFORMS]..."
55-
echo ""
56119

57120
# Loop through all platforms and call the build function
58121
for PLATFORM in $PLATFORMS; do
@@ -62,6 +125,6 @@ for PLATFORM in $PLATFORMS; do
62125
done
63126

64127
# Complete successfully
65-
echo ""
128+
echo
66129
echo "Building $TARGET completed successfully!"
67-
echo ""
130+
echo

scripts/chmod.sh

Lines changed: 74 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,81 @@
11
#!/bin/bash
22

3-
# Documentation:
4-
# This script makes all scripts in this folder executable.
5-
6-
# Usage:
7-
# scripts_chmod.sh
8-
# e.g. `bash scripts/chmod.sh`
9-
103
# Exit immediately if a command exits with a non-zero status
114
set -e
125

13-
# Use the script folder to refer to other scripts.
14-
FOLDER="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
6+
# Function to display usage information
7+
show_usage() {
8+
echo
9+
echo "This script makes all .sh files in the current directory executable."
1510

16-
# Find all .sh files in the FOLDER except chmod.sh
17-
find "$FOLDER" -name "*.sh" ! -name "chmod.sh" -type f | while read -r script; do
18-
chmod +x "$script"
11+
echo
12+
echo "Usage: $0 [OPTIONS]"
13+
echo " -h, --help Show this help message"
14+
15+
echo
16+
echo "Examples:"
17+
echo " $0"
18+
echo " bash scripts/chmod.sh"
19+
echo
20+
}
21+
22+
# Function to display error message, show usage, and exit
23+
show_error_and_exit() {
24+
echo
25+
local error_message="$1"
26+
echo "Error: $error_message"
27+
show_usage
28+
exit 1
29+
}
30+
31+
# Parse command line arguments
32+
while [[ $# -gt 0 ]]; do
33+
case $1 in
34+
-h|--help)
35+
show_usage; exit 0 ;;
36+
-*)
37+
show_error_and_exit "Unknown option $1" ;;
38+
*)
39+
show_error_and_exit "Unexpected argument '$1'" ;;
40+
esac
1941
done
42+
43+
# Use the script folder to refer to other scripts
44+
FOLDER="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
45+
46+
# Function to make scripts executable
47+
make_executable() {
48+
local script="$1"
49+
local filename=$(basename "$script")
50+
51+
echo "Making $filename executable..."
52+
if ! chmod +x "$script"; then
53+
echo "Failed to make $filename executable" ; return 1
54+
fi
55+
56+
echo "Successfully made $filename executable"
57+
}
58+
59+
# Start script
60+
echo
61+
echo "Making all .sh files in $(basename "$FOLDER") executable..."
62+
63+
# Find all .sh files in the FOLDER except chmod.sh and make them executable
64+
SCRIPT_COUNT=0
65+
while read -r script; do
66+
if ! make_executable "$script"; then
67+
exit 1
68+
fi
69+
((SCRIPT_COUNT++))
70+
done < <(find "$FOLDER" -name "*.sh" ! -name "chmod.sh" -type f)
71+
72+
# Complete successfully
73+
if [ $SCRIPT_COUNT -eq 0 ]; then
74+
echo
75+
echo "No .sh files found to make executable (excluding chmod.sh)"
76+
else
77+
echo
78+
echo "Successfully made $SCRIPT_COUNT script(s) executable!"
79+
fi
80+
81+
echo

0 commit comments

Comments
 (0)