当前位置: 首页 > news >正文

第6.3节 iOS Agent开发<二>

(2)Swift项目覆盖率

此模块为主要功能,包含下载项目源码,覆盖率数据profdata文件,下载测试包ipa解压取出可执行的二进制文件,使用xcrun命令行成覆盖率执行,通过git diff过滤生成增量报告,解析覆盖率报告数据,下载覆盖率报告功能。
  • Swift生成报告类swiftCovReportOperations
    # coding=utf-8
    import json
    import os,asynciofrom iOSOCAndSwiftAgent.UtilsOperation.const import DEBUG_SERVICE
    from iOSOCAndSwiftAgent.UtilsOperation.iOS_Diff_Parser import iOSDiffParserclass swiftCovReportOperations():"""生成Swift报告相关的操作类"""def __init__(self):if DEBUG_SERVICE.find("Agent")>-1:#写死Agent上的路径scriptpath="/Users/*****/ScriptFiles/"else:#本机debugscriptpath="/Users/*****/ScriptFiles/"self.genhtml=scriptpath+"lcov-1.14/bin/genhtml"def getBinDataFilePath(self,propath):"""获取应用对应的可执行文件:return:"""return propath+"Kima"def createXcodeCoverageReport(self,propath,curbranch,combranch):"""生成XcodeCoverage格式的报告:param propath: 项目地址:return:"""curpath = os.getcwd()profrawfold=propath+"profrawdata"#获取文件夹下的所有文件,并进行合并allprofraw=""frawlist=os.walk(profrawfold)for path,dir_list,file_list in frawlist:for file_name in file_list:if file_name.find("profraw")>-1:allprofraw=allprofraw+" "+file_name#合并覆盖率数据if len(allprofraw)>0:os.chdir(profrawfold)mergedcmd="xcrun llvm-profdata merge"+allprofraw+" -output ./coverage_merged.profraw"os.system(mergedcmd)#转换数据文件类型changecov="xcrun llvm-profdata merge -sparse ./coverage_merged.profraw -o ./coverage_merged.profdata"os.system(changecov)#生在info文件appbinpath=self.getBinDataFilePath(propath)infocmd="xcrun llvm-cov export "+appbinpath+" --instr-profile=./coverage_merged.profdata -use-color --format=lcov > ./allreport.info"os.system(infocmd)newpropath=propath+"packages"newpropath=newpropath.replace("/","\/")print("当前项目路径:"+newpropath)changecmd="sed -i '' 's/\/Users\/****/packages/"+newpropath+"/g' ./allreport.info"os.system(changecmd)print("替换allreport.info中的项目路径")#删除allreport.info中的Pods相关的文件信息self.removePodFileFromInfoFile(profrawfold+"/allreport.info")print("删除allreport.info文件中的Pods相关文件信息")#生成全量XcoverageReportreportcmd=self.genhtml+" -o "+propath+"/allreport "+profrawfold+"/allreport.info"os.system(reportcmd)os.chdir(curpath)#生成增量覆盖率报告self.createDiffReport(propath,curbranch,combranch,"normal")else:print("没有覆盖率数据,无需生成覆盖率报告")def getCurrentCommitOfPro(self,propath):"""获取当前项目的最新版本:param propath::return:"""curpath=os.getcwd()os.chdir(propath)getcutcont=os.popen("git log").read()linescheck=getcutcont.split("\n")curcommitinfo=linescheck[0]curcommit=curcommitinfo[curcommitinfo.index(" ")+1:]os.chdir(curpath)return curcommitdef createDiffReport(self,propath,curbranch,combranch,difftype):"""生成增量XcodeCoverage报告:param propath: 项目地址:param target_branch: 目标分支:param source_branch: 源分支:param difftype 增量报告的类型,正常为normal,合并覆盖率的为merged:return:"""if not propath.endswith("/"):propath=propath+"/"if len(propath)>0:#处理一下source_branch,去掉:remotes/origin/if combranch.find("/")>-1:combranch=combranch[combranch.rindex("/")+1:]print("要对比的路径是:"+combranch)else:if curbranch.find("/")>-1:curbranch=self.getCurrentCommitOfPro(propath)print("对比的是版本,当前版本:"+curbranch+",对比版本:"+combranch)#生成增量的info文件iosdiffoper=iOSDiffParser()iosdiffoper.createDiffInfoFile(propath,combranch,curbranch,difftype)#生成增量覆盖率报告profrawfold=propath+"profrawdata"#如果diffreport.info为空if os.path.getsize(profrawfold+"/diffreport.info")>0:reportcmd=self.genhtml+" -o "+propath+"/diffreport "+profrawfold+"/diffreport.info"os.system(reportcmd)else:#将diff文件详情记录下来with open(propath+"difffilelist.json","w",encoding='utf-8') as fp:json.dump(iosdiffoper.file_diff_line,fp,ensure_ascii=False)print("diffreport.info为空,无需要生成增量报告!")else:print("项目地址为空,无法生成覆盖率报告")def createCommitsMergedReports(self,propath,srccommit,desccomit):"""生成跨版本合并的覆盖率报告:param propath::param srccommit::param desccomit::return:"""#获取合并的最新版本号resultjson=propath+"/profrawdata/allcommits_infofile_detail.json"if os.path.exists(resultjson) and os.path.getsize(resultjson)>0:with open(resultjson, "r") as readjson:json_data = json.load(readjson)for commits in json_data.keys():pass#切换到指定的版本os.system("git checkout "+commits)commits_merged_infofile=propath+"/profrawdata/all_commits_megedreport.info"#去掉Pod相关的文件信息self.removePodFileFromInfoFile(commits_merged_infofile)if os.path.getsize(commits_merged_infofile)>0:#生成合并后的全量报告reportcmd=self.genhtml+" -o "+propath+"/allreport "+commits_merged_infofileos.system(reportcmd)#生成增量覆盖率报告self.createDiffReport(propath,commits,desccomit,"merged")else:print("合并后的info数据为空,无需生成报告!")#切换相应的分支os.system("git checkout "+srccommit)def removePodFileFromInfoFile(self,infofilepath):"""去掉info文件中,有关Pod路径下的项目:param infofilepath::return:"""cutcont="cat "+infofilepath+"|grep SF:"getcutcont=os.popen(cutcont).read()linescheck=getcutcont.split("\n")for i in range(len(linescheck)):covfile=linescheck[i]if len(covfile)>0 and covfile.find("Pods")>-1:#获取指定行号之间的内容fileloccmd="grep -n '"+covfile+"' "+infofilepathfileloccont=os.popen(fileloccmd).read()fileloc=fileloccont[0:fileloccont.index(":")]endloccmd="grep -n '"+linescheck[i+1]+"' "+infofilepathendloccont=os.popen(endloccmd).read()endloc=int(endloccont[0:endloccont.index(":")])-1if endloc==0:#找出文件最后一行行号lastloccont=os.popen("wc -l "+infofilepath).read()lastloccont=lastloccont.strip()lastloc=lastloccont[0:lastloccont.index("/")-1]endloc=lastloc#删除指定的行之间的内容sedcmd="sed -i '' '"+fileloc+","+str(endloc)+"d' "+infofilepathos.system(sedcmd)if __name__ == '__main__':covreport=CovReportOperations()

    Agent架构中其他功能,由于涉及到公司内部的资料,不方便公开,在此就不展开介绍了。

http://www.dtcms.com/a/403153.html

相关文章:

  • 【Trie】 UVA1401 Remember the Word
  • 深度学习学习路线图:从MNIST到MobileNetV4,从理论到实践的完整指南
  • PyTorch 数据处理工具箱:从数据加载到可视化的完整指南
  • LinuxC++项目开发日志——基于正倒排索引的boost搜索引擎(4——通过jsoncpp库建立搜索模块)
  • LVS三种模式及原理
  • 有招聘网站策划的吗济南网站开发招聘
  • 【多线程】互斥锁(Mutex)是什么?
  • 18.1 Python+AI一键生成PPT!ChatPPT核心技术深度解析
  • 影响网站权重的因素有哪些wordpress 仪表盘 渗透
  • Nginx反向代理与缓存功能-第一章
  • 精读《C++20设计模式》——创造型设计模式:构建器系列
  • SpringCloud高可用集群搭建及负载均衡配置实战
  • AI产品独立开发完全指南:技术栈选择、案例分析与商业化路径
  • Jenkins+Tomcat持续集成教程
  • 哪里有免费建设网站承德在线
  • 【金融保研复习】知识点与可能的题目
  • 基于ZYNQ的ARM+FPGA+yolo AI火灾实时监测与识别系统
  • 【Python语法基础学习笔记】常用函数
  • Uniapp运行时错误修复报告
  • PHP 8.0+ 高级特性深度探索:架构设计与性能优化
  • 网站管理建设总结大数据营销的概念
  • 顺德品牌网站建设辽宁建设工程信息网上
  • Oracle Clint11g安装
  • Gerkin+unittest(python)实现自动化
  • MySQL基础语法大全
  • 从企业实战中学习Appium自动化(二)
  • Unity 使用ADB工具打包Apk 安装到Android手机或平板
  • 一、移动零,复写零,快乐数
  • React资源合集
  • sem是什么职业邢台做网站建设优化制作公司