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
|
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
import ArgumentParser
import Foundation
struct Build: ParsableCommand {
static let configuration = CommandConfiguration(
abstract: "Build swift-syntax."
)
@OptionGroup
var arguments: BuildArguments
func run() throws {
let executor = BuildExecutor(
swiftPMBuilder: SwiftPMBuilder(
toolchain: try arguments.toolchain,
buildDir: arguments.buildDir,
multirootDataFile: arguments.multirootDataFile,
release: arguments.release,
enableRawSyntaxValidation: arguments.enableRawSyntaxValidation,
enableTestFuzzing: arguments.enableTestFuzzing,
verbose: arguments.verbose
),
warningsAsErrors: arguments.warningsAsErrors
)
try executor.run()
}
}
struct BuildExecutor {
private let swiftPMBuilder: SwiftPMBuilder
private let warningsAsErrors: Bool
init(swiftPMBuilder: SwiftPMBuilder, warningsAsErrors: Bool = false) {
self.swiftPMBuilder = swiftPMBuilder
self.warningsAsErrors = warningsAsErrors
}
func run() throws {
try swiftPMBuilder.buildTarget(
packageDir: Paths.packageDir,
targetName: "SwiftSyntax-all",
warningsAsErrors: self.warningsAsErrors
)
// Never build examples with `warningsAsErrors`. Some of the macro examples are expected to generate warnings.
try swiftPMBuilder.buildTarget(packageDir: Paths.examplesDir, targetName: "Examples-all", warningsAsErrors: false)
try swiftPMBuilder.buildTarget(
packageDir: Paths.swiftParserCliDir,
targetName: "swift-parser-cli",
warningsAsErrors: self.warningsAsErrors
)
try buildEditorExtension()
}
private func buildEditorExtension() throws {
#if os(macOS)
logSection("Building Editor Extension")
try invokeXcodeBuild(projectPath: Paths.editorExtensionProjectPath, scheme: "SwiftRefactorExtension")
#endif
}
@discardableResult
private func invokeXcodeBuild(projectPath: URL, scheme: String) throws -> ProcessResult {
try withTemporaryDirectory { tempDir in
let processRunner = ProcessRunner(
executableURL: try Paths.xcodebuildExec,
arguments: [
"-project", projectPath.path,
"-scheme", scheme,
"-derivedDataPath", tempDir.path,
],
additionalEnvironment: [:]
)
let result = try processRunner.run(verbose: swiftPMBuilder.verbose)
return result
}
}
}
|