Austin Schuh | 1eb16d1 | 2015-09-06 17:21:56 -0700 | [diff] [blame^] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | import os |
| 4 | import sys |
| 5 | import subprocess |
| 6 | import shutil |
| 7 | |
| 8 | CMAKE = '@CMAKE_COMMAND@' |
| 9 | CMAKE_BUILD_TYPE = '@CMAKE_BUILD_TYPE@' |
| 10 | TMPDIR = '@TMPDIR@' |
| 11 | SRCDIR = '@SRCDIR@' |
| 12 | GFLAGS_DIR = '@gflags_BINARY_DIR@' |
| 13 | |
| 14 | if __name__ == "__main__": |
| 15 | if len(sys.argv) != 4: |
| 16 | sys.stderr.write(' '.join(['usage:', sys.argv[0], '<test_name> <srcdir> <expect_fail:0|1>\n'])) |
| 17 | sys.exit(1) |
| 18 | test_name = sys.argv[1] |
| 19 | srcdir = sys.argv[2] |
| 20 | expect_fail = (sys.argv[3].lower() in ['true', 'yes', 'on', '1']) |
| 21 | bindir = os.path.join(TMPDIR, test_name) |
| 22 | if TMPDIR == '': |
| 23 | sys.stderr.write('Temporary directory not set!\n') |
| 24 | sys.exit(1) |
| 25 | # create build directory |
| 26 | if os.path.isdir(bindir): shutil.rmtree(bindir) |
| 27 | os.makedirs(bindir) |
| 28 | # configure the build tree |
| 29 | if subprocess.call([CMAKE, '-DCMAKE_BUILD_TYPE:STRING='+CMAKE_BUILD_TYPE, |
| 30 | '-Dgflags_DIR:PATH='+GFLAGS_DIR, |
| 31 | '-DTEST_NAME:STRING='+test_name, srcdir], cwd=bindir) != 0: |
| 32 | sys.stderr.write('Failed to configure the build tree!\n') |
| 33 | sys.exit(1) |
| 34 | # build the test project |
| 35 | exit_code = subprocess.call([CMAKE, '--build', bindir, '--config', CMAKE_BUILD_TYPE], cwd=bindir) |
| 36 | if expect_fail == True: |
| 37 | if exit_code == 0: |
| 38 | sys.stderr.write('Build expected to fail, but it succeeded!\n') |
| 39 | sys.exit(1) |
| 40 | else: |
| 41 | sys.stderr.write('Build failed as expected\n') |
| 42 | exit_code = 0 |
| 43 | sys.exit(exit_code) |