Skip to content

Commit 78d0510

Browse files
authored
Merge pull request #339 from tayloraswift/diagnose-wrong-directory
QoL diagnostic when specifying the wrong package path
2 parents 9229838 + 5b53c20 commit 78d0510

File tree

4 files changed

+38
-9
lines changed

4 files changed

+38
-9
lines changed

Package.resolved

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Sources/SymbolGraphBuilder/Builds/SSGC.PackageBuild.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,15 @@ extension SSGC.PackageBuild
286286
json: artifacts / "\(self.id.package).package.json",
287287
leaf: true)
288288

289+
// SwiftPM will climb up the directory tree until it finds a `Package.swift` file.
290+
// It is trying to be helpful, but it will cause problems so we need to diagnose if
291+
// this is happening.
292+
switch FilePath.Directory.init(manifest.root.path)
293+
{
294+
case self.root: break
295+
case let other: throw SSGC.PackagePathError.init(computed: self.root, manifest: other)
296+
}
297+
289298
print("""
290299
Resolving dependencies for '\(self.id.package)' \
291300
(swift-tools-version: \(manifest.format))
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import System
2+
3+
extension SSGC
4+
{
5+
struct PackagePathError:Error
6+
{
7+
let computed:FilePath.Directory
8+
let manifest:FilePath.Directory
9+
}
10+
}
11+
extension SSGC.PackagePathError:CustomStringConvertible
12+
{
13+
var description:String
14+
{
15+
"""
16+
Attempting to build a package at '\(computed)' \
17+
but the nearest manifest is located in '\(manifest)'
18+
"""
19+
}
20+
}

Sources/SymbolGraphBuilder/FilePath (ext).swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ extension FilePath
1111
else if
1212
let current:FilePath.Directory = .current()
1313
{
14-
return current.path.appending(self.components)
14+
return current.path.appending(self.components).lexicallyNormalized()
1515
}
1616
else
1717
{

0 commit comments

Comments
 (0)