def easy_build(code, clean_up=True, build_path=None): path = temp_build_dir('my_test_lib', build_path) formatting.put_file(path, 'test.cc', code, True) Log.br() Log.note("Cmaking...") build_folder = os.path.join(path, 'build') cmake_output = cmake.cmake(path, build_folder) Log.note('CMake Output:') Log.br() print(cmake_output) Log.br() Log.note("Building...") make_output, success = cmake.make(build_folder) Log.br() if success: Log.note("Success! Make Output:") else: Log.error("ERROR: Make failed, output:") compilers.gcc.prettify_output(make_output) Log.br() # Clean up the build folder, now that the output has been generated if clean_up: Log.warn('Cleaning up build output...') shutil.rmtree(path)
def temp_build_dir(lib_name, build_path=None): if build_path is None: Log.warn("Building in tmp directory") folder = tempfile.mkdtemp(prefix='cpy-') else: Log.info("Building at {}".format(build_path)) assert os.path.exists(build_path), "Build path must exist!" folder = build_path targ = cmake.Target(lib_name, ['test.cc'], { 'Boost': '1.45.0', 'PythonLibs': '2.7', 'Eigen3': None }, executable=False) cmake_file = cmake.CMake('.', python=True) cmake_file.add_target(targ) formatting.put_file(folder, 'CMakeLists.txt', cmake_file.text) build_folder = os.path.join(folder, 'build') os.mkdir(build_folder) return folder