Skip to content

Commit f945399

Browse files
authored
SPM: Add support for file suffixes
This is helpful if multiple Swift packages are present
1 parent 903919f commit f945399

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

spm/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,11 @@ The tool creates a `generated-sources.json` and a `setup-offline.sh` file in the
3838

3939
See the quickstart project for a complete example.
4040

41+
### Suffix
42+
43+
Optionally, add a third argument with a suffix for the file names. This can be helpful if multiple Swift packages are present.
44+
```
45+
swift flatpak-spm-generator.swift ./quickstart ./quickstart quickstart
46+
```
47+
48+
The tool then creates a `generated-sources-<suffix>.json` and a `setup-offline-<suffix>.sh` file in the directory of the Flatpak manifest.

spm/flatpak-spm-generator.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ let arguments = CommandLine.arguments
66
let path = arguments.count > 1 ? arguments[1] : "."
77
// The path to the directory containing the Flatpak manifest.
88
let pathToManifest = arguments.count > 2 ? arguments[2] : "."
9+
/// An optional suffix.
10+
var suffix = arguments.count > 3 ? arguments[3] : ""
11+
12+
if !suffix.isEmpty {
13+
suffix = "-" + suffix
14+
}
915

1016
// Build the Swift package to get a complete list of dependencies under "{path}/.build/workspace-state.json".
1117
let task = Process()
@@ -60,17 +66,17 @@ content.append("""
6066
6167
{
6268
"type": "file",
63-
"path": "setup-offline.sh"
69+
"path": "setup-offline\(suffix).sh"
6470
}
6571
""")
6672
content.append("\n]")
6773

6874
// Save the files.
69-
let pathToSetup = "\(pathToManifest)/setup-offline.sh"
75+
let pathToSetup = "\(pathToManifest)/setup-offline\(suffix).sh"
7076

7177
let contentData = content.data(using: .utf8)
7278
let shellContentData = shellContent.data(using: .utf8)
73-
try contentData?.write(to: .init(fileURLWithPath: "\(pathToManifest)/generated-sources.json"))
79+
try contentData?.write(to: .init(fileURLWithPath: "\(pathToManifest)/generated-sources\(suffix).json"))
7480
try shellContentData?.write(to: .init(fileURLWithPath: pathToSetup))
7581

7682
let executable = Process()

0 commit comments

Comments
 (0)