blob: cda13bbf8216d9989ac238d9f793b92556317922 [file] [log] [blame]
Austin Schuhe89fa2d2019-08-14 20:24:23 -07001#!/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
16import os
17import platform
18import subprocess
19import sys
20
21EXECUTABLE_EXTENSION = '.exe' if platform.system() == 'Windows' else ''
22# Paths to search for flatc relative to the current working directory.
23FLATC_SEARCH_PATHS = [os.path.curdir, 'Release', 'Debug']
24
25def 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
45if __name__ == '__main__':
46 sys.exit(main())