Xcode 4.3 - preprocess plist not working anymore for #define with "http://"?
Asked Answered
E

2

6

I just upgraded to the latest 4.3 Xcode. I have my plist.which is preprocessed and compared to 4.2 does not seem to work anymore.

I set Info.plist other pre-processor flag -traditional (to be able to skip // considered as a comment).

I set

 #define MYSERVER  http://127.0.0.1:1234/

and in my plist

    <key>myhost</key>
    <string>MYSERVER</string>

When I check in the new Xcode 4.3 I see inside NSDictionary *bundle = [[NSBundle mainBundle] infoDictionary];

 myhost = "http:/ /127.0.0.1:1234/"

I have a quick hack for it.

    NSString *hack = [[[[NSBundle mainBundle] infoDictionary] objectForKey:@"myhost"] stringByReplacingOccurrencesOfString:@" " withString:@""];
    url = [NSURL URLWithString:hack];

This is making my app working again, but I would like to have a clean solution. Any ideas?

Eleventh answered 18/2, 2012 at 5:0 Comment(1)
The comment in the clang bug says this is fixed (llvm.org/bugs/show_bug.cgi?id=12035), but as of Xcode 7.2 it is not working for me. The documentation for -traditional is here: developer.apple.com/library/mac/technotes/tn2175/_index.htmlGuava
E
3

This is actually a bug in clang's preprocessor which is shipped with Xcode 4.3 (clang 3.1) and it affects all preprocessing, not just Info.plists. I've filed a bug (LLVM bug 12035, rdar://10883862).

A workaround for this is to force Xcode 4.3 to use llvm-gcc for Info.plist preprocessing instead of clang. The only way I've found so far is to rewrite the "cc" symlink which is used in Info.plist preprocessing phase:

sudo ln -fs /usr/bin/llvm-gcc /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc

To revert this hack, just rewrite it back to clang: sudo ln -fs /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc

Euphemize answered 19/2, 2012 at 8:36 Comment(3)
Thanks for this info. I'll keep watching the bug you filed and hope it will be shortly fixed.Eleventh
Another solution, which doesn't require replacing cc symlink, is to place all Info.plist macro expansion values in quotes and trim the quotes when reading the values at runtime. Quoted values will be preserved by clang's preprocessor.Euphemize
thanks. That is similar to (temporary) hack :-) NSString *hack = [[[[NSBundle mainBundle] infoDictionary] objectForKey:@"myhost"] stringByReplacingOccurrencesOfString:@" " withString:@""];Eleventh
B
0

You could consider skipping the pre-processor and use PlistBuddy.

Something like this in the script phase of the build should work:

#!/bin/sh

MYSERVER = 'http://127.0.0.1:1234/'

/usr/libexec/PlistBuddy -c "Set :myhost ${MYSERVER}" path/to/Info.plist

Notice that if you do it on the ProejctName-Info.plist in a standard Xcode setup, the file will be marked as modified by svn/github each time you build, and depending on your needs that may not be ideal.

Basis answered 18/2, 2012 at 10:7 Comment(1)
thanks, but I have more than few #define I use #if defined .... to switch between different environments. Move to a different tool will not be so straight forward.Eleventh

© 2022 - 2024 — McMap. All rights reserved.