Upload upstream chromium 114.0.5735.31
[platform/framework/web/chromium-efl.git] / tools / sublime / ninja_options_script.py
1 #!/usr/bin/env python
2 # Copyright 2016 The Chromium Authors
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5 #
6 # Usage within SublimeClang:
7 #   "sublimeclang_options_script": "python
8 #       ${project_path}/src/tools/sublime/ninja_options_script.py \
9 #       -d '/path/to/depot_tools'"
10 #
11 #
12 # NOTE: ${project_path} expands to the directory of the Sublime project file,
13 # and SublimeClang passes the absolute file path to the current file as an
14 # additional argument. You should change the -d argument to point to your
15 # depot_tools directory.
16
17 from __future__ import print_function
18
19 import imp
20 import optparse
21 import os
22 import pipes
23
24 ycm_module_path = os.path.normpath(
25     os.path.join(os.path.dirname(os.path.abspath(__file__)),
26     '../vim/chromium.ycm_extra_conf.py'))
27 ycm_extra_conf = imp.load_source('ycm_extra_conf', ycm_module_path)
28
29 def main():
30   usage = "usage: %prog [options] file"
31   parser = optparse.OptionParser(usage)
32   parser.add_option("-d", "--depot_tools", dest="depot_path",
33                   help="path to depot_tools")
34   (options, args) = parser.parse_args()
35   if options.depot_path:
36     os.environ["PATH"] += ":%s" % options.depot_path
37   if len(args) != 1:
38     parser.error("incorrect number of arguments")
39
40   path = os.path.realpath(args[0])
41   results = ycm_extra_conf.FlagsForFile(path)
42
43   for flag in results['flags']:
44     # The sublimeclang plugin expects to parse its input with shlex.
45     # Defines and include path names may have spaces or quotes.
46     print(pipes.quote(flag))
47
48
49 if __name__ == "__main__":
50   main()