35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
# File 'lib/zerg_xcode/plugins/retarget.rb', line 35
def retarget!(project, regexp, targets)
file_type_phases = {}
file_phases = {}
build_files = {}
project['targets'].each do |target|
target.all_files.each do |file|
build_file = file[:build_object]
phase_type = file[:phase]['isa']
build_files[file[:object]] = build_file
file_type_phases[build_file.file_type] = phase_type
file_phases[file[:object]] = phase_type
end
end
in_targets = project['targets'].select do |target|
targets.include? target['name']
end
out_targets = project['targets'] - in_targets
out_targets.each do |target|
target['buildPhases'].each do |phase|
phase['files'].reject! { |build_file| regexp =~ build_file.filename }
end
end
new_files = project.all_files.map { |file| file[:object] }.select do |file|
regexp =~ file['path']
end
new_files.each do |file|
next if build_files[file]
build_file = PBXBuildFile.new 'fileRef' => file
build_files[file] = build_file
file_phases[file] = file_type_phases[build_file.file_type] ||
build_file.guessed_build_phase_type
end
in_targets.each do |target|
already_in = Set.new(target.all_files.map { |file| file[:object] })
new_files.each do |file|
file_ref = file[:object]
next if already_in.include? file
phase_type = file_phases[file]
phase = target['buildPhases'].find { |p| p['isa'] == phase_type }
unless phase
phase = PBXBuildPhase.new_phase phase_type
target['buildPhases'] << phase
end
phase['files'] << build_files[file]
end
end
end
|