Skip to content

Commit 0bdc813

Browse files
committed
swift format
1 parent 0665430 commit 0bdc813

File tree

10 files changed

+220
-224
lines changed

10 files changed

+220
-224
lines changed

Package.swift

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,26 @@ let package = Package(
1212
name: "swift-aws-lambda-runtime",
1313
platforms: platforms,
1414
products: [
15-
16-
/*
17-
The runtime library targets
18-
*/
19-
15+
16+
//
17+
// The runtime library targets
18+
//
19+
2020
// this library exports `AWSLambdaRuntimeCore` and adds Foundation convenience methods
2121
.library(name: "AWSLambdaRuntime", targets: ["AWSLambdaRuntime"]),
2222

2323
// this has all the main functionality for lambda and it does not link Foundation
2424
.library(name: "AWSLambdaRuntimeCore", targets: ["AWSLambdaRuntimeCore"]),
2525

26-
/*
27-
The plugins
28-
'lambda-init' creates a new Lambda function
29-
'lambda-build' packages the Lambda function
30-
'lambda-deploy' deploys the Lambda function
31-
32-
Plugins requires Linux or at least macOS v15
26+
//
27+
// The plugins
28+
// 'lambda-init' creates a new Lambda function
29+
// 'lambda-build' packages the Lambda function
30+
// 'lambda-deploy' deploys the Lambda function
31+
//
32+
// Plugins requires Linux or at least macOS v15
33+
//
3334

34-
*/
3535
// plugin to create a new Lambda function, based on a template
3636
.plugin(name: "AWSLambdaInitializer", targets: ["AWSLambdaInitializer"]),
3737

@@ -41,9 +41,10 @@ let package = Package(
4141
// plugin to deploy a Lambda function
4242
.plugin(name: "AWSLambdaDeployer", targets: ["AWSLambdaDeployer"]),
4343

44-
/*
45-
Testing targets
46-
*/
44+
//
45+
// Testing targets
46+
//
47+
4748
// for testing only
4849
.library(name: "AWSLambdaTesting", targets: ["AWSLambdaTesting"]),
4950
],
@@ -88,23 +89,23 @@ let package = Package(
8889
),
8990
// keep this one (with "archive") to not break workflows
9091
// This will be deprecated at some point in the future
91-
// .plugin(
92-
// name: "AWSLambdaPackager",
93-
// capability: .command(
94-
// intent: .custom(
95-
// verb: "archive",
96-
// description:
97-
// "Archive the Lambda binary and prepare it for uploading to AWS. Requires docker on macOS or non Amazonlinux 2 distributions."
98-
// ),
99-
// permissions: [
100-
// .allowNetworkConnections(
101-
// scope: .docker,
102-
// reason: "This plugin uses Docker to create the AWS Lambda ZIP package."
103-
// )
104-
// ]
105-
// ),
106-
// path: "Plugins/AWSLambdaBuilder" // same sources as the new "lambda-build" plugin
107-
// ),
92+
// .plugin(
93+
// name: "AWSLambdaPackager",
94+
// capability: .command(
95+
// intent: .custom(
96+
// verb: "archive",
97+
// description:
98+
// "Archive the Lambda binary and prepare it for uploading to AWS. Requires docker on macOS or non Amazonlinux 2 distributions."
99+
// ),
100+
// permissions: [
101+
// .allowNetworkConnections(
102+
// scope: .docker,
103+
// reason: "This plugin uses Docker to create the AWS Lambda ZIP package."
104+
// )
105+
// ]
106+
// ),
107+
// path: "Plugins/AWSLambdaBuilder" // same sources as the new "lambda-build" plugin
108+
// ),
108109
.plugin(
109110
name: "AWSLambdaBuilder",
110111
capability: .command(

Plugins/AWSLambdaBuilder/Plugin.swift

Lines changed: 63 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ import PackagePlugin
1717

1818
@main
1919
struct AWSLambdaPackager: CommandPlugin {
20-
20+
2121
func performCommand(context: PackagePlugin.PluginContext, arguments: [String]) async throws {
22-
22+
2323
// values to pass to the AWSLambdaPluginHelper
2424
let outputDirectory: URL
2525
let products: [Product]
@@ -29,15 +29,15 @@ struct AWSLambdaPackager: CommandPlugin {
2929
let packageDirectory = context.package.directoryURL
3030
let dockerToolPath = try context.tool(named: "docker").url
3131
let zipToolPath = try context.tool(named: "zip").url
32-
32+
3333
// extract arguments that require PluginContext to fully resolve
3434
// resolve them here and pass them to the AWSLambdaPluginHelper as arguments
3535
var argumentExtractor = ArgumentExtractor(arguments)
36-
36+
3737
let outputPathArgument = argumentExtractor.extractOption(named: "output-path")
3838
let productsArgument = argumentExtractor.extractOption(named: "products")
3939
let configurationArgument = argumentExtractor.extractOption(named: "configuration")
40-
40+
4141
if let outputPath = outputPathArgument.first {
4242
#if os(Linux)
4343
var isDirectory: Bool = false
@@ -52,7 +52,7 @@ struct AWSLambdaPackager: CommandPlugin {
5252
} else {
5353
outputDirectory = context.pluginWorkDirectoryURL.appending(path: "\(AWSLambdaPackager.self)")
5454
}
55-
55+
5656
let explicitProducts = !productsArgument.isEmpty
5757
if explicitProducts {
5858
let _products = try context.package.products(named: productsArgument)
@@ -62,11 +62,11 @@ struct AWSLambdaPackager: CommandPlugin {
6262
}
6363
}
6464
products = _products
65-
65+
6666
} else {
6767
products = context.package.products.filter { $0 is ExecutableProduct }
6868
}
69-
69+
7070
if let _buildConfigurationName = configurationArgument.first {
7171
guard let _buildConfiguration = PackageManager.BuildConfiguration(rawValue: _buildConfigurationName) else {
7272
throw BuilderErrors.invalidArgument("invalid build configuration named '\(_buildConfigurationName)'")
@@ -75,22 +75,23 @@ struct AWSLambdaPackager: CommandPlugin {
7575
} else {
7676
buildConfiguration = .release
7777
}
78-
78+
7979
// TODO: When running on Amazon Linux 2, we have to build directly from the plugin
8080
// launch the build, then call the helper just for the ZIP part
81-
81+
8282
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
9495

9596
// Invoke the plugin helper on the target directory, passing a configuration
9697
// file from the package directory.
@@ -103,52 +104,52 @@ struct AWSLambdaPackager: CommandPlugin {
103104
Diagnostics.error("AWSLambdaPluginHelper invocation failed: \(problem)")
104105
}
105106
}
106-
107+
107108
// 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+
// }
147148
}
148149

149150
private enum BuilderErrors: Error, CustomStringConvertible {
150151
case invalidArgument(String)
151-
152+
152153
var description: String {
153154
switch self {
154155
case .invalidArgument(let description):

Plugins/AWSLambdaInitializer/Plugin.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ struct AWSLambdaPackager: CommandPlugin {
2020

2121
func performCommand(context: PackagePlugin.PluginContext, arguments: [String]) async throws {
2222
let tool = try context.tool(named: "AWSLambdaPluginHelper")
23-
23+
2424
let args = ["init", "--dest-dir", context.package.directoryURL.path()] + arguments
2525

2626
// Invoke the plugin helper on the target directory, passing a configuration
@@ -35,4 +35,3 @@ struct AWSLambdaPackager: CommandPlugin {
3535
}
3636
}
3737
}
38-

Sources/AWSLambdaPluginHelper/AWSLambdaPluginHelper.swift

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414

1515
@main
1616
struct AWSLambdaPluginHelper {
17-
17+
1818
private enum Command: String {
1919
case `init`
2020
case build
2121
case deploy
2222
}
23-
23+
2424
public static func main() async throws {
2525
let args = CommandLine.arguments
2626
let helper = AWSLambdaPluginHelper()
@@ -34,18 +34,18 @@ struct AWSLambdaPluginHelper {
3434
try await Deployer().deploy(arguments: args)
3535
}
3636
}
37-
37+
3838
private func command(from arguments: [String]) throws -> Command {
3939
let args = CommandLine.arguments
40-
40+
4141
guard args.count > 2 else {
4242
throw AWSLambdaPluginHelperError.noCommand
4343
}
4444
let commandName = args[1]
4545
guard let command = Command(rawValue: commandName) else {
4646
throw AWSLambdaPluginHelperError.invalidCommand(commandName)
4747
}
48-
48+
4949
return command
5050
}
5151
}
@@ -54,4 +54,3 @@ private enum AWSLambdaPluginHelperError: Error {
5454
case noCommand
5555
case invalidCommand(String)
5656
}
57-

Sources/AWSLambdaPluginHelper/Vendored/crypto/Padding.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public protocol PaddingProtocol {
3333
}
3434

3535
public enum Padding: PaddingProtocol {
36-
case noPadding, zeroPadding
36+
case noPadding, zeroPadding
3737
public func add(to: [UInt8], blockSize: Int) -> [UInt8] {
3838
switch self {
3939
case .noPadding:

Sources/AWSLambdaPluginHelper/Vendored/spm/ArgumentExtractor.swift

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,11 @@ public struct ArgumentExtractor {
5050
values.append(val)
5151
args.remove(at: idx)
5252
}
53-
}
54-
else if arg.starts(with: "--\(name)=") {
53+
} else if arg.starts(with: "--\(name)=") {
5554
arg.removeFirst(2 + name.count + 1)
5655
values.append(arg)
5756
args.remove(at: idx)
58-
}
59-
else {
57+
} else {
6058
idx += 1
6159
}
6260
}
@@ -72,8 +70,7 @@ public struct ArgumentExtractor {
7270
if arg == "--\(name)" {
7371
args.remove(at: idx)
7472
count += 1
75-
}
76-
else {
73+
} else {
7774
idx += 1
7875
}
7976
}
@@ -82,11 +79,11 @@ public struct ArgumentExtractor {
8279

8380
/// Returns any unextracted flags or options (based strictly on whether remaining arguments have a "--" prefix).
8481
public var unextractedOptionsOrFlags: [String] {
85-
return args.filter{ $0.hasPrefix("--") }
82+
args.filter { $0.hasPrefix("--") }
8683
}
8784

8885
/// Returns all remaining arguments, including any literals after the first `--` if there is one.
8986
public var remainingArguments: [String] {
90-
return args + literals
87+
args + literals
9188
}
92-
}
89+
}

0 commit comments

Comments
 (0)