Skip to content

Ensure we parse diagnostics from CustomTasks in PIF #85

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
Feb 5, 2025
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
2 changes: 1 addition & 1 deletion Sources/SWBCore/CustomTaskTypeDescription.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public final class CustomTaskTypeDescription: TaskTypeDescription {
}

public func customOutputParserType(for task: any ExecutableTask) -> (any TaskOutputParser.Type)? {
nil
ShellScriptOutputParser.self
}

public func interestingPath(for task: any ExecutableTask) -> Path? {
Expand Down
104 changes: 104 additions & 0 deletions Tests/SWBBuildSystemTests/CustomTaskBuildOperationTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
//===----------------------------------------------------------------------===//
//
// 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 SWBTestSupport
import SWBTaskExecution
import SWBUtil

@Suite
fileprivate struct CustomTaskBuildOperationTests: CoreBasedTests {

@Test(.requireSDKs(.host))
func outputParsing() async throws {
try await withTemporaryDirectory { tmpDir in
let testProject = TestProject(
"aProject",
sourceRoot: tmpDir,
groupTree: TestGroup(
"SomeFiles", path: "Sources",
children: [
TestFile("tool.swift"),
TestFile("foo.c"),
]),
buildConfigurations: [
TestBuildConfiguration(
"Debug",
buildSettings: [
"GENERATE_INFOPLIST_FILE": "YES",
"PRODUCT_NAME": "$(TARGET_NAME)",
"SWIFT_VERSION": try await swiftVersion,
"SDKROOT": "auto",
"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)/tool"],
environment: [:],
workingDirectory: tmpDir.str,
executionDescription: "My Custom Task",
inputs: ["$(BUILD_DIR)/$(CONFIGURATION)/tool"],
outputs: [Path.root.join("output").str],
enableSandboxing: false,
preparesForIndexing: false)
],
dependencies: ["tool"]
),
TestStandardTarget(
"tool", type: .hostBuildTool,
buildPhases: [
TestSourcesBuildPhase(["tool.swift"])
]
),
])
let core = try await getCore()
let tester = try await BuildOperationTester(core, testProject, simulated: false)

let parameters = BuildParameters(action: .build, configuration: "Debug")

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) { results in
results.checkWarning(.contains("this is a warning"))
results.checkNoDiagnostics()
}
}
}
}