|
| 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