-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Combine MacOSBundler, IOSBundler, TVOSBundler, and VisionOSBundler in…
…to a single DarwinBundler (along with other clean up) Makes a huge difference to maintainability, they were basically all just slightly changed copies of each other. Did some basic testing and everything seems to still be working (haven't tested provisioning profile support yet though, will do once automatic provisioning has been implemented)
- Loading branch information
1 parent
893f7a1
commit 90d829b
Showing
19 changed files
with
538 additions
and
1,369 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
64 changes: 64 additions & 0 deletions
64
Sources/swift-bundler/Bundler/DarwinAppBundleStructure.swift
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,64 @@ | ||
import Foundation | ||
|
||
/// The file/directory structure of a particular app bundle on disk. | ||
struct DarwinAppBundleStructure { | ||
let contentsDirectory: URL | ||
let resourcesDirectory: URL | ||
let librariesDirectory: URL | ||
let executableDirectory: URL | ||
let infoPlistFile: URL | ||
let pkgInfoFile: URL | ||
let provisioningProfileFile: URL | ||
let appIconFile: URL | ||
|
||
/// Describes the structure of an app bundle for the specific platform. Doesn't | ||
/// create anything on disk (see ``DarwinAppBundleStructure/createDirectories()``). | ||
init(at bundleDirectory: URL, platform: ApplePlatform) { | ||
let os = platform.os | ||
switch os { | ||
case .macOS: | ||
contentsDirectory = bundleDirectory.appendingPathComponent("Contents") | ||
executableDirectory = contentsDirectory.appendingPathComponent("MacOS") | ||
resourcesDirectory = contentsDirectory.appendingPathComponent("Resources") | ||
case .iOS, .tvOS, .visionOS: | ||
contentsDirectory = bundleDirectory | ||
executableDirectory = contentsDirectory | ||
resourcesDirectory = contentsDirectory | ||
} | ||
|
||
librariesDirectory = contentsDirectory.appendingPathComponent("Libraries") | ||
|
||
infoPlistFile = contentsDirectory.appendingPathComponent("Info.plist") | ||
pkgInfoFile = contentsDirectory.appendingPathComponent("PkgInfo") | ||
provisioningProfileFile = contentsDirectory.appendingPathComponent( | ||
"embedded.mobileprovision" | ||
) | ||
appIconFile = contentsDirectory.appendingPathComponent("AppIcon.icns") | ||
} | ||
|
||
/// Attempts to create all directories within the app bundle. Ignores directories which | ||
/// already exist. | ||
func createDirectories() -> Result<Void, DarwinBundlerError> { | ||
let directories = [ | ||
contentsDirectory, resourcesDirectory, librariesDirectory, executableDirectory, | ||
] | ||
|
||
for directory in directories { | ||
guard !FileManager.default.itemExists(at: directory, withType: .directory) else { | ||
continue | ||
} | ||
do { | ||
try FileManager.default.createDirectory( | ||
at: directory, | ||
withIntermediateDirectories: true | ||
) | ||
} catch { | ||
return .failure( | ||
.failedToCreateAppBundleDirectoryStructure(error) | ||
) | ||
} | ||
} | ||
|
||
return .success() | ||
} | ||
} |
Oops, something went wrong.