shibapm / Komondor

Git Hooks for Swift projects 🐩
MIT License
552 stars 32 forks source link

protocol type 'PackageConfig' cannot be instantiated #30

Closed piterwilson closed 4 years ago

piterwilson commented 4 years ago

Hello,

I'm having trouble getting the basic setup sample to work. I used the instructions here: https://github.com/shibapm/Komondor/blob/master/Documentation/with_swiftpm.md

// swift-tools-version:5.1
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
    name: "xxx",
    platforms: [
        .iOS(.v11),
        .macOS(.v10_13),
        .tvOS(.v11)
    ],
    products: [
        // Products define the executables and libraries produced by a package, and make them visible to other packages.
        .library(
            name: "xxx",
            targets: ["xxx"])
    ],
    dependencies: [
        .package(url: "https://github.com/shibapm/Komondor.git", from: "1.0.0"),
        .package(url: "https://github.com/Realm/SwiftLint", from: "0.35.8")
    ],
    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: "xxx",
            dependencies: []),
        .testTarget(
            name: "xxxTests",
            dependencies: ["xxx"])
    ]
)

// The settings for the git hooks for our repo
#if canImport(PackageConfig)
    import PackageConfig

    let config = PackageConfig([
        "komondor": [
            "pre-commit": [
                "swift run swiftlint --path Sources --config .swiftlint.yml"
            ]
        ]
    ])
#endif

Which results in this error

Package.swift:39:18: error: protocol type 'PackageConfig' cannot be instantiated
    let config = PackageConfig([
                 ^~~~~~~~~~~~~
Package.swift:39:32: error: missing argument label 'from:' in call
    let config = PackageConfig([
                               ^
                               from: 
Package.swift:39:32: error: argument type '[String : [String : [String]]]' does not conform to expected type 'Decoder'
    let config = PackageConfig([
                               ^
Fatal error: Error raised at top level: PackageConfig.Error(reason: "Could not find a file at /var/folders/mf/jv01kf3d3nxdjtyp9dgnx9y80000gn/T/package-config - something went wrong with compilation step probably"): file /BuildRoot/Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-1100.8.280/swift/stdlib/public/core/ErrorType.swift, line 200
.git/hooks/pre-commit: line 21: 21516 Illegal instruction: 4  $komondor run pre-commit

May i ask what i could be doing wrong? or is this an issue with Komondor?

Thank you!

piterwilson commented 4 years ago

Adding some extra information:

swift --version
Apple Swift version 5.2 (swiftlang-1103.0.32.1 clang-1103.0.32.29)
Target: x86_64-apple-darwin19.3.0
orta commented 4 years ago

think your timing was just off a little re: #29 which would have fixed the docs

orta commented 4 years ago

or not, we just have more docs to update actually

piterwilson commented 4 years ago

@orta thank you for the link to the issue. I can confirm that changing the configuration to the following does work:

// swift-tools-version:5.1
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
    name: "xxx",
    platforms: [
        .iOS(.v11),
        .macOS(.v10_13),
        .tvOS(.v11)
    ],
    products: [
        // Products define the executables and libraries produced by a package, and make them visible to other packages.
        .library(
            name: "xxx",
            targets: ["xxx"])
    ],
    dependencies: [
        .package(url: "https://github.com/shibapm/Komondor.git", from: "1.0.0"),
        .package(url: "https://github.com/Realm/SwiftLint", from: "0.35.8")
    ],
    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: "xxx",
            dependencies: []),
        .testTarget(
            name: "xxxTests",
            dependencies: ["xxx"])
    ]
)

// The settings for the git hooks for our repo
#if canImport(PackageConfig)
    import PackageConfig

    let config = PackageConfiguration([
        "komondor": [
            "pre-commit": [
                "swift run swiftlint --path Sources --config .swiftlint.yml"
            ]
        ]
    ])

I can see that the import being called PackageConfig was probably the source of the confusion.

Thanks for the work you put into this package!