Bug 1522140 - Make .ycm_extra_conf.py handle headers better. r=Ehsan
authorEmilio Cobos Álvarez <emilio@crisal.io>
Wed, 23 Jan 2019 17:17:18 +0000
changeset 515141 2a22490b8a06c9a5eef192ef3192386f8e7ff74f
parent 515140 6aefbed9ce430f1da6b59a4ff98fb69375fa4f8f
child 515142 f4b12306c336c70a3d5a5bd5ede941507e59a126
push id1953
push userffxbld-merge
push dateMon, 11 Mar 2019 12:10:20 +0000
treeherdermozilla-release@9c35dcbaa899 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersEhsan
bugs1522140
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1522140 - Make .ycm_extra_conf.py handle headers better. r=Ehsan Files with .h extension are built with the c compiler by default, which makes the diagnostics useless. If we know this is a cpp file, hint it so that it builds it with the right mode. Differential Revision: https://phabricator.services.mozilla.com/D17372
.ycm_extra_conf.py
--- a/.ycm_extra_conf.py
+++ b/.ycm_extra_conf.py
@@ -19,16 +19,26 @@ path = os.path.join(os.path.dirname(__fi
 if not os.path.exists(path):
     path = os.path.join(os.path.dirname(__file__), 'config.status')
     config = imp.load_module('_buildconfig', open(path), path, ('', 'r', imp.PY_SOURCE))
     path = os.path.join(config.topsrcdir, 'mach')
 mach_module = imp.load_module('_mach', open(path), path, ('', 'r', imp.PY_SOURCE))
 
 sys.dont_write_bytecode = old_bytecode
 
+def _is_likely_cpp_header(filename):
+    if not filename.endswith('.h'):
+        return False
+
+    if filename.endswith('Inlines.h') or filename.endswith('-inl.h'):
+        return True
+
+    cpp_file = filename[:-1] + 'cpp'
+    return os.path.exists(cpp_file)
+
 def FlagsForFile(filename):
     mach = mach_module.get_mach()
     out = StringIO()
 
     # Mach calls sys.stdout.fileno(), so we need to fake it when capturing it.
     # Returning an invalid file descriptor does the trick.
     out.fileno = lambda: -1
     out.encoding = None
@@ -36,12 +46,15 @@ def FlagsForFile(filename):
 
     flag_list = shlex.split(out.getvalue())
 
     # This flag is added by Fennec for android build and causes ycmd to fail to parse the file.
     # Removing this flag is a workaround until ycmd starts to handle this flag properly.
     # https://github.com/Valloric/YouCompleteMe/issues/1490
     final_flags = [x for x in flag_list if not x.startswith('-march=armv')]
 
+    if _is_likely_cpp_header(filename):
+        final_flags += ["-x", "c++"]
+
     return {
         'flags': final_flags,
         'do_cache': True
     }