Class: CacheManager

Inherits:
Object
  • Object
show all
Defined in:
lib/sbuild.rb

Instance Method Summary collapse

Instance Method Details

#add_cache(target, target_info) ⇒ Object



421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
# File 'lib/sbuild.rb', line 421

def add_cache(target, target_info)

    target_md5 = target_info[:target_md5]
    product_dir = target_info[CONFIGURATION_BUILD_DIR]
    full_product_name = target_info[FULL_PRODUCT_NAME]

    unless product_dir.length > 0 and full_product_name.length > 0
        [SYMROOT, OBJROOT, SRCROOT, CONFIGURATION_BUILD_DIR, TARGET_BUILD_DIR, TARGET_TEMP_DIR, FULL_PRODUCT_NAME].sort.each do | key |
            if CONFIGURATION_BUILD_DIR and ENV[CONFIGURATION_BUILD_DIR]
                product_dir = ENV[CONFIGURATION_BUILD_DIR]
            end

            if FULL_PRODUCT_NAME and ENV[FULL_PRODUCT_NAME]
                full_product_name = ENV[FULL_PRODUCT_NAME]
            end
        end
    end

    Dir.glob("#{product_dir}/**/*.modulemap").each do | modulemap |
        modulemap_content = File.read(modulemap)
        if modulemap_content.include? File.dirname(modulemap) + "/"
            modulemap_content = modulemap_content.gsub(File.dirname(modulemap) + "/", "")
            File.write(modulemap, modulemap_content)
        end
    end

    unless full_product_name and full_product_name.size > 0 and File.exist? "#{product_dir}/#{full_product_name}"
        puts "<ERROR> #{target.name} #{product_dir}/#{full_product_name} should exist"
        return false
    end

    zip_start_time = Time.now

    command = "cd \"#{File.dirname(product_dir)}\" && tar -L -c -f #{target.name}.#{FILE_NAME_PRODUCT} #{File.basename(product_dir)}/#{full_product_name}"
    if target.product_type == "com.apple.product-type.library.static"
        command = "cd \"#{File.dirname(product_dir)}\" && tar --exclude=*.bundle --exclude=*.framework -L -c -f #{target.name}.#{FILE_NAME_PRODUCT} #{File.basename(product_dir)}"
    end
    
    unless system command
        puts "<INFO> #{command} should succeed"
        return false
    end


    if is_private_target(target) 
        already_target_cache_dirs = Dir.glob(get_branch_cache_folder + "/" + target.name + "-" + target_md5 + "-*")
    else
        already_target_cache_dirs = Dir.glob(get_default_cache_folder + "/" + target.name + "-" + target_md5 + "-*")
    end

    already_target_cache_dirs.each do |path|
        if File.exist? path
            raise unless system "rm -rf \"#{path}\""
        end
    end


    if is_private_target(target) 
        target_cache_dir = get_branch_cache_folder + "/" + target.name + "-" + target_md5 + "-" + (Time.now.to_f * 1000).to_i.to_s
    else
        target_cache_dir = get_default_cache_folder + "/" + target.name + "-" + target_md5 + "-" + (Time.now.to_f * 1000).to_i.to_s
    end

    if File.exist? target_cache_dir
        puts "<INFO> #{target_cache_dir} should not exist"
        raise unless system "rm -rf \"#{target_cache_dir}\""
        return false
    end

    command = "mkdir -p \"#{target_cache_dir}\""
    unless system command
        puts "<INFO> #{command} should succeed"
        return false
    end

    cache_product_path = target_cache_dir + "/#{FILE_NAME_PRODUCT}"
    command = "mv \"#{File.dirname(product_dir)}/#{target.name}.#{FILE_NAME_PRODUCT}\" \"#{cache_product_path}\""
    unless system command
        puts "<INFO> #{command} should succeed"
        return false
    end
    unless File.exist? cache_product_path
            puts "<INFO> #{cache_product_path} should exist after mv"
        return false
    end

    target_info[:product_md5] = get_file_md5(cache_product_path)
    target_info[:build_product_dir] = target_info[CONFIGURATION_BUILD_DIR].gsub(target_info[SYMROOT] + "/", "")
    target_info[:build_intermediate_dir] = target_info[TARGET_TEMP_DIR].gsub(target_info[OBJROOT] + "/", "")

    target_info.delete(:target_status)
    target_info.delete(:hit_target_cache_dir)
    target_info.delete(:target_md5_content)

    File.write(target_cache_dir + "/" + FILE_NAME_CONTEXT, target_info.to_yaml)
    
    return true
  
end

#add_cache_flagObject



348
349
350
351
352
353
354
355
356
357
358
359
360
361
# File 'lib/sbuild.rb', line 348

def add_cache_flag
    target_name = ARGV[1]
    project_path = ARGV[2]
    if File.exist? "#{project_path}/#{target_name}.#{FILE_NAME_TARGET_CONTEXT}" 
        target_context = YAML.load(File.read("#{project_path}/#{target_name}.#{FILE_NAME_TARGET_CONTEXT}"))
        [SYMROOT, OBJROOT, SRCROOT, CONFIGURATION_BUILD_DIR, TARGET_BUILD_DIR, TARGET_TEMP_DIR, FULL_PRODUCT_NAME].sort.each do | key |
            if ENV[key]
                target_context[key] = ENV[key] 
            end
        end
        target_context[:target_status] = CACHE_STATUS_READY
        File.write("#{project_path}/#{target_name}.#{FILE_NAME_TARGET_CONTEXT}", target_context.to_yaml)
    end
end

#backup_project(project) ⇒ Object



109
110
111
112
# File 'lib/sbuild.rb', line 109

def backup_project(project)
    command = "cp \"#{project.path}/project.pbxproj\" \"#{project.path}/ysTest_backup.pbxproj\""
    raise unless system command
end

#can_cache_target(target) ⇒ Object



128
129
130
131
132
133
134
135
# File 'lib/sbuild.rb', line 128

def can_cache_target(target)
    if target.product_type == "com.apple.product-type.bundle" or
        target.product_type == "com.apple.product-type.library.static" or
        target.product_type == "com.apple.product-type.framework"
        return true
    end
    return false
end

#clean_temp_filesObject



114
115
116
117
118
# File 'lib/sbuild.rb', line 114

def clean_temp_files

    command = "rm -rf Pods/*.xcodeproj/*.#{FILE_NAME_TARGET_CONTEXT}"
    raise unless system command
end

#copy_cacheObject



385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
# File 'lib/sbuild.rb', line 385

def copy_cache

    start_time = Time.now
    target_cache_dir = ARGV[1]
    cache_product_path = target_cache_dir + "/#{FILE_NAME_PRODUCT}"

    [SYMROOT, CONFIGURATION_BUILD_DIR, OBJROOT, TARGET_BUILD_DIR, TARGET_TEMP_DIR, SRCROOT, FULL_PRODUCT_NAME].sort.each do | key |
        unless ENV.has_key? key and ENV[key] and ENV[key].size > 0
            raise "<INFO> #{$0} should have #{key}"
            break
        end
    end

    command = "mkdir -p \"#{ENV[CONFIGURATION_BUILD_DIR]}\" && cd \"#{File.dirname(ENV[CONFIGURATION_BUILD_DIR])}/\" && tar -xf \"#{cache_product_path}\""
    raise unless system command

    if ENV[CONFIGURATION_BUILD_DIR] != ENV[TARGET_BUILD_DIR]

        command = "rm -rf \"#{ENV[TARGET_BUILD_DIR]+"/"+ENV[FULL_PRODUCT_NAME]}\""
        raise unless system command

        command = "mkdir -p \"#{File.dirname(ENV[TARGET_BUILD_DIR]+"/"+ENV[FULL_PRODUCT_NAME])}\""
        raise unless system command

        command = "mv \"#{ENV[CONFIGURATION_BUILD_DIR]+"/"+ENV[FULL_PRODUCT_NAME]}\" \"#{ENV[TARGET_BUILD_DIR]+"/"+ENV[FULL_PRODUCT_NAME]}\""
        raise unless system command

        command = "/bin/ln -sfh \"#{ENV[TARGET_BUILD_DIR]+"/"+ENV[FULL_PRODUCT_NAME]}\" \"#{ENV[CONFIGURATION_BUILD_DIR]+"/"+ENV[FULL_PRODUCT_NAME]}\""
        raise unless system command
    end 

    puts "<INFO> duration = #{((Time.now - start_time)*1000).to_i} ms in copy cache action"

end

#generate_target_all_infomation(main_path, project, target, source_files) ⇒ Object



173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
# File 'lib/sbuild.rb', line 173

def generate_target_all_infomation(main_path, project, target, source_files)
    podfile_lock_path = "Podfile.lock"
    if main_path.length > 0 
        podfile_lock_path = main_path + "/Podfile.lock"
    end
    if $podfile_spec_checksums == nil and File.exist? podfile_lock_path
        podfile_lock = YAML.load(File.read(podfile_lock_path))
        $podfile_spec_checksums = podfile_lock["SPEC CHECKSUMS"]
    end

    project_configuration = project.build_configurations.detect { | config | config.name == $target_build_configuration}
    project_configuration_content = project_configuration.pretty_print.to_yaml

    project_xcconfig = ""
    if project_configuration.base_configuration_reference
        config_file_path = project_configuration.base_configuration_reference.real_path
        if File.exist? config_file_path
            project_xcconfig = File.read(config_file_path).lines.reject{|line|line.include? "_SEARCH_PATHS"}.sort.join("")
        end
    end

    target_configuration = target.build_configurations.detect { | config | config.name == $target_build_configuration}
    target_configuration_content = target_configuration.pretty_print.to_yaml

    target_xcconfig = ""
    if target_configuration.base_configuration_reference
        config_file_path = target_configuration.base_configuration_reference.real_path
        if File.exist? config_file_path
            target_xcconfig = File.read(config_file_path).lines.reject{|line|line.include? "_SEARCH_PATHS"}.sort.join("")
        end
    end


    files_configuration = []
    build_phases = []
    build_phases.push target.source_build_phase if target.methods.include? :source_build_phase
    build_phases.push target.resources_build_phase if target.methods.include? :resources_build_phase
    build_phases.each do | build_phase |
        target.source_build_phase.files_references.each do | files_reference |
            if files_reference.class == Xcodeproj::Project::Object::PBXVariantGroup
                files_reference.files.each do |file_ref_in_group|
                    file_ref_in_group.build_files.each do |build_file|
                        if build_file.settings and build_file.settings.class == Hash
                            first_configuration.push File.basename(build_file.file_ref.real_path.to_s) + "\n" + build_file.settings.to_yaml
                        end
                    end
                end
            else
                files_reference.build_files.each do |build_file|
                    if build_file.settings and build_file.settings.class == Hash
                        files_configuration.push File.basename(build_file.file_ref.real_path.to_s) + "\n" + build_file.settings.to_yaml
                    end
                end
            end
        end
    end
    files_configuration = files_configuration.sort.uniq.join("\n")


    source_md5_list = []
    has_found_checksum = false
    split_parts = target.name.split("-")
    split_parts.each_with_index do | part, index |
        spec_name = split_parts[0..index].join("-")
        if $podfile_spec_checksums.has_key? spec_name
            source_md5_list.push "SPEC CHECKSUM : #{spec_name} #{$podfile_spec_checksums[spec_name]}"
            has_found_checksum = true
        end
    end

    if has_found_checksum
        if target.name.start_with? "AK" or target.name.start_with? "EUR"

            source_md5_list.push "Project : #{File.basename(project.path)}"
            source_md5_list.push "Project configuration : "
            source_md5_list.push project_configuration_content.strip
            source_md5_list.push "Project xcconfig : "
            source_md5_list.push project_xcconfig.strip

            source_md5_list.push "Target : #{target.name}, #{target.product_type}"
            source_md5_list.push "Target configuration : "
            source_md5_list.push target_configuration_content.strip
            source_md5_list.push "Target xcconfig : "
            source_md5_list.push target_xcconfig.strip
            source_md5_list.push "Files settings : "
            source_md5_list.push files_configuration.strip

            source_md5_list.push "Files MD5 : "
            source_files.uniq.sort.each do | file |
                path = file
                if target.name == "AKULocalizedStrings" or target.name == "EURLocalizedStrings"
                    if file.include? ".swift"
                        source_md5_list.push path + " : " + get_file_md5(path)
                    end
                else
                    source_md5_list.push path + " : " + get_file_md5(path)
                end
            end
        else
            source_md5_list.push "Target configuration: #{$target_build_configuration}"    
        end

        source_md5_content = source_md5_list.join("\n")
        return source_md5_content
    end
end

#get_branch_cache_folderObject



43
44
45
# File 'lib/sbuild.rb', line 43

def get_branch_cache_folder
    return Dir.home + "/sbBuild" +"/#{$project_build_branch.gsub("/", ".")}"
end

#get_cache_root_pathObject



51
52
53
# File 'lib/sbuild.rb', line 51

def get_cache_root_path
    return Dir.home + "/sbBuild"
end

#get_content_without_pwd(content) ⇒ Object



67
68
69
70
# File 'lib/sbuild.rb', line 67

def get_content_without_pwd(content)
    content = content.gsub("#{Dir.pwd}/", "").gsub(/#{Dir.pwd}(\W|$)/, '\1')
    return content
end

#get_default_cache_folderObject



55
56
57
# File 'lib/sbuild.rb', line 55

def get_default_cache_folder
    return Dir.home + "/sbBuild/master"
end

#get_file_md5(file) ⇒ Object



72
73
74
75
76
77
78
79
# File 'lib/sbuild.rb', line 72

def get_file_md5(file)
    if $file_md5_hash.has_key? file
        return $file_md5_hash[file]
    end
    md5 = Digest::MD5.hexdigest(File.read(file))
    $file_md5_hash[file] = md5
    return md5
end

#get_main_project_info_pathObject



47
48
49
# File 'lib/sbuild.rb', line 47

def get_main_project_info_path
    return Dir.home + "/sbBuild/" + "#{FILE_NAME_MAIN_PROJECT_CONTEXT}"
end

#get_projects(project_path) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/sbuild.rb', line 82

def get_projects(project_path)
    pods_project_path = "Pods/Pods.xcodeproj"
    if project_path.length > 0 
        pods_project_path = project_path + "/Pods/Pods.xcodeproj"
    end
    pods_project = Xcodeproj::Project.open(pods_project_path)
    super_project_paths = get_super_project(pods_project)
    super_projects = []
    super_project_paths.each do | path |
        next if path.end_with? pods_project_path
        project = Xcodeproj::Project.open(path)
        super_projects.push project
    end
    return (super_projects + [pods_project])
end

#get_super_project(project) ⇒ Object



98
99
100
101
102
103
104
105
106
# File 'lib/sbuild.rb', line 98

def get_super_project(project)
    wrapper_projects = project.files.select{|file|file.last_known_file_type=="wrapper.pb-project"}
    wrapper_project_paths = []
    wrapper_projects.each do | wrapper_project_file |
        wrapper_project_file_path = wrapper_project_file.real_path.to_s
        wrapper_project_paths.push wrapper_project_file_path
    end
    return wrapper_project_paths.uniq
end

#get_target_cache(target, target_md5) ⇒ Object



282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
# File 'lib/sbuild.rb', line 282

def get_target_cache(target, target_md5)

    dependency_start_time = Time.now

    if is_private_target(target) 
        target_cache_dirs = Dir.glob(get_branch_cache_folder + "/" + target.name + "-" + target_md5 + "-*")
    else
        target_cache_dirs = Dir.glob(get_default_cache_folder + "/" + target.name + "-" + target_md5 + "-*")
    end

    hit_results = []

    target_cache_dirs.each do |target_cache_dir|
        unless File.exist? target_cache_dir + "/" + FILE_NAME_PRODUCT
            puts "<ERROR> #{target.name} target cache dir missed files: #{target_cache_dir}"
            next
        end
        unless File.exist? target_cache_dir + "/" + FILE_NAME_CONTEXT
            puts "<ERROR> #{target.name} target cache dir missed files: #{target_cache_dir}"
            next
        end

        target_context = YAML.load(File.read(target_cache_dir + "/" + FILE_NAME_CONTEXT))

        if target_context[:target_md5] != target_md5 or target_context[:product_md5] != get_file_md5(target_cache_dir + "/" + FILE_NAME_PRODUCT)
            command = "rm -rf \"#{target_cache_dir}\""
            raise unless system command
            puts "<ERROR> #{target.name} target md5 does not match: #{target_cache_dir}"
        end
    
        hit_results.push target_cache_dir

    end

    return hit_results

end

#get_target_source_files(target) ⇒ Object



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/sbuild.rb', line 138

def get_target_source_files(target)
    files = []
    #获取所有可执行文件(.m .swift .cpp .mm)
    target.source_build_phase.files.each do | file |
        file_path = file.file_ref.real_path.to_s
        files.push file_path
    end

    #获取所有头文件(.h)
    target.headers_build_phase.files.each do | file |
        file_path = file.file_ref.real_path.to_s
        files.push file_path
    end
    #获取所有资源文件(.png,.strings .json .html)
    target.resources_build_phase.files.each do | file |
        file_path = file.file_ref.real_path.to_s
        files.push file_path
    end
    expand_files = []
    files.uniq.each do | file |
        next unless File.exist? file
        if File.file? file
            expand_files.push file
        else
            Find.find(file).each do | file_in_dir |
                if File.file? file_in_dir
                    expand_files.push file_in_dir
                end
            end
        end
    end
    return expand_files.uniq
end

#inject_cache_action(project, target) ⇒ Object



363
364
365
366
367
368
# File 'lib/sbuild.rb', line 363

def inject_cache_action(project, target)
    command_exec = "\"#{$0}\"" 
    inject_phase = target.new_shell_script_build_phase("sb_cache_#{target.name}")
    inject_phase.shell_script = "#{command_exec} #{"cache"} #{target.name} \"#{project.path}\""
    inject_phase.show_env_vars_in_log = '1'
end

#inject_copy_action(project, target, target_context) ⇒ Object



370
371
372
373
374
375
376
377
378
379
380
381
382
383
# File 'lib/sbuild.rb', line 370

def inject_copy_action(project, target, target_context)
    target_cache_dir = target_context[:hit_target_cache_dir]

    target.build_phases.delete_if { | build_phase | 
        build_phase.class == Xcodeproj::Project::Object::PBXHeadersBuildPhase or 
        build_phase.class == Xcodeproj::Project::Object::PBXSourcesBuildPhase or 
        build_phase.class == Xcodeproj::Project::Object::PBXResourcesBuildPhase
    }

    command_exec = "\"#{$0}\""    
    inject_phase = target.new_shell_script_build_phase("sb_copy_#{target.name}")
    inject_phase.shell_script = "#{command_exec} #{"copy"} \"#{target_cache_dir}\""
    inject_phase.show_env_vars_in_log = '1'
end

#is_private_target(target) ⇒ Object



59
60
61
62
63
64
65
# File 'lib/sbuild.rb', line 59

def is_private_target(target)
    if target.name.start_with? "AK" or target.name.start_with? "EUR" or target.name.start_with? "A4K"
        return true
    else
        return false
    end
end

#project_task_begin(argv) ⇒ Object



522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
# File 'lib/sbuild.rb', line 522

def project_task_begin(argv)

    system "pod install"

    g = Git.open("./")
    $project_build_branch = g.current_branch

    projects = get_projects("")
    total_count = 0
    hit_count = 0
    miss_count = 0
    error_count = 0
    hit_target_md5_cache_set = Set.new
    miss_target_cache_set = Set.new

    pre_targets_info = {}

    projects.each do |project|
        backup_project(project)
    end

    clean_temp_files 
    
    projects.each do |project|
        project.native_targets.each do |target|
            target.build_phases.delete_if { |phase|
                phase.class == Xcodeproj::Project::Object::PBXShellScriptBuildPhase and phase.name.include? "sb_inject"
            }
            if can_cache_target(target)
                total_count = total_count + 1
                source_files = get_target_source_files(target)
                target_md5_content = generate_target_all_infomation("", project, target, source_files)
                unless target_md5_content
                    puts "<ERROR> target md5 content can not generate: #{target.name}"
                    error_count = error_count + 1
                    next
                end

                target_md5 = Digest::MD5.hexdigest(target_md5_content)
                hit_target_cache_dirs = get_target_cache(target, target_md5)
                target_info = {}

                if hit_target_cache_dirs.count == 0
                    puts "<INFO> #{target.name} #{target_md5} does not hit any cache"
                    target_info[:target_status] = CACHE_STATUS_MISS
                    inject_cache_action(project, target)
                    miss_count = miss_count + 1
                else
                    target_info[:hit_target_cache_dir] = hit_target_cache_dirs
                    hit_target_md5_cache_set.add "#{target.name}-#{target_md5}"

                    if hit_target_cache_dirs.count > 0 
                        puts "<INFO> #{target.name} #{target_md5} hit cache"
                        hit_count = hit_count + 1
                        target_really_hit_dir = hit_target_cache_dirs[0]
                        hit_target_info = YAML.load(File.read(target_really_hit_dir + "/" + FILE_NAME_CONTEXT))
                        target_info = target_info.merge!(hit_target_info)
                        target_info[:target_status] = CACHE_STATUS_HIT
                        target_info[:hit_target_cache_dir] = target_really_hit_dir
                        inject_copy_action(project, target, target_info)
                    end
                end
                File.write("#{project.path}/#{target.name}.#{FILE_NAME_TARGET_CONTEXT}", target_info.to_yaml)
            end
        end   
        project.save
    end
    puts "<INFO> total count: #{total_count}, hit count: #{hit_count}, miss_count: #{miss_count}, error_count: #{error_count}"
end

#project_task_end(argv) ⇒ Object



593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
# File 'lib/sbuild.rb', line 593

def project_task_end(argv)
    project_name = argv[1]
    project_path = ""
    project_path_key = "SBUILD_#{project_name}_PATH"
    project_path = ENV[project_path_key]
    if project_path == nil or project_path.length == 0 
        if File.exist? get_main_project_info_path
            project_info = YAML.load(File.read(get_main_project_info_path))
            project_path = project_info[project_name]
        end
    end
    raise unless project_path.length > 0

    g = Git.open(project_path)
    $project_build_branch = g.current_branch

    projects = get_projects(project_path)
    post_targets_context = {}
    total_add_count = 0

    projects.each do |project|
        project.native_targets.each do | target |
            target_context_file = "#{project.path}/#{target.name}.#{FILE_NAME_TARGET_CONTEXT}"
            if can_cache_target(target)
                if File.exist? target_context_file
                    post_targets_context = YAML.load(File.read(target_context_file))
                end
                next unless post_targets_context[:target_status] != CACHE_STATUS_HIT

                source_files = get_target_source_files(target)
                target_md5_content = generate_target_all_infomation(project_path, project, target, source_files)
                next unless target_md5_content && target_md5_content.length > 0 

                cur_target_md5 = Digest::MD5.hexdigest(target_md5_content)

                post_targets_context[:target_md5] = cur_target_md5

                if add_cache(target, post_targets_context)
                    puts  "<INFO> #{target} is being added to cache dir"
                    total_add_count = total_add_count + 1
                    target.build_phases.delete_if { |phase|
                        phase.class == Xcodeproj::Project::Object::PBXShellScriptBuildPhase and phase.name.include? "sb_"
                    }
                end
            end
        end
    restore_project(project)
    end
    puts "<INFO> total add cache count: #{total_add_count}"
end

#restore_project(project) ⇒ Object



120
121
122
123
124
125
# File 'lib/sbuild.rb', line 120

def restore_project(project)
    if File.exist? "#{project.path}/ysTest_backup.pbxproj"
        command = "mv \"#{project.path}/ysTest_backup.pbxproj\" \"#{project.path}/project.pbxproj\""
        raise unless system command
    end
end

#set_main_project_envObject



320
321
322
323
324
325
326
327
328
329
330
331
332
# File 'lib/sbuild.rb', line 320

def set_main_project_env
    main_project_name = ARGV[1]
    main_project_path = ARGV[2]

    target_context = {} 
    if File.exist? get_main_project_info_path
        target_context = YAML.load(File.read(get_main_project_info_path))
    else
        Dir.mkdir(get_cache_root_path)
    end
    target_context[main_project_name] = main_project_path  
    File.write(get_main_project_info_path, target_context.to_yaml)
end

#set_target_envObject



334
335
336
337
338
339
340
341
342
343
344
345
346
# File 'lib/sbuild.rb', line 334

def set_target_env
    target_name = ARGV[1]
    project_path = ARGV[2]

    target_context = {}       
    [SYMROOT, OBJROOT, SRCROOT, CONFIGURATION_BUILD_DIR, TARGET_BUILD_DIR, TARGET_TEMP_DIR, FULL_PRODUCT_NAME].sort.each do | key |
        if ENV[key]
            target_context[key] = ENV[key] 
        end
    end
    target_context[:target_status] = CACHE_STATUS_READY
    File.write("#{project_path}/#{target_name}.#{FILE_NAME_TARGET_CONTEXT}", target_context.to_yaml)
end