blob: 02e7b2143d59df1165c4f9e743c11bbf8940e758 [file] [log] [blame]
#!/usr/bin/python2.7
# Notes:
# - cmake, gcc, make and git should be added to the PATH
# - to see what exactly this script does just check the git modifications to the assimp sources after running it
# - framework headers are included directly in the source files and not in headers and this may be lighter
# that a real-world scenario because the ifdef-ed headers are included only once in each translation unit
framework = "doctest" # catch/doctest
compiler = "GCC" # GCC/MSVC/BOTH - GCC is MinGW under Windows and is the only option for linux
config = "Debug" # Debug/Release - the configuration that will be built
include = True # True/False - whether to include the framework headers at all
in_sources = True # True/False - whether to insert tests in the source files
in_headers = False # True/False - whether to insert tests in header files (doctest only)
disable = False # True/False - whether to disable the test registration (doctest only)
test_mult = 1 # 1/2/3..100.. - a multiplier for the amount of tests to be added
MSVC_dir = "C:\\Program Files (x86)\\Microsoft Visual Studio 12.0"
MSVC_cmake_generator = "Visual Studio 12 Win64"
#================================================================================================================================
import os
import sys
import random
import string
import multiprocessing
from datetime import datetime
# setup the right values for OS-specific vars
windows = False
makefile = "Unix Makefiles"
make = "make"
if os.name == "nt":
windows = True
makefile = "MinGW Makefiles"
make = "mingw32-make"
# the path to the appropriate header
framework_header = '"../../catch/single_include/catch.hpp"'
if framework == "doctest":
framework_header = '"../../../../doctest/doctest.h"'
# files that (probably) should not be modified
skipList = ["AssimpPCH.cpp", "AssimpPCH.h"]
# clones the repositories and calls cmake for the first time
def setup():
os.system("git clone https://github.com/philsquared/Catch catch")
os.system("git clone https://github.com/assimp/assimp assimp")
os.chdir("assimp")
if windows:
os.makedirs("MSVC")
os.chdir("MSVC")
os.system('cmake -DASSIMP_BUILD_ASSIMP_TOOLS=OFF -DASSIMP_BUILD_TESTS=OFF -G "' + MSVC_cmake_generator + '" ../')
os.chdir("../");
os.makedirs("GCC_Debug")
os.chdir("GCC_Debug")
os.system('cmake -DASSIMP_BUILD_ASSIMP_TOOLS=OFF -DASSIMP_BUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=Debug -G "' + makefile + '" ../')
os.chdir("../");
os.makedirs("GCC_Release")
os.chdir("GCC_Release")
os.system('cmake -DASSIMP_BUILD_ASSIMP_TOOLS=OFF -DASSIMP_BUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=Release -G "' + makefile + '" ../')
os.chdir("../../");
def randomword():
return ''.join(random.choice(string.digits + string.letters + "_ <>(){}[]-=+&*&^%$#@!~") for i in range(random.randint(5, 15)))
def createTest(framework):
if framework == "catch":
return '\nTEST_CASE("' + randomword() + '", "") {\n printf("hello from %s!\\n", __func__);\n}\n'
else:
return '\ndoctest_test("' + randomword() + '") {\n printf("hello from %s!\\n", __func__);\n}\n'
def defineFuncMacro():
return '#if defined(_MSC_VER)\n' + '#define __func__ __FUNCTION__\n' + '#endif // _MSC_VER\n\n'
# setup everything if not already done
if not os.path.exists("assimp"):
setup()
# clear the log file (will be appended to it later)
os.system('echo ==================================== >log.txt');
# reset git stuff
os.chdir("assimp")
os.system("git checkout .")
# headers/defines at the top of translation units
if include:
# insert headers and defines for all translation units (assimp/code/*.cpp)
for filename in os.listdir('code'):
if filename[-3:] == "cpp" and filename not in skipList:
f = open('./code/' + filename, "r+")
old = f.read()
f.seek(0)
# ensure the __func__ macro is present everywhere
f.write(defineFuncMacro())
if framework == "doctest" and disable:
f.write('#define DOCTEST_GLOBAL_DISABLE\n')
# stuff that should be in only one translation unit
if filename == "Assimp.cpp":
if framework == "catch":
f.write("#define CATCH_CONFIG_RUNNER\n")
else:
f.write('#include ' + framework_header + '\n')
if framework == "doctest":
f.write("#define DOCTEST_DONT_INCLUDE_IMPLEMENTATION\n")
f.write('#include ' + framework_header + '\n')
f.write('#include <stdio.h>\n')
f.write(old)
if filename == "Assimp.cpp" and framework == "doctest":
f.write("\nASSIMP_API int runTests(int argc, char** argv) {\n")
f.write(" void* params = doctest::createParams(argc, argv);\n")
f.write(" int res = doctest::runTests(params);\n")
f.write(" doctest::freeParams(params);\n")
f.write(" return res;\n")
f.write("}\n")
f.close()
# if inserting tests and not only including the headers
if in_sources:
numTests = 0
for filename in os.listdir('code'):
if filename[-4:] == ".cpp" and filename not in skipList:
f = open('./code/' + filename, "r+")
lines = f.readlines()
f.seek(0)
prev = ""
for line in lines:
if prev == "}\n" and line == "\n":
for i in range(0, test_mult):
numTests = numTests + 1
f.write(createTest(framework))
f.write(line)
prev = line;
f.close()
print("Inserted " + str(numTests) + " tests in source files")
# if inserting tests in headers too
if in_headers and framework == "doctest":
numTests = 0
for filename in os.listdir('code'):
if filename[-2:] == ".h" and filename not in skipList:
f = open('./code/' + filename, "r+")
f.seek(-1, 2) # no idea what this does... seems like going to the end?
f.write("\n")
f.write("#define DOCTEST_DONT_INCLUDE_IMPLEMENTATION\n")
f.write('#include ' + framework_header + '\n')
f.write('#include <stdio.h>\n')
# ensure the __func__ macro is present everywhere
f.write(defineFuncMacro())
# add tests in multiples of 10
for k in range(0, test_mult):
for i in range(0, 10):
numTests = numTests + 1
f.write(createTest(framework))
f.close()
print("Inserted " + str(numTests) + " tests in headers")
# MSVC
if windows and (compiler == "MSVC" or compiler == "BOTH"):
os.chdir("MSVC")
os.system('call "' + MSVC_dir + '\\VC\\vcvarsall.bat" amd64 >>../../log.txt 2>&1 & ' +
'msbuild Assimp.sln /t:Clean >>../../log.txt 2>&1')
print("About to compile with MSVC")
start = datetime.now()
os.system('call "' + MSVC_dir + '\\VC\\vcvarsall.bat" amd64 >>../../log.txt 2>&1 & ' +
'msbuild Assimp.sln /p:Configuration=' + config + ';Platform=X64 >>../../log.txt 2>&1')
end = datetime.now()
print("Time for compiling (+ linking): " + str(end - start))
os.chdir("../");
# GCC
if compiler == "GCC" or compiler == "BOTH":
os.chdir("GCC_" + config)
os.system(make + " clean")
print("About to compile with GCC")
start = datetime.now()
os.system(make + " -j" + str(multiprocessing.cpu_count()) + " >>../../log.txt 2>&1")
end = datetime.now()
print("Time for compiling (+ linking): " + str(end - start))
os.chdir("../")
os.chdir("../");