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