yonaskolb / XcodeGen

A Swift command line tool for generating your Xcode project
MIT License
7.01k stars 818 forks source link

Add support for adding build tool plugins to targets #1374

Closed BarredEwe closed 1 year ago

BarredEwe commented 1 year ago

Short description 📝

Support for Build Tool Plugins has been added here. A detailed discussion can be read here: https://github.com/yonaskolb/XcodeGen/issues/1290

Screenshot 2023-07-16 at 13 18 29

Details ⚙️

API

To use plugins, you need to specify in your target which plugin you want to connect.

targets:
  App:
    buildToolPlugins:
      - plugin: PrefirePlaybookPlugin
        package: Prefire

And don't forget to connect the package.

packages:
  Prefire:
    url: https://github.com/BarredEwe/Prefire
    from: 1.3.0

What is generated

  1. Added PBXTargetDependency:
    E157C6348B8AD6A28C706801 /* PBXTargetDependency */ = {
    isa = PBXTargetDependency;
    productRef = DC47EF1BFBBD751E3C1C95E3 /* PrefirePlaybookPlugin */;
    };
  2. Added Plugin information. An additional prefix (plugin:) is added:
    DC47EF1BFBBD751E3C1C95E3 /* PrefirePlaybookPlugin */ = {
    isa = XCSwiftPackageProductDependency;
    package = 41BBDD09D038D66F59D14D11 /* XCRemoteSwiftPackageReference "Prefire" */;
    productName = "plugin:PrefirePlaybookPlugin";
    };

What is being validated

If you add a plugin that references a package that is not in the project:

packages:
  Prefire:
    url: https://github.com/BarredEwe/Prefire
    from: 1.3.0
targets:
  App:
    buildToolPlugins:
      - plugin: PrefirePlaybookPlugin
        package: SomeName # Must be `Prefire`

There will be an error:

Spec validation error: Plugin PrefirePlaybookPlugin has invalide package reference SomeName

yanniks commented 1 year ago

Hi @yonaskolb and @freddi-kit ! Do you already have an update when this is about to be merged? We're eagerly waiting for this feature :blush: .

Cheers, Yannik

yonaskolb commented 1 year ago

@yanniks this feature is good to go, we're just waiting on a release of XcodeProj (And the recent merge conflicts to be resolved)

OmranK commented 1 year ago

Was there a dependency on Xcode version for this to work? Works fine on my machine with Xcode 14.3.1 but seems to not link it up correctly on my colleague's machine which is on Xcode 14.2

BarredEwe commented 1 year ago

@OmranK Can you add an Xcode error?

PS: If you add a plugin without XcodeGen in Xcode 14.2, does it work correctly?

OmranK commented 1 year ago

@BarredEwe There is no error. It simply shows "Run Build Tool Plug-ins (0 items)". If he manually clicks + and adds in SwiftLintPlugin, it works.

BarredEwe commented 1 year ago

@OmranK I can't reproduce this on Xcode 14.2 and the project Fixtures/SPM.