Resolve local package name from abstract path

- Also, added Comment
This commit is contained in:
freddi 2020-03-19 23:58:52 +09:00
parent 5c380bf917
commit af3a7e0596
2 changed files with 8 additions and 3 deletions

View File

@ -184,8 +184,13 @@ extension Project {
} else {
packages = [:]
}
// For backward compatibility of old `localPackages:` format
if let localPackages: [String] = jsonDictionary.json(atKeyPath: "localPackages") {
packages.merge(localPackages.reduce(into: [String: SwiftPackage](), { $0[$1] = .local(path: $1) }))
packages.merge(localPackages.reduce(into: [String: SwiftPackage](), {
// Project name will be obtained by resolved abstractpath's lastComponent for dealing with some path case, like "../"
let packageName = (basePath + Path($1).normalize()).lastComponent
$0[packageName] = .local(path: $1) })
)
}
if jsonDictionary["options"] != nil {
options = try jsonDictionary.json(atKeyPath: "options")

View File

@ -1108,7 +1108,7 @@ class SpecLoadingTests: XCTestCase {
"package7": .remote(url: "package.git", versionRequirement: .exact("1.2.2")),
"package8": .remote(url: "package.git", versionRequirement: .upToNextMajorVersion("4.0.0-beta.5")),
"package9": .local(path: "package/package"),
"../XcodeGen": .local(path: "../XcodeGen")
"XcodeGen": .local(path: "../XcodeGen")
], options: .init(localPackagesGroup: "MyPackages"))
let dictionary: [String: Any] = [
@ -1135,7 +1135,7 @@ class SpecLoadingTests: XCTestCase {
$0.it("parses old local package format") {
let project = Project(name: "spm", packages: [
"../XcodeGen": .local(path: "../XcodeGen"),
"XcodeGen": .local(path: "../XcodeGen"),
"Yams": .local(path: "Yams")
], options: .init(localPackagesGroup: "MyPackages"))