2 # Copyright 2016 The Chromium Authors. All rights reserved.
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.
22 ycm_module_path = os.path.normpath(
23 os.path.join(os.path.dirname(os.path.abspath(__file__)),
24 '../vim/chromium.ycm_extra_conf.py'))
25 ycm_extra_conf = imp.load_source('ycm_extra_conf', ycm_module_path)
28 usage = "usage: %prog [options] file"
29 parser = optparse.OptionParser(usage)
30 parser.add_option("-d", "--depot_tools", dest="depot_path",
31 help="path to depot_tools")
32 (options, args) = parser.parse_args()
33 if options.depot_path:
34 os.environ["PATH"] += ":%s" % options.depot_path
36 parser.error("incorrect number of arguments")
38 path = os.path.realpath(args[0])
39 results = ycm_extra_conf.FlagsForFile(path)
41 for flag in results['flags']:
42 # The sublimeclang plugin expects to parse its input with shlex.
43 # Defines and include path names may have spaces or quotes.
44 print pipes.quote(flag)
46 if __name__ == "__main__":