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
xcodegen 2.3.0
Thanks.
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:
touch file.swift before generatingoptions.disabledValidations. Something like missingSourceFilesgenerated: trueallowMissing: truetransient: trueIn 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
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
optionalfor file sources. Missing directory sources will still not be added