Skip to content

Commit 0e1e42f

Browse files
authored
Merge pull request #335 from tayloraswift/fix-322
don’t case-fold package names before constructing directory paths
2 parents 09a41f3 + 5aa700e commit 0e1e42f

File tree

8 files changed

+67
-69
lines changed

8 files changed

+67
-69
lines changed

Sources/SymbolGraphBuilder/Builds/SSGC.PackageBuild.swift

+13-8
Original file line numberDiff line numberDiff line change
@@ -112,24 +112,29 @@ extension SSGC.PackageBuild
112112
/// - flags:
113113
/// Additional flags to pass to the Swift compiler.
114114
public static
115-
func local(
116-
project projectName:Symbol.Package,
117-
among projects:FilePath.Directory,
115+
func local(project location:FilePath.Directory,
118116
using scratchName:FilePath.Component = ".build.ssgc",
119117
as type:SSGC.ProjectType = .package,
120118
flags:Flags = .init()) -> Self
121119
{
122120
/// The projects path could be absolute or relative. If it’s relative, we need to
123121
/// convert it to an absolute path.
124-
let projects:FilePath.Directory = projects.absolute()
125-
let project:FilePath.Directory = projects / "\(projectName)"
122+
let location:FilePath.Directory = location.absolute()
123+
/// For a local project, the project name is the last component of the path, lowercased.
124+
guard
125+
let last:FilePath.Component = location.path.components.last
126+
else
127+
{
128+
fatalError("Can’t build a Swift package at file system root!")
129+
}
130+
126131
let scratch:SSGC.PackageBuildDirectory = .init(configuration: .debug,
127-
location: project / scratchName)
132+
location: location / scratchName)
128133

129-
return .init(id: .unversioned(projectName),
134+
return .init(id: .unversioned(.init(last.string)),
130135
scratch: scratch,
131136
flags: flags,
132-
root: project,
137+
root: location,
133138
type: type)
134139
}
135140

Sources/SymbolGraphBuilder/SSGC.Compile.swift

+34-34
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ extension SSGC
7373
The symbolic name of the project to build — \
7474
this is not the name specified in the `Package.swift` manifest!
7575
""")
76-
var name:Symbol.Package
76+
var project:String
7777

7878
@Option(
7979
name: [.customLong("project-type"), .customShort("b")],
@@ -227,21 +227,26 @@ extension SSGC.Compile
227227

228228
let object:SymbolGraphObject<Void>
229229

230-
if self.name == .swift
231-
{
232-
object = try workspace.build(some: SSGC.StandardLibraryBuild.swift,
233-
toolchain: toolchain,
234-
status: status,
235-
logger: logger,
236-
clean: self.cleanArtifacts)
237-
}
238-
else if
239-
let search:FilePath.Directory = self.search
230+
if let repo:String = self.repo,
231+
let ref:String = self.ref
240232
{
241-
let build:SSGC.PackageBuild = .local(project: self.name,
242-
among: search,
243-
using: ".build.ssgc",
244-
as: self.type)
233+
let symbol:Symbol.Package = .init(self.project)
234+
235+
defer
236+
{
237+
let repoClone:FilePath.Directory = workspace.checkouts / "\(symbol)"
238+
239+
if self.removeClone
240+
{
241+
try? repoClone.remove()
242+
}
243+
}
244+
245+
let build:SSGC.PackageBuild = try .remote(project: symbol,
246+
from: repo,
247+
at: ref,
248+
as: self.type,
249+
in: workspace)
245250

246251
defer
247252
{
@@ -251,31 +256,20 @@ extension SSGC.Compile
251256
}
252257
}
253258

259+
try status?.send(.didCloneRepository)
260+
254261
object = try workspace.build(some: build,
255262
toolchain: toolchain,
256263
status: status,
257264
logger: logger,
258265
clean: self.cleanArtifacts)
259266
}
260267
else if
261-
let repo:String = self.repo,
262-
let ref:String = self.ref
268+
let search:FilePath.Directory = self.search
263269
{
264-
defer
265-
{
266-
let repoClone:FilePath.Directory = workspace.checkouts / "\(self.name)"
267-
268-
if self.removeClone
269-
{
270-
try? repoClone.remove()
271-
}
272-
}
273-
274-
let build:SSGC.PackageBuild = try .remote(project: self.name,
275-
from: repo,
276-
at: ref,
277-
as: self.type,
278-
in: workspace)
270+
let build:SSGC.PackageBuild = .local(project: search / self.project,
271+
using: ".build.ssgc",
272+
as: self.type)
279273

280274
defer
281275
{
@@ -285,14 +279,20 @@ extension SSGC.Compile
285279
}
286280
}
287281

288-
try status?.send(.didCloneRepository)
289-
290282
object = try workspace.build(some: build,
291283
toolchain: toolchain,
292284
status: status,
293285
logger: logger,
294286
clean: self.cleanArtifacts)
295287
}
288+
else if self.project == "swift"
289+
{
290+
object = try workspace.build(some: SSGC.StandardLibraryBuild.swift,
291+
toolchain: toolchain,
292+
status: status,
293+
logger: logger,
294+
clean: self.cleanArtifacts)
295+
}
296296
else
297297
{
298298
throw SSGC.SearchPathRequiredError.init()

Sources/SymbolGraphBuilder/Symbol.Package (ext).swift

-6
This file was deleted.

Sources/SymbolGraphBuilderTests/Main.swift

+3-5
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ enum Main:TestMain, TestBattery
7777
tests.do
7878
{
7979
let package:SSGC.PackageBuild = .local(
80-
project: "swift-snippets",
81-
among: "TestPackages")
80+
project: "TestPackages" / "swift-snippets")
8281

8382
try workspace.cache.create()
8483

@@ -158,9 +157,8 @@ enum Main:TestMain, TestBattery
158157
if let tests:TestGroup = tests / "Local",
159158
let docs:SymbolGraphObject<Void> = (tests.do
160159
{
161-
try workspace.build(package: .local(
162-
project: "swift-test",
163-
among: "TestPackages"),
160+
try workspace.build(
161+
package: .local(project: "TestPackages" / "swift-test"),
164162
with: toolchain)
165163
})
166164
{

Sources/UnidocClient/Unidoc.Client.swift

+10-8
Original file line numberDiff line numberDiff line change
@@ -279,33 +279,34 @@ extension Unidoc.Client<HTTP.Client2>
279279
}
280280

281281
public
282-
func buildAndUpload(local symbol:Symbol.Package,
282+
func buildAndUpload(local name:String,
283283
search:FilePath.Directory?,
284284
type:SSGC.ProjectType,
285285
with toolchain:Unidoc.Toolchain) async throws
286286
{
287-
let object:SymbolGraphObject<Void> = try await self.build(local: symbol,
287+
let object:SymbolGraphObject<Void> = try await self.build(local: name,
288288
search: search,
289289
type: type,
290290
with: toolchain)
291291

292292
try await self.connect { try await $0.upload(object) }
293293

294+
// The final URL path component might have different casing than the directory name.
294295
print("""
295296
View the generated documentation at:
296-
https://\(self.http.remote):\(self.port)/tags/\(symbol)
297+
https://\(self.http.remote):\(self.port)/tags/\(object.metadata.package.id)
297298
""")
298299
}
299300
}
300301
extension Unidoc.Client<HTTP.Client1>
301302
{
302303
public
303-
func buildAndUpload(local symbol:Symbol.Package,
304+
func buildAndUpload(local name:String,
304305
search:FilePath.Directory?,
305306
type:SSGC.ProjectType,
306307
with toolchain:Unidoc.Toolchain) async throws
307308
{
308-
let object:SymbolGraphObject<Void> = try await self.build(local: symbol,
309+
let object:SymbolGraphObject<Void> = try await self.build(local: name,
309310
search: search,
310311
type: type,
311312
with: toolchain)
@@ -314,14 +315,15 @@ extension Unidoc.Client<HTTP.Client1>
314315

315316
print("""
316317
View the generated documentation at:
317-
http://\(self.http.remote):\(self.port)/tags/\(symbol)
318+
http://\(self.http.remote):\(self.port)/tags/\(object.metadata.package.id)
318319
""")
319320
}
320321
}
321322
extension Unidoc.Client
322323
{
324+
/// Name is case-sensitive, so it is not modeled as a ``Symbol.Package``.
323325
private
324-
func build(local symbol:Symbol.Package,
326+
func build(local name:String,
325327
search:FilePath.Directory?,
326328
type:SSGC.ProjectType,
327329
with toolchain:Unidoc.Toolchain) async throws -> SymbolGraphObject<Void>
@@ -332,7 +334,7 @@ extension Unidoc.Client
332334
var arguments:[String] = [
333335
"compile",
334336

335-
"--package-name", "\(symbol)",
337+
"--package-name", "\(name)",
336338
"--project-type", "\(type)",
337339
"--workspace", "\(workspace.location)",
338340
"--output", "\(docs)",

Sources/UnidocQueryTests/Tests/LinkResolution.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import MongoDB
22
import MongoTesting
33
import SymbolGraphBuilder
44
import SymbolGraphs
5+
import System
56
@_spi(testable)
67
import UnidocDB
78

@@ -16,9 +17,8 @@ struct LinkResolution:UnidocDatabaseTestBattery
1617
let workspace:SSGC.Workspace = try .create(at: ".testing")
1718
let toolchain:SSGC.Toolchain = try .detect(pretty: true)
1819

19-
let example:SymbolGraphObject<Void> = try workspace.build(package: .local(
20-
project: "swift-test",
21-
among: "TestPackages"),
20+
let example:SymbolGraphObject<Void> = try workspace.build(
21+
package: .local(project: "TestPackages" / "swift-test"),
2222
with: toolchain)
2323

2424
example.roundtrip(for: tests, in: workspace.location)

Sources/UnidocQueryTests/Tests/SymbolQueries.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import SymbolGraphBuilder
44
import SymbolGraphs
55
import SymbolGraphTesting
66
import Symbols
7+
import System
78
import Unidoc
89
@_spi(testable)
910
import UnidocDB
@@ -20,9 +21,8 @@ struct SymbolQueries:UnidocDatabaseTestBattery
2021
let workspace:SSGC.Workspace = try .create(at: ".testing")
2122
let toolchain:SSGC.Toolchain = try .detect(pretty: true)
2223

23-
let example:SymbolGraphObject<Void> = try workspace.build(package: .local(
24-
project: "swift-malibu",
25-
among: "TestPackages"),
24+
let example:SymbolGraphObject<Void> = try workspace.build(
25+
package: .local(project: "TestPackages" / "swift-malibu"),
2626
with: toolchain)
2727

2828
example.roundtrip(for: tests, in: workspace.location)

Sources/unidoc-tools/Main.Local.swift

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import ArgumentParser
22
import HTTP
33
import NIOPosix
44
import SymbolGraphCompiler
5-
import Symbols
65
import System
76
import UnidocClient
87

@@ -11,7 +10,7 @@ extension Main
1110
struct Local
1211
{
1312
@Argument
14-
var project:Symbol.Package
13+
var project:String
1514

1615
@Option(
1716
name: [.customLong("host"), .customShort("h")],

0 commit comments

Comments
 (0)