yonaskolb / XcodeGen

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

Support generating multiple Info.plist files for single target #940

Open yhkaplan opened 4 years ago

yhkaplan commented 4 years ago

I use separate Info.plist files for different build configurations, but they share many of the same values, so I would like to use XcodeGen to generate them. Looking through the documentation and existing GitHub issues, it doesn't appear that generating multiple Info.plist files for a single target is currently possible, so I have a few questions.

As for background info, the differences between the release and debug info.plists include: CFBundleDisplayName (${PRODUCT_NAME} Beta for debug builds), FacebookAppID, NSAllowsLocalNetworking, and some NSExceptionDomains (production versus staging environments for third party services).

  1. Is this already possible in some way I overlooked?
  2. Is this a feature you would benefit from me adding in a PR?
  3. Is there some alternate method people use instead of separate plists?
yonaskolb commented 4 years ago
  1. It's not currently possible to generate multiple per target
  2. It's come up once before, so happy for a PR
  3. Generation is just a convenience. You can still reference multiple plists that are checked in like normal, just by changing the INFOPLIST_FILE build setting per config
frederoni commented 3 years ago

For posterity, you can overwrite individual values in the Info.plist with INFOPLIST_PREPROCESS and INFOPLIST_PREPROCESSOR_DEFINITIONS

Example:

<key>CFBundleDisplayName</key>
<string>MY_DISPLAY_NAME</string>
settings:
    base:
        INFOPLIST_PREPROCESS: YES
        INFOPLIST_FILE: Info.plist
    Staging:
        INFOPLIST_PREPROCESSOR_DEFINITIONS: "MY_DISPLAY_NAME=AppStaging"
    Production:
        INFOPLIST_PREPROCESSOR_DEFINITIONS: "MY_DISPLAY_NAME=App"
yonaskolb commented 3 years ago

Wow, didn’t know that, thanks @frederoni!

sroebert commented 3 years ago

Unfortunately INFOPLIST_PREPROCESS only works for string related settings, not for dictionaries/booleans. I would for example like to add NSAppTransportSecurity only for the debug configuration. I think this feature could still add a lot of benefit.

Instead of INFOPLIST_PREPROCESS, you can btw also simply refer to settings using $(SETTING_NAME) name in the plist file.