.ycm_extra_conf.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # This Source Code Form is subject to the terms of the Mozilla Public
  2. # License, v. 2.0. If a copy of the MPL was not distributed with this
  3. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
  4. import imp
  5. import os
  6. import shlex
  7. import sys
  8. try:
  9. from StringIO import StringIO
  10. except ImportError:
  11. from io import StringIO
  12. old_bytecode = sys.dont_write_bytecode
  13. sys.dont_write_bytecode = True
  14. path = os.path.join(os.path.dirname(__file__), 'mach')
  15. if not os.path.exists(path):
  16. path = os.path.join(os.path.dirname(__file__), 'config.status')
  17. config = imp.load_module('_buildconfig', open(path), path, ('', 'r', imp.PY_SOURCE))
  18. path = os.path.join(config.topsrcdir, 'mach')
  19. mach_module = imp.load_module('_mach', open(path), path, ('', 'r', imp.PY_SOURCE))
  20. sys.dont_write_bytecode = old_bytecode
  21. def FlagsForFile(filename):
  22. mach = mach_module.get_mach()
  23. out = StringIO()
  24. # Mach calls sys.stdout.fileno(), so we need to fake it when capturing it.
  25. # Returning an invalid file descriptor does the trick.
  26. out.fileno = lambda: -1
  27. out.encoding = None
  28. mach.run(['compileflags', filename], stdout=out, stderr=out)
  29. flag_list = shlex.split(out.getvalue())
  30. # This flag is added by Fennec for android build and causes ycmd to fail to parse the file.
  31. # Removing this flag is a workaround until ycmd starts to handle this flag properly.
  32. # https://github.com/Valloric/YouCompleteMe/issues/1490
  33. final_flags = [x for x in flag_list if not x.startswith('-march=armv')]
  34. return {
  35. 'flags': final_flags,
  36. 'do_cache': True
  37. }