Revision control

Other Tools

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
5
from __future__ import absolute_import, print_function
6
import json
7
import os
8
import shlex
9
import subprocess
10
import sys
11
12
old_bytecode = sys.dont_write_bytecode
13
sys.dont_write_bytecode = True
14
15
path = os.path.abspath(os.path.join(os.path.dirname(__file__), 'mach'))
16
17
# If mach is not here, we're on the objdir go to the srcdir.
18
if not os.path.exists(path):
19
with open(os.path.join(os.path.dirname(__file__), 'mozinfo.json')) as info:
20
config = json.loads(info.read())
21
path = os.path.join(config['topsrcdir'], 'mach')
22
23
sys.dont_write_bytecode = old_bytecode
24
25
def _is_likely_cpp_header(filename):
26
if not filename.endswith('.h'):
27
return False
28
29
if filename.endswith('Inlines.h') or filename.endswith('-inl.h'):
30
return True
31
32
cpp_file = filename[:-1] + 'cpp'
33
return os.path.exists(cpp_file)
34
35
def FlagsForFile(filename):
36
output = subprocess.check_output([path, 'compileflags', filename])
37
output = output.decode('utf-8')
38
39
flag_list = shlex.split(output)
40
41
# This flag is added by Fennec for android build and causes ycmd to fail to parse the file.
42
# Removing this flag is a workaround until ycmd starts to handle this flag properly.
44
final_flags = [x for x in flag_list if not x.startswith('-march=armv')]
45
46
if _is_likely_cpp_header(filename):
47
final_flags += ["-x", "c++"]
48
49
return {
50
'flags': final_flags,
51
'do_cache': True
52
}
53
54
if __name__ == '__main__':
55
print(FlagsForFile(sys.argv[1]))