Files
David Evans 94e3fb42f5 Update dependencies (#493)
* Update packages

* Run swift format

* Update
2021-03-23 17:21:41 +00:00

64 lines
1.7 KiB
Swift

//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftNIO open source project
//
// Copyright (c) 2020 Apple Inc. and the SwiftNIO project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of SwiftNIO project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//
import Foundation
#if canImport(Darwin)
import Darwin
#else
import Glibc
#endif
#if os(Linux) || os(macOS)
let filePath: String
#if compiler(>=5.3)
filePath = (#file)
#else
filePath = (#file)
#endif
let swiftFormat = URL(fileURLWithPath: CommandLine.arguments.first!)
.deletingLastPathComponent()
.appendingPathComponent("swiftformat")
let sourceCode = URL(fileURLWithPath: filePath)
.deletingLastPathComponent()
.deletingLastPathComponent()
.deletingLastPathComponent()
if #available(macOS 10.13, /* Linux */ *) {
print("Alright, let's format the source code in \(sourceCode) using \(swiftFormat).")
let process = Process()
process.executableURL = swiftFormat
process.arguments = [
sourceCode.path,
"--self", "insert",
"--extensionacl", "on-declarations",
]
try process.run()
process.waitUntilExit()
switch process.terminationReason {
case .exit:
exit(process.terminationStatus)
case .uncaughtSignal:
kill(getpid(), process.terminationStatus)
#if canImport(Darwin)
@unknown default:
exit(process.terminationStatus)
#endif
}
}
#endif
// Fallthrough, something wasn't right
print("ERROR: Unsupported OS\n")
exit(EXIT_FAILURE)