Home | History | Annotate | Download | only in support
      1 # Copyright 2014 The Chromium Authors. All rights reserved.
      2 # Use of this source code is governed by a BSD-style license that can be
      3 # found in the LICENSE file.
      4 
      5 import os.path
      6 from subprocess import check_call
      7 import sys
      8 
      9 
     10 def RunBindingsGenerator(out_dir, root_dir, mojom_file, extra_flags=None):
     11   out_dir = os.path.abspath(out_dir)
     12   root_dir = os.path.abspath(root_dir)
     13   mojom_file = os.path.abspath(mojom_file)
     14 
     15   # The mojom file should be under the root directory somewhere.
     16   assert mojom_file.startswith(root_dir)
     17   mojom_reldir = os.path.dirname(os.path.relpath(mojom_file, root_dir))
     18 
     19   # TODO(vtl): Abstract out the "main" functions, so that we can just import
     20   # the bindings generator (which would be more portable and easier to use in
     21   # tests).
     22   this_dir = os.path.dirname(os.path.abspath(__file__))
     23   # We're in src/mojo/public/tools/bindings/pylib/mojom_tests/support;
     24   # mojom_bindings_generator.py is in .../bindings.
     25   bindings_generator = os.path.join(this_dir, os.pardir, os.pardir, os.pardir,
     26                                     "mojom_bindings_generator.py")
     27 
     28   args = ["python", bindings_generator,
     29           "-o", os.path.join(out_dir, mojom_reldir)]
     30   if extra_flags:
     31     args.extend(extra_flags)
     32   args.append(mojom_file)
     33 
     34   check_call(args)
     35 
     36 
     37 def main(argv):
     38   if len(argv) < 4:
     39     print "usage: %s out_dir root_dir mojom_file [extra_flags]" % argv[0]
     40     return 1
     41 
     42   RunBindingsGenerator(argv[1], argv[2], argv[3], extra_flags=argv[4:])
     43   return 0
     44 
     45 
     46 if __name__ == '__main__':
     47   sys.exit(main(sys.argv))
     48