python调用.a静态库_Python小工具: 去除iOS静态库(.a或.framework)模拟器架构代码

#coding=utf-8

importsysimportosimportsubprocessimporttimedefget_sdk_infos(sdk_path):

cmd= "lipo -info %s" %sdk_path

cmpsplit=cmd.split()

output=subprocess.check_output(cmpsplit)

result=set(output.split())

architectures=[];

thin_sdks=[];for d inresult:if('armv7' in d or 'armv7s' in d or 'arm64' in d or 'x86_64' in d or 'i386' ind):

architectures.append(d);

output_path=create_arch_framework(sdk_path, d);if ('armv7' in d or 'armv7s' in d or 'arm64' ind):

thin_sdks.append(output_path);

str= ' '.join(thin_sdks)

created_file_path=sdk_path

cmd= u"lipo -create %s -output %s" %(str, created_file_path)

cmpsplit=cmd.split()try:

output=subprocess.check_output(cmpsplit)exceptsubprocess.CalledProcessError, e:print '%s error:%s!' %(cmd, e)

time.sleep(2)for file_temp inthin_sdks:if(os.path.exists(file_temp)):pass

pass

defget_file_path(sdk_path,rename_name):

root_path=os.path.dirname(sdk_path);

output_sdk_path= ''

if(os.path.isfile(sdk_path)):

array_result= sdk_path.split('/');

framework_path= array_result[len(array_result)-2];

framework_sdk_path=array_result[len(array_result)-1];if '.a' inframework_sdk_path:

temp_sdk_path=os.path.split(sdk_path)

file_name= temp_sdk_path[1];

file_name_ext= file_name.split('.');

file_name= file_name_ext[0] + '_%s' %(rename_name);

new_file_name= '%s/%s.%s' % (root_path, file_name, file_name_ext[1]);

output_sdk_path=new_file_name;else:

framework_root_path=os.path.dirname(sdk_path);

output_sdk_path=os.path.join(framework_root_path,'%s_%s' %(framework_sdk_path,rename_name));pass

returnoutput_sdk_path;defcreate_arch_framework(sdk_path,arch):

output_sdk_path=get_file_path(sdk_path,arch);

cmd= u"lipo %s -thin %s -output %s" %(sdk_path,arch,output_sdk_path)

cmpsplit=cmd.split()try:

output=subprocess.check_output(cmpsplit)exceptsubprocess.CalledProcessError, e:print '%s error:%s!' %(cmd,e)pass

returnoutput_sdk_path;if __name__ == '__main__':

paras_len=len(sys.argv)#检查执行命令是否有效,举例: python SDK_Thinning.py /Users/您的电脑用户名/Desktop/python/AMap_iOS_SDK_ALL/MAMapKit.framework/MAMapKit

if paras_len>=1:

source_file_path= sys.argv[1]#获取源文件路径参数,源文件类型为.a或者.framework静态库文件

print 'source_file_path:',source_file_path

result_file_path=get_sdk_infos(source_file_path);print 'success!'

else:print 'error!'

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值