Skip to content

Run CodeGeneration tests in CI #2171

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,48 +24,47 @@ struct Test: ParsableCommand, BuildCommand {
var arguments: BuildArguments

func run() throws {
try buildExample(exampleName: "ExamplePlugin")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious, and unrelated to the PR: why remove the buildExample step? Do we build in another command now? (Just learning about the scripts, and will read more — very likely that I'll stumble at the answer on my own in 5 minutes)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, we needed to build the example for the lit test, which I removed in #2160. I just forgot to remove buildExample in that PR.


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(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is neat!

action: "test",
packageDir: Paths.packageDir,
packageDir: Paths.codeGenerationDir,
additionalArguments: swiftpmCallArguments,
additionalEnvironment: additionalEnvironment,
additionalEnvironment: swiftPMEnvironmentVariables,
captureStdout: false,
captureStderr: false
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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"

Expand All @@ -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
)
Expand Down