XcodeProj,使用Ruby更改工程文件
一,Ruby基础
Ruby迭代器each、map、collect、inject
each——连续访问集合的所有元素
collect—-从集合中获得各个元素传递给block,block返回的结果生成新的集合。
map——-同collect。
inject——遍历集合中的各个元素,将各个元素累积成返回一个值。
二,Ruby脚本
此脚本的作用是,待CoreLib工程中的文件copy到SDK工程中后,给这些文件添加依赖。目的是为了减少人工干预。
灵感来自于Cocapods。需要使用到Xcodeproj这个工具。
此脚本的缺陷是:如果是在编译过程中去给文件添加依赖,修改到了Xcode的工程文件,工程会停止运行,必须要跑两遍,才会有结果,所以后来这个方法被否决了。
require 'xcodeproj'
project_path = './EcoRobotCoreLib/EcoRobotCoreLib.xcodeproj' # 工程的全路径
sdk_project_path = './EcoRobotSDK/EcoRobotSDK.xcodeproj'
project = Xcodeproj::Project.open(project_path) # 、显示所有的target
project.targets.each do |target|
puts target.name
end # 增加新的文件到工程中
target = project.targets.first
group = project.main_group.find_subpath(File.join('testXcodeproj','newGroup'), true)
group.set_source_tree('SOURCE_ROOT') # 获取全部的文件引用
file_ref_list = target.source_build_phase.files_references # 设置文件引用是否存在标识
file_ref_mark = false # 检测需要添加的文件是否存在
for file_ref_temp in file_ref_list
puts file_ref_temp.path.to_s
if file_ref_temp.path.to_s.end_with?('ViewController1.m') then
file_ref_mark = true
end
end if !file_ref_mark then
file_ref = group.new_reference('ViewController1.h文件路径')
target.add_file_references([file_ref])
else
puts '文件引用已存在'
end if !file_ref_mark then
file_ref = group.new_reference('ViewController1.m文件路径')
target.add_file_references([file_ref])
else
puts '文件引用已存在'
end
project.save
puts '文件添加完成'
require 'xcodeproj'
project_path = './EcoRobotSDK/EcoRobotSDK.xcodeproj' # 工程的全路径
project = Xcodeproj::Project.open(project_path) #获取target
target = project.targets.first
puts target.name
#根据路径名寻找group,def find_subpath(path, should_create = false) ,不重新创建
group = project.main_group.find_subpath(File.join('CommonClass(公共类)','StaticLibaryHeaders', 'iotclient'), false)
#如果找不到路径,就退出
if !group
exit
end
group.set_source_tree('<group>') #SOURCE_ROOT "<group>"
puts "group.real_path:#{group.real_path}" header_path=group.real_path.to_s; #+"/Class/StaticLibaryHeaders/iotclient";
puts "#{header_path}" # 获取全部的文件引用
file_ref_list = target.headers_build_phase.files_references
file_ref_mark = false;
if File::directory?(header_path)
Dir::foreach(header_path) do |file|
if file !="." and file !=".."
# puts file.to_s
for file_ref_temp in file_ref_list
if file_ref_temp && file_ref_temp.path.to_s.end_with?(file.to_s)
then
# if file_ref_temp.path.to_s.end_with?(file.to_s) then
file_ref_mark = true
puts "文件依赖存在,头文件:#{file}"
break;
end
end
if file_ref_temp && !file_ref_mark
puts "文件依赖不存在,file:#{file}"
puts File.basename(file)
puts "路径地址:#{header_path}/#{file}"
file_ref = group.new_reference("#{header_path}/#{file}")
target.add_file_references([file_ref]); end
file_ref_mark = false end end
end project.save; # def traverse_dir(file_path)
# if File.directory? file_path
# Dir.foreach(file_path) do |file|
# if file !="." and file !=".."
# traverse_dir(file_path+"/"+file)
# end
# end
# else
# puts "File:#{File.basename(file_path)}"
# # 检测需要添加的文件是否存在
# # for file_ref_temp in file_ref_list
# # puts file_ref_temp.path.to_s
# # if file_ref_temp.path.to_s.end_with?('#{File.basename(file_path)}') then
# # # file_ref_mark = true
# # file_ref = group.new_reference(file_path)
# # target.add_file_references([file_ref]);
# # end
# # end # end
# end # traverse_dir(header_path); #对的
# if File::directory?(header_path)
# Dir::foreach(header_path) do |file|
# puts file.to_s
# end
# end # file_ref_list = target.headers_build_phase.files_references
# for file_ref_temp in file_ref_list
# if file_ref_temp
# puts file_ref_temp.path.to_s
# end
# end
XcodeProj,使用Ruby更改工程文件的更多相关文章
- Xcodeproj相关以及删除 多层文件夹、库、资源逻辑
一.介绍Xcodeproj是CocoaPods用ruby开发的一个插件库,可以用来新建.修改Xcode工程. 二.wiki和资源Xcodeproj wiki :https://www.rubydo ...
- Xcode工程文件pbxproj
Xcode工程文件pbxproj Xcode会去读Project.pbxproj文件,把pbxproj转成plist文件,看起根目录结构 rootObject:指向的是我们的工程对象.(对应一个24个 ...
- Visual Studio各版本工程文件之间的转换
转载于:http://www.cnblogs.com/jmliao/p/5594179.html 由于VS版本比较多,低版本无法直接打开高版本的工程文件,通过对工程文件进行一些修改可以解决这些问题. ...
- 转:使用vs2013打开VS2015的工程文件的解决方案(适用于大多数vs低版本打开高版本)
http://www.cnblogs.com/WayneLiu/p/5060277.html 前言:重装系统前我使用的是vs2015(有点装*),由于使用2015实在在班上太另类了, 导致我想在其他同 ...
- SVN版本更新后,upData工程之后,Xcode 工程文件打不开解决办法
svn更新代码后,打开xcode工程文件,会出现 xxx..xcodeproj cannot be opened becausethe project file cannot be parsed. ...
- Xcode 工程文件打开不出来, cannot be opened because the project file cannot be parsed.
svn更新代码后,打开xcode工程文件,会出现 xxx..xcodeproj cannot be opened because the project file cannot be parsed ...
- Android开发:彻底更改工程名
对于已经建立的工程,如果发现原来的工程名不合适,此时若想彻底更改工程名,需要三个步骤: 1.更改工程名 选中工程名,右键-->Refactor-->Rename. 2.更改src文件下包名 ...
- Keil工程文件的建立、设置与目标文件的获得
单片机开发中除必要的硬件外,同样离不开软件,我们写的汇编语言源程序要变为 CPU 可以执行的机器码有两种方法,一种是手工汇编,另一种是机器汇编,目前已极少使用手工 汇编的方法了.机器汇编是通过汇编软件 ...
- Xcode工程文件打不开:cannot be opened because the project file cannot be parsed
svn更新代码后,打开xcode工程文件,会出现 xxx..xcodeproj cannot be opened because the project file cannot be parsed ...
随机推荐
- Deeplab v3+的结构代码简要分析
添加了解码模块来重构精确的图像物体边界.对比如图 deeplab v3+采用了与deeplab v3类似的多尺度带洞卷积结构ASPP,然后通过上采样,以及与不同卷积层相拼接,最终经过卷积以及上采样得到 ...
- serlvet中的过滤器filter
1.概念 过滤作用,对从客户端向服务器端发送的请求进行过滤,也可以对服务器端返回的响应进行处理.它使用户可以改变一个request和修改一个 response..Filter 不是一个servlet, ...
- 突然pom.xml中引用的jar包出错。
在你的本地仓库中,用window搜索包含.lastupdated的文件,全部删除!然后再去项目上maven ------update project
- mysql制造大量测试数据心得
为了测试1000万条数据的查询性能,就需要1000万条数据,于是在我们做的项目的一个游客表的一条记录的基础上来制造. 1.使用mysql的while循环语句,比如手机号的循环,还有一些随机数,比如性别 ...
- C++中overload(重载),override(覆盖),overwrite(重写/覆写)的区别
#include <cstdio> #include <cstdlib> class Base { public: #pragma region MyRegion1 //函数重 ...
- kali linux wifi破解(aircrack)
需要一个能监听的网卡 airmon-ng start wlan0(監聽網卡) airmon-ng check kill(清除其他有影响的環境) airodump-ng mon0 (掃描附近wifi) ...
- Spring Cloud 服务的注册与发现(Eureka)
Eureka服务注册中心 一.Eureka Server Eureka Server是服务的注册中心,这是分布式服务的基础,我们看看这一部分如何搭建. 首先,Spring Cloud是基于Spring ...
- [博客迁移]探索Windows Azure 监控和自动伸缩系列2 - 获取虚拟机的监控定义和监控数据
上一篇博文介绍了如何连接Windows Azure: http://www.cnblogs.com/teld/p/5113063.html 本篇我们继续上次的示例代码,获取虚拟机的监控定义和监控数据. ...
- [openjudge-搜索]广度优先搜索之鸣人和佐助
题目描述 描述 佐助被大蛇丸诱骗走了,鸣人在多少时间内能追上他呢?已知一张地图(以二维矩阵的形式表示)以及佐助和鸣人的位置.地图上的每个位置都可以走到,只不过有些位置上有大蛇丸的手下,需要先打败大蛇丸 ...
- FileChannel
1, FileChannel 虚拟类,不可以直接实例化,可以通过FileInputStream FileOutputStream 获取 例:文件的复制 public class ChannelDem ...