yonaskolb / XcodeGen

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

Clang settings appears to be applied to the wrong configuration list in the project.pbxproj file #1184

Open tww0003 opened 2 years ago

tww0003 commented 2 years ago

Clang settings appear to be added to the wrong configuration list within the project.pbxproj file.

When trying to set CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED to YES in order to silence a warning, Xcodegen adds them to the PBXNativeTarget build configuration list while changing the setting within Xcode applies it within the PBXProject build configuration list.

Is there a way to make sure that this setting gets applied to the correct configuration list?

yonaskolb commented 2 years ago

You can apply the setting to the whole project under the top level settings, instead of in a target

philprime commented 4 months ago

Still an issue.

Setting it on the project level works, but I believe it should also be possible setting on individual targets.

yonaskolb commented 2 months ago

I'm not sure I understand the issue? What is Xcode doing that is different? If when you're applying this in Xcode using the Build Settings tab, it applies the set build setting depending at which level you click on (target, project, config..etc). Is there something specific about this particular build setting I'm not understanding?

philprime commented 2 months ago

I am trying to create a reproducible example

philprime commented 2 months ago

Ok I tried it multiple times even before posting my comment with a project from scratch, but could not reproduce it. I can still reproduce it in our mono-repo with an Xcode workspace and two Xcode Projects containing a variety of targets. I just tried to reduce the project to minimal version, so I can upload it here, but for some reason the issue disappeared during that.

But to give you some insights on the issue, I can at least give further explanation:

First my project file looked roughly like this:

targets:
  Editor:
    type: application
    platform: iOS
    sources:
      - Sources
    settingPresets: all
    settings:
      base:
        INFOPLIST_FILE: Generated/XcodeGen/Editor/Base.lproj/Info.plist

Which resulted in this warning:

Screenshot 2024-04-19 at 14 21 53

So I added the necessary settings:

targets:
  Editor:
    type: application
    platform: iOS
    sources:
      - Sources
    settingPresets: all
    settings:
      base:
        INFOPLIST_FILE: Generated/XcodeGen/Editor/Base.lproj/Info.plist

        CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED: 'YES'
        ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS: 'NO'
        ENABLE_USER_SCRIPT_SANDBOXING: 'NO'

The warning still persists, but now the 'Enable User Script Sandboxing' is gone:

Screenshot 2024-04-19 at 14 23 57

I expected all warnings to be resolved. Now if I move the settings to a project wide settings area, like this:

settings:
  CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED: 'YES'
  ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS: 'NO'
  ENABLE_USER_SCRIPT_SANDBOXING: 'NO'

targets:
  Editor:
    type: application
    platform: iOS
    sources:
      - Sources
    settingPresets: all
    settings:
      base:
        INFOPLIST_FILE: Generated/XcodeGen/Editor/Base.lproj/Info.plist

        CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED: 'YES'
        ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS: 'NO'
        ENABLE_USER_SCRIPT_SANDBOXING: 'NO'

The warnings are gone, and the diff of the project.pbxproj looks like this for the 'Debug', 'Staging' and 'Production' configuration:

Screenshot 2024-04-19 at 14 26 56

Now if I remove the settings from the target like the following:

settings:
  CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED: 'YES'
  ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS: 'NO'
  ENABLE_USER_SCRIPT_SANDBOXING: 'NO'

#########
# Targets
#########

targets:
  Editor:
    type: application
    platform: iOS
    sources:
      - Sources
    settingPresets: all
    settings:
      base:
        INFOPLIST_FILE: Generated/XcodeGen/Editor/Base.lproj/Info.plist

        # CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED: 'YES'
        # ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS: 'NO'
        # ENABLE_USER_SCRIPT_SANDBOXING: 'NO'

The errors are still gone and the changes in the project.pbxproj look like this:

Screenshot 2024-04-19 at 14 29 32