Blame .ycm_extra_conf.py

Packit f0b94e
# This Source Code Form is subject to the terms of the Mozilla Public
Packit f0b94e
# License, v. 2.0. If a copy of the MPL was not distributed with this
Packit f0b94e
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
Packit f0b94e
Packit f0b94e
import imp
Packit f0b94e
import os
Packit f0b94e
import shlex
Packit f0b94e
import sys
Packit f0b94e
try:
Packit f0b94e
    from StringIO import StringIO
Packit f0b94e
except ImportError:
Packit f0b94e
    from io import StringIO
Packit f0b94e
Packit f0b94e
old_bytecode = sys.dont_write_bytecode
Packit f0b94e
sys.dont_write_bytecode = True
Packit f0b94e
Packit f0b94e
path = os.path.join(os.path.dirname(__file__), 'mach')
Packit f0b94e
Packit f0b94e
if not os.path.exists(path):
Packit f0b94e
    path = os.path.join(os.path.dirname(__file__), 'config.status')
Packit f0b94e
    config = imp.load_module('_buildconfig', open(path), path, ('', 'r', imp.PY_SOURCE))
Packit f0b94e
    path = os.path.join(config.topsrcdir, 'mach')
Packit f0b94e
mach_module = imp.load_module('_mach', open(path), path, ('', 'r', imp.PY_SOURCE))
Packit f0b94e
Packit f0b94e
sys.dont_write_bytecode = old_bytecode
Packit f0b94e
Packit f0b94e
def FlagsForFile(filename):
Packit f0b94e
    mach = mach_module.get_mach()
Packit f0b94e
    out = StringIO()
Packit f0b94e
Packit f0b94e
    # Mach calls sys.stdout.fileno(), so we need to fake it when capturing it.
Packit f0b94e
    # Returning an invalid file descriptor does the trick.
Packit f0b94e
    out.fileno = lambda: -1
Packit f0b94e
    out.encoding = None
Packit f0b94e
    mach.run(['compileflags', filename], stdout=out, stderr=out)
Packit f0b94e
Packit f0b94e
    flag_list = shlex.split(out.getvalue())
Packit f0b94e
Packit f0b94e
    # This flag is added by Fennec for android build and causes ycmd to fail to parse the file.
Packit f0b94e
    # Removing this flag is a workaround until ycmd starts to handle this flag properly.
Packit f0b94e
    # https://github.com/Valloric/YouCompleteMe/issues/1490
Packit f0b94e
    final_flags = [x for x in flag_list if not x.startswith('-march=armv')]
Packit f0b94e
Packit f0b94e
    return {
Packit f0b94e
        'flags': final_flags,
Packit f0b94e
        'do_cache': True
Packit f0b94e
    }