gflags_build.py.in 1.5 KB

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