swiftlang / swift-package-manager

The Package Manager for the Swift Programming Language
Apache License 2.0
9.74k stars 1.34k forks source link

PackagePlugin is entirely broken #6851

Closed compnerd closed 1 month ago

compnerd commented 1 year ago

Description

PackagePlugin.Path has an unusable ctor:

public init(_ string: String) {
    self._string = string
}

The paths in SPM are fundamentally unusable as they do not represent a real path but some fabricated reality. They drop the drive and the resulting path is unusable. This prevents the use of build tools as the input is never found and ignored by SPM. There is currently no way to reconstruct the true file system path within the context of the plugin, which prevents build plugins from being usable.

Expected behavior

Paths provided to the plugin would be real paths with drives.

Actual behavior

Paths provided to the plugin are relative to the current drive.

Steps to reproduce

No response

Swift Package Manager version/commit hash

No response

Swift & OS version (output of swift --version ; uname -a)

No response

neonichu commented 1 year ago

Isn't this the same as https://github.com/apple/swift-package-manager/pull/5817?

compnerd commented 1 year ago

Yes, #5817 might help paper over the underlying issue a bit.

neonichu commented 1 year ago

I guess AbsolutePath also doesn't fully work so it can only be a partial solution. At least we wouldn't have yet another bespoke path library with a very simplistic view of path computation.

neonichu commented 1 year ago

IMO, the correct solution is probably to yank PackagePlugin.Path and let people use Foundation.URL. I don't think it makes sense to force package plugins to be their own little world of their own where we have to solve common concerns of Swift programs again.

compnerd commented 1 year ago

Yeah, I agree, this is best resolved by use of Foundation.URL. We should ensure that the URL is constructed properly (i.e. URL(fileURLWithPath:).).