From 91cc9560984742709426f5b685487d781222e033 Mon Sep 17 00:00:00 2001 From: Leo Fang Date: Sun, 23 Oct 2016 13:24:06 -0400 Subject: [PATCH] Add the workaround from https://gist.github.com/cpradog/aad88d51001ea83ecfc6 In the FAQ of [Valloric/YouCompleteMe](https://github.com/Valloric/YouCompleteMe), there was an issue of C++ standard library headers not found (Valloric/YouCompleteMe#303) that has been resolved with a workaround, and @cpradog has kindly implemented it. However, this workaround has not yet been incorporated into template.py in [rdnetto/YCM-Generator](https://github.com/rdnetto/YCM-Generator), so adding this becomes the main purpose of this fork. --- template.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/template.py b/template.py index 2985a70..d9cb772 100644 --- a/template.py +++ b/template.py @@ -30,12 +30,28 @@ import os import ycm_core +import re +import subprocess + flags = [ # INSERT FLAGS HERE ] +def LoadSystemIncludes(): + regex = re.compile(ur'(?:\#include \<...\> search starts here\:)(?P.*?)(?:End of search list)', re.DOTALL); + process = subprocess.Popen(['clang', '-v', '-E', '-x', 'c++', '-'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE); + process_out, process_err = process.communicate(''); + output = process_out + process_err; + includes = []; + for p in re.search(regex, output).group('list').split('\n'): + p = p.strip(); + if len(p) > 0 and p.find('(framework directory)') < 0: + includes.append('-isystem'); + includes.append(p); + return includes; + # Set this to the absolute path to the folder (NOT the file!) containing the # compile_commands.json file to use that instead of 'flags'. See here for # more details: http://clang.llvm.org/docs/JSONCompilationDatabase.html @@ -54,6 +70,8 @@ database = None SOURCE_EXTENSIONS = [ '.C', '.cpp', '.cxx', '.cc', '.c', '.m', '.mm' ] +systemIncludes = LoadSystemIncludes(); +flags = flags + systemIncludes; def DirectoryOfThisScript(): return os.path.dirname( os.path.abspath( __file__ ) ) @@ -121,7 +139,7 @@ def FlagsForFile( filename, **kwargs ): final_flags = MakeRelativePathsInFlagsAbsolute( compilation_info.compiler_flags_, - compilation_info.compiler_working_dir_ ) + compilation_info.compiler_working_dir_ ) + systemIncludes else: relative_to = DirectoryOfThisScript()