Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-14464] SwiftPM fails to resolve packages with relative paths on Windows #4437

Open
karwa opened this issue Apr 9, 2021 · 5 comments
Open
Labels

Comments

@karwa
Copy link
Contributor

karwa commented Apr 9, 2021

Previous ID SR-14464
Radar None
Original Reporter @karwa
Type Bug
Environment

Github actions CI, windows-latest (copied the setup script from compnerd's WinRT demo).

Swift for Windows DEVELOPMENT-SNAPSHOT-2021-03-25

Additional Detail from JIRA
Votes 1
Component/s Package Manager
Labels Bug
Assignee None
Priority Medium

md5: b1cde91a09c2e3091c4b1cf515d9891d

Issue Description:

I have a package for a library, swift-url. Within its repository, I have a folder "Benchmarks", containing another Swift package. The Package.swift for Benchmarks looks as follows:

// swift-tools-version:5.3
import PackageDescription

let package = Package(
    name: "swift-url-benchmark",
    products: [
        .executable(name: "WebURLBenchmark", targets: ["WebURLBenchmark"])
    ],
    dependencies: [
      .package(name: "Benchmark", url: "https://github.com/google/swift-benchmark", from: "0.1.0"),
      .package(name: "swift-url", path: ".."),
    ],
    targets: [
      .target(
        name: "WebURLBenchmark",
        dependencies: [
          .product(name: "WebURL", package: "swift-url"),
          .product(name: "Benchmark", package: "Benchmark")
        ]
      )
    ]
)

Where the "WebURL" product is defined by swift-url's Package.swift.

swift-url builds, and its tests build, run, and pass on macOS, Linux, and Windows. Benchmarks fails to build on Windows only, and it seems like the issue is the relative path.

On macOS and Linux, I can build and run WebURLBenchmark even if I omit naming the parent package as "swift-url" in the package dependencies list (just writing `.package(path: "..")`) even if I refer to it by name in the target dependencies. SwiftPM somehow figures it out from the parent folder's name. If I try that on Windows, I get the following error:

D:\a\swift-url\swift-url\Benchmarks: error: unknown package 'swift-url' in dependencies of target 'WebURLBenchmark'; valid packages are: 'Benchmark', 'D:'
Error: Process completed with exit code 1.

"D:" is obviously not my package name. Seems like some path issues. If I add an explicit package name in the package dependencies list (so it looks like the snippet I pasted above), the error becomes:

Running resolver because the following dependencies were added: 'https://github.com/google/swift-benchmark', 'D:\'
error: D:\Package.swift has no Package.swift manifest
Error: Process completed with exit code 1.
@typesanitizer
Copy link

cc @compnerd

@kabiroberai
Copy link
Contributor

I'm able to reproduce this issue with Swift 5.4.2. As a temporary solution I've resorted to the following function:

func rel(_ path: String) -> String {
  #if os(Windows)
  return URL(
    fileURLWithPath: path, 
    relativeTo: URL(fileURLWithPath: FileManager.default.currentDirectoryPath)
  ).path
  #else
  return path
  #endif
}

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 4, 2022
@stevenbrix
Copy link

fwiw i've been using swift 5.8 and haven't noticed this issue

@MaxDesiatov
Copy link
Member

@karwa would you have a moment to clarify if this is still reproducible for you?

@karwa
Copy link
Contributor Author

karwa commented Mar 28, 2023

Unfortunately I don't have easy access to a Windows VM at the moment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants