XcodeProj 使用记录

使用Ruby xcodeproj 自动对xcodeproj工程添加运行脚本

1
ruby bundleScript.rb /xxxx/AGEmojiKeyboard/Example/AGEmojiKeyboardSample.xcodeproj AGEmojiKeyboardSample /Debug/ntescs/lib/clang/brt/res 1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# addScript
# $LOAD_PATH << '.'
# $LOAD_PATH.unshift

# $LOAD_PATH.unshift(File.dirname(__FILE__))
require 'xcodeproj'
# ARGV[0]:project 路径
# ARGV[1]:target名字
# ARGV[2]:添加的scirpt资源路径
puts 'ruby start'
projPath = ARGV[0]
targetName = ARGV[1]
bundleSourePath = ARGV[2]
bundleScriptAction = ARGV[3]
# puts projPath.length
# #打开创建的Example.xcodeproj文件
puts projPath
proj=Xcodeproj::Project.open(projPath)
targetIndex = 0
proj.targets.each_with_index do |target, index|
if target.name == targetName
targetIndex = index
end
end
target = proj.targets[targetIndex]
scirptArr = target.shell_script_build_phases
for tmpPhase in scirptArr do
if tmpPhase.name.end_with?("NtescsBundleScript" )
puts "NtescsBundleScript exist"
ntescsBundleScript = tmpPhase
end
end
shell_script = "function copyResdir(){\nfor element in `ls $1` \n do\n Bundle_Source_Path=$1\"/\"$element \nif [ -d $Bundle_Source_Path ] \nthen \necho \"Bundle_Source_Path: ${Bundle_Source_Path} \" \nBundle_Source_TO_PATH=\"${BUILT_PRODUCTS_DIR}/${TARGET_NAME}.app\" \necho \"to path: ${Bundle_Source_TO_PATH} \" \n/bin/cp -a \"${Bundle_Source_Path}\" \"${Bundle_Source_TO_PATH}\" \nfi \ndone \n} \nroot_dir=\"#{bundleSourePath}\" \ncopyResdir $root_dir"
if ntescsBundleScript

if bundleScriptAction
puts "change shell_script"
ntescsBundleScript.shell_script = shell_script
else
puts "remove shell_script"
ntescsBundleScript.shell_script = ""
end
else
puts "new shell_script"
phase = target.new_shell_script_build_phase("NtescsBundleScript")
phase.shell_script = shell_script
end
puts 'true'
proj.save
puts 'true'