mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-07 18:04:46 +00:00
Bug 1522135 - Make .ycm_extra_conf.py work with python3. r=jgraham
By calling into mach instead, which knows how to get to run itself with the right python version. Differential Revision: https://phabricator.services.mozilla.com/D17371
This commit is contained in:
parent
5a3fdda6e0
commit
85a91cac86
@ -2,25 +2,23 @@
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
import imp
|
||||
from __future__ import absolute_import, print_function
|
||||
import json
|
||||
import os
|
||||
import shlex
|
||||
import subprocess
|
||||
import sys
|
||||
try:
|
||||
from StringIO import StringIO
|
||||
except ImportError:
|
||||
from io import StringIO
|
||||
|
||||
old_bytecode = sys.dont_write_bytecode
|
||||
sys.dont_write_bytecode = True
|
||||
|
||||
path = os.path.join(os.path.dirname(__file__), 'mach')
|
||||
path = os.path.abspath(os.path.join(os.path.dirname(__file__), 'mach'))
|
||||
|
||||
# If mach is not here, we're on the objdir go to the srcdir.
|
||||
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))
|
||||
with open(os.path.join(os.path.dirname(__file__), 'mozinfo.json')) as info:
|
||||
config = json.loads(info.read())
|
||||
path = os.path.join(config['topsrcdir'], 'mach')
|
||||
|
||||
sys.dont_write_bytecode = old_bytecode
|
||||
|
||||
@ -35,16 +33,10 @@ def _is_likely_cpp_header(filename):
|
||||
return os.path.exists(cpp_file)
|
||||
|
||||
def FlagsForFile(filename):
|
||||
mach = mach_module.get_mach()
|
||||
out = StringIO()
|
||||
output = subprocess.check_output([path, 'compileflags', filename])
|
||||
output = output.decode('utf-8')
|
||||
|
||||
# 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
|
||||
mach.run(['compileflags', filename], stdout=out, stderr=out)
|
||||
|
||||
flag_list = shlex.split(out.getvalue())
|
||||
flag_list = shlex.split(output)
|
||||
|
||||
# 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.
|
||||
@ -58,3 +50,6 @@ def FlagsForFile(filename):
|
||||
'flags': final_flags,
|
||||
'do_cache': True
|
||||
}
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(FlagsForFile(sys.argv[1]))
|
||||
|
Loading…
Reference in New Issue
Block a user