hardly | b1e7e14 | 2014-08-06 00:43:51 +0300 | [diff] [blame] | 1 | #!/usr/bin/python2.7 |
| 2 | |
onqtam | d4669c1 | 2016-05-22 00:24:44 +0300 | [diff] [blame] | 3 | with_gcc = 0 |
onqtam | cef6149 | 2016-05-22 00:56:21 +0300 | [diff] [blame] | 4 | is_debug = 1 |
hardly | b1e7e14 | 2014-08-06 00:43:51 +0300 | [diff] [blame] | 5 | |
onqtam | df09f51 | 2016-09-15 13:43:50 +0300 | [diff] [blame] | 6 | numFiles = 10 |
hardly | b1e7e14 | 2014-08-06 00:43:51 +0300 | [diff] [blame] | 7 | |
onqtam | eae70c7 | 2016-06-07 22:36:24 +0300 | [diff] [blame] | 8 | with_doctest = 1 |
onqtam | 9497821 | 2016-05-22 00:07:30 +0300 | [diff] [blame] | 9 | |
onqtam | eae70c7 | 2016-06-07 22:36:24 +0300 | [diff] [blame] | 10 | with_implement = 1 |
| 11 | with_header = 1 |
| 12 | with_num_tests = 25 |
onqtam | df09f51 | 2016-09-15 13:43:50 +0300 | [diff] [blame] | 13 | with_num_assertions = 100 |
onqtam | eae70c7 | 2016-06-07 22:36:24 +0300 | [diff] [blame] | 14 | doctest_disable = 0 |
hardly | b1e7e14 | 2014-08-06 00:43:51 +0300 | [diff] [blame] | 15 | |
onqtam | df09f51 | 2016-09-15 13:43:50 +0300 | [diff] [blame] | 16 | the_folder = 'project' |
| 17 | |
| 18 | doctest_header = 'doctest.h' |
onqtam | 7ff1dc1 | 2016-09-18 12:59:51 +0300 | [diff] [blame] | 19 | #doctest_header = 'doctest_1_0.h' |
| 20 | #macro = "FAST_CHECK_EQ" |
| 21 | macro = "CHECK" |
| 22 | operator = " == " |
| 23 | #operator = ", " |
onqtam | 5456545 | 2016-05-19 18:09:20 +0300 | [diff] [blame] | 24 | |
| 25 | GCC_cmake_generator = '"MinGW Makefiles"' |
| 26 | MSVC_cmake_generator = '"Visual Studio 14 Win64"' # MSVC 2015 |
| 27 | |
| 28 | # ============================================================================== |
| 29 | # ============================================================================== |
| 30 | # ============================================================================== |
hardly | b1e7e14 | 2014-08-06 00:43:51 +0300 | [diff] [blame] | 31 | |
| 32 | import os |
| 33 | import sys |
| 34 | import random |
| 35 | import string |
| 36 | import multiprocessing |
| 37 | from datetime import datetime |
onqtam | 5456545 | 2016-05-19 18:09:20 +0300 | [diff] [blame] | 38 | import shutil |
| 39 | from time import sleep |
hardly | b1e7e14 | 2014-08-06 00:43:51 +0300 | [diff] [blame] | 40 | |
onqtam | df09f51 | 2016-09-15 13:43:50 +0300 | [diff] [blame] | 41 | if os.name != "nt": |
| 42 | GCC_cmake_generator = "Makefiles" |
| 43 | |
onqtam | 5456545 | 2016-05-19 18:09:20 +0300 | [diff] [blame] | 44 | # clean and make the folder |
| 45 | if os.path.exists(the_folder): |
| 46 | shutil.rmtree(the_folder) |
hardly | b1e7e14 | 2014-08-06 00:43:51 +0300 | [diff] [blame] | 47 | |
onqtam | d4669c1 | 2016-05-22 00:24:44 +0300 | [diff] [blame] | 48 | sleep(2) # or the script might fail... |
hardly | b1e7e14 | 2014-08-06 00:43:51 +0300 | [diff] [blame] | 49 | |
onqtam | 5456545 | 2016-05-19 18:09:20 +0300 | [diff] [blame] | 50 | if not os.path.exists(the_folder): |
| 51 | os.makedirs(the_folder) |
hardly | b1e7e14 | 2014-08-06 00:43:51 +0300 | [diff] [blame] | 52 | |
onqtam | 5456545 | 2016-05-19 18:09:20 +0300 | [diff] [blame] | 53 | # make the source files |
| 54 | for i in range(0, numFiles): |
| 55 | f = open(the_folder + '/' + str(i) + '.cpp', 'w') |
| 56 | if with_header: |
| 57 | if with_doctest: |
| 58 | if doctest_disable: |
| 59 | f.write('#define DOCTEST_CONFIG_DISABLE\n') |
onqtam | df09f51 | 2016-09-15 13:43:50 +0300 | [diff] [blame] | 60 | f.write('#include "' + doctest_header + '"\n\n') |
onqtam | 5456545 | 2016-05-19 18:09:20 +0300 | [diff] [blame] | 61 | else: |
| 62 | f.write('#include "catch.hpp"\n\n') |
onqtam | eae70c7 | 2016-06-07 22:36:24 +0300 | [diff] [blame] | 63 | for t in range(0, with_num_tests): |
onqtam | 5456545 | 2016-05-19 18:09:20 +0300 | [diff] [blame] | 64 | f.write('TEST_CASE("") {\n') |
onqtam | eae70c7 | 2016-06-07 22:36:24 +0300 | [diff] [blame] | 65 | for a in range(0, with_num_assertions): |
| 66 | f.write(' int a' + str(a) + ' = 5;\n') |
| 67 | f.write(' int b' + str(a) + ' = 6;\n') |
onqtam | 7ff1dc1 | 2016-09-18 12:59:51 +0300 | [diff] [blame] | 68 | f.write(' ' + macro + '(a' + str(a) + operator + 'b' + str(a) + ');\n') |
onqtam | 5456545 | 2016-05-19 18:09:20 +0300 | [diff] [blame] | 69 | f.write('}\n\n') |
| 70 | f.write('int f' + str(i) + '() { return ' + str(i) + '; }\n\n') |
| 71 | f.close() |
hardly | b1e7e14 | 2014-08-06 00:43:51 +0300 | [diff] [blame] | 72 | |
onqtam | 5456545 | 2016-05-19 18:09:20 +0300 | [diff] [blame] | 73 | # the main file |
| 74 | f = open(the_folder + '/main.cpp', 'w') |
| 75 | if with_implement: |
| 76 | if with_doctest: |
| 77 | if doctest_disable: |
| 78 | f.write('#define DOCTEST_CONFIG_DISABLE\n') |
| 79 | f.write('#define DOCTEST_CONFIG_IMPLEMENT\n') |
onqtam | df09f51 | 2016-09-15 13:43:50 +0300 | [diff] [blame] | 80 | f.write('#include "' + doctest_header + '"\n\n') |
hardly | b1e7e14 | 2014-08-06 00:43:51 +0300 | [diff] [blame] | 81 | else: |
onqtam | 5456545 | 2016-05-19 18:09:20 +0300 | [diff] [blame] | 82 | f.write('#define CATCH_CONFIG_RUNNER\n') |
| 83 | f.write('#include "catch.hpp"\n\n') |
| 84 | f.write('int main(int argc, char** argv) {\n') |
| 85 | if with_implement: |
| 86 | if with_doctest: f.write(' int res = doctest::Context(argc, argv).run();\n') |
| 87 | else: f.write(' int res = Catch::Session().run(argc, argv);\n') |
| 88 | else: |
| 89 | f.write(' int res = 0;\n') |
| 90 | for i in range(0, numFiles): |
| 91 | f.write(' int f' + str(i) + '(); res += f' + str(i) + '();\n') |
| 92 | f.write(' return res;\n}\n') |
| 93 | f.close() |
hardly | b1e7e14 | 2014-08-06 00:43:51 +0300 | [diff] [blame] | 94 | |
onqtam | 5456545 | 2016-05-19 18:09:20 +0300 | [diff] [blame] | 95 | # the cmake file |
| 96 | f = open(the_folder + '/CMakeLists.txt', 'w') |
| 97 | f.write('cmake_minimum_required(VERSION 2.8)\n\n') |
onqtam | 9497821 | 2016-05-22 00:07:30 +0300 | [diff] [blame] | 98 | f.write('project(bench)\n\n') |
onqtam | 5456545 | 2016-05-19 18:09:20 +0300 | [diff] [blame] | 99 | if with_doctest: f.write('include_directories("../../../doctest/")\n\n') |
| 100 | else: f.write('include_directories("../catch/single_include/")\n\n') |
onqtam | 9497821 | 2016-05-22 00:07:30 +0300 | [diff] [blame] | 101 | f.write('add_executable(bench main.cpp\n') |
onqtam | 5456545 | 2016-05-19 18:09:20 +0300 | [diff] [blame] | 102 | for i in range(0, numFiles): |
| 103 | f.write(' ' + str(i) + '.cpp\n') |
| 104 | f.write(')\n') |
| 105 | f.close() |
hardly | b1e7e14 | 2014-08-06 00:43:51 +0300 | [diff] [blame] | 106 | |
onqtam | 5456545 | 2016-05-19 18:09:20 +0300 | [diff] [blame] | 107 | # invoke cmake |
| 108 | os.chdir(the_folder); |
hardly | b1e7e14 | 2014-08-06 00:43:51 +0300 | [diff] [blame] | 109 | |
onqtam | 5456545 | 2016-05-19 18:09:20 +0300 | [diff] [blame] | 110 | if with_gcc: |
onqtam | 5456545 | 2016-05-19 18:09:20 +0300 | [diff] [blame] | 111 | cmake_build_type = 'Release' |
| 112 | if is_debug: |
| 113 | cmake_build_type = 'Debug' |
onqtam | 5456545 | 2016-05-19 18:09:20 +0300 | [diff] [blame] | 114 | os.system('cmake . -G ' + GCC_cmake_generator + ' -DCMAKE_BUILD_TYPE=' + cmake_build_type); |
| 115 | else: |
| 116 | os.system('cmake . -G ' + MSVC_cmake_generator); |
hardly | b1e7e14 | 2014-08-06 00:43:51 +0300 | [diff] [blame] | 117 | |
onqtam | 5456545 | 2016-05-19 18:09:20 +0300 | [diff] [blame] | 118 | the_config = '' |
| 119 | if with_gcc == False: |
| 120 | if is_debug: |
| 121 | the_config = ' --config Debug' |
| 122 | else: |
| 123 | the_config = ' --config Release' |
hardly | b1e7e14 | 2014-08-06 00:43:51 +0300 | [diff] [blame] | 124 | |
onqtam | d4669c1 | 2016-05-22 00:24:44 +0300 | [diff] [blame] | 125 | # build it |
| 126 | start = datetime.now() |
onqtam | 5456545 | 2016-05-19 18:09:20 +0300 | [diff] [blame] | 127 | os.system('cmake --build .' + the_config) |
| 128 | end = datetime.now() |
onqtam | d4669c1 | 2016-05-22 00:24:44 +0300 | [diff] [blame] | 129 | |
onqtam | 5456545 | 2016-05-19 18:09:20 +0300 | [diff] [blame] | 130 | print("Time for compiling (+ linking): " + str(end - start)) |
hardly | b1e7e14 | 2014-08-06 00:43:51 +0300 | [diff] [blame] | 131 | |
| 132 | os.chdir("../"); |
| 133 | |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | |
| 142 | |
| 143 | |
| 144 | |
| 145 | |
| 146 | |