diff --git a/SwiftSyntaxDevUtils/Sources/swift-syntax-dev-utils/commands/Build.swift b/SwiftSyntaxDevUtils/Sources/swift-syntax-dev-utils/commands/Build.swift index cc8000a1fc1..22d2742f485 100644 --- a/SwiftSyntaxDevUtils/Sources/swift-syntax-dev-utils/commands/Build.swift +++ b/SwiftSyntaxDevUtils/Sources/swift-syntax-dev-utils/commands/Build.swift @@ -20,5 +20,13 @@ struct Build: ParsableCommand, BuildCommand { func run() throws { try buildTarget(packageDir: Paths.packageDir, targetName: "SwiftSyntax-all") try buildTarget(packageDir: Paths.examplesDir, targetName: "Examples-all") + try buildEditorExtension() + } + + private func buildEditorExtension() throws { + #if os(macOS) + logSection("Building Editor Extension") + try invokeXcodeBuild(projectPath: Paths.editorExtensionProjectPath) + #endif } } diff --git a/SwiftSyntaxDevUtils/Sources/swift-syntax-dev-utils/common/BuildCommand.swift b/SwiftSyntaxDevUtils/Sources/swift-syntax-dev-utils/common/BuildCommand.swift index fc19ac0a218..d321edbc49d 100644 --- a/SwiftSyntaxDevUtils/Sources/swift-syntax-dev-utils/common/BuildCommand.swift +++ b/SwiftSyntaxDevUtils/Sources/swift-syntax-dev-utils/common/BuildCommand.swift @@ -89,6 +89,27 @@ extension BuildCommand { return result } + @discardableResult + func invokeXcodeBuild(projectPath: URL) throws -> ProcessResult { + guard let xcodebuildExec = Paths.xcodebuildExec else { + throw ScriptExectutionError( + message: """ + Error: Could not find xcodebuild. + Looking at '\(Paths.xcodebuildExec?.path ?? "N/A")'. + """ + ) + } + let processRunner = ProcessRunner( + executableURL: xcodebuildExec, + arguments: ["-project", projectPath.path], + additionalEnvironment: [:] + ) + + let result = try processRunner.run(verbose: arguments.verbose) + + return result + } + private func build(packageDir: URL, name: String, isProduct: Bool) throws { let args: [String] diff --git a/SwiftSyntaxDevUtils/Sources/swift-syntax-dev-utils/common/Paths.swift b/SwiftSyntaxDevUtils/Sources/swift-syntax-dev-utils/common/Paths.swift index a0b7a05a8ac..48a42e5e42f 100644 --- a/SwiftSyntaxDevUtils/Sources/swift-syntax-dev-utils/common/Paths.swift +++ b/SwiftSyntaxDevUtils/Sources/swift-syntax-dev-utils/common/Paths.swift @@ -37,6 +37,12 @@ enum Paths { .appendingPathComponent("CodeGeneration") } + static var editorExtensionProjectPath: URL { + packageDir + .appendingPathComponent("EditorExtension") + .appendingPathComponent("SwiftRefactorExtension.xcodeproj") + } + static var workspaceDir: URL { packageDir .deletingLastPathComponent() @@ -63,6 +69,10 @@ enum Paths { return lookupExecutable(for: "diff") } + static var xcodebuildExec: URL? { + return lookupExecutable(for: "xcodebuild") + } + private static var envSearchPaths: [URL] { // Compute search paths from PATH variable. #if os(Windows)