Skip to content

Commit b557129

Browse files
authored
Merge pull request #6 from cybozu/output-message
Warning text is now displayed in Xcode
2 parents 1bdc8c7 + b8398ef commit b557129

File tree

6 files changed

+32
-18
lines changed

6 files changed

+32
-18
lines changed

Package.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ let package = Package(
1010
products: [
1111
.executable(
1212
name: "license-checker",
13-
targets: ["LicenseChecker"]
13+
targets: ["license-checker"]
1414
),
1515
.plugin(
1616
name: "LicenseCheckerPlugin",
@@ -26,7 +26,7 @@ let package = Package(
2626
targets: [
2727
.target(name: "LicenseCheckerModule"),
2828
.executableTarget(
29-
name: "LicenseChecker",
29+
name: "license-checker",
3030
dependencies: [
3131
.target(name: "LicenseCheckerModule"),
3232
.product(
@@ -52,15 +52,15 @@ let package = Package(
5252
.testTarget(
5353
name: "LicenseCheckerTests",
5454
dependencies: [
55-
.target(name: "LicenseChecker"),
55+
.target(name: "license-checker"),
5656
.target(name: "TestResources")
5757
]
5858
),
5959
.plugin(
6060
name: "LicenseCheckerPlugin",
6161
capability: .buildTool(),
6262
dependencies: [
63-
.target(name: "LicenseChecker")
63+
.target(name: "license-checker")
6464
]
6565
)
6666
]

Plugins/LicenseCheckerPlugin/main.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import PackagePlugin
44
@main
55
struct LicenseCheckerPlugin: BuildToolPlugin {
66
struct SourcePackagesNotFoundError: Error & CustomStringConvertible {
7-
let description: String = "SourcePackages not found"
7+
let description: String = "error: SourcePackages not found"
88
}
99

1010
func sourcePackages(_ pluginWorkDirectory: Path) throws -> Path {
@@ -19,7 +19,7 @@ struct LicenseCheckerPlugin: BuildToolPlugin {
1919
}
2020

2121
func createBuildCommands(context: PluginContext, target: Target) async throws -> [Command] {
22-
let executablePath = try context.tool(named: "LicenseChecker").path
22+
let executablePath = try context.tool(named: "license-checker").path
2323
let sourcePackagesPath = try sourcePackages(context.pluginWorkDirectory)
2424
let whiteListPath = context.package.directory.appending(subpath: "white-list.json")
2525

@@ -48,7 +48,7 @@ import XcodeProjectPlugin
4848
/// This command works with `Run Build Tool Plug-ins` in Xcode `Build Phase`.
4949
extension LicenseCheckerPlugin: XcodeBuildToolPlugin {
5050
func createBuildCommands(context: XcodePluginContext, target: XcodeTarget) throws -> [Command] {
51-
let executablePath = try context.tool(named: "LicenseChecker").path
51+
let executablePath = try context.tool(named: "license-checker").path
5252
let sourcePackagesPath = try sourcePackages(context.pluginWorkDirectory)
5353
let whiteListPath = context.xcodeProject.directory.appending(subpath: "white-list.json")
5454

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
11
import Foundation
22

3-
public enum LCError: Error, LocalizedError {
3+
public enum LCError: LocalizedError {
44
case notLoadedWorkspaceState
55
case notLoadedWhiteList
66
case forbiddenLibraryFound
77

88
public var errorDescription: String? {
99
switch self {
1010
case .notLoadedWorkspaceState:
11-
return "🚨 Couldn't load workspace-state.json"
11+
"Couldn't load workspace-state.json"
1212
case .notLoadedWhiteList:
13-
return "🚨 Couldn't load white-list.json"
13+
"Couldn't load white-list.json"
1414
case .forbiddenLibraryFound:
15-
return "🚨 Library with forbidden license is found."
15+
"Library with forbidden license is found."
16+
}
17+
}
18+
19+
public var exitCode: Int32 {
20+
switch self {
21+
case .notLoadedWorkspaceState: 1
22+
case .notLoadedWhiteList: 2
23+
case .forbiddenLibraryFound: 3
1624
}
1725
}
1826
}

Sources/LicenseChecker/LicenseChecker.swift renamed to Sources/license-checker/LicenseChecker.swift

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import ArgumentParser
2+
import Darwin
23
import LicenseCheckerModule
34

45
struct LicenseChecker: ParsableCommand {
@@ -21,9 +22,14 @@ struct LicenseChecker: ParsableCommand {
2122
var whiteListPath: String
2223

2324
mutating func run() throws {
24-
try LCMain().run(
25-
sourcePackagesPath: self.sourcePackagesPath,
26-
whiteListPath: self.whiteListPath
27-
)
25+
do {
26+
try LCMain().run(
27+
sourcePackagesPath: self.sourcePackagesPath,
28+
whiteListPath: self.whiteListPath
29+
)
30+
} catch let error as LCError {
31+
Swift.print("error:", error.errorDescription!)
32+
Darwin.exit(error.exitCode)
33+
}
2834
}
2935
}
File renamed without changes.

Tests/LicenseCheckerTests/LicenseCheckerTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ final class LicenseCheckerTests: XCTestCase {
175175
let data = pipe.fileHandleForReading.readDataToEndOfFile()
176176
let output = try XCTUnwrap(String(data: data, encoding: .utf8))
177177

178-
XCTAssertTrue(output.hasSuffix("🚨 Couldn't load workspace-state.json\n"))
178+
XCTAssertTrue(output.hasSuffix("error: Couldn't load workspace-state.json\n"))
179179
XCTAssertEqual(process.terminationStatus, 1)
180180
}
181181

@@ -194,7 +194,7 @@ final class LicenseCheckerTests: XCTestCase {
194194
let data = pipe.fileHandleForReading.readDataToEndOfFile()
195195
let output = try XCTUnwrap(String(data: data, encoding: .utf8))
196196

197-
XCTAssertTrue(output.hasSuffix("🚨 Couldn't load white-list.json\n"))
197+
XCTAssertTrue(output.hasSuffix("error: Couldn't load white-list.json\n"))
198198
XCTAssertEqual(process.terminationStatus, 1)
199199
}
200200

@@ -213,7 +213,7 @@ final class LicenseCheckerTests: XCTestCase {
213213
let data = pipe.fileHandleForReading.readDataToEndOfFile()
214214
let output = try XCTUnwrap(String(data: data, encoding: .utf8))
215215

216-
XCTAssertTrue(output.hasSuffix("🚨 Library with forbidden license is found.\n"))
216+
XCTAssertTrue(output.hasSuffix("error: Library with forbidden license is found.\n"))
217217
XCTAssertEqual(process.terminationStatus, 1)
218218
}
219219
}

0 commit comments

Comments
 (0)