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