-
Notifications
You must be signed in to change notification settings - Fork 187
Expand file tree
/
Copy pathCustomTaskBuildOperationTests.swift
More file actions
113 lines (104 loc) · 4.6 KB
/
Copy pathCustomTaskBuildOperationTests.swift
File metadata and controls
113 lines (104 loc) · 4.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2024 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 Testing
import SWBBuildSystem
import SWBCore
import SWBProtocol
import SWBTestSupport
import SWBTaskExecution
import SWBUtil
import SWBProtocol
import class Foundation.ProcessInfo
@Suite
fileprivate struct CustomTaskBuildOperationTests: CoreBasedTests {
@Test(.requireSDKs(.host))
func outputParsing() async throws {
try await withTemporaryDirectory { tmpDir in
let destination: RunDestinationInfo = .host
let core = try await getCore()
let toolchain = try #require(core.toolchainRegistry.defaultToolchain)
let environment = destination.hostRuntimeEnvironment(core)
let testProject = TestProject(
"aProject",
sourceRoot: tmpDir,
groupTree: TestGroup(
"SomeFiles", path: "Sources",
children: [
TestFile("tool.swift"),
TestFile("foo.c"),
]),
buildConfigurations: [
TestBuildConfiguration(
"Debug",
buildSettings: [
"ARCHS": "$(ARCHS_STANDARD)",
"GENERATE_INFOPLIST_FILE": "YES",
"PRODUCT_NAME": "$(TARGET_NAME)",
"SWIFT_VERSION": try await swiftVersion,
"SDKROOT": "$(HOST_PLATFORM)",
"SUPPORTED_PLATFORMS": "$(HOST_PLATFORM)",
"CODE_SIGNING_ALLOWED": "NO",
"MACOSX_DEPLOYMENT_TARGET": "$(RECOMMENDED_MACOSX_DEPLOYMENT_TARGET)"
]),
],
targets: [
TestStandardTarget(
"CoreFoo", type: .dynamicLibrary,
buildPhases: [
TestSourcesBuildPhase(["foo.c"])
],
customTasks: [
TestCustomTask(
commandLine: ["$(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/tool\(destination == .windows ? ".exe" : "")"],
environment: .init(environment),
workingDirectory: tmpDir.str,
executionDescription: "My Custom Task",
inputs: ["$(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/tool\(destination == .windows ? ".exe" : "")"],
outputs: [Path.root.join("output").str],
enableSandboxing: false,
preparesForIndexing: false)
],
dependencies: ["tool"]
),
TestStandardTarget(
"tool", type: .hostBuildTool,
buildPhases: [
TestSourcesBuildPhase(["tool.swift"])
]
),
])
let tester = try await BuildOperationTester(core, testProject, simulated: false)
let parameters = BuildParameters(action: .build, configuration: "Debug", activeRunDestination: .host)
try await tester.fs.writeFileContents(tmpDir.join("Sources").join("tool.swift")) { stream in
stream <<<
"""
@main
struct Entry {
static func main() {
print("warning: this is a warning")
}
}
"""
}
try await tester.fs.writeFileContents(tmpDir.join("Sources").join("foo.c")) { stream in
stream <<<
"""
void foo(void) {}
"""
}
try await tester.checkBuild(parameters: parameters, runDestination: .host) { results in
results.checkWarning(.contains("this is a warning"))
results.checkNoDiagnostics()
}
}
}
}