-
Notifications
You must be signed in to change notification settings - Fork 187
Expand file tree
/
Copy pathEXUtil.swift
More file actions
124 lines (106 loc) · 5.89 KB
/
Copy pathEXUtil.swift
File metadata and controls
124 lines (106 loc) · 5.89 KB
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
//===----------------------------------------------------------------------===//
//
// 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 SWBUtil
import SWBMacro
import SWBCore
import SWBProtocol
import Foundation
final class ExtensionPointExtractorSpec: GenericCommandLineToolSpec, SpecIdentifierType, @unchecked Sendable {
public static let identifier = "com.apple.compilers.extract-appextensionpoints"
static func shouldConstructTask(scope: MacroEvaluationScope, productType: ProductTypeSpec?, isApplePlatform: Bool) -> Bool {
let isNormalVariant = scope.evaluate(BuiltinMacros.CURRENT_VARIANT) == "normal"
let buildComponents = scope.evaluate(BuiltinMacros.BUILD_COMPONENTS)
let isBuild = buildComponents.contains("build")
let indexEnableBuildArena = scope.evaluate(BuiltinMacros.INDEX_ENABLE_BUILD_ARENA)
let isAppProductType = productType?.conformsTo(identifier: "com.apple.product-type.application") ?? false
let extensionPointExtractorEnabled = scope.evaluate(BuiltinMacros.EX_ENABLE_EXTENSION_POINT_GENERATION)
let result = (
isBuild
&& isNormalVariant
&& extensionPointExtractorEnabled
&& !indexEnableBuildArena
&& isAppProductType
&& isApplePlatform
)
return result
}
override func constructTasks(_ cbc: CommandBuildContext, _ delegate: any TaskGenerationDelegate) async {
guard Self.shouldConstructTask(scope: cbc.scope, productType: cbc.producer.productType, isApplePlatform: cbc.producer.isApplePlatform) else {
return
}
let inputs = cbc.inputs.map { input in
return delegate.createNode(input.absolutePath)
}.filter { node in
node.path.fileExtension == "swiftconstvalues"
}
var outputs = [any PlannedNode]()
let outputPath = cbc.scope.evaluate(BuiltinMacros.EXTENSIONS_FOLDER_PATH).join(Path("\(cbc.scope.evaluate(BuiltinMacros.PRODUCT_MODULE_NAME))-generated.appexpt"))
outputs.append(delegate.createNode(outputPath))
let commandLine = await commandLineFromTemplate(cbc, delegate, optionContext: discoveredCommandLineToolSpecInfo(cbc.producer, cbc.scope, delegate)).map(\.asString)
delegate.createTask(type: self,
ruleInfo: defaultRuleInfo(cbc, delegate),
commandLine: commandLine,
environment: environmentFromSpec(cbc, delegate),
workingDirectory: cbc.producer.defaultWorkingDirectory,
inputs: inputs,
outputs: outputs,
action: nil,
execDescription: resolveExecutionDescription(cbc, delegate),
enableSandboxing: enableSandboxing)
}
}
final class AppExtensionPlistGeneratorSpec: GenericCommandLineToolSpec, SpecIdentifierType, @unchecked Sendable {
public static let identifier = "com.apple.compilers.appextension-plist-generator"
static func shouldConstructTask(scope: MacroEvaluationScope, productType: ProductTypeSpec?, isApplePlatform: Bool) -> Bool {
let isNormalVariant = scope.evaluate(BuiltinMacros.CURRENT_VARIANT) == "normal"
let buildComponents = scope.evaluate(BuiltinMacros.BUILD_COMPONENTS)
let isBuild = buildComponents.contains("build")
let indexEnableBuildArena = scope.evaluate(BuiltinMacros.INDEX_ENABLE_BUILD_ARENA)
let isAppExtensionProductType = productType?.conformsTo(identifier: "com.apple.product-type.extensionkit-extension") ?? false
let extensionPointAttributesGenerationEnabled = !scope.evaluate(BuiltinMacros.EX_DISABLE_APPEXTENSION_ATTRIBUTES_GENERATION)
let result = ( isBuild
&& isNormalVariant
&& extensionPointAttributesGenerationEnabled
&& !indexEnableBuildArena
&& (isAppExtensionProductType)
&& isApplePlatform )
return result
}
override func constructTasks(_ cbc: CommandBuildContext, _ delegate: any TaskGenerationDelegate) async {
let scope = cbc.scope
let productType = cbc.producer.productType
let isApplePlatform = cbc.producer.isApplePlatform
guard Self.shouldConstructTask(scope: scope, productType: productType, isApplePlatform: isApplePlatform) else {
return
}
let inputs = cbc.inputs.map { input in
return delegate.createNode(input.absolutePath)
}.filter { node in
node.path.fileExtension == "swiftconstvalues"
}
var outputs = [any PlannedNode]()
let outputPath = cbc.output
outputs.append(delegate.createNode(outputPath))
let commandLine = await commandLineFromTemplate(cbc, delegate, optionContext: discoveredCommandLineToolSpecInfo(cbc.producer, cbc.scope, delegate)).map(\.asString)
delegate.createTask(type: self,
ruleInfo: defaultRuleInfo(cbc, delegate),
commandLine: commandLine,
environment: environmentFromSpec(cbc, delegate),
workingDirectory: cbc.producer.defaultWorkingDirectory,
inputs: inputs,
outputs: outputs,
action: nil,
execDescription: resolveExecutionDescription(cbc, delegate),
enableSandboxing: enableSandboxing
)
}
}