Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build of package using swift-openapi-generator fails with "Multiple commands produce ... Types.swift" #376

Closed
timbms opened this issue Nov 13, 2023 · 13 comments
Labels
kind/support Adopter support requests.

Comments

@timbms
Copy link

timbms commented Nov 13, 2023

Hi,
I want to migrate to swift-openapi-generator. It worked fine when I experimented with the inclusion as demonstrated in the WWDC demo.
Now I want to shift the generator code to the embedded package that is defined via a Package.swift:

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

import PackageDescription

let package = Package(
    name: "OpenHABCore",
    platforms: [.iOS(.v13), .watchOS(.v7)],
    products: [
        // Products define the executables and libraries a package produces, and make them visible to other packages.
        .library(
            name: "OpenHABCore",
            targets: ["OpenHABCore"]
        )
    ],
    dependencies: [
        // Dependencies declare other packages that this package depends on.
        .package(url: "https://github.com/Alamofire/Alamofire.git", .upToNextMajor(from: "5.4.4")),
        .package(url: "https://github.com/cezheng/Fuzi.git", .upToNextMajor(from: "3.0.0")),
        .package(url: "https://github.com/onevcat/Kingfisher.git", .upToNextMajor(from: "7.0.0")),
        .package(url: "https://github.com/apple/swift-openapi-runtime", .upToNextMinor(from: "0.3.6")),
        .package(url: "https://github.com/apple/swift-openapi-urlsession", .upToNextMinor(from: "0.3.0")),
        .package(url: "https://github.com/apple/swift-openapi-generator", .upToNextMinor(from: "0.3.4"))
    ],
    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 this package depends on.
        .target(
            name: "OpenHABCore",
            dependencies: [
                .product(name: "Alamofire", package: "Alamofire"),
                .product(name: "Fuzi", package: "Fuzi"),
                .product(name: "Kingfisher", package: "Kingfisher"),
                .product(name: "OpenAPIRuntime", package: "swift-openapi-runtime"),
                .product(name: "OpenAPIURLSession", package: "swift-openapi-urlsession")
            ],
            plugins: [
                .plugin(name: "OpenAPIGenerator", package: "swift-openapi-generator")
            ]
        ),
        .testTarget(
            name: "OpenHABCoreTests",
            dependencies: ["OpenHABCore"],
            resources: [
                .process("Resources")
            ]
        )
    ]
)

Build fails with the following message:

Multiple commands produce '/Users/tms/Library/Developer/Xcode/DerivedData/openHAB-ckplhxolppnyfvfzhxhwmsaovpap/SourcePackages/plugins/openhabcore.output/OpenHABCore/OpenAPIGenerator/GeneratedSources/Types.swift'

That command depends on command in Target 'OpenHABCore' (project 'OpenHABCore'): script phase “Running swift-openapi-generator”
That command depends on command in Target 'OpenHABCore' (project 'OpenHABCore'): script phase “Running swift-openapi-generator”
Multiple commands produce '/Users/tms/Library/Developer/Xcode/DerivedData/openHAB-ckplhxolppnyfvfzhxhwmsaovpap/SourcePackages/plugins/openhabcore.output/OpenHABCore/OpenAPIGenerator/GeneratedSources/Client.swift'

Multiple commands produce '/Users/tms/Library/Developer/Xcode/DerivedData/openHAB-ckplhxolppnyfvfzhxhwmsaovpap/SourcePackages/plugins/openhabcore.output/OpenHABCore/OpenAPIGenerator/GeneratedSources/Server.swift'

Any help would be very much appreciated.
Tim

@czechboy0 czechboy0 added the kind/support Adopter support requests. label Nov 13, 2023
@luomein
Copy link

luomein commented Nov 13, 2023

Try add swift-http-types dependency.

let package = Package(
    name: "OpenHABCore",
    platforms: [.iOS(.v13), .watchOS(.v7)],
    products: [
        // Products define the executables and libraries a package produces, and make them visible to other packages.
        .library(
            name: "OpenHABCore",
            targets: ["OpenHABCore"]
        )
    ],
    dependencies: [
        // Dependencies declare other packages that this package depends on.
        .package(url: "https://github.com/Alamofire/Alamofire.git", .upToNextMajor(from: "5.4.4")),
        .package(url: "https://github.com/cezheng/Fuzi.git", .upToNextMajor(from: "3.0.0")),
        .package(url: "https://github.com/onevcat/Kingfisher.git", .upToNextMajor(from: "7.0.0")),
        .package(url: "https://github.com/apple/swift-openapi-runtime", .upToNextMinor(from: "0.3.6")),
        .package(url: "https://github.com/apple/swift-openapi-urlsession", .upToNextMinor(from: "0.3.0")),
        .package(url: "https://github.com/apple/swift-openapi-generator", .upToNextMinor(from: "0.3.4")),
        .package(url: "https://github.com/apple/swift-http-types", from: "1.0.0"),
    ],
    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 this package depends on.
        .target(
            name: "OpenHABCore",
            dependencies: [
                .product(name: "Alamofire", package: "Alamofire"),
                .product(name: "Fuzi", package: "Fuzi"),
                .product(name: "Kingfisher", package: "Kingfisher"),
                .product(name: "OpenAPIRuntime", package: "swift-openapi-runtime"),
                .product(name: "OpenAPIURLSession", package: "swift-openapi-urlsession"),
                .product(name: "HTTPTypes", package: "swift-http-types"),
            ],
            plugins: [
                .plugin(name: "OpenAPIGenerator", package: "swift-openapi-generator")
            ]
        ),
        .testTarget(
            name: "OpenHABCoreTests",
            dependencies: ["OpenHABCore"],
            resources: [
                .process("Resources")
            ]
        )
    ]
)

@czechboy0
Copy link
Collaborator

Hi @timbms,

I don't think @luomein's suggestion will address your issue, you shouldn't have to explicitly depend on swift-http-types.

A few things to check:

  1. Did you open the package in Xcode directly, or is this package nested in an Xcode project or workspace? The logs almost suggest that the generator is running twice. But you should either add the plugin in Package.swift, or add it as a Run build plugin phase in the Xcode project, not both.
  2. Do you have files that are called Types.swift, Client.swift, or Server.swift in your target? If so, please rename them. Alternatively, you could move the generated code into a dedicated module, and import it from OpenHABCore, at which point the duplicate file names wouldn't be an issue. More in https://swiftpackageindex.com/apple/swift-openapi-generator/0.3.4/documentation/swift-openapi-generator/api-stability-of-generated-code#Create-a-curated-client-library-package

@timbms
Copy link
Author

timbms commented Nov 13, 2023

Thanks for the quick support.

  1. The package is nested in a Xcode workspace. The generator plugin is added to the Package.swift only. There is no addition to the Run build plugin phase in the Xcode project. I rechecked for all targets. Still the plugin seems to be run twice.
  2. There are no files named Types.swift, Client.swift, Server.swift in the package. Seems there is only the possibility to go via the curated library

I also gave @luomein's idea a try. Without success

@czechboy0
Copy link
Collaborator

If you open the package using open Package.swift instead of opening it within your Xcode workspace, does it still fail?

And sure, try with the curated library, it helps separate generated and hand-written code nicely anyway, and hopefully it'll address your issue.

@kelvinlauKL

This comment has been minimized.

@kelvinlauKL

This comment has been minimized.

@simonjbeaumont

This comment was marked as resolved.

@czechboy0
Copy link
Collaborator

Hi @timbms, were you able to resolve the issue?

@czechboy0
Copy link
Collaborator

Closing for now, please comment again if this is still reproducing and we can reopen.

@czechboy0 czechboy0 closed this as not planned Won't fix, can't repro, duplicate, stale Dec 11, 2023
@AkiraHayakawaJMAS
Copy link

AkiraHayakawaJMAS commented Feb 29, 2024

Hello.
I am also experiencing the same problem (version is 1.2.1).
Perhaps this is happening when you are using your own Package library from both iOS and watchOS app targets?

@czechboy0
Copy link
Collaborator

Can you provide your Package.swift? So far every time we saw this it was a misconfiguration.

@AkiraHayakawaJMAS
Copy link

@czechboy0
Thanks for the response.
I have prepared a sample app project.
SampleApp_issues_376.zip

It consists of an iOS app, a watchOS app and a library configured with a local Swift Package that uses openapi generator.
Try running SampleApp.xcworkspace with Xcode 15.0 or later and run build with the iOS application build scheme.
You will see that the error reported here is reported by Xcode.
On the other hand, if you remove the MyLibrary reference from the watchOS app target in the sample project, the build will succeed. (although the watchOS app cannot reference MyLibrary)

I think it is probably a problem with Xcode, Swift Package Manager, not with openapi generator, but I think it is very inconvenient at the moment, regardless of the solution.

@czechboy0
Copy link
Collaborator

I see, yes please file an issue using feedbackassistant.apple.com. In the meantime, as a workaround, you could switch to ahead-of-time generation which should hopefully unblock you: https://swiftpackageindex.com/apple/swift-openapi-generator/1.2.1/documentation/swift-openapi-generator/manually-invoking-the-generator-cli

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/support Adopter support requests.
Projects
None yet
Development

No branches or pull requests

6 participants