Bug 1770025 [wpt PR 34116] - Update wpt metadata, a=testonly
[gecko.git] / .ycm_extra_conf.py
blob26b584e90532f17ecc774fb02db08aaad5b9cb1e
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/.
5 from __future__ import absolute_import, print_function
6 import json
7 import os
8 import shlex
9 import subprocess
10 import sys
12 old_bytecode = sys.dont_write_bytecode
13 sys.dont_write_bytecode = True
15 path = os.path.abspath(os.path.join(os.path.dirname(__file__), "mach"))
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")
23 sys.dont_write_bytecode = old_bytecode
26 def _is_likely_cpp_header(filename):
27 if not filename.endswith(".h"):
28 return False
30 if filename.endswith("Inlines.h") or filename.endswith("-inl.h"):
31 return True
33 cpp_file = filename[:-1] + "cpp"
34 return os.path.exists(cpp_file)
37 def Settings(**kwargs):
38 if kwargs["language"] == "cfamily":
39 return FlagsForFile(kwargs["filename"])
40 # This is useful for generic language server protocols, like rust-analyzer,
41 # to discover the right project root instead of guessing based on where the
42 # closest Cargo.toml is.
43 return {
44 "project_directory": ".",
48 def FlagsForFile(filename):
49 output = subprocess.check_output([path, "compileflags", filename])
50 output = output.decode("utf-8")
52 flag_list = shlex.split(output)
54 # This flag is added by Fennec for android build and causes ycmd to fail to parse the file.
55 # Removing this flag is a workaround until ycmd starts to handle this flag properly.
56 # https://github.com/Valloric/YouCompleteMe/issues/1490
57 final_flags = [x for x in flag_list if not x.startswith("-march=armv")]
59 if _is_likely_cpp_header(filename):
60 final_flags += ["-x", "c++"]
62 return {"flags": final_flags, "do_cache": True}
65 if __name__ == "__main__":
66 print(FlagsForFile(sys.argv[1]))