]>
git.saurik.com Git - apple/security.git/blob - certificates/CertificateTool/BuildiOSAsset/BuildAsset.rb
5 # Copyright 2012 Apple Inc. All rights reserved.
11 attr_reader
:ios_SDK_path
12 attr_reader
:base_path
13 attr_reader
:output_directory
14 attr_reader
:asset_directory
15 attr_reader
:asset_top_directory
16 attr_reader
:asset_data_directory
17 attr_reader
:staging_directory
18 attr_reader
:info_plist_path
21 def validate_path(path
, isDir
= true)
22 return false if path
.nil? || path
.empty
?
23 return false if !FileTest
.exists
?(path
)
24 return false if isDir !
= FileTest
.directory
?(path
)
28 def output_str(str
, header
= false)
31 puts
"=====================================================" if header
35 def ensure_directory(path
)
36 FileUtils
.mkdir_p path
if !
validate_path(path
)
41 def initialize(input_dir
, output_directory
, project_path
, staging_directory
, verbose
= false)
46 output_str
"In BuildPKIAsset.initialize"
47 output_str
"input_dir = #{input_dir}"
48 output_str
"output_directory = #{output_directory}"
49 output_str
"staging_directory = #{staging_directory}"
53 # Check the input parameter
54 if !
ensure_directory(input_dir
)
55 puts
"Invalid base directory given: #{input_dir}"
59 @base_path = File
.expand_path(input_dir
)
61 @info_plist_path = File
.join(File
.join(File
.expand_path(project_path
), "CertificateTool"), "Info.plist")
63 if !FileTest
.exists
? @info_plist_path
64 puts
"Could not find the Info.plist file"
69 if output_directory
.nil? || output_directory
.empty
?
70 puts
"No output directory was given"
74 asset_tool_path
= `xcodebuild -sdk iphoneos.internal -find assettool`
75 if asset_tool_path
.nil?
76 puts
"Unable to find the mobile asset tool in the iPhone SDK"
81 @output_directory = File
.expand_path(output_directory
)
83 @asset_directory = File
.join(@output_directory, "Assets")
84 ensure_directory(@asset_directory)
86 @asset_top_directory = File
.join(@asset_directory, "SecurityCertificatesAssets")
87 ensure_directory(@asset_top_directory)
89 @asset_data_directory = File
.join(@asset_top_directory, "AssetData/PKITrustData")
90 ensure_directory(@asset_data_directory)
92 @staging_directory = File
.expand_path(staging_directory
)
93 ensure_directory(@staging_directory)
97 output_str
"@base_path = #{@base_path }"
98 output_str
"@output_directory = #{@output_directory }"
99 output_str
"@asset_directory = #{@asset_directory }"
100 output_str
"@asset_top_directory = #{@asset_top_directory }"
101 output_str
"@asset_data_directory = #{@asset_data_directory }"
102 output_str
"@staging_directory = #{@staging_directory }"
103 output_str
"@info_plist_path = #{@info_plist_path}"
104 output_str
"Done with BuildPKIAsset.initialize"
105 output_str(nil, true)
112 output_str(nil, true)
113 output_str
"In BuildPKIAsset.stage"
114 output_str(nil, true)
117 #copy over the files into the asset directory
118 input_plist_file_path
= @info_plist_path
120 output_str(nil, true)
121 output_str
"input_plist_file_path = #{input_plist_file_path}"
123 FileUtils
.cp(input_plist_file_path
, @asset_top_directory)
125 output_str
"About to copy over the plist files"
127 # copy all of the necessary files into the asset data directory
128 file_list
= %w(AppleESCertificates
.plist AssetVersion
.plist Blocked
.plist GrayListedKeys
.plist EVRoots
.plist certsIndex
.data certsTable
.data manifest
.data)
129 file_list
.each
do |file
|
130 file_path
= File
.join(@base_path, file
)
131 if !FileTest
.exists
?(file_path
)
132 output_str(nil, true)
134 puts
"#{file_path} is missing in the base directory"
137 FileUtils
.cp(file_path
, @asset_data_directory)
140 output_str
"Completed copying over the plist files"
142 output_str
"About to call assettool stage"
143 `xcrun -sdk iphoneos.internal assettool stage -p #{@asset_directory} -s #{@staging_directory}`
144 output_str
"Completed call to assettool stage"
145 output_str(nil, true)
148 output_str(nil, true)
149 output_str
"Done with BuildPKIAsset.stage"
150 output_str(nil, true)
155 output_str(nil, true)
156 output_str
"In BuildPKIAsset.sign"
157 output_str
"About to call assettool sign"
158 `xcrun -sdk iphoneos.internal assettool sign -s #{@staging_directory}`
159 output_str
"Completed call to assettool sign"
160 output_str
"Done with BuildPKIAsset.sign"
161 output_str(nil, true)
169 def do_output_str(str
, header
= false)
172 puts
"=====================================================" if header
173 puts str
if !str
.nil?
176 build_dir
= ENV["BUILT_PRODUCTS_DIR"]
177 project_dir
= ENV["PROJECT_DIR"]
179 do_output_str
"Environment variables"
181 do_output_str
"build_dir = #{build_dir}"
182 do_output_str
"project_dir = #{project_dir}"
183 do_output_str(nil, true)
186 input_path
= File
.join(build_dir
, "asset_out")
187 output_path
= File
.join(build_dir
, "Asset")
188 staging_path
= File
.join(build_dir
, "staging")
189 asset_name
= "com_apple_MobileAsset_PKITrustServices_PKITrustData"
190 full_asset_path
= File
.join(staging_path
, asset_name
)
192 do_output_str(nil, true)
193 do_output_str
"Path variables"
195 do_output_str
"input_path = #{input_path}"
196 do_output_str
"output_path = #{output_path}"
197 do_output_str
"staging_path = #{staging_path}"
198 do_output_str
"full_asset_path = #{full_asset_path}"
199 do_output_str(nil, true)
202 do_output_str(nil, true)
203 do_output_str
"Creating a BuildPKIAsset object to stage and sign the asset"
204 b
= BuildPKIAsset
.new(input_path
, output_path
, project_dir
, staging_path
, @verbose)
208 do_output_str
"Finished with BuildAsset"
209 do_output_str(nil, true)
212 do_output_str(nil, true)
213 do_output_str
"Output Path variables"
215 do_output_str
"build_dir = #{build_dir}"
216 do_output_str
"full_asset_path = #{full_asset_path}"
218 #FileUtils.cp_r(full_asset_path, build_dir)
220 do_output_str
"That's all folks!"
221 do_output_str(nil, true)