@@ -17,9 +17,9 @@ import PackagePlugin
17
17
18
18
@main
19
19
struct AWSLambdaPackager : CommandPlugin {
20
-
20
+
21
21
func performCommand( context: PackagePlugin . PluginContext , arguments: [ String ] ) async throws {
22
-
22
+
23
23
// values to pass to the AWSLambdaPluginHelper
24
24
let outputDirectory : URL
25
25
let products : [ Product ]
@@ -29,15 +29,15 @@ struct AWSLambdaPackager: CommandPlugin {
29
29
let packageDirectory = context. package . directoryURL
30
30
let dockerToolPath = try context. tool ( named: " docker " ) . url
31
31
let zipToolPath = try context. tool ( named: " zip " ) . url
32
-
32
+
33
33
// extract arguments that require PluginContext to fully resolve
34
34
// resolve them here and pass them to the AWSLambdaPluginHelper as arguments
35
35
var argumentExtractor = ArgumentExtractor ( arguments)
36
-
36
+
37
37
let outputPathArgument = argumentExtractor. extractOption ( named: " output-path " )
38
38
let productsArgument = argumentExtractor. extractOption ( named: " products " )
39
39
let configurationArgument = argumentExtractor. extractOption ( named: " configuration " )
40
-
40
+
41
41
if let outputPath = outputPathArgument. first {
42
42
#if os(Linux)
43
43
var isDirectory : Bool = false
@@ -52,7 +52,7 @@ struct AWSLambdaPackager: CommandPlugin {
52
52
} else {
53
53
outputDirectory = context. pluginWorkDirectoryURL. appending ( path: " \( AWSLambdaPackager . self) " )
54
54
}
55
-
55
+
56
56
let explicitProducts = !productsArgument. isEmpty
57
57
if explicitProducts {
58
58
let _products = try context. package . products ( named: productsArgument)
@@ -62,11 +62,11 @@ struct AWSLambdaPackager: CommandPlugin {
62
62
}
63
63
}
64
64
products = _products
65
-
65
+
66
66
} else {
67
67
products = context. package . products. filter { $0 is ExecutableProduct }
68
68
}
69
-
69
+
70
70
if let _buildConfigurationName = configurationArgument. first {
71
71
guard let _buildConfiguration = PackageManager . BuildConfiguration ( rawValue: _buildConfigurationName) else {
72
72
throw BuilderErrors . invalidArgument ( " invalid build configuration named ' \( _buildConfigurationName) ' " )
@@ -75,22 +75,23 @@ struct AWSLambdaPackager: CommandPlugin {
75
75
} else {
76
76
buildConfiguration = . release
77
77
}
78
-
78
+
79
79
// TODO: When running on Amazon Linux 2, we have to build directly from the plugin
80
80
// launch the build, then call the helper just for the ZIP part
81
-
81
+
82
82
let tool = try context. tool ( named: " AWSLambdaPluginHelper " )
83
- let args = [
84
- " build " ,
85
- " --output-path " , outputDirectory. path ( ) ,
86
- " --products " , products. map { $0. name } . joined ( separator: " , " ) ,
87
- " --configuration " , buildConfiguration. rawValue,
88
- " --package-id " , packageID,
89
- " --package-display-name " , packageDisplayName,
90
- " --package-directory " , packageDirectory. path ( ) ,
91
- " --docker-tool-path " , dockerToolPath. path,
92
- " --zip-tool-path " , zipToolPath. path
93
- ] + arguments
83
+ let args =
84
+ [
85
+ " build " ,
86
+ " --output-path " , outputDirectory. path ( ) ,
87
+ " --products " , products. map { $0. name } . joined ( separator: " , " ) ,
88
+ " --configuration " , buildConfiguration. rawValue,
89
+ " --package-id " , packageID,
90
+ " --package-display-name " , packageDisplayName,
91
+ " --package-directory " , packageDirectory. path ( ) ,
92
+ " --docker-tool-path " , dockerToolPath. path,
93
+ " --zip-tool-path " , zipToolPath. path,
94
+ ] + arguments
94
95
95
96
// Invoke the plugin helper on the target directory, passing a configuration
96
97
// file from the package directory.
@@ -103,52 +104,52 @@ struct AWSLambdaPackager: CommandPlugin {
103
104
Diagnostics . error ( " AWSLambdaPluginHelper invocation failed: \( problem) " )
104
105
}
105
106
}
106
-
107
+
107
108
// TODO: When running on Amazon Linux 2, we have to build directly from the plugin
108
- // private func build(
109
- // packageIdentity: Package.ID,
110
- // products: [Product],
111
- // buildConfiguration: PackageManager.BuildConfiguration,
112
- // verboseLogging: Bool
113
- // ) throws -> [LambdaProduct: URL] {
114
- // print("-------------------------------------------------------------------------")
115
- // print("building \"\(packageIdentity)\"")
116
- // print("-------------------------------------------------------------------------")
117
- //
118
- // var results = [LambdaProduct: URL]()
119
- // for product in products {
120
- // print("building \"\(product.name)\"")
121
- // var parameters = PackageManager.BuildParameters()
122
- // parameters.configuration = buildConfiguration
123
- // parameters.otherSwiftcFlags = ["-static-stdlib"]
124
- // parameters.logging = verboseLogging ? .verbose : .concise
125
- //
126
- // let result = try packageManager.build(
127
- // .product(product.name),
128
- // parameters: parameters
129
- // )
130
- // guard let artifact = result.executableArtifact(for: product) else {
131
- // throw Errors.productExecutableNotFound(product.name)
132
- // }
133
- // results[.init(product)] = artifact.url
134
- // }
135
- // return results
136
- // }
137
-
138
- // private func isAmazonLinux2() -> Bool {
139
- // if let data = FileManager.default.contents(atPath: "/etc/system-release"),
140
- // let release = String(data: data, encoding: .utf8)
141
- // {
142
- // return release.hasPrefix("Amazon Linux release 2")
143
- // } else {
144
- // return false
145
- // }
146
- // }
109
+ // private func build(
110
+ // packageIdentity: Package.ID,
111
+ // products: [Product],
112
+ // buildConfiguration: PackageManager.BuildConfiguration,
113
+ // verboseLogging: Bool
114
+ // ) throws -> [LambdaProduct: URL] {
115
+ // print("-------------------------------------------------------------------------")
116
+ // print("building \"\(packageIdentity)\"")
117
+ // print("-------------------------------------------------------------------------")
118
+ //
119
+ // var results = [LambdaProduct: URL]()
120
+ // for product in products {
121
+ // print("building \"\(product.name)\"")
122
+ // var parameters = PackageManager.BuildParameters()
123
+ // parameters.configuration = buildConfiguration
124
+ // parameters.otherSwiftcFlags = ["-static-stdlib"]
125
+ // parameters.logging = verboseLogging ? .verbose : .concise
126
+ //
127
+ // let result = try packageManager.build(
128
+ // .product(product.name),
129
+ // parameters: parameters
130
+ // )
131
+ // guard let artifact = result.executableArtifact(for: product) else {
132
+ // throw Errors.productExecutableNotFound(product.name)
133
+ // }
134
+ // results[.init(product)] = artifact.url
135
+ // }
136
+ // return results
137
+ // }
138
+
139
+ // private func isAmazonLinux2() -> Bool {
140
+ // if let data = FileManager.default.contents(atPath: "/etc/system-release"),
141
+ // let release = String(data: data, encoding: .utf8)
142
+ // {
143
+ // return release.hasPrefix("Amazon Linux release 2")
144
+ // } else {
145
+ // return false
146
+ // }
147
+ // }
147
148
}
148
149
149
150
private enum BuilderErrors : Error , CustomStringConvertible {
150
151
case invalidArgument( String )
151
-
152
+
152
153
var description : String {
153
154
switch self {
154
155
case . invalidArgument( let description) :
0 commit comments