美文网首页
阿里小程序mPass依赖pod统计分析

阿里小程序mPass依赖pod统计分析

作者: 孢子菌 | 来源:发表于2023-09-20 14:39 被阅读0次

    最近看了下阿里的 mPass,发现是真滴狠,拉下来好多仓库,眼睛都花了。
    和原有项目里的库混在一起,无法分清了,所以写了一个pthon脚本,来帮我把 mPass 的依赖 pods 库分离出来,方便自己看。
    分享一下,给有同样烦恼的朋友。
    后续打算统计下 mPass 这些库(静态库)的大小,现在没时间做,以后再来补充

    import json
    
    def get_pods_from_mpass_config(file_path) :
        with open('/Users/Shared/.mPaaSCocoaPodsPlugin/baseline/xxxxx/content.json', 'r') as fcc_file:
            fcc_data = json.load(fcc_file)
            options = fcc_data['options']
            modules = fcc_data['modules']
        
            default_mpass_pods = ['mPaaS_TinyApp', 'mPaaS_ScanCode', 'mPaaS_TinyApp_Scan','mPaaS_TinyApp_BabaSSL','mPaaS_TinyApp_Player','mPaaS_Canvas','mPaaS_Log']
            origin_mpass_pods = default_mpass_pods
    
            mpass_pods = [] + origin_mpass_pods
            for mpass_pod in origin_mpass_pods :
                if mpass_pod in options :
                    mpass_pods += options[mpass_pod]
    
            real_pods = []
            for pod in mpass_pods :
                if pod in modules :
                    real_pods += modules[pod]
    
            uni_list = list(set(real_pods))
            ## uni_list.sort(cmp=lambda x,y: cmp(x.lower(), y.lower()))
    
            # print('真实pod(去重):')
            # for p in sorted_mpass_pod:
            #   print(p)
            # print('\n')
    
            return sorted(uni_list, key=str.casefold)
    
    def get_pods_from_lockfile(file_path) :
        with open('./Podfile.lock', 'r') as f:
            pods_lock = []
            line = f.readline()
    
            entry_flag = False
            while line :
                res0 = line.find('SPEC REPOS:')
                if res0 > -1:
                    print('find spec')
                    entry_flag = False
    
                if entry_flag:
                    # print(line, end='')
                    pods_lock.append(line)
                
                res1 = line.find('DEPENDENCIES:')
                if  res1 != -1 :
                    print('find depends')
                    entry_flag = True
    
                line = f.readline()
            
            return pods_lock
    
    def depart_mpass_installed_or_not(sorted_mpass_pod, pods_lock) :
        # 下面的内容也可以通过set做,但是要统一格式
        # 输出 mpass 配置和实际 pod 拉取差别
        config_inlock = []
        config_not_in = []
        for mpass_pod in sorted_mpass_pod :
            found = False
            for pod_lock in pods_lock :
                res = pod_lock.find(mpass_pod)
                if res > -1 :
                    found = True
            if found :
                config_inlock.append(mpass_pod)
            else :
                config_not_in.append(mpass_pod)
    
        f = open('./MPASS_INSTALLED_RES.txt', 'w')
        f.write('=======config_inlock:=======\n')
        for pod_str in config_inlock :
            f.write(pod_str + '\n')
        f.write('=======config_not_in:=======\n')
        for pod_str in config_not_in :
            f.write(pod_str + '\n')
        f.close()
    
    def depart_lock_mpass_and_others(sorted_mpass_pod, pods_lock) :
        mpass_pod_lock = []
        other_pod_lock = []
        for pod_lock in pods_lock :
            found = False
            for mpass_pod in sorted_mpass_pod :
                res = pod_lock.find(mpass_pod)
                if res > -1 :
                    found = True
            if found :
                mpass_pod_lock.append(pod_lock)
            else :
                other_pod_lock.append(pod_lock)
    
        f = open('./PODFILE_ANALYSIS.txt', 'w')
        f.write('=======mpass_pod_info:=======\n')
        for pod_str in mpass_pod_lock :
            f.write(pod_str)
        f.write('=======other_pod_info:=======\n')
        for pod_str in other_pod_lock :
            f.write(pod_str)
        f.close()
    
    
    def main():
        # 1.读取mpass baseline 配置,得到真实 pod 数据
        sorted_mpass_pod = get_pods_from_mpass_config('')
        # 2.读取podfile.lock 中的 pod 数据
        pods_lock = get_pods_from_lockfile('')
        # 3.区分 mpass 中的那些pod 被下载了,哪些没有
        depart_mpass_installed_or_not(sorted_mpass_pod, pods_lock)
        # 4.区分 lock 中哪些是 mpass 的库,哪些不是
        depart_lock_mpass_and_others(sorted_mpass_pod, pods_lock)
    
    if __name__=="__main__":
        main()
    
    

    相关文章

      网友评论

          本文标题:阿里小程序mPass依赖pod统计分析

          本文链接:https://www.haomeiwen.com/subject/grxavdtx.html