-
Notifications
You must be signed in to change notification settings - Fork 454
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Resolve variable substitution for xcconfig declared build settings #501
Conversation
expression = /\$\((.*)\)/ | ||
match_data = config_setting.match(expression) | ||
if match_data.nil? | ||
return name if config_setting.eql?('CONFIGURATION') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this is an exhaustive way to resolve the value, would love feedback on this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this only change the behavior when $(CONFIGURATION)
needs to be expanded?
@@ -82,6 +82,7 @@ def type | |||
def resolve_build_setting(key) | |||
setting = build_settings[key] | |||
config_setting = base_configuration_reference && config[key] | |||
config_setting = resolve_variable_substitution(config_setting) if !config_setting.nil? && config_setting.is_a?(String) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need to check is_a?(String)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
xcconfig file parsing goes through XCBuildConfiguration#normalize_array_settings
and we get array values from there. I'm completely ignoring those, as I believe it's mostly used for OTHER_LDFLAGS
, but I don't fully understand why those have to be arrays, I assume this is expected in other parts of system.
@segiddins not sure if I get the question correctly. Previously |
But does it effect any other setting names? |
@segiddins Yes. It basically should capture anything between Sorry about the rebase, someone reported a problem with my implementation, which should be fixed now. I'll add more tests to try to cover all the different scenarios. |
This looks reasonable to me. 👍 |
The major thing to watch out for is that the variables you are attempting to expand are actually valid as xcconfig identifiers. Otherwise you are going to run into problems with invalid xcconfig files and people wondering why their unicode configuration names aren't working as expected. |
Some changes I did after the last review:
Thanks to the feedback on fastlane/fastlane#9760 (comment) I realised that there's a problem with this approach: If a build setting defined at a project level uses variable substitution referencing values at a target level the method won't work. I'm still looking into this. Ideally I'd like to jump to the target level from this point (if Update: I think that problem can be avoided by using |
…tween project and targets
@segiddins @dantoml anything else I can do here to move forward this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks 👍 other than the minor comments
setting = build_settings[key] | ||
setting = resolve_variable_substitution(setting, root_target) if !setting.nil? && setting.is_a?(String) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
checking both nil?
and is_a?
is redundant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes totally sense!
config_setting = base_configuration_reference && config[key] | ||
config_setting = resolve_variable_substitution(config_setting, root_target) if !config_setting.nil? && config_setting.is_a?(String) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
checking both nil? and is_a? is redundant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes totally sense!
@@ -103,6 +108,20 @@ def expand_build_setting(build_setting_value, config_value) | |||
build_setting_value.map { |value| Constants::INHERITED_KEYWORDS.include?(value) ? inherited : value }.flatten | |||
end | |||
|
|||
def resolve_variable_substitution(config_setting, root_target) | |||
expression = /\$[{(]([^inherited][$(){}_a-zA-Z0-9]*?)[})]/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extract this into a constant and please comment the regexp
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
…pression to local class constant
I'll let @dantoml merge this one |
@@ -96,13 +101,42 @@ def resolve_build_setting(key) | |||
|
|||
private | |||
|
|||
CAPTURE_VARIABLE_IN_BUILD_CONFIG = / |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for documenting the regex 👍
Any plans for a new release with this commit? |
@litalhassine you can use http://bundler.io/ and point to a specific SHA or branch to use this. |
@dnkoutso it would be really nice to have this as a patch release (probably nobody is using that API anyway) so we could submit a fix for the issue described here: fastlane/fastlane#9460 (comment). |
Thanks this resolved one of the issue I had in my sample for environment variables substitution So it did not work with xcodeproj 1.5.1 However it works in 1.5.2, great work 🚀 |
This don't seem to work for me. I am using fastlane and it always fails on export now, did work earlier though (Xcode8? Xcode9 now). I have I see This worked for a while and now it does not... |
@epatel I'm happy to have a look if you could open an issue with a sample project to reproduce this. |
Currently, given an xcconfig like:
Using
XCBuildConfiguration#resolve_build_setting
forPRODUCT_BUNDLE_IDENTIFIER
would return$(PRODUCT_BUNDLE_IDENTIFIER_$(CONFIGURATION))
. With this change, it returns the proper valuecom.cocoapods.app
orcom.cocoapods.app.dev
depending of the configuration.