同步操作将从 李雪健/CMakeTutorial 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
import osimport shleximport subprocessimport datetimeimport timeimport shutilfrom setuptools import setup, Extensioncwd = os.path.dirname(os.path.abspath(__file__))def execute_command(cmdstring, cwd=None, timeout=None, shell=False):"""执行一个SHELL命令封装了subprocess的Popen方法, 支持超时判断,支持读取stdout和stderrArguments:cmdstring {[type]} -- 命令字符创Keyword Arguments:cwd {str} -- 运行命令时更改路径,如果被设定,子进程会直接先更改当前路径到cwd (default: {None})timeout {str} -- 超时时间,秒,支持小数,精度0.1秒 (default: {None})shell {bool} -- 是否通过shell运行 (default: {False})"""if shell:cmdstring_list = cmdstringelse:cmdstring_list = shlex.split(cmdstring)if timeout:end_time = datetime.datetime.now() + datetime.timedelta(seconds=timeout)# 没有指定标准输出和错误输出的管道,因此会打印到屏幕上;sub = subprocess.Popen(cmdstring_list, cwd=cwd, stdin=subprocess.PIPE,shell=shell,bufsize=4096)# subprocess.poll()方法:检查子进程是否结束了,如果结束了,设定并返回码,放在subprocess.returncode变量中while sub.poll() is None:time.sleep(0.1)if timeout:if end_time <= datetime.datetime.now():raise Exception("Timeout:%s"%cmdstring)return sub.returncodedef build_library():envs = os.environcmake_prefix_path = envs.get('CMAKE_PREFIX_PATH', None)if cmake_prefix_path is None:raise EnvironmentError("Please specify CMAKE_PREFIX_PATH env.")config_command = "cmake -DCMAKE_PREFIX_PATH={} -S {} -B {}"path_to_source = cwdpath_to_build = os.path.join(cwd, "build")if os.path.exists(path_to_build):shutil.rmtree(path_to_build)config_command = config_command.format(cmake_prefix_path, path_to_source, path_to_build)code = execute_command(config_command)if code != 0:raise RuntimeError("Run configure command fail.")build_command = "cmake --build {}".format(os.path.join(cwd, "build"))code = execute_command(build_command)if code != 0:raise RuntimeError("Run build Command fail.")def main():build_library()extention = Extension("matrix",libraries=["matrix"],sources=["stub.cc"],language="c++",extra_compile_args=['-std=c++11'],include_dirs=[cwd],library_dirs=[os.path.join(cwd, "build")])setup(name="fputs",version="1.0.0",description="A Simple Matrix Library.",author="hanbing",author_email="beatmight@gmail.com",ext_modules=[extention])if __name__ == "__main__":main()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。