Skip to content

Commit 579aa20

Browse files
committed
Add plugin to autogenerate windows installer content
1 parent 7cd307d commit 579aa20

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

Package.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,13 @@ let package = Package(
413413
verb: "cmake-smoke-test",
414414
description: "Build Swift Build using CMake for validation purposes"
415415
))
416+
),
417+
.plugin(
418+
name: "generate-windows-installer-component-groups",
419+
capability: .command(intent: .custom(
420+
verb: "generate-windows-installer-component-groups",
421+
description: "Generate XML fragments for cli.wxs in swift-installer-scripts"
422+
))
416423
)
417424
],
418425
swiftLanguageModes: [.v5, .v6],
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift open source project
4+
//
5+
// Copyright (c) 2025 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See http://swift.org/LICENSE.txt for license information
9+
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
import PackagePlugin
14+
import Foundation
15+
16+
@main
17+
struct GenerateWindowsInstallerComponentGroups: CommandPlugin {
18+
func performCommand(context: PluginContext, arguments: [String]) async throws {
19+
var librariesComponent = #" <ComponentGroup Id="SwiftBuild" Directory="_usr_bin">\#n"#
20+
var resourcesComponents = ""
21+
var groupRefs = #" <ComponentGroupRef Id="SwiftBuild" />\#n"#
22+
var directories = #" <Directory Id="_usr_share_pm" Name="pm">\#n"#
23+
for target in context.package.targets.sorted(by: { $0.name < $1.name }).filter({ !["SWBTestSupport", "SwiftBuildTestSupport"].contains($0.name) }) {
24+
guard let sourceModule = target.sourceModule, sourceModule.kind == .generic else {
25+
continue
26+
}
27+
librariesComponent += #"""
28+
<Component>
29+
<File Source="$(ToolchainRoot)\usr\bin\\#(sourceModule.name).dll" />
30+
</Component>
31+
32+
"""#
33+
34+
let resources = sourceModule.sourceFiles.filter { resource in resource.type == .resource && ["xcspec", "xcbuildrule"].contains(resource.url.pathExtension) }
35+
if !resources.isEmpty {
36+
groupRefs += #" <ComponentGroupRef Id="\#(sourceModule.name)Resources" />\#n"#
37+
directories += #" <Directory Id="_usr_share_pm_\#(sourceModule.name)" Name="SwiftBuild_\#(sourceModule.name).resources" />\#n"#
38+
resourcesComponents += #" <ComponentGroup Id="\#(sourceModule.name)Resources" Directory="_usr_share_pm_\#(sourceModule.name)">\#n"#
39+
for resource in resources {
40+
resourcesComponents += #"""
41+
<Component>
42+
<File Source="$(ToolchainRoot)\usr\share\pm\SwiftBuild_\#(sourceModule.name).resources\\#(resource.url.lastPathComponent)" />
43+
</Component>
44+
45+
"""#
46+
}
47+
resourcesComponents += " </ComponentGroup>\n"
48+
}
49+
}
50+
librariesComponent += " </ComponentGroup>\n"
51+
directories += " </Directory>\n"
52+
53+
print("Component Groups")
54+
print(String(repeating: "-", count: 80))
55+
print(librariesComponent)
56+
print(resourcesComponents)
57+
print("Group Refs")
58+
print(String(repeating: "-", count: 80))
59+
print(groupRefs)
60+
print("Directories")
61+
print(String(repeating: "-", count: 80))
62+
print(directories)
63+
}
64+
}

0 commit comments

Comments
 (0)