diff --git a/config_gen.py b/config_gen.py index c282026..ee10a6f 100755 --- a/config_gen.py +++ b/config_gen.py @@ -323,7 +323,8 @@ def parse_flags(build_log): # macro definitions should be handled separately, so we can resolve duplicates define_flags = dict() - define_regex = re.compile("-D([a-zA-Z0-9_]+)=(.*)") + define_regex = re.compile("-D\s*([a-zA-Z0-9_]+)(=.*)?") + define_flag = '-D' # Used to only bundle filenames with applicable arguments filename_flags = ["-o", "-I", "-isystem", "-include", "-imacros", "-isysroot"] @@ -337,8 +338,12 @@ def parse_flags(build_log): line_count += 1 words = split_flags(line) + cmd_pwd = './' + for (i, word) in enumerate(words): if(word[0] != '-' or not flags_whitelist.match(word)): + if(word.find('YCM_CONFIG_GEN_PWD') == 0): + cmd_pwd = word[word.find("=") + 1:] continue # handle macro definitions @@ -351,9 +356,13 @@ def parse_flags(build_log): continue + if(word == define_flag): + flags.add(word + words[i+1]) + continue + # include arguments for this option, if there are any, as a tuple if(i != len(words) - 1 and word in filename_flags and words[i + 1][0] != '-'): - flags.add((word, words[i + 1])) + flags.add((word, os.path.realpath(os.path.join(cmd_pwd, words[i + 1])))) else: flags.add(word) @@ -374,7 +383,10 @@ def parse_flags(build_log): print("WARNING: {} distinct definitions of macro {} found".format(len(values), name)) values.sort() - flags.add("-D{}={}".format(name, values[0])) + if values[0] != None: + flags.add("-D{}{}".format(name, values[0])) + else: + flags.add("-D{}".format(name)) return (line_count, skip_count, sorted(flags)) diff --git a/fake-toolchain/Unix/cc b/fake-toolchain/Unix/cc index 9a321b6..4c52fcd 100755 --- a/fake-toolchain/Unix/cc +++ b/fake-toolchain/Unix/cc @@ -9,6 +9,6 @@ elif [ "$1" = "-v" ] || [ "$1" = "--version" ]; then $YCM_CONFIG_GEN_CC_PASSTHROUGH $@ else - echo "$@" >> $YCM_CONFIG_GEN_CC_LOG + echo "YCM_CONFIG_GEN_PWD=$(pwd) $@" >> $YCM_CONFIG_GEN_CC_LOG fi