def main(): ''' 主入口函数 ''' # 加载 .env 中的配置信息 load_dotenv(dotenv_path='.config.env', encoding='UTF-8') # 若无配置信息则自动复制一份文件出来 if not Common.is_file_exists('.config.env'): shutil.copyfile('.config.env.sample', '.config.env') # 显示欢迎信息 Common.welcome('编译流程辅助脚本') # 只能在 Windows 环境运行 if platform.system() != 'Windows': Message.ShowError('很抱歉, 此脚本只能在 Windows 环境上运行') Common.exit_with_pause(-1) # 判断本机是否安装了支持的 Visual Studio detected_vs, vs_name = detect_vs() if not detected_vs: Message.ShowError('无法检测到合适的 Visual Studio 版本 (2015 或 2017)') Common.exit_with_pause(-1) else: Message.ShowStatus('检测到已安装: %s 应可正常编译' % vs_name) print('') # 读取当前的 Pandas 主程序版本号 pandas_ver = Common.get_pandas_ver(os.path.abspath(project_slndir)) Message.ShowInfo('当前模拟器的主版本是 %s' % pandas_ver) # 判断是否已经写入了对应的更新日志, 若没有则要给予提示再继续 if (has_changelog(pandas_ver)): Message.ShowStatus('已经在更新日志中找到了 %s 的版本信息.' % pandas_ver) else: Message.ShowWarning('没有在更新日志中找到 %s 版本的信息, 请注意完善!' % pandas_ver) # 判断当前 git 工作区是否干净, 若工作区不干净要给予提示 if git.Repo(project_slndir).is_dirty(): if not Inputer().requireBool({ 'tips': '当前模拟器代码仓库的工作区不干净, 要继续编译吗?', 'default': False }): Message.ShowStatus('您主动放弃了继续操作') Common.exit_with_pause(-1) else: Message.ShowStatus('当前模拟器代码仓库的工作区是干净的.') # 检查 Crashrpt 使用的信息是否都设置好了, 若没有且企图编译正式版, 则给与提示 if Common.is_pandas_release(os.path.abspath(project_slndir)): if not os.getenv("DEFINE_CRASHRPT_APPID"): Message.ShowWarning('当前并未设置 AppID, 且企图编译正式版.') Common.exit_with_pause(-1) if Common.md5(os.getenv("DEFINE_CRASHRPT_APPID") ) != '952648de2d8f063a07331ae3827bc406': Message.ShowWarning('当前已设置了 AppID, 但并非正式版使用的 AppID.') Common.exit_with_pause(-1) if not os.getenv("DEFINE_CRASHRPT_PUBLICKEY"): Message.ShowWarning('当前并未设置 PublicKey, 且企图编译正式版.') Common.exit_with_pause(-1) Message.ShowStatus('即将开始编译, 编译速度取决于电脑性能, 请耐心...') # 清理目前的工作目录, 把一些可明确移除的删掉 clean_environment() # 编译 Pandas 的复兴前版本 compile_prere(pandas_ver) # 编译 Pandas 的复兴后版本 compile_renewal(pandas_ver) Message.ShowStatus('编译工作已经全部结束, 请归档符号并执行打包流程.') # 友好退出, 主要是在 Windows 环境里给予暂停 Common.exit_with_pause()
def main(): # 加载 .env 中的配置信息 load_dotenv(dotenv_path='.config.env', encoding='UTF-8') # 若无配置信息则自动复制一份文件出来 if not Common.is_file_exists('.config.env'): shutil.copyfile('.config.env.sample', '.config.env') # 显示欢迎信息 Common.welcome('符号归档辅助脚本') print('') # 由于 pdbparse 只能在 Windows 环境下安装, 此处进行限制 if platform.system() != 'Windows': Message.ShowWarning('该脚本只能在 Windows 环境下运行, 程序终止.') Common.exit_with_pause(-1) # 若环境变量为空则设置个默认值 if not os.getenv('DEFINE_PROJECT_NAME'): os.environ["DEFINE_PROJECT_NAME"] = "Pandas" if not os.getenv('DEFINE_SYMBOLS_SOURCE'): os.environ["DEFINE_SYMBOLS_SOURCE"] = "PandasWS/Pandas" if not os.getenv('DEFINE_COMPILE_MODE'): os.environ["DEFINE_COMPILE_MODE"] = "re,pre" # 符号仓库工程路径 global project_symstoredir project_symstoredir = os.path.abspath(project_slndir + '../Symbols/' + os.getenv('DEFINE_PROJECT_NAME')) Message.ShowInfo('当前输出的项目名称为: %s' % os.getenv('DEFINE_PROJECT_NAME')) # 检查是否已经完成了编译 if 're' in os.getenv('DEFINE_COMPILE_MODE').split(','): if not Common.is_compiled(project_slndir, checkmodel='re'): Message.ShowWarning('检测到打包需要的编译产物不完整, 请重新编译. 程序终止.') Common.exit_with_pause(-1) if 'pre' in os.getenv('DEFINE_COMPILE_MODE').split(','): if not Common.is_compiled(project_slndir, checkmodel='pre'): Message.ShowWarning('检测到打包需要的编译产物不完整, 请重新编译. 程序终止.') Common.exit_with_pause(-1) # 检查符号仓库是否存在, 不存在则创建 if not ensure_store(): Message.ShowWarning('你放弃了拉取符号仓库, 后续工作无法继续. 程序终止.') Common.exit_with_pause(-1) else: Message.ShowStatus('符号仓库已经存在于本地, 开始确认工作区状态...') # 若符号文件存在, 则确保工作区干净 if not ensure_store_clean(): Message.ShowWarning('为了防止出现意外, 请确保符号仓库的工作区是干净的. 程序终止.') Common.exit_with_pause(-1) else: Message.ShowStatus('很好, 符号仓库的工作区是干净的.') # 尝试更新本地的符号仓库到最新 if not update_store(): Message.ShowWarning('为了防止出现意外, 请确保符号仓库同步到最新. 程序终止.') Common.exit_with_pause(-1) else: Message.ShowStatus('符号仓库已经同步到最新, 开始归档新的符号文件...') # 搜索工程目录全部 pdb 文件和 exe 文件, 进行归档 deploy_symbols(project_slndir) # 若环境变量为空则设置个默认值 if not os.getenv('DEFINE_SYMBOLS_COMMIT'): os.environ["DEFINE_SYMBOLS_COMMIT"] = "3" commit_flag = int(os.getenv('DEFINE_SYMBOLS_COMMIT')) # 自动进行 git 提交操作 if commit_flag & 1 == 1: if not Common.is_pandas_release(os.path.abspath(project_slndir)): Message.ShowStatus('符号文件已经归档完毕, 但并非正式版所以未自动提交...') Common.exit_with_pause() if commit_flag & 2 == 2: if Common.md5(os.getenv("DEFINE_CRASHRPT_APPID") ) != '952648de2d8f063a07331ae3827bc406': Message.ShowStatus( '符号文件已经归档完毕, 但未设置熊猫模拟器官方正式版的崩溃上报 APPID, 所以并未自动提交...') Common.exit_with_pause() Message.ShowStatus('符号文件已经归档完毕, 正在提交...') if not make_commit(): Message.ShowWarning('很抱歉, 提交失败! 请确认失败的原因. 程序终止.') Common.exit_with_pause(-1) else: Message.ShowStatus('提交成功, 请手工推送到远程仓库.') # 友好退出, 主要是在 Windows 环境里给予暂停 Common.exit_with_pause()