ninja_options_script.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/usr/bin/env python
  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.
  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. from __future__ import print_function
  17. import imp
  18. import optparse
  19. import os
  20. import pipes
  21. ycm_module_path = os.path.normpath(
  22. os.path.join(os.path.dirname(os.path.abspath(__file__)),
  23. '../vim/chromium.ycm_extra_conf.py'))
  24. ycm_extra_conf = imp.load_source('ycm_extra_conf', ycm_module_path)
  25. def main():
  26. usage = "usage: %prog [options] file"
  27. parser = optparse.OptionParser(usage)
  28. parser.add_option("-d", "--depot_tools", dest="depot_path",
  29. help="path to depot_tools")
  30. (options, args) = parser.parse_args()
  31. if options.depot_path:
  32. os.environ["PATH"] += ":%s" % options.depot_path
  33. if len(args) != 1:
  34. parser.error("incorrect number of arguments")
  35. path = os.path.realpath(args[0])
  36. results = ycm_extra_conf.FlagsForFile(path)
  37. for flag in results['flags']:
  38. # The sublimeclang plugin expects to parse its input with shlex.
  39. # Defines and include path names may have spaces or quotes.
  40. print(pipes.quote(flag))
  41. if __name__ == "__main__":
  42. main()