Skip to content

Commit f63edf9

Browse files
authored
Merge pull request #2241 from loopandlearn/xcode16_profile_support_take2
Adjust provisioning profile path in script for Xcode 16 compatibility
2 parents 56ac6bb + ae76f90 commit f63edf9

File tree

2 files changed

+30
-42
lines changed

2 files changed

+30
-42
lines changed

Diff for: Common/Models/BuildDetails.swift

+5-41
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,16 @@ class BuildDetails {
1313
static var `default` = BuildDetails()
1414

1515
let dict: [String: Any]
16-
private var cachedProfileExpirationDate: Date?
1716

1817
init() {
1918
guard let url = Bundle.main.url(forResource: "BuildDetails", withExtension: ".plist"),
20-
let data = try? Data(contentsOf: url),
21-
let parsed = try? PropertyListSerialization.propertyList(from: data, format: nil) as? [String: Any] else
19+
let data = try? Data(contentsOf: url),
20+
let parsed = try? PropertyListSerialization.propertyList(from: data, format: nil) as? [String: Any] else
2221
{
2322
dict = [:]
2423
return
2524
}
2625
dict = parsed
27-
cachedProfileExpirationDate = loadProfileExpirationDate()
2826
}
2927

3028
var buildDateString: String? {
@@ -48,11 +46,11 @@ class BuildDetails {
4846
}
4947

5048
var profileExpiration: Date? {
51-
return cachedProfileExpirationDate
49+
return dict["com-loopkit-Loop-profile-expiration"] as? Date
5250
}
5351

5452
var profileExpirationString: String {
55-
if let profileExpiration = cachedProfileExpirationDate {
53+
if let profileExpiration = profileExpiration {
5654
return "\(profileExpiration)"
5755
} else {
5856
return "N/A"
@@ -65,41 +63,7 @@ class BuildDetails {
6563
}
6664

6765
var workspaceGitBranch: String? {
68-
return dict["com-loopkit-LoopWorkspace-git-branch"] as? String
69-
}
70-
71-
private func loadProfileExpirationDate() -> Date? {
72-
guard
73-
let profilePath = Bundle.main.path(forResource: "embedded", ofType: "mobileprovision"),
74-
let profileData = try? Data(contentsOf: URL(fileURLWithPath: profilePath)),
75-
let profileNSString = NSString(data: profileData, encoding: String.Encoding.ascii.rawValue)
76-
else {
77-
print(
78-
"WARNING: Could not find or read `embedded.mobileprovision`. If running on Simulator, there are no provisioning profiles."
79-
)
80-
return nil
81-
}
82-
83-
let regexPattern = "<key>ExpirationDate</key>[\\W]*?<date>(.*?)</date>"
84-
guard let regex = try? NSRegularExpression(pattern: regexPattern, options: []),
85-
let match = regex.firstMatch(
86-
in: profileNSString as String,
87-
options: [],
88-
range: NSRange(location: 0, length: profileNSString.length)
89-
),
90-
let range = Range(match.range(at: 1), in: profileNSString as String)
91-
else {
92-
print("Warning: Could not create regex or find match.")
93-
return nil
94-
}
95-
96-
let dateString = String(profileNSString.substring(with: NSRange(range, in: profileNSString as String)))
97-
let dateFormatter = DateFormatter()
98-
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss'Z'"
99-
dateFormatter.locale = Locale(identifier: "en_US_POSIX")
100-
dateFormatter.timeZone = TimeZone(secondsFromGMT: 0)
101-
102-
return dateFormatter.date(from: dateString)
66+
return dict["com-loopkit-LoopWorkspace-git-branch"] as? String
10367
}
10468
}
10569

Diff for: Scripts/capture-build-details.sh

+25-1
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,18 @@ info() {
2626

2727
info_plist_path="${BUILT_PRODUCTS_DIR}/${CONTENTS_FOLDER_PATH}/BuildDetails.plist"
2828
xcode_build_version=${XCODE_PRODUCT_BUILD_VERSION:-$(xcodebuild -version | grep version | cut -d ' ' -f 3)}
29+
2930
while [[ $# -gt 0 ]]
3031
do
3132
case $1 in
3233
-i|--info-plist-path)
3334
info_plist_path="${2}"
3435
shift 2
3536
;;
37+
-p|--provisioning-profile-path)
38+
provisioning_profile_path="${2}"
39+
shift 2
40+
;;
3641
esac
3742
done
3843

@@ -42,7 +47,6 @@ fi
4247

4348
if [ "${info_plist_path}" == "/" -o ! -e "${info_plist_path}" ]; then
4449
error "File does not exist: ${info_plist_path}"
45-
#error "Must provide valid --info-plist-path, or have valid \${BUILT_PRODUCTS_DIR} and \${INFOPLIST_PATH} set."
4650
fi
4751

4852
info "Gathering build details in ${PWD}"
@@ -62,6 +66,26 @@ plutil -replace com-loopkit-Loop-srcroot -string "${PWD}" "${info_plist_path}"
6266
plutil -replace com-loopkit-Loop-build-date -string "$(date)" "${info_plist_path}"
6367
plutil -replace com-loopkit-Loop-xcode-version -string "${xcode_build_version}" "${info_plist_path}"
6468

69+
# Determine the provisioning profile path
70+
if [ -z "${provisioning_profile_path}" ]; then
71+
if [ -e "${HOME}/Library/MobileDevice/Provisioning Profiles/${EXPANDED_PROVISIONING_PROFILE}.mobileprovision" ]; then
72+
provisioning_profile_path="${HOME}/Library/MobileDevice/Provisioning Profiles/${EXPANDED_PROVISIONING_PROFILE}.mobileprovision"
73+
elif [ -e "${HOME}/Library/Developer/Xcode/UserData/Provisioning Profiles/${EXPANDED_PROVISIONING_PROFILE}.mobileprovision" ]; then
74+
provisioning_profile_path="${HOME}/Library/Developer/Xcode/UserData/Provisioning Profiles/${EXPANDED_PROVISIONING_PROFILE}.mobileprovision"
75+
else
76+
warn "Provisioning profile not found in expected locations"
77+
fi
78+
fi
79+
80+
if [ -e "${provisioning_profile_path}" ]; then
81+
profile_expire_date=$(security cms -D -i "${provisioning_profile_path}" | plutil -p - | grep ExpirationDate | cut -b 23-)
82+
# Convert to plutil format
83+
profile_expire_date=$(date -j -f "%Y-%m-%d %H:%M:%S" "${profile_expire_date}" +"%Y-%m-%dT%H:%M:%SZ")
84+
plutil -replace com-loopkit-Loop-profile-expiration -date "${profile_expire_date}" "${info_plist_path}"
85+
else
86+
warn "Invalid provisioning profile path ${provisioning_profile_path}"
87+
fi
88+
6589
# determine if this is a workspace build
6690
# if so, fill out the git revision and branch
6791
if [ -e ../.git ]

0 commit comments

Comments
 (0)