Xcodegen: Optional path not working

Created on 27 Mar 2019  路  12Comments  路  Source: yonaskolb/XcodeGen

Hi.
Following project spec should make optional file reference, but it's not made.

name: MyProject
targets:
  MyFramework:
    platform: iOS
    type: framework
    sources:
      - path: Sources
      - path: Sources/File.swift
        optional: true

527 might be related.

xcodegen 2.3.0

Thanks.

bug

Most helpful comment

After looking at the problem a bit more closely, I've decided to modify the change that was made in #527, by allowing missing file sources to be added when they are optional #557.
This was a regression and a bug. You can now continue to use optional for file sources. Missing directory sources will still not be added

All 12 comments

Hi @KyoheiG3. Could you explain your issue a bit more?
The optional property just controls whether XcodeGen will fail or not if the source is missing. It's doesn't make "optional file references" as you say

If create the above project.yml and execute xcodegen in the following file tree state:

I need the file reference to be created even if the file doesn't actually exist.

But, executing xcodegen does not create a file reference (File.swift). This is from version 2.3.0. The reason why I need the file reference is that the file may actually be created by a script etc in the build phase of xcode.
For example, run swiftgen in the build phase.

Oh I see. The optional property doesn't cater for that. As mentioned in https://github.com/yonaskolb/XcodeGen/pull/547 I would suggest running your other generation scripts before xcodegen. This issue tracks adding a preGen hook https://github.com/yonaskolb/XcodeGen/issues/479, but for now you can just add the script to a generate.sh script or something

Thank you for your reply. I'll wait to be merged #479.

@yonaskolb

I can't agree to close this issue.
Running the generator tool such as SwiftGen in preGen hook, slows down the execution of frequently executed xcodegen, and it's redundant because it executed even in the build phase.

Also, that a file is missing isn't an error, IMO.
It means a reference to the file that should be.
So I would like to leave an optional file reference in Xcode or add a new option like allows_missing.

Also, needs to run xcodegen & pod install twice if we installed SwiftGen via CocoaPods.

So some options would be:

  • run touch file.swift before generating
  • check in the swiftgen files
  • add new option in options.disabledValidations. Something like missingSourceFiles
  • add a flag to a target source so it adds a missing file to the project. Possible names:

    • generated: true

    • allowMissing: true

    • transient: true

In our use case, we use Sourcery with XcodeGen.

Before building a source with Sourcery, we have to generate Xcode project with XcodeGen.
We used optional to make a reference to not existed file on 2.1.0, however, we can't use anymore.

Your new proposal seems to work well also in this case 馃憤

I prefer to introduce allowMissing option.

Agreed.

I also prefer the allowMissing option.
If this opinion makes sense to @yonaskolb , I'll send a pull request within days.

That would be great @ra1028

After looking at the problem a bit more closely, I've decided to modify the change that was made in #527, by allowing missing file sources to be added when they are optional #557.
This was a regression and a bug. You can now continue to use optional for file sources. Missing directory sources will still not be added

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mrtsamma picture mrtsamma  路  3Comments

samedson picture samedson  路  5Comments

yonaskolb picture yonaskolb  路  3Comments

brentleyjones picture brentleyjones  路  6Comments

AlexisQapa picture AlexisQapa  路  3Comments