-
Notifications
You must be signed in to change notification settings - Fork 139
Add initial support for generating non-Darwin test entrypoints #390
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
Sources/SWBUniversalPlatform/Specs/TestEntryPointGenerator.xcspec
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // This source file is part of the Swift open source project | ||
| // | ||
| // Copyright (c) 2025 Apple Inc. and the Swift project authors | ||
| // Licensed under Apache License v2.0 with Runtime Library Exception | ||
| // | ||
| // See http://swift.org/LICENSE.txt for license information | ||
| // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| ( | ||
| { Identifier = "org.swift.test-entry-point-generator"; | ||
| Type = Compiler; | ||
| Name = "Generate Test Entry Point"; | ||
| Description = "Generates the entry point for a test target."; | ||
| CommandLine = "builtin-generateTestEntryPoint [options] --output $(OutputPath)"; | ||
| RuleName = "GenerateTestEntryPoint $(OutputPath)"; | ||
| ExecDescription = "Generate entry point for $(PRODUCT_NAME)"; | ||
| Outputs = ( | ||
| "$(OutputPath)" | ||
| ); | ||
| Options = ( | ||
| ); | ||
| } | ||
| ) |
83 changes: 83 additions & 0 deletions
83
Sources/SWBUniversalPlatform/TestEntryPointGenerationTaskAction.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // This source file is part of the Swift open source project | ||
| // | ||
| // Copyright (c) 2025 Apple Inc. and the Swift project authors | ||
| // Licensed under Apache License v2.0 with Runtime Library Exception | ||
| // | ||
| // See http://swift.org/LICENSE.txt for license information | ||
| // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| import SWBUtil | ||
| import SWBCore | ||
| import SWBTaskExecution | ||
| import ArgumentParser | ||
|
|
||
| class TestEntryPointGenerationTaskAction: TaskAction { | ||
| override class var toolIdentifier: String { | ||
| "TestEntryPointGenerationTaskAction" | ||
| } | ||
|
|
||
| override func performTaskAction(_ task: any ExecutableTask, dynamicExecutionDelegate: any DynamicTaskExecutionDelegate, executionDelegate: any TaskExecutionDelegate, clientDelegate: any TaskExecutionClientDelegate, outputDelegate: any TaskOutputDelegate) async -> CommandResult { | ||
| do { | ||
| let options = try Options.parse(Array(task.commandLineAsStrings.dropFirst())) | ||
| try executionDelegate.fs.write(options.output, contents: #""" | ||
| #if canImport(Testing) | ||
| import Testing | ||
| #endif | ||
|
|
||
| @main | ||
| @available(macOS 10.15, iOS 11, watchOS 4, tvOS 11, visionOS 1, *) | ||
| @available(*, deprecated, message: "Not actually deprecated. Marked as deprecated to allow inclusion of deprecated tests (which test deprecated functionality) without warnings") | ||
| struct Runner { | ||
| private static func testingLibrary() -> String { | ||
| var iterator = CommandLine.arguments.makeIterator() | ||
| while let argument = iterator.next() { | ||
| if argument == "--testing-library", let libraryName = iterator.next() { | ||
| return libraryName.lowercased() | ||
| } | ||
| } | ||
|
|
||
| // Fallback if not specified: run XCTest (legacy behavior) | ||
| return "xctest" | ||
| } | ||
|
|
||
| #if os(Linux) | ||
| @_silgen_name("$ss13_runAsyncMainyyyyYaKcF") | ||
| private static func _runAsyncMain(_ asyncFun: @Sendable @escaping () async throws -> ()) | ||
|
|
||
| static func main() { | ||
| let testingLibrary = Self.testingLibrary() | ||
| #if canImport(Testing) | ||
| if testingLibrary == "swift-testing" { | ||
| _runAsyncMain { | ||
| await Testing.__swiftPMEntryPoint() as Never | ||
| } | ||
| } | ||
| #endif | ||
| } | ||
| #else | ||
| static func main() async { | ||
| let testingLibrary = Self.testingLibrary() | ||
| #if canImport(Testing) | ||
| if testingLibrary == "swift-testing" { | ||
| await Testing.__swiftPMEntryPoint() as Never | ||
| } | ||
| #endif | ||
| } | ||
| #endif | ||
| } | ||
| """#) | ||
| return .succeeded | ||
| } catch { | ||
| outputDelegate.emitError("\(error)") | ||
| return .failed | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private struct Options: ParsableArguments { | ||
| @Option var output: Path | ||
| } | ||
23 changes: 23 additions & 0 deletions
23
Sources/SWBUniversalPlatform/TestEntryPointGenerationTool.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // This source file is part of the Swift open source project | ||
| // | ||
| // Copyright (c) 2025 Apple Inc. and the Swift project authors | ||
| // Licensed under Apache License v2.0 with Runtime Library Exception | ||
| // | ||
| // See http://swift.org/LICENSE.txt for license information | ||
| // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| import SWBUtil | ||
| import SWBMacro | ||
| import SWBCore | ||
|
|
||
| final class TestEntryPointGenerationToolSpec: GenericCommandLineToolSpec, SpecIdentifierType, @unchecked Sendable { | ||
| static let identifier = "org.swift.test-entry-point-generator" | ||
|
|
||
| override func createTaskAction(_ cbc: CommandBuildContext, _ delegate: any TaskGenerationDelegate) -> (any PlannedTaskAction)? { | ||
| TestEntryPointGenerationTaskAction() | ||
| } | ||
| } |
35 changes: 35 additions & 0 deletions
35
Sources/SWBUniversalPlatform/TestEntryPointTaskProducer.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // This source file is part of the Swift open source project | ||
| // | ||
| // Copyright (c) 2025 Apple Inc. and the Swift project authors | ||
| // Licensed under Apache License v2.0 with Runtime Library Exception | ||
| // | ||
| // See http://swift.org/LICENSE.txt for license information | ||
| // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| import SWBCore | ||
| import SWBTaskConstruction | ||
|
|
||
| class TestEntryPointTaskProducer: PhasedTaskProducer, TaskProducer { | ||
| func generateTasks() async -> [any PlannedTask] { | ||
| var tasks: [any PlannedTask] = [] | ||
| if context.settings.globalScope.evaluate(BuiltinMacros.GENERATE_TEST_ENTRY_POINT) { | ||
| await self.appendGeneratedTasks(&tasks) { delegate in | ||
| let scope = context.settings.globalScope | ||
| let outputPath = scope.evaluate(BuiltinMacros.GENERATED_TEST_ENTRY_POINT_PATH) | ||
| let cbc = CommandBuildContext(producer: context, scope: scope, inputs: [], outputs: [outputPath]) | ||
| await context.testEntryPointGenerationToolSpec.constructTasks(cbc, delegate) | ||
| } | ||
| } | ||
| return tasks | ||
| } | ||
| } | ||
|
|
||
| extension TaskProducerContext { | ||
| var testEntryPointGenerationToolSpec: TestEntryPointGenerationToolSpec { | ||
| return workspaceContext.core.specRegistry.getSpec(TestEntryPointGenerationToolSpec.identifier, domain: domain) as! TestEntryPointGenerationToolSpec | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.