While adopting local packages that mirror remote ones using swift package manager's set-mirror (https://docs.swift.org/swiftpm/documentation/packagemanagerdocs/packageconfigsetmirror) I have faced the following error as part of the build process when SwiftPackageListPlugin executes
Error: The file “AEXML” couldn’t be opened because there is no such file. Program ended with exit code: 1
Below follows the contents of mirrors.json and Package.resolved files:
Mirrors.json
{ "object": [ { "mirror": "<my_directory>/TestLocalMirrors/LocalMirrors/AEXML", "original": "https://github.com/tadija/AEXML" }, { "mirror": "/<my_directory>/TestLocalMirrors/LocalMirrors/analytics-ios", "original": "https://github.com/segmentio/analytics-ios" }, { "mirror": "<my_directory>/TestLocalMirrors/LocalMirrors/swift-argument-parser", "original": "https://github.com/apple/swift-argument-parser" }, { "mirror": "<my_directory>eTstLocalMirrors/LocalMirrors/swift-package-list", "original": "https://github.com/FelixHerrmann/swift-package-list" } ], "version": 1 }
Package.resolved
{ "originHash" : "7e1b589942a81651aa427ee5fbf71b7b9bc62038ebe88abd5c1ae1f2ce397b0d", "pins" : [ { "identity" : "aexml", "kind" : "localSourceControl", "location" : "https://github.com/tadija/AEXML", "state" : { "revision" : "db806756c989760b35108146381535aec231092b", "version" : "4.7.0" } }, { "identity" : "analytics-ios", "kind" : "localSourceControl", "location" : "https://github.com/segmentio/analytics-ios", "state" : { "revision" : "78423aaae2e48e32a07246850f37c76f3d34cb84", "version" : "4.1.8" } }, { "identity" : "swift-argument-parser", "kind" : "localSourceControl", "location" : "https://github.com/apple/swift-argument-parser", "state" : { "revision" : "cdd0ef3755280949551dc26dee5de9ddeda89f54", "version" : "1.6.2" } }, { "identity" : "swift-package-list", "kind" : "localSourceControl", "location" : "https://github.com/FelixHerrmann/swift-package-list", "state" : { "revision" : "22ef2a2b1b51b453be02ce2bd780753718e8893a", "version" : "4.8.0" } } ], "version" : 3 }
After debugging your source code, I found the issue lies on the following lines of code PackageResolved.swift:
Currently, it is being assumed that packages of kind localSourceControl have a local file URL, which is not the case. pin.location will contain the value of location contained in Package.resolved. In other words, AEXML's pin.location would be "https://github.com/tadija/AEXML" and not a local path. In turn, URL(fileURLWithPath: will create an invalid URL and the code will later on throw.
As far as I am aware, packages are of kind localSourceControl only when using this concept of local mirroring relying of git repos, not for packages within the codebase itself. Furthermore, in this later case, the dependencies won't be part of Package.resolved.
How to solve this issue?
By modifying the code snipet above to treat both remoteSourceControl and localSourceControl similarly and allowing them both to be derived from packageSource = checkouts.packageSource(location: pin.location) instead, I managed to resolve the issue and get the correct output as expected.
@FelixHerrmann could you please share your views? Please let me know if I am missing something.
Thank you.
While adopting local packages that mirror remote ones using swift package manager's set-mirror (https://docs.swift.org/swiftpm/documentation/packagemanagerdocs/packageconfigsetmirror) I have faced the following error as part of the build process when SwiftPackageListPlugin executes
Error: The file “AEXML” couldn’t be opened because there is no such file. Program ended with exit code: 1Below follows the contents of
mirrors.jsonandPackage.resolvedfiles:Mirrors.json
{ "object": [ { "mirror": "<my_directory>/TestLocalMirrors/LocalMirrors/AEXML", "original": "https://github.com/tadija/AEXML" }, { "mirror": "/<my_directory>/TestLocalMirrors/LocalMirrors/analytics-ios", "original": "https://github.com/segmentio/analytics-ios" }, { "mirror": "<my_directory>/TestLocalMirrors/LocalMirrors/swift-argument-parser", "original": "https://github.com/apple/swift-argument-parser" }, { "mirror": "<my_directory>eTstLocalMirrors/LocalMirrors/swift-package-list", "original": "https://github.com/FelixHerrmann/swift-package-list" } ], "version": 1 }Package.resolved
{ "originHash" : "7e1b589942a81651aa427ee5fbf71b7b9bc62038ebe88abd5c1ae1f2ce397b0d", "pins" : [ { "identity" : "aexml", "kind" : "localSourceControl", "location" : "https://github.com/tadija/AEXML", "state" : { "revision" : "db806756c989760b35108146381535aec231092b", "version" : "4.7.0" } }, { "identity" : "analytics-ios", "kind" : "localSourceControl", "location" : "https://github.com/segmentio/analytics-ios", "state" : { "revision" : "78423aaae2e48e32a07246850f37c76f3d34cb84", "version" : "4.1.8" } }, { "identity" : "swift-argument-parser", "kind" : "localSourceControl", "location" : "https://github.com/apple/swift-argument-parser", "state" : { "revision" : "cdd0ef3755280949551dc26dee5de9ddeda89f54", "version" : "1.6.2" } }, { "identity" : "swift-package-list", "kind" : "localSourceControl", "location" : "https://github.com/FelixHerrmann/swift-package-list", "state" : { "revision" : "22ef2a2b1b51b453be02ce2bd780753718e8893a", "version" : "4.8.0" } } ], "version" : 3 }After debugging your source code, I found the issue lies on the following lines of code
PackageResolved.swift:Currently, it is being assumed that packages of kind
localSourceControlhave a local file URL, which is not the case.pin.locationwill contain the value oflocationcontained inPackage.resolved. In other words,AEXML's pin.location would be "https://github.com/tadija/AEXML" and not a local path. In turn,URL(fileURLWithPath:will create an invalid URL and the code will later on throw.As far as I am aware, packages are of kind
localSourceControlonly when using this concept of local mirroring relying of git repos, not for packages within the codebase itself. Furthermore, in this later case, the dependencies won't be part ofPackage.resolved.How to solve this issue?
By modifying the code snipet above to treat both
remoteSourceControlandlocalSourceControlsimilarly and allowing them both to be derived frompackageSource = checkouts.packageSource(location: pin.location)instead, I managed to resolve the issue and get the correct output as expected.@FelixHerrmann could you please share your views? Please let me know if I am missing something.
Thank you.