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.
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'"
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.
17 from __future__ import print_function
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)
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
38 parser.error("incorrect number of arguments")
40 path = os.path.realpath(args[0])
41 results = ycm_extra_conf.FlagsForFile(path)
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))
49 if __name__ == "__main__":