1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
|
//===----------------------------------------------------------------------===//
//
// 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 SWBCore
import SWBUtil
import SWBMacro
import SWBTaskConstruction
final class ExtensionPointExtractorTaskProducer: PhasedTaskProducer, TaskProducer {
override var defaultTaskOrderingOptions: TaskOrderingOptions {
return .unsignedProductRequirement
}
private func filterBuildFiles(_ buildFiles: [BuildFile]?, identifiers: [String], buildFilesProcessingContext: BuildFilesProcessingContext) -> [FileToBuild] {
guard let buildFiles else {
return []
}
let fileTypes = identifiers.compactMap { identifier in
context.lookupFileType(identifier: identifier)
}
return fileTypes.flatMap { fileType in
buildFiles.compactMap { buildFile in
guard let resolvedBuildFileInfo = try? self.context.resolveBuildFileReference(buildFile),
!buildFilesProcessingContext.isExcluded(resolvedBuildFileInfo.absolutePath, filters: buildFile.platformFilters),
resolvedBuildFileInfo.fileType.conformsTo(fileType) else {
return nil
}
return FileToBuild(absolutePath: resolvedBuildFileInfo.absolutePath, fileType: fileType)
}
}
}
func generateTasks() async -> [any PlannedTask] {
guard ExtensionPointExtractorSpec.shouldConstructTask(scope: context.settings.globalScope, productType: context.productType, isApplePlatform: context.isApplePlatform) else {
return []
}
context.addDeferredProducer {
let scope = self.context.settings.globalScope
let buildFilesProcessingContext = BuildFilesProcessingContext(scope)
let perArchConstMetadataFiles = self.context.generatedSwiftConstMetadataFiles()
let constMetadataFiles: [Path]
if let firstArch = perArchConstMetadataFiles.keys.sorted().first {
constMetadataFiles = perArchConstMetadataFiles[firstArch]!
} else {
constMetadataFiles = []
}
let constMetadataFilesToBuild = constMetadataFiles.map { absolutePath -> FileToBuild in
let fileType = self.context.workspaceContext.core.specRegistry.getSpec("file") as! FileTypeSpec
return FileToBuild(absolutePath: absolutePath, fileType: fileType)
}
let inputs = constMetadataFilesToBuild
guard inputs.isEmpty == false else {
return []
}
var deferredTasks: [any PlannedTask] = []
let cbc = CommandBuildContext(producer: self.context, scope: scope, inputs: inputs, resourcesDir: buildFilesProcessingContext.resourcesDir)
await self.appendGeneratedTasks(&deferredTasks) { delegate in
let domain = self.context.settings.platform?.name ?? ""
guard let spec = self.context.specRegistry.getSpec("com.apple.compilers.extract-appextensionpoints", domain:domain) as? ExtensionPointExtractorSpec else {
return
}
await spec.constructTasks(cbc, delegate)
}
return deferredTasks
}
return []
}
}
final class AppExtensionInfoPlistGeneratorTaskProducer: PhasedTaskProducer, TaskProducer {
override var defaultTaskOrderingOptions: TaskOrderingOptions {
return .unsignedProductRequirement
}
private func filterBuildFiles(_ buildFiles: [BuildFile]?, identifiers: [String], buildFilesProcessingContext: BuildFilesProcessingContext) -> [FileToBuild] {
guard let buildFiles else {
return []
}
let fileTypes = identifiers.compactMap { identifier in
context.lookupFileType(identifier: identifier)
}
return fileTypes.flatMap { fileType in
buildFiles.compactMap { buildFile in
guard let resolvedBuildFileInfo = try? self.context.resolveBuildFileReference(buildFile),
!buildFilesProcessingContext.isExcluded(resolvedBuildFileInfo.absolutePath, filters: buildFile.platformFilters),
resolvedBuildFileInfo.fileType.conformsTo(fileType) else {
return nil
}
return FileToBuild(absolutePath: resolvedBuildFileInfo.absolutePath, fileType: fileType)
}
}
}
func generateTasks() async -> [any PlannedTask] {
let scope = context.settings.globalScope
let productType = context.productType
let isApplePlatform = context.isApplePlatform
guard AppExtensionPlistGeneratorSpec.shouldConstructTask(scope: scope, productType: productType, isApplePlatform: isApplePlatform) else {
return []
}
let tasks: [any PlannedTask] = []
let buildFilesProcessingContext = BuildFilesProcessingContext(scope)
let moduelName = context.settings.globalScope.evaluate(BuiltinMacros.TARGET_NAME)
let plistPath = buildFilesProcessingContext.tmpResourcesDir.join(Path("\(moduelName)-appextension-generated-info.plist"))
context.addDeferredProducer {
let perArchConstMetadataFiles = self.context.generatedSwiftConstMetadataFiles()
let constMetadataFiles: [Path]
if let firstArch = perArchConstMetadataFiles.keys.sorted().first {
constMetadataFiles = perArchConstMetadataFiles[firstArch]!
} else {
constMetadataFiles = []
}
let constMetadataFilesToBuild = constMetadataFiles.map { absolutePath -> FileToBuild in
let fileType = self.context.workspaceContext.core.specRegistry.getSpec("file") as! FileTypeSpec
return FileToBuild(absolutePath: absolutePath, fileType: fileType)
}
let inputs = constMetadataFilesToBuild
var deferredTasks: [any PlannedTask] = []
let cbc = CommandBuildContext(producer: self.context, scope: scope, inputs: inputs, output: plistPath)
await self.appendGeneratedTasks(&deferredTasks) { delegate in
let domain = self.context.settings.platform?.name ?? ""
guard let spec = self.context.specRegistry.getSpec("com.apple.compilers.appextension-plist-generator",domain: domain) as? AppExtensionPlistGeneratorSpec else {
return
}
await spec.constructTasks(cbc, delegate)
}
return deferredTasks
}
self.context.addGeneratedInfoPlistContent(plistPath)
return tasks
}
}
|