@@ -10,38 +10,63 @@ if [ -z "$VERSION" ]; then
1010fi
1111
1212PROJECT_FILE=" RxCode.xcodeproj/project.pbxproj"
13+ BUNDLE_IDENTIFIER=" com.rxlab.RxCode"
1314
1415if [ ! -f " $PROJECT_FILE " ]; then
1516 echo " Error: $PROJECT_FILE not found"
1617 exit 1
1718fi
1819
19- echo " Updating MARKETING_VERSION to $VERSION in $PROJECT_FILE "
20+ echo " Updating MARKETING_VERSION to $VERSION in $PROJECT_FILE for $BUNDLE_IDENTIFIER "
2021
2122# Create a temporary file
2223TMP_FILE=$( mktemp)
2324
24- # Use awk to update only the RxCode main target (matched by PRODUCT_BUNDLE_IDENTIFIER)
25- awk -v new_version=" $VERSION " '
26- /MARKETING_VERSION = / {
27- # Store the current line
28- marketing_line = $0
29- # Read the next line
30- getline
31- # Check if this is the main app target (not Tests or UITests)
32- if ($0 ~ /PRODUCT_BUNDLE_IDENTIFIER = com\.idealapp\.RxCode;$/) {
33- # Update MARKETING_VERSION
34- gsub(/MARKETING_VERSION = [^;]+;/, "MARKETING_VERSION = " new_version ";", marketing_line)
35- print marketing_line
36- print
37- } else {
38- # Keep both lines unchanged
39- print marketing_line
40- print
25+ # Update only build settings blocks for the macOS RxCode app target.
26+ # Matching the whole block is safer than assuming MARKETING_VERSION is adjacent
27+ # to PRODUCT_BUNDLE_IDENTIFIER in project.pbxproj.
28+ awk -v new_version=" $VERSION " -v bundle_id=" $BUNDLE_IDENTIFIER " '
29+ BEGIN {
30+ in_build_settings = 0
31+ block = ""
32+ matched_bundle = 0
33+ updated_count = 0
34+ }
35+
36+ /^[[:space:]]*buildSettings = \{[[:space:]]*$/ {
37+ in_build_settings = 1
38+ block = $0 ORS
39+ matched_bundle = 0
40+ next
41+ }
42+
43+ in_build_settings {
44+ block = block $0 ORS
45+ if (index($0, "PRODUCT_BUNDLE_IDENTIFIER = " bundle_id ";") > 0) {
46+ matched_bundle = 1
47+ }
48+ if ($0 ~ /^[[:space:]]*\};[[:space:]]*$/) {
49+ if (matched_bundle) {
50+ updated_count += gsub(/MARKETING_VERSION = [^;]+;/, "MARKETING_VERSION = " new_version ";", block)
51+ }
52+ printf "%s", block
53+ in_build_settings = 0
54+ block = ""
55+ matched_bundle = 0
4156 }
4257 next
4358}
59+
4460{ print }
61+
62+ END {
63+ if (in_build_settings) {
64+ printf "%s", block
65+ }
66+ if (updated_count == 0) {
67+ exit 1
68+ }
69+ }
4570' " $PROJECT_FILE " > " $TMP_FILE "
4671
4772# Replace the original file
0 commit comments