Skip to content

Commit

Permalink
Added version.txt file for extracting framework version in SPM
Browse files Browse the repository at this point in the history
- Updated Package.swift to process resources
- Updated FrameworkInfo to include the SPM path for extracting the version
  • Loading branch information
rmigneco committed Nov 11, 2024
1 parent bfab00c commit 6de0a80
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ let package = Package(
"HLS ObjectiveC",
"PlaylistParserError",
"mamba.h"
],
resources: [
.process("Resources")
]
),
.target(
Expand Down
12 changes: 11 additions & 1 deletion mambaSharedFramework/FrameworkInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,22 @@ public enum FrameworkInfo {
/// returns the version of the mamba framework
public static var version: String {

/// When exporting a framework on SPM, there is no way to access the info dictionary, so the version should be provided differently
#if SWIFT_PACKAGE
guard let versionFilePathUrl = Bundle.module.url(forResource: "version", withExtension: "txt"),
let version = try? String(contentsOf: versionFilePathUrl, encoding: .utf8)
.trimmingCharacters(in: .whitespacesAndNewlines)
else {
assertionFailure("Unable to find version string in framework bundle")
return "Error: Unable to find version string in framework bundle"
}
#else
let bundle = Bundle(for: PlaylistParser.self)

guard let version = bundle.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String else {
assertionFailure("Unable to find version string in framework bundle")
return "Error: Unable to find version string in framework bundle"
}
#endif

return version
}
Expand Down
1 change: 1 addition & 0 deletions mambaSharedFramework/Resources/version.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.3.0

0 comments on commit 6de0a80

Please sign in to comment.