利用xcodeproj修改xcode工程文件

一,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

最新文章

  1. 下面就介绍下Android NDK的入门学习过程(转)
  2. 并行计算之OpenMP入门简介
  3. (C/C++) Interview in English - Basic concepts.
  4. bug_ _fragment的1
  5. 51nod1225 余数之和
  6. UIVIewController自定义切换效果-b
  7. libpng causes error concerning pngconf.h
  8. Redis Cluster架构优化
  9. 从二进制数据流中构造GDAL可以读取的图像数据(C#)
  10. maven打包额外的资源文件
  11. android Q build 变化
  12. Discovery Scanning
  13. mysql查看及设置最大连接数
  14. Objective-C Programming The Big Nerd Ranch Guide 笔记 19-37
  15. 关于python性能相关测试cProfile库
  16. 在ASP.NET MVC 框架中调用 html文件及解析get请求中的参数值
  17. word怎么在方框中打对号
  18. CDH6离线安装
  19. iPhone开发--正则表达式获取字符串中的内容
  20. (深搜)Sum It Up -- poj --1564

热门文章

  1. MyBatis基础入门《十七》动态SQL
  2. EL的隐含对象 (二)【访问作用域范围的隐含对象】
  3. hbase-java-api001
  4. js单双引号
  5. Django后台管理系统讲解及使用
  6. kail linux arp欺骗
  7. 【Linux学习二】文件系统
  8. spring部分注解
  9. 20165305 苏振龙《Java程序设计》第六周学习总结
  10. Vim 文本编辑器的基本使用