Skip to content

Commit 8eecb15

Browse files
authored
Merge pull request #511 from cwakamo/dev/add-multiple-target-test
Added a new test of the SwiftBuildMessage stream to ensure we get the right number of targetStarted events.
2 parents e7543d1 + 769b50e commit 8eecb15

File tree

1 file changed

+108
-0
lines changed

1 file changed

+108
-0
lines changed

Tests/SwiftBuildTests/BuildLogTests.swift

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,114 @@ struct BuildLogTests {
142142
}
143143
}
144144

145+
@Test(.requireSDKs(.macOS))
146+
func testTargetStartedEventsForMultipleTargets() async throws {
147+
try await withTemporaryDirectory { (temporaryDirectory: NamedTemporaryDirectory) in
148+
try await withAsyncDeferrable { deferrable in
149+
let tmpDirPath = temporaryDirectory.path
150+
let testSession = try await TestSWBSession(temporaryDirectory: temporaryDirectory)
151+
await deferrable.addBlock {
152+
await #expect(throws: Never.self) {
153+
try await testSession.close()
154+
}
155+
}
156+
157+
let srcroot = tmpDirPath.join("Test")
158+
159+
let dependencyTarget = TestStandardTarget(
160+
"Dependency", type: .objectFile,
161+
buildConfigurations: [
162+
TestBuildConfiguration(
163+
"Debug",
164+
buildSettings: [
165+
"PRODUCT_NAME": "$(TARGET_NAME)",
166+
"USE_HEADERMAP": "NO",
167+
"ALWAYS_SEARCH_USER_PATHS": "NO",
168+
// FIXME: There should be a way to automatically populate the version here, but since these tests are not CoreBasedTests, there isn't a good way to do so right now.
169+
"SWIFT_VERSION": "5.0",
170+
]),
171+
],
172+
buildPhases: [
173+
TestSourcesBuildPhase([
174+
TestBuildFile("Dependency.swift"),
175+
]),
176+
]
177+
)
178+
let dylibTarget = TestStandardTarget(
179+
"Dylib", type: .dynamicLibrary,
180+
buildConfigurations: [
181+
TestBuildConfiguration(
182+
"Debug",
183+
buildSettings: [
184+
"PRODUCT_NAME": "$(TARGET_NAME)",
185+
"USE_HEADERMAP": "NO",
186+
"ALWAYS_SEARCH_USER_PATHS": "NO",
187+
// FIXME: There should be a way to automatically populate the version here, but since these tests are not CoreBasedTests, there isn't a good way to do so right now.
188+
"SWIFT_VERSION": "5.0",
189+
]),
190+
],
191+
buildPhases: [
192+
TestSourcesBuildPhase([
193+
TestBuildFile("Dylib.swift"),
194+
]),
195+
TestFrameworksBuildPhase([
196+
TestBuildFile(.target("Dependency")),
197+
]),
198+
],
199+
dependencies: [
200+
"Dependency",
201+
]
202+
)
203+
204+
let testProject = TestProject(
205+
"aProject",
206+
defaultConfigurationName: "Release",
207+
groupTree: TestGroup("Foo", children: [
208+
TestFile("Dependency.swift"),
209+
TestFile("Dylib.swift"),
210+
]),
211+
targets: [dependencyTarget, dylibTarget])
212+
213+
let testWorkspace = TestWorkspace(
214+
"aWorkspace",
215+
sourceRoot: srcroot,
216+
projects: [testProject]
217+
)
218+
let SRCROOT = testWorkspace.sourceRoot.join("aProject")
219+
220+
let fs = localFS
221+
_ = try await CoreQualificationTester(testWorkspace, testSession, fs: fs)
222+
223+
// Write the test sources.
224+
try await fs.writeFileContents(SRCROOT.join("Dependency.swift")) { contents in
225+
contents <<< "open class MyClass {}\n"
226+
}
227+
try await fs.writeFileContents(SRCROOT.join("Dylib.swift")) { contents in
228+
contents <<< "internal import Dependency; final class DylibClass: DependencyClass {}\n"
229+
}
230+
231+
// Run a test build.
232+
var request = SWBBuildRequest()
233+
request.parameters = SWBBuildParameters()
234+
request.parameters.action = "build"
235+
request.parameters.configurationName = "Debug"
236+
request.add(target: SWBConfiguredTarget(guid: dylibTarget.guid, parameters: nil))
237+
238+
let events = try await testSession.runBuildOperation(request: request, delegate: TestBuildOperationDelegate())
239+
240+
let targetStartedInfos = events.compactMap {
241+
if case let .targetStarted(info) = $0 {
242+
return info
243+
} else {
244+
return nil
245+
}
246+
}
247+
248+
#expect(targetStartedInfos.count == 2)
249+
}
250+
}
251+
}
252+
145253
// Regression test for rdar://95168084 (invocation spits out json as part of log output)
146254
@Test(.requireSDKs(.macOS))
147255
func swiftParseableOutputDoesNotAppearInBuildLogWithWMO() async throws {

0 commit comments

Comments
 (0)