Can we prefer local package and fallback to url package

Inspired by this PR, found another workaround. Enable library evolution for SwiftDocC library via a conditional by franklinsch · Pull Request #123 · apple/swift-docc · GitHub

We can use #filePath and deletingLastPathComponent API to workaround with the sandbox limitation.

Note: ".." will not work, use deletingLastPathComponent instead

extension Package.Dependency {
    static func package(
        preferLocal: Bool = true,
        name: String,
        location: String? = nil,
        url: String,
        _ requirement: Package.Dependency.Requirement) -> Package.Dependency {
        let manifestLocation = URL(fileURLWithPath: #filePath)
        let location = location ?? name
        let packageLocation = manifestLocation
            .deletingLastPathComponent()
            .deletingLastPathComponent()
            .appendingPathComponent(location)
        if preferLocal, FileManager.default.fileExists(atPath: packageLocation.path) {
            return .package(path: packageLocation.path)
        } else {
            return .package(url: url, requirement)
        }
    }
}

Using the above method, we could check the existence of some folder in the parent directory of the Package without adding --disable-sandbox flag. Is this a SPM sandbox bug or a known use case? cc @tomerd