2015-04-24 22:12:50 +03:00
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
# 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/.
|
|
|
|
|
2019-01-23 18:58:44 +03:00
|
|
|
from __future__ import absolute_import, print_function
|
|
|
|
import json
|
2015-04-24 22:12:50 +03:00
|
|
|
import os
|
|
|
|
import shlex
|
2019-01-23 18:58:44 +03:00
|
|
|
import subprocess
|
2015-05-07 14:48:00 +03:00
|
|
|
import sys
|
|
|
|
|
|
|
|
old_bytecode = sys.dont_write_bytecode
|
|
|
|
sys.dont_write_bytecode = True
|
2015-04-24 22:12:50 +03:00
|
|
|
|
2020-10-24 03:36:18 +03:00
|
|
|
path = os.path.abspath(os.path.join(os.path.dirname(__file__), "mach"))
|
2015-04-24 22:12:50 +03:00
|
|
|
|
2019-01-23 18:58:44 +03:00
|
|
|
# If mach is not here, we're on the objdir go to the srcdir.
|
2015-04-24 22:12:50 +03:00
|
|
|
if not os.path.exists(path):
|
2020-10-24 03:36:18 +03:00
|
|
|
with open(os.path.join(os.path.dirname(__file__), "mozinfo.json")) as info:
|
2019-01-23 18:58:44 +03:00
|
|
|
config = json.loads(info.read())
|
2020-10-24 03:36:18 +03:00
|
|
|
path = os.path.join(config["topsrcdir"], "mach")
|
2015-04-24 22:12:50 +03:00
|
|
|
|
2015-05-07 14:48:00 +03:00
|
|
|
sys.dont_write_bytecode = old_bytecode
|
|
|
|
|
2020-10-26 21:34:53 +03:00
|
|
|
|
2019-01-23 20:17:18 +03:00
|
|
|
def _is_likely_cpp_header(filename):
|
2020-10-24 03:36:18 +03:00
|
|
|
if not filename.endswith(".h"):
|
2019-01-23 20:17:18 +03:00
|
|
|
return False
|
|
|
|
|
2020-10-24 03:36:18 +03:00
|
|
|
if filename.endswith("Inlines.h") or filename.endswith("-inl.h"):
|
2019-01-23 20:17:18 +03:00
|
|
|
return True
|
|
|
|
|
2020-10-24 03:36:18 +03:00
|
|
|
cpp_file = filename[:-1] + "cpp"
|
2019-01-23 20:17:18 +03:00
|
|
|
return os.path.exists(cpp_file)
|
|
|
|
|
2020-04-28 13:08:00 +03:00
|
|
|
|
|
|
|
def Settings(**kwargs):
|
2020-10-24 03:36:18 +03:00
|
|
|
if kwargs["language"] == "cfamily":
|
|
|
|
return FlagsForFile(kwargs["filename"])
|
2020-06-17 20:53:56 +03:00
|
|
|
# This is useful for generic language server protocols, like rust-analyzer,
|
|
|
|
# to discover the right project root instead of guessing based on where the
|
|
|
|
# closest Cargo.toml is.
|
|
|
|
return {
|
2020-10-24 03:36:18 +03:00
|
|
|
"project_directory": ".",
|
2020-06-17 20:53:56 +03:00
|
|
|
}
|
2020-04-28 13:08:00 +03:00
|
|
|
|
|
|
|
|
2015-04-24 22:12:50 +03:00
|
|
|
def FlagsForFile(filename):
|
2020-10-24 03:36:18 +03:00
|
|
|
output = subprocess.check_output([path, "compileflags", filename])
|
|
|
|
output = output.decode("utf-8")
|
2016-08-09 07:00:20 +03:00
|
|
|
|
2019-01-23 18:58:44 +03:00
|
|
|
flag_list = shlex.split(output)
|
2015-05-04 08:15:00 +03:00
|
|
|
|
|
|
|
# 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.
|
|
|
|
# https://github.com/Valloric/YouCompleteMe/issues/1490
|
2020-10-24 03:36:18 +03:00
|
|
|
final_flags = [x for x in flag_list if not x.startswith("-march=armv")]
|
2015-05-04 08:15:00 +03:00
|
|
|
|
2019-01-23 20:17:18 +03:00
|
|
|
if _is_likely_cpp_header(filename):
|
|
|
|
final_flags += ["-x", "c++"]
|
|
|
|
|
2020-10-24 03:36:18 +03:00
|
|
|
return {"flags": final_flags, "do_cache": True}
|
2020-10-26 21:34:53 +03:00
|
|
|
|
2019-01-23 18:58:44 +03:00
|
|
|
|
2020-10-24 03:36:18 +03:00
|
|
|
if __name__ == "__main__":
|
2019-01-23 18:58:44 +03:00
|
|
|
print(FlagsForFile(sys.argv[1]))
|