Home | History | Annotate | Download | only in jni
      1 #!/usr/bin/python
      2 # Copyright 2015 Google Inc. All rights reserved.
      3 #
      4 # Licensed under the Apache License, Version 2.0 (the "License");
      5 # you may not use this file except in compliance with the License.
      6 # You may obtain a copy of the License at
      7 #
      8 #     http://www.apache.org/licenses/LICENSE-2.0
      9 #
     10 # Unless required by applicable law or agreed to in writing, software
     11 # distributed under the License is distributed on an "AS IS" BASIS,
     12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 # See the License for the specific language governing permissions and
     14 # limitations under the License.
     15 
     16 import os
     17 import platform
     18 import subprocess
     19 import sys
     20 
     21 EXECUTABLE_EXTENSION = '.exe' if platform.system() == 'Windows' else ''
     22 # Paths to search for flatc relative to the current working directory.
     23 FLATC_SEARCH_PATHS = [os.path.curdir, 'Release', 'Debug']
     24 
     25 def main():
     26   """Script that finds and runs flatc built from source."""
     27   if len(sys.argv) < 2:
     28     sys.stderr.write('Usage: run_flatc.py flatbuffers_dir [flatc_args]\n')
     29     return 1
     30   cwd = os.getcwd()
     31   flatc = ''
     32   flatbuffers_dir = sys.argv[1]
     33   for path in FLATC_SEARCH_PATHS:
     34     current = os.path.join(flatbuffers_dir, path,
     35                            'flatc' + EXECUTABLE_EXTENSION)
     36     if os.path.exists(current):
     37       flatc = current
     38       break
     39   if not flatc:
     40     sys.stderr.write('flatc not found\n')
     41     return 1
     42   command = [flatc] + sys.argv[2:]
     43   return subprocess.call(command)
     44 
     45 if __name__ == '__main__':
     46   sys.exit(main())
     47