Skip to content

Commit 1558dc9

Browse files
committed
cleanup
1 parent e9555cb commit 1558dc9

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

Plugins/MetaProtocolCodable/Plugin.swift

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ struct MetaProtocolCodable: BuildToolPlugin {
4646
) throws -> [Command] where Context: MetaProtocolCodablePluginContext {
4747
// Get config
4848
let tool = try context.tool(named: "ProtocolGen")
49+
#if swift(<6)
50+
let toolUrl = URL(string: tool.path.string)!
51+
#else
52+
let toolUrl = tool.url
53+
#endif
4954
let config = try fetchConfig(for: target)
5055
let (allTargets, imports) = config.scanInput(for: target, in: context)
5156

@@ -61,25 +66,28 @@ struct MetaProtocolCodable: BuildToolPlugin {
6166
return target.sourceFiles(withSuffix: "swift").map { file in
6267
let moduleName = target.moduleName
6368
#if swift(<6)
64-
let fileName = URL(string: file.path.string)!
69+
let fileUrl = URL(string: file.path.string)!
6570
#else
66-
let fileName = file.url.lastPathComponent
71+
let fileUrl = file.url
6772
#endif
73+
let fileName = fileUrl.deletingPathExtension().lastPathComponent
6874
let genFileName = "\(moduleName)-\(fileName)-gen.json"
6975
let genFile = genFolder.appending(path: genFileName)
7076
intermFiles.append(genFile)
77+
78+
7179
return Command.buildCommand(
7280
displayName: """
7381
Parse source file "\(fileName)" in module "\(moduleName)"
7482
""",
75-
executable: tool.url,
83+
executable: toolUrl,
7684
arguments: [
7785
"parse",
78-
file.url.absoluteString,
86+
fileUrl.absoluteString,
7987
"--output",
8088
genFile.absoluteString,
8189
],
82-
inputFiles: [file.url],
90+
inputFiles: [fileUrl],
8391
outputFiles: [genFile]
8492
)
8593
}
@@ -88,7 +96,7 @@ struct MetaProtocolCodable: BuildToolPlugin {
8896
// Create syntax generation command
8997
let moduleName = target.moduleName
9098
let genFileName = "\(moduleName)+ProtocolHelperCoders.swift"
91-
let genPath = genFolder.appending(path:genFileName)
99+
let genPath = genFolder.appending(path: genFileName)
92100
var genArgs = ["generate", "--output", genPath.absoluteString]
93101
for `import` in imports {
94102
genArgs.append(contentsOf: ["--module", `import`])
@@ -101,7 +109,7 @@ struct MetaProtocolCodable: BuildToolPlugin {
101109
displayName: """
102110
Generate protocol decoding/encoding syntax for "\(moduleName)"
103111
""",
104-
executable: tool.url,
112+
executable: toolUrl,
105113
arguments: genArgs,
106114
inputFiles: intermFiles,
107115
outputFiles: [genPath]

Plugins/MetaProtocolCodable/SourceTarget/SwiftPackageTarget.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ struct SwiftPackageTarget {
99
///
1010
/// The conformances provided uses this module.
1111
let module: any SourceModuleTarget
12-
1312
}
1413

1514
/// This is a workaround because PackageDescription.Target.directoryURL will not be available until version 6.1
@@ -54,7 +53,7 @@ extension SwiftPackageTarget: MetaProtocolCodableSourceTarget {
5453
default:
5554
nil
5655
}
57-
}.map { (target: any SourceModuleTarget) in Self.init(module: target) }
56+
}.map { Self.init(module: $0) }
5857
}
5958

6059
/// All the targets on which current target depends on.
@@ -93,7 +92,7 @@ extension SwiftPackageTarget: MetaProtocolCodableSourceTarget {
9392
let contents = try fileManager.contentsOfDirectory(at: directory, includingPropertiesForKeys: nil)
9493
let file = contents.first { file in
9594
return name.lowercased()
96-
== file.lastPathComponent
95+
== file.deletingPathExtension().lastPathComponent
9796
.components(separatedBy: .alphanumerics.inverted)
9897
.joined(separator: "")
9998
.lowercased()

0 commit comments

Comments
 (0)