SwiftLint icon indicating copy to clipboard operation
SwiftLint copied to clipboard

SPM plugin: Mac Catalyst build fails

Open PierreMardon opened this issue 1 year ago • 5 comments

New Issue Checklist

Describe the bug

My small lib PDefaults uses SwiftLint as a SPM plugin.

It won't build using XCode 14.3.1 with My Mac (Mac Catalyst) run destination.

It's in fact SourceKitten that's failing.

Complete output
/Users/pierremardon/Library/Developer/Xcode/DerivedData/PDefaults-djcfgicqqjpoyxfbpddekwbrdfka/SourcePackages/checkouts/SourceKitten/Source/SourceKittenFramework/Exec.swift:80:25: error: 'executableURL' is unavailable in Mac Catalyst
                process.executableURL = URL(fileURLWithPath: command)
                        ^~~~~~~~~~~~~
Foundation.Process:5:14: note: 'executableURL' has been explicitly marked unavailable here
    open var executableURL: URL? { get set }
             ^
/Users/pierremardon/Library/Developer/Xcode/DerivedData/PDefaults-djcfgicqqjpoyxfbpddekwbrdfka/SourcePackages/checkouts/SourceKitten/Source/SourceKittenFramework/Exec.swift:81:25: error: 'currentDirectoryURL' is unavailable in Mac Catalyst
                process.currentDirectoryURL = URL(fileURLWithPath: currentDirectory)
                        ^~~~~~~~~~~~~~~~~~~
Foundation.Process:10:14: note: 'currentDirectoryURL' has been explicitly marked unavailable here
    open var currentDirectoryURL: URL? { get set }
             ^
/Users/pierremardon/Library/Developer/Xcode/DerivedData/PDefaults-djcfgicqqjpoyxfbpddekwbrdfka/SourcePackages/checkouts/SourceKitten/Source/SourceKittenFramework/Exec.swift:82:29: error: 'run()' is unavailable in Mac Catalyst
                try process.run()
                            ^~~
Foundation.Process:16:15: note: 'run()' has been explicitly marked unavailable here
    open func run() throws
              ^
/Users/pierremardon/Library/Developer/Xcode/DerivedData/PDefaults-djcfgicqqjpoyxfbpddekwbrdfka/SourcePackages/checkouts/SourceKitten/Source/SourceKittenFramework/Exec.swift:84:25: error: 'launchPath' is unavailable in Mac Catalyst
                process.launchPath = command
                        ^~~~~~~~~~
Foundation.Process:4:14: note: 'launchPath' has been explicitly marked unavailable here
    open var launchPath: String? { get set }
             ^
/Users/pierremardon/Library/Developer/Xcode/DerivedData/PDefaults-djcfgicqqjpoyxfbpddekwbrdfka/SourcePackages/checkouts/SourceKitten/Source/SourceKittenFramework/Exec.swift:85:25: error: 'currentDirectoryPath' is unavailable in Mac Catalyst
                process.currentDirectoryPath = currentDirectory
                        ^~~~~~~~~~~~~~~~~~~~
Foundation.Process:7:14: note: 'currentDirectoryPath' has been explicitly marked unavailable here
    open var currentDirectoryPath: String { get set }
             ^
/Users/pierremardon/Library/Developer/Xcode/DerivedData/PDefaults-djcfgicqqjpoyxfbpddekwbrdfka/SourcePackages/checkouts/SourceKitten/Source/SourceKittenFramework/Exec.swift:86:17: error: ambiguous use of 'launch()'
                process.launch()
                ^
Foundation.Process:20:15: note: found this candidate
    open func launch() throws
              ^
Foundation.Process:10:15: note: found this candidate
    open func launch()
              ^

/Users/pierremardon/Library/Developer/Xcode/DerivedData/PDefaults-djcfgicqqjpoyxfbpddekwbrdfka/SourcePackages/checkouts/SourceKitten/Source/SourceKittenFramework/Exec.swift:80:25: 'executableURL' is unavailable in Mac Catalyst

/Users/pierremardon/Library/Developer/Xcode/DerivedData/PDefaults-djcfgicqqjpoyxfbpddekwbrdfka/SourcePackages/checkouts/SourceKitten/Source/SourceKittenFramework/Exec.swift:81:25: 'currentDirectoryURL' is unavailable in Mac Catalyst

/Users/pierremardon/Library/Developer/Xcode/DerivedData/PDefaults-djcfgicqqjpoyxfbpddekwbrdfka/SourcePackages/checkouts/SourceKitten/Source/SourceKittenFramework/Exec.swift:82:29: 'run()' is unavailable in Mac Catalyst

/Users/pierremardon/Library/Developer/Xcode/DerivedData/PDefaults-djcfgicqqjpoyxfbpddekwbrdfka/SourcePackages/checkouts/SourceKitten/Source/SourceKittenFramework/Exec.swift:84:25: 'launchPath' is unavailable in Mac Catalyst

/Users/pierremardon/Library/Developer/Xcode/DerivedData/PDefaults-djcfgicqqjpoyxfbpddekwbrdfka/SourcePackages/checkouts/SourceKitten/Source/SourceKittenFramework/Exec.swift:85:25: 'currentDirectoryPath' is unavailable in Mac Catalyst

/Users/pierremardon/Library/Developer/Xcode/DerivedData/PDefaults-djcfgicqqjpoyxfbpddekwbrdfka/SourcePackages/checkouts/SourceKitten/Source/SourceKittenFramework/Exec.swift:86:17: Ambiguous use of 'launch()'

caused by this snippet, the compiler considering canImport(Darwin) is true:

#if canImport(Darwin)
            if #available(macOS 10.13, *) {
                process.executableURL = URL(fileURLWithPath: command)
                process.currentDirectoryURL = URL(fileURLWithPath: currentDirectory)
                try process.run()
            } else {
                process.launchPath = command
                process.currentDirectoryPath = currentDirectory
                process.launch()
            }
#else
            process.executableURL = URL(fileURLWithPath: command)
            process.currentDirectoryURL = URL(fileURLWithPath: currentDirectory)
            try process.run()
#endif

Environment

  • SwiftLint version (run swiftlint version to be sure)? 0.52.3
  • Installation method used (Homebrew, CocoaPods, building from source, etc)? SPM plugin
  • Paste your configuration file: not relevant
  • Are you using nested configurations? not relevant
  • Which Xcode version are you using (check xcodebuild -version)? 14.3.1
  • Do you have a sample that shows the issue?
  • Create a dummy package with SwiftLint used as a plugin like this:
import PackageDescription

let package = Package(
    name: "PDefaults",
    platforms: [
        .macOS(.v12),
        .iOS(.v13)
    ],
    products: [
        .library(
            name: "PDefaults",
            targets: ["PDefaults"]
        ),
    ],
    dependencies: [
        .package(url: "https://github.com/realm/SwiftLint", exact: "0.52.3")
    ],
    targets: [
        .target(
            name: "PDefaults",
            dependencies: [],
            plugins: [.plugin(name: "SwiftLintPlugin", package: "SwiftLint")]
        ),
    ]
)
  • try to build it for Mac Catalyst with XCode 14.3.1

PierreMardon avatar Jul 03 '23 15:07 PierreMardon

I have the same issue and have opened the following pull request (https://github.com/jpsim/SourceKitten/pull/801) to get SourceKitten fixed.

chotchki avatar Feb 23 '24 05:02 chotchki

@PierreMardon If you're still fighting this error, I forked SwiftLint to pull in my SourceKitten fix. It seems to work great!

Repo here: https://github.com/chotchki/SwiftLint

chotchki avatar Feb 23 '24 06:02 chotchki

It's not relevant for my use case anymore, but thanks for the update 😉

PierreMardon avatar Feb 23 '24 17:02 PierreMardon

Hello, we have a Swift package that supports Mac Catalyst and we are running into the same issue when adding SwiftLint as a build plugin.

@PierreMardon If you're still fighting this error, I forked SwiftLint to pull in my SourceKitten fix. It seems to work great!

Any idea when that PR will get merged and when SwiftLint will pick up that change?

Thanks!

zkline101 avatar Apr 02 '24 17:04 zkline101

@zkline101 SourceKitten hasn't had a release since 2023 and hasn't merged commits in the last 2months. I'm not sure when this fix will get merged. For my projects I've just been using my forked version as an easy solution interim fix.

I just rebased my fix onto the latest Swiftlint, hope it helps!

chotchki avatar Apr 07 '24 22:04 chotchki