From 9dfc53212bc6e2d34ac2fd23a80d8359e64f8545 Mon Sep 17 00:00:00 2001 From: Alex Hoppen Date: Fri, 8 Sep 2023 09:40:18 -0700 Subject: [PATCH] Run CodeGeneration tests in CI With the migration of build-script.py to Swift, we accidentally dropped running the CodeGeneration tests. Re-enable them. --- .../commands/Test.swift | 45 +++++++++---------- .../common/BuildCommand.swift | 37 +++++++-------- 2 files changed, 38 insertions(+), 44 deletions(-) diff --git a/SwiftSyntaxDevUtils/Sources/swift-syntax-dev-utils/commands/Test.swift b/SwiftSyntaxDevUtils/Sources/swift-syntax-dev-utils/commands/Test.swift index 68a89a2896b..6a5c3270cf0 100644 --- a/SwiftSyntaxDevUtils/Sources/swift-syntax-dev-utils/commands/Test.swift +++ b/SwiftSyntaxDevUtils/Sources/swift-syntax-dev-utils/commands/Test.swift @@ -24,48 +24,47 @@ struct Test: ParsableCommand, BuildCommand { var arguments: BuildArguments func run() throws { - try buildExample(exampleName: "ExamplePlugin") - try runTests() + try runCodeGenerationTests() logSection("All tests passed") } private func runTests() throws { logSection("Running SwiftSyntax Tests") - var swiftpmCallArguments: [String] = [] + var swiftpmCallArguments = [ + "--test-product", "swift-syntaxPackageTests", + ] if arguments.verbose { swiftpmCallArguments += ["--verbose"] } - swiftpmCallArguments += ["--test-product", "swift-syntaxPackageTests"] - - var additionalEnvironment: [String: String] = [:] - additionalEnvironment["SWIFT_BUILD_SCRIPT_ENVIRONMENT"] = "1" + try invokeSwiftPM( + action: "test", + packageDir: Paths.packageDir, + additionalArguments: swiftpmCallArguments, + additionalEnvironment: swiftPMEnvironmentVariables, + captureStdout: false, + captureStderr: false + ) + } - if arguments.enableRawSyntaxValidation { - additionalEnvironment["SWIFTSYNTAX_ENABLE_RAWSYNTAX_VALIDATION"] = "1" - } + private func runCodeGenerationTests() throws { + logSection("Running CodeGeneration Tests") + var swiftpmCallArguments = [ + "--test-product", "CodeGenerationPackageTests", + ] - if arguments.enableTestFuzzing { - additionalEnvironment["SWIFTPARSER_ENABLE_ALTERNATE_TOKEN_INTROSPECTION"] = "1" + if arguments.verbose { + swiftpmCallArguments += ["--verbose"] } - // Tell other projects in the unified build to use local dependencies - additionalEnvironment["SWIFTCI_USE_LOCAL_DEPS"] = "1" - additionalEnvironment["SWIFT_SYNTAX_PARSER_LIB_SEARCH_PATH"] = - arguments.toolchain - .appendingPathComponent("lib") - .appendingPathComponent("swift") - .appendingPathComponent("macosx") - .path - try invokeSwiftPM( action: "test", - packageDir: Paths.packageDir, + packageDir: Paths.codeGenerationDir, additionalArguments: swiftpmCallArguments, - additionalEnvironment: additionalEnvironment, + additionalEnvironment: swiftPMEnvironmentVariables, captureStdout: false, captureStderr: false ) diff --git a/SwiftSyntaxDevUtils/Sources/swift-syntax-dev-utils/common/BuildCommand.swift b/SwiftSyntaxDevUtils/Sources/swift-syntax-dev-utils/common/BuildCommand.swift index be0293f8502..a0301c8902d 100644 --- a/SwiftSyntaxDevUtils/Sources/swift-syntax-dev-utils/common/BuildCommand.swift +++ b/SwiftSyntaxDevUtils/Sources/swift-syntax-dev-utils/common/BuildCommand.swift @@ -27,11 +27,6 @@ extension BuildCommand { try build(packageDir: packageDir, name: targetName, isProduct: false) } - func buildExample(exampleName: String) throws { - logSection("Building example " + exampleName) - try build(packageDir: Paths.examplesDir, name: exampleName, isProduct: true) - } - @discardableResult func invokeSwiftPM( action: String, @@ -116,15 +111,9 @@ extension BuildCommand { } } - private func build(packageDir: URL, name: String, isProduct: Bool) throws { - let args: [String] - - if isProduct { - args = ["--product", name] - } else { - args = ["--target", name] - } - + /// Environment variables that should be set when invoking `swift build` or + /// `swift test`. + var swiftPMEnvironmentVariables: [String: String] { var additionalEnvironment: [String: String] = [:] additionalEnvironment["SWIFT_BUILD_SCRIPT_ENVIRONMENT"] = "1" @@ -138,18 +127,24 @@ extension BuildCommand { // Tell other projects in the unified build to use local dependencies additionalEnvironment["SWIFTCI_USE_LOCAL_DEPS"] = "1" - additionalEnvironment["SWIFT_SYNTAX_PARSER_LIB_SEARCH_PATH"] = - arguments.toolchain - .appendingPathComponent("lib") - .appendingPathComponent("swift") - .appendingPathComponent("macos") - .path + + return additionalEnvironment + } + + private func build(packageDir: URL, name: String, isProduct: Bool) throws { + let args: [String] + + if isProduct { + args = ["--product", name] + } else { + args = ["--target", name] + } try invokeSwiftPM( action: "build", packageDir: packageDir, additionalArguments: args, - additionalEnvironment: additionalEnvironment, + additionalEnvironment: swiftPMEnvironmentVariables, captureStdout: false, captureStderr: false )