mxcl / Path.swift

Delightful, robust, cross-platform and chainable file-pathing functions.
The Unlicense
946 stars 36 forks source link

How I can properly add Path to swift manifest file #65

Closed vkuznet closed 4 years ago

vkuznet commented 4 years ago

Hi, I tried to add Path to dependencies of Package.swift file and I'm getting this error if I list "Path" as target.dependecies["Path"].

Updating https://github.com/mxcl/Path.swift
Resolving https://github.com/mxcl/Path.swift at 1.2.0
'MyCode' /Users/vk/Work/Languages/Swift/MyCode: error: dependency 'Path' in target 'SwiftMLExample' requires explicit declaration; reference the package in the target dependency with '.product(name: "Path", package: "Path.swift")'

If I list it as

.target(dependencies[.product(name: "Path", package: "Path")])

I get this error: unknown package 'Path' in dependencies of target.

Can someone show example of Package.swift file where Path is included in dependencies? I'm new to swift. Thanks, Valentin.

mxcl commented 4 years ago
.target(dependencies[.product(name: "Path", package: "Path")])

Is not valid Swift, nor is it the correct syntax, I suggest letting Xcode do the completion for you.

.target(name: "Foo:", dependencies: [.product(name: "Path", package: "Path")])
vkuznet commented 4 years ago

This is exactly what I have in my Package.swift (among other things):

        .target(
            name: "SwiftMLExample",
            dependencies: [
                "Just",
                .product(name: "Path", package: "Path"),
                .product(name: "ArgumentParser", package: "swift-argument-parser")
            ])

and, swift build throws this error:

/Users/vk/Work/Languages/Swift/SwiftMLExample: error: unknown package 'Path' in dependencies of target 'SwiftMLExample'

And, XCode is not universally available, e.g. there is no Xcode on Linux. So, I want to learn how to do it by hand. All other packages I used are working and Path some how does not.

Here is how to reproduce the problem with fresh environment:

  1. create new package with
    swift package init --type executable
    Creating executable package: TestPathVanila
    Creating Package.swift
    Creating README.md
    Creating .gitignore
    Creating Sources/
    Creating Sources/TestPathVanila/main.swift
    Creating Tests/
    Creating Tests/LinuxMain.swift
    Creating Tests/TestPathVanilaTests/
    Creating Tests/TestPathVanilaTests/TestPathVanilaTests.swift
    Creating Tests/TestPathVanilaTests/XCTestManifests.swift
  2. Add Path to dependencies, see my Package.swift
    
    // swift-tools-version:5.2
    // The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package( name: "TestPathVanila", dependencies: [ // Dependencies declare other packages that this package depends on. // .package(url: / package url /, from: "1.0.0"), .package(url: "https://github.com/mxcl/Path.swift", from: "1.2.0"), ], targets: [ // Targets are the basic building blocks of a package. A target can define a module or a test suite. // Targets can depend on other targets in this package, and on products in packages which this package depends on. .target( name: "TestPathVanila", dependencies: [.product(name: "Path", package: "Path")]), .testTarget( name: "TestPathVanilaTests", dependencies: ["TestPathVanila"]), ] )

3. build package

swift build /Users/vk/Work/Languages/Swift/tmp/TestPathVanila: error: unknown package 'Path' in dependencies of target 'TestPathVanila'

mxcl commented 4 years ago
.product(name: "Path", package: "Path.swift")
vkuznet commented 4 years ago

This works! Thanks.