Skip to content

Add plugin to autogenerate windows installer content #497

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

Merged
merged 1 commit into from
May 8, 2025
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
7 changes: 7 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,13 @@ let package = Package(
verb: "cmake-smoke-test",
description: "Build Swift Build using CMake for validation purposes"
))
),
.plugin(
name: "generate-windows-installer-component-groups",
capability: .command(intent: .custom(
verb: "generate-windows-installer-component-groups",
description: "Generate XML fragments for cli.wxs in swift-installer-scripts"
))
)
],
swiftLanguageModes: [.v5, .v6],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2025 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

import PackagePlugin
import Foundation

@main
struct GenerateWindowsInstallerComponentGroups: CommandPlugin {
func performCommand(context: PluginContext, arguments: [String]) async throws {
var librariesComponent = #" <ComponentGroup Id="SwiftBuild" Directory="_usr_bin">\#n"#
var resourcesComponents = ""
var groupRefs = #" <ComponentGroupRef Id="SwiftBuild" />\#n"#
var directories = #" <Directory Id="_usr_share_pm" Name="pm">\#n"#
for target in context.package.targets.sorted(by: { $0.name < $1.name }).filter({ !["SWBTestSupport", "SwiftBuildTestSupport"].contains($0.name) }) {
guard let sourceModule = target.sourceModule, sourceModule.kind == .generic else {
continue
}
librariesComponent += #"""
<Component>
<File Source="$(ToolchainRoot)\usr\bin\\#(sourceModule.name).dll" />
</Component>

"""#

let resources = sourceModule.sourceFiles.filter { resource in resource.type == .resource && ["xcspec", "xcbuildrule"].contains(resource.url.pathExtension) }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: this needs to be xcbuildrules

if !resources.isEmpty {
groupRefs += #" <ComponentGroupRef Id="\#(sourceModule.name)Resources" />\#n"#
directories += #" <Directory Id="_usr_share_pm_\#(sourceModule.name)" Name="SwiftBuild_\#(sourceModule.name).resources" />\#n"#
resourcesComponents += #" <ComponentGroup Id="\#(sourceModule.name)Resources" Directory="_usr_share_pm_\#(sourceModule.name)">\#n"#
for resource in resources {
resourcesComponents += #"""
<Component>
<File Source="$(ToolchainRoot)\usr\share\pm\SwiftBuild_\#(sourceModule.name).resources\\#(resource.url.lastPathComponent)" />
</Component>

"""#
}
resourcesComponents += " </ComponentGroup>\n"
}
}
librariesComponent += " </ComponentGroup>\n"
directories += " </Directory>\n"

print("Component Groups")
print(String(repeating: "-", count: 80))
print(librariesComponent)
print(resourcesComponents)
print("Group Refs")
print(String(repeating: "-", count: 80))
print(groupRefs)
print("Directories")
print(String(repeating: "-", count: 80))
print(directories)
}
}
Loading