Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Felix/source packages path option #42

Merged
merged 4 commits into from
Jul 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,16 @@ Open the terminal and run `swift-package-list <project-path>` with the path to t

In addition to that you can specify the following options:

| Option | Description |
| --------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- |
| -d, --derived-data-path \<derived-data-path\> | The path to your DerivedData-folder. (default: ~/Library/Developer/Xcode/DerivedData) |
| -o, --output-path \<output-path\> | The path where the package-list file will be stored. (default: ~/Desktop) |
| -f, --file-type \<file-type\> | The file type of the generated package-list file. Available options are json, plist, settings-bundle and pdf. (default: json) |
| -c, --custom-file-name <custom-file-name> | A custom filename to be used instead of the default ones. |
| --requires-license | Will skip the packages without a license-file. |
| --version | Show the version. |
| -h, --help | Show help information. |
| Option | Description |
| ------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- |
| -d, --derived-data-path \<derived-data-path\> | The path to your DerivedData-folder. (default: ~/Library/Developer/Xcode/DerivedData) |
| -s, --source-packages-path <source-packages-path> | The path to a custom SourcePackages-folder. |
| -o, --output-path \<output-path\> | The path where the package-list file will be stored. (default: ~/Desktop) |
| -f, --file-type \<file-type\> | The file type of the generated package-list file. Available options are json, plist, settings-bundle and pdf. (default: json) |
| -c, --custom-file-name <custom-file-name> | A custom filename to be used instead of the default ones. |
| --requires-license | Will skip the packages without a license-file. |
| --version | Show the version. |
| -h, --help | Show help information. |

### Run Script Phase

Expand Down
21 changes: 17 additions & 4 deletions Sources/SwiftPackageListCommand/SwiftPackageListCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ struct SwiftPackageListCommand: ParsableCommand {
@Option(name: .shortAndLong, help: "The path to your DerivedData-folder.")
var derivedDataPath = "\(NSHomeDirectory())/Library/Developer/Xcode/DerivedData"

@Option(name: .shortAndLong, help: "The path to a custom SourcePackages-folder.")
var sourcePackagesPath: String?

@Option(name: .shortAndLong, help: "The path where the package-list file will be stored.")
var outputPath: String = "\(NSHomeDirectory())/Desktop"

Expand All @@ -39,13 +42,23 @@ struct SwiftPackageListCommand: ParsableCommand {
throw ValidationError("The project file is not an Xcode Project or Workspace")
}

guard let checkoutsDirectory = try project.checkoutsDirectory(in: derivedDataPath) else {
throw RuntimeError("No checkouts-path found in your DerivedData-folder")
}

guard FileManager.default.fileExists(atPath: project.packageResolvedFileURL.path) else {
throw CleanExit.message("This project has no Swift-Package dependencies")
}

let checkoutsDirectory: URL
if let sourcePackagesPath = sourcePackagesPath {
checkoutsDirectory = URL(fileURLWithPath: sourcePackagesPath).appendingPathComponent("checkouts")
} else {
guard let buildDirectory = try project.buildDirectory(in: derivedDataPath) else {
throw RuntimeError("No build-directory found in your DerivedData-folder")
}
checkoutsDirectory = buildDirectory.appendingPathComponent("/SourcePackages/checkouts")
}
guard FileManager.default.fileExists(atPath: checkoutsDirectory.path) else {
throw RuntimeError("No checkouts-directory found in your SourcePackages-folder")
}

let packageResolved = try PackageResolved(at: project.packageResolvedFileURL)
let packages = try packageResolved.packages(in: checkoutsDirectory, requiresLicense: requiresLicense)

Expand Down
13 changes: 6 additions & 7 deletions Sources/SwiftPackageListCore/File Representations/Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,16 @@ extension Project {
let WorkspacePath: String
}

public func checkoutsDirectory(in derivedDataPath: String) throws -> URL? {
let derivedDataDirectories = try FileManager.default.contentsOfDirectory(at: URL(fileURLWithPath: derivedDataPath), includingPropertiesForKeys: [.isDirectoryKey], options: [.skipsHiddenFiles])
public func buildDirectory(in derivedDataPath: String) throws -> URL? {
let buildDirectories = try FileManager.default.contentsOfDirectory(at: URL(fileURLWithPath: derivedDataPath), includingPropertiesForKeys: [.isDirectoryKey], options: [.skipsHiddenFiles])

for derivedDataDirectory in derivedDataDirectories {
let projectFiles = try FileManager.default.contentsOfDirectory(at: derivedDataDirectory, includingPropertiesForKeys: [.isRegularFileKey], options: [.skipsHiddenFiles])
guard let infoDotPlist = projectFiles.first(where: { $0.lastPathComponent == "info.plist" }) else { continue }
for buildDirectory in buildDirectories {
let buildFiles = try FileManager.default.contentsOfDirectory(at: buildDirectory, includingPropertiesForKeys: [.isRegularFileKey], options: [.skipsHiddenFiles])
guard let infoDotPlist = buildFiles.first(where: { $0.lastPathComponent == "info.plist" }) else { continue }
let infoPlistData = try Data(contentsOf: infoDotPlist)
let infoPlist = try PropertyListDecoder().decode(InfoPlist.self, from: infoPlistData)
if infoPlist.WorkspacePath == fileURL.path {
let checkoutsDirectory = derivedDataDirectory.appendingPathComponent("/SourcePackages/checkouts")
return checkoutsDirectory
return buildDirectory
}
}

Expand Down