kronenthaler / mod-pbxproj

A python module to manipulate XCode projects
MIT License
1.2k stars 294 forks source link

[FEAT] How do you get a flag value ? #329

Open pitoneux opened 1 year ago

pitoneux commented 1 year ago

thanks for this package!

Question: I want to change the minimum version of the project only if it is different from a given value. The idea is I don't want to mess with the project file if I don't have to.

1) read the current value 2) compare to another value 3) if different change it and save the new project file.

so something like

minimumVersion = project.get_flag(IPHONEOS_DEPLOYMENT_TARGET)

with the standard options to get it from a given target...

is there a way to do this ?

May be the "set_flag" method could return how many flags got changed ? we could decide to save or not then...

Also, would be nice to have a single page with all the methods...

thanks in advance for your help!

kronenthaler commented 1 year ago

There are some reasons why this API does not exist. The following snippet will probably solve your issue and will help to explain why is not practical.

for conf in project.objects.get_project_configurations('Debug'): # returns a generator
    print(conf.buildSettings['IPHONEOS_DEPLOYMENT_TARGET'])

or in a one-liner

next(project.objects.get_project_configurations('Debug')).buildSettings['IPHONEOS_DEPLOYMENT_TARGET']

As you can see, the main problem is that the flags (for projects and/or targets) are bound to a configuration. You need to specify the configuration you want to add them to or read them from.

In most methods, a configuration_name parameter is provided, which can be ignored (defaults to None), in which case the action takes place in ALL configurations available. There already exist a set_flags method for the targets and add_project_flags for projects, but they do not return anything because it can be applied to multiple configurations.

I'm trying to not add too many wrapper methods as it will become harder and harder to maintain, but if it makes sense i will include it. But no promises.