realm / SwiftLint

A tool to enforce Swift style and conventions.
https://realm.github.io/SwiftLint
MIT License
18.7k stars 2.23k forks source link

SPM plugin: Mac Catalyst build fails #5093

Open PierreMardon opened 1 year ago

PierreMardon commented 1 year ago

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

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")]
        ),
    ]
)
chotchki commented 9 months ago

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

chotchki commented 9 months ago

@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

PierreMardon commented 9 months ago

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

zkline101 commented 7 months ago

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!

chotchki commented 7 months ago

@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!