jerrymarino/XcodeCompilationDatabase

CommandLine arguments not escaped

AndreasVerhoeven opened this issue · 3 comments

First of all: great tool!

The arguments in XCDependencyCommandInvocationRecord.commandLineArguments are unescaped (e.g. think of path with spaces), however, the command in the compile_commands.json espects a commandline and thus escaped arguments.

This creates a problem with paths with spaces, which get an invalid entry in the compilation database. As a quick fix, I added the following piece of code to EntriesForCompileCRecord:

NSMutableArray* escapedCLIArgs = [NSMutableArray arrayWithCapacity:CLIArgs.count];
    for(NSString* arg in CLIArgs)
    {
        NSString* escapedArg = [arg stringByReplacingOccurrencesOfString:@" " withString:@"\\ "];
        [escapedCLIArgs addObject:escapedArg];
    }
    CLIArgs = [escapedCLIArgs copy];

A more robust fix might be more desirable tho. If you're fin with this, please let me know and I'll make a PR

@AndreasVerhoeven thanks for the kind words and feedback, I hope this is useful for you.

You make a really good point, it doesn't support file names with spaces at all.

If you have the bandwidth to submit a PR ( in any capacity ), I'd be happy to merge it in 👍

Great, I have opened a PR that fixes the spaces issue at least!

This was solved - thanks for merging the PR! :)