diff options
author | Alon Zakai <alonzakai@gmail.com> | 2012-11-13 13:32:41 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2012-11-13 13:32:41 -0800 |
commit | 7453def33e4df4225453da2d0407658b3a711cda (patch) | |
tree | 1ac4d0adc9bcb3e3b427ce0bd13f4a9dd74e98ae /tests/runner.py | |
parent | 36308403a7bb76edd288e1557dee4acb8f1e8d7b (diff) | |
parent | 075317782e3195382741d0bc22ff314235cfeeda (diff) |
Merge pull request #703 from juj/cmake
Cmake support.
Diffstat (limited to 'tests/runner.py')
-rwxr-xr-x | tests/runner.py | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/tests/runner.py b/tests/runner.py index 5b1aef35..dfe435a7 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -7523,6 +7523,61 @@ f.close() # TODO: test normal project linking, static and dynamic: get_library should not need to be told what to link! # TODO: deprecate llvm optimizations, dlmalloc, etc. in emscripten.py. + def test_cmake(self): + # On Windows, we want to build cmake-generated Makefiles with mingw32-make instead of e.g. cygwin make, since mingw32-make + # understands Windows paths, and cygwin make additionally produces a cryptic 'not valid bitcode file' errors on files that + # *are* valid bitcode files. + if os.name == 'nt': + make_command = 'mingw32-make' + emscriptencmaketoolchain = path_from_root('cmake', 'Platform', 'Emscripten.cmake') + else: + make_command = 'make' + emscriptencmaketoolchain = path_from_root('cmake', 'Platform', 'Emscripten_unix.cmake') + + cmake_cases = ['target_js', 'target_html'] + cmake_outputs = ['hello_world.js', 'hello_world_gles.html'] + for i in range(0, 2): + for configuration in ['Debug', 'Release']: + + # Create a temp workspace folder + cmakelistsdir = path_from_root('tests', 'cmake', cmake_cases[i]) + tempdirname = tempfile.mkdtemp(prefix='emscripten_test_' + self.__class__.__name__ + '_', dir=TEMP_DIR) + try: + os.chdir(tempdirname) + + # Run Cmake + cmd = ['cmake', '-DCMAKE_TOOLCHAIN_FILE='+emscriptencmaketoolchain, + '-DCMAKE_BUILD_TYPE=' + configuration, + '-DCMAKE_MODULE_PATH=' + path_from_root('cmake').replace('\\', '/'), + '-G' 'Unix Makefiles', cmakelistsdir] + ret = Popen(cmd, stdout=PIPE, stderr=PIPE).communicate() + if ret[1] != None and len(ret[1].strip()) > 0: + print >> sys.stderr, ret[1] # If there were any errors, print them directly to console for diagnostics. + if 'error' in ret[1].lower(): + print >> sys.stderr, 'Failed command: ' + ' '.join(cmd) + print >> sys.stderr, 'Result:\n' + ret[1] + raise Exception('cmake call failed!') # cmake spams this silly message to stderr, so hide it: "Platform/Emscripten to use this system, please send your config file to cmake@www.cmake.org so it can be added to cmake" + assert os.path.exists(tempdirname + '/Makefile'), 'CMake call did not produce a Makefile!' + + # Build + cmd = [make_command] + ret = Popen(cmd, stdout=PIPE).communicate() + if ret[1] != None and len(ret[1].strip()) > 0: + print >> sys.stderr, ret[1] # If there were any errors, print them directly to console for diagnostics. + if 'error' in ret[0].lower() and not '0 error(s)' in ret[0].lower(): + print >> sys.stderr, 'Failed command: ' + ' '.join(cmd) + print >> sys.stderr, 'Result:\n' + ret[0] + raise Exception('make failed!') + assert os.path.exists(tempdirname + '/' + cmake_outputs[i]), 'Building a cmake-generated Makefile failed to produce an output file %s!' % tempdirname + '/' + cmake_outputs[i] + + # Run through node, if CMake produced a .js file. + if cmake_outputs[i].endswith('.js'): + ret = Popen([NODE_JS, tempdirname + '/' + cmake_outputs[i]], stdout=PIPE).communicate()[0] + assert 'hello, world!' in ret, 'Running cmake-based .js application failed!' + finally: + os.chdir(path_from_root('tests')) # Move away from the directory we are about to remove. + shutil.rmtree(tempdirname) + def test_Os(self): for opt in ['s', '0']: output = Popen(['python', EMCC, path_from_root('tests', 'hello_world.c'), '-O' + opt], stdout=PIPE, stderr=PIPE).communicate() |