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

Swift plugin target sourceFiles do not include generated files #6221

Open
doozMen opened this issue Mar 3, 2023 · 0 comments
Open

Swift plugin target sourceFiles do not include generated files #6221

doozMen opened this issue Mar 3, 2023 · 0 comments
Labels

Comments

@doozMen
Copy link

doozMen commented Mar 3, 2023

Description

I have a plugin that generates a swift file on build via a plugin. In another target in the same package I would like to use that file as input. However I notice that the sourcefiles on the target do not include generated source files in the pluginWorkingDirectory?

Inside my plugin I have the following:

import Foundation
import PackagePlugin

enum Error: Swift.Error {
  case missingAssetSwiftFile
  case missingUIComponents
}

@main
struct ReuseGenerated: BuildToolPlugin {

  func createBuildCommands(context: PluginContext, target: Target) async throws -> [Command] {

    print("📦 reuse generated started")
    guard let uiComponents = try context.package.targets(named: ["UIComponents"]).first as? SwiftSourceModuleTarget else {
      throw Error.missingUIComponents
    }
    print("Did find files in UIComponents")

    print(uiComponents.sourceFiles.map { $0.path.string}.joined(separator: "\n"))

    print("---")

    guard let swiftAssetFile = (uiComponents.sourceFiles.first { $0.path.lastComponent == "Assets.swift"}) else {
      throw Error.missingAssetSwiftFile
    }

    let output = context.pluginWorkDirectory.appending("Assets.swift")

    return [
      .prebuildCommand(
        displayName: "📦 Generate new content based on generated source code of other target",
        executable: .init("/usr/bin/touch"),
        arguments: [output.string],
        outputFilesDirectory: context.pluginWorkDirectory)
    ]
  }

}

Expected behavior

I would expect the file generated before to be there, or the docs telling me that sourceFiles only include non generated files

Actual behavior

It is not there

Steps to reproduce

I have created a sample project reporduces the issue when building lib Foo doozMen/swift-generated-asset-plugin: Shows how to generate an asset catalog that can load colors into a SwiftUI view from the plugin working directory

Swift Package Manager version/commit hash

releases with xcode 14.3 beta 2

Swift & OS version (output of swift --version && uname -a)

swift-driver version: 1.75.1 Apple Swift version 5.8 (swiftlang-5.8.0.119.11 clang-1403.0.22.11.100)
Target: arm64-apple-macosx13.0
Darwin stijns-mac.lan 22.3.0 Darwin Kernel Version 22.3.0: Mon Jan 30 20:38:37 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6000 arm64

@doozMen doozMen added the bug label Mar 3, 2023
@neonichu neonichu self-assigned this Mar 3, 2023
@neonichu neonichu removed their assignment Jan 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants