Class: Phoenx::TargetBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/phoenx/use_cases/generate_target.rb

Direct Known Subclasses

TestTargetBuilder, TestableTargetBuilder

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project, target_spec, project_spec) ⇒ TargetBuilder

Returns a new instance of TargetBuilder.



11
12
13
14
15
16
# File 'lib/phoenx/use_cases/generate_target.rb', line 11

def initialize(project, target_spec, project_spec)
	@project = project
	@target_spec = target_spec
	@project_spec = project_spec
	@framework_files = []
end

Instance Attribute Details

#framework_filesObject (readonly)

Returns the value of attribute framework_files.



9
10
11
# File 'lib/phoenx/use_cases/generate_target.rb', line 9

def framework_files
  @framework_files
end

#projectObject (readonly)

Returns the value of attribute project.



5
6
7
# File 'lib/phoenx/use_cases/generate_target.rb', line 5

def project
  @project
end

#project_specObject (readonly)

Returns the value of attribute project_spec.



8
9
10
# File 'lib/phoenx/use_cases/generate_target.rb', line 8

def project_spec
  @project_spec
end

#target_specObject (readonly)

Returns the value of attribute target_spec.



7
8
9
# File 'lib/phoenx/use_cases/generate_target.rb', line 7

def target_spec
  @target_spec
end

Instance Method Details

#add_build_phase_scriptsObject



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/phoenx/use_cases/generate_target.rb', line 41

def add_build_phase_scripts
	@target_spec.pre_build_scripts.each do |script|
		phase = self.target.new_shell_script_build_phase(script[:name])
		phase.shell_script = script[:script]
		self.target.build_phases.move(phase, 0)
	end
	@target_spec.post_build_scripts.each do |script|
		phase = self.target.new_shell_script_build_phase(script[:name])
		phase.shell_script = script[:script]
		self.target.build_phases.move(phase, self.target.build_phases.count - 1)
	end
end

#add_config_filesObject



153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/phoenx/use_cases/generate_target.rb', line 153

def add_config_files
	# Add configuration group
	Phoenx.add_groups_for_files(@project, @target_spec.config_files.values)
	@target_spec.config_files.each do |config,file_name|
		unless file_name == nil
			file = Phoenx.get_or_add_file(@project,file_name)
			configuration = self.target.build_configuration_list[config]
			unless configuration
				abort "Config file assigned to invalid configuration '#{config}' ".red + file_name.bold
			end
			configuration.base_configuration_reference = file
		end
	end
end

#add_frameworks_and_librariesObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/phoenx/use_cases/generate_target.rb', line 23

def add_frameworks_and_libraries
	# Add Framework dependencies
	frameworks_group = @project.main_group.find_subpath(FRAMEWORKS_ROOT, true)
	Phoenx.add_groups_for_files(@project,@target_spec.frameworks)
	frameworks = Phoenx.merge_files_array(@target_spec.frameworks)
	frameworks.each do |framework|
		file = Phoenx.get_or_add_file(@project,framework)
		@framework_files << file
		self.target.frameworks_build_phases.add_file_reference(file)
	end
	Phoenx.add_groups_for_files(@project, @target_spec.libraries)
	libraries = Phoenx.merge_files_array(@target_spec.libraries)
	libraries.each do |framework|
		file = Phoenx.get_or_add_file(@project,framework)
		self.target.frameworks_build_phases.add_file_reference(file)
	end
end

#add_headers(header_files, excluded_header_files, attributes) ⇒ Object



128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/phoenx/use_cases/generate_target.rb', line 128

def add_headers(header_files, excluded_header_files, attributes)
	headers = Phoenx.merge_files_array(header_files, excluded_header_files)
	unless !header_files || header_files.empty? || !headers.empty?
		puts "No #{attributes["ATTRIBUTES"].first} headers found".yellow
	end
	Phoenx.add_groups_for_files(@project, headers)
	headers.each do |header|
		file = Phoenx.get_or_add_file(@project,header)
		build_file = self.target.headers_build_phase.add_file_reference(file, true)
		build_file.settings = attributes
	end
end

#add_private_headersObject



145
146
147
# File 'lib/phoenx/use_cases/generate_target.rb', line 145

def add_private_headers
	self.add_headers(@target_spec.private_headers, @target_spec.excluded_private_headers, ATTRIBUTES_PRIVATE_HEADERS)
end

#add_project_headersObject



149
150
151
# File 'lib/phoenx/use_cases/generate_target.rb', line 149

def add_project_headers
	self.add_headers(@target_spec.project_headers, @target_spec.excluded_project_headers, ATTRIBUTES_PROJECT_HEADERS)
end

#add_public_headersObject



141
142
143
# File 'lib/phoenx/use_cases/generate_target.rb', line 141

def add_public_headers
	self.add_headers(@target_spec.public_headers, @target_spec.excluded_public_headers, ATTRIBUTES_PUBLIC_HEADERS)
end

#add_resourcesObject



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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/phoenx/use_cases/generate_target.rb', line 64

def add_resources
	# Add Resource files
	resources = Phoenx.merge_files_array(@target_spec.resources, @target_spec.excluded_resources)
	unless !@target_spec.resources || @target_spec.resources.empty? || !resources.empty?
		puts "No resources found".yellow
	end
	Phoenx.add_groups_for_files(@project, resources)
	resources.each do |source|
		file = nil
		if Phoenx.is_bundle?(source)
			parts = source.split("/")
			group = @project.main_group
			parts.each do |part|
				if Phoenx.is_bundle?(part)
					file = group.find_file_by_path(part)
					unless file != nil
						file = group.new_file(part)
						self.target.resources_build_phase.add_file_reference(file)
					end
					break
				else
					group = group.find_subpath(part, false)
				end
			end
		elsif Phoenx.is_translation_folder?(source)
			parts = source.split("/")
			translation_folder_index = parts.index { |part| Phoenx.is_translation_folder?(part) }
			parent_path = parts[0..translation_folder_index - 1].join('/')
			parent_group = @project.main_group.find_subpath(parent_path)
			variant_group = parent_group[File.basename(source)]
			if variant_group == nil
				variant_group = parent_group.new_variant_group(File.basename(source))
				self.target.resources_build_phase.add_file_reference(variant_group)
			end
			variant_group.new_file(parts[translation_folder_index..parts.count].join('/'))
		else
			group = @project.main_group.find_subpath(File.dirname(source), false)
			unless group == nil
				file = group.find_file_by_path(File.basename(source))
				unless file != nil
					file = group.new_file(File.basename(source))
					self.target.resources_build_phase.add_file_reference(file)
				end
			end
		end
	end
end

#add_sourcesObject



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/phoenx/use_cases/generate_target.rb', line 112

def add_sources
	# Add Source files
	sources = Phoenx.merge_files_array(@target_spec.sources, @target_spec.excluded_sources)
	unless !@target_spec.sources || @target_spec.sources.empty? || !sources.empty?
		puts "No sources found".yellow
	end
	Phoenx.add_groups_for_files(@project, sources)
	sources.each do |source|
		file = Phoenx.get_or_add_file(@project,source)
		# Add to Compile sources phase
		unless File.extname(source) == ".h" || File.extname(source) == ".pch"
			self.target.add_file_references([file])
		end
	end
end

#add_support_filesObject



18
19
20
21
# File 'lib/phoenx/use_cases/generate_target.rb', line 18

def add_support_files
	files = Phoenx.merge_files_array(@target_spec.support_files, @target_spec.excluded_support_files)
	Phoenx.get_or_add_files(@project, files)
end

#add_system_dependenciesObject



54
55
56
57
58
59
60
61
62
# File 'lib/phoenx/use_cases/generate_target.rb', line 54

def add_system_dependencies
	# Add Framework dependencies
	@target_spec.system_frameworks.each do |framework|
		self.target.add_system_framework(framework)
	end
	@target_spec.system_libraries.each do |library|
		self.target.add_system_library(library)
	end
end

#buildObject



173
174
175
# File 'lib/phoenx/use_cases/generate_target.rb', line 173

def build

end

#configure_targetObject



168
169
170
171
# File 'lib/phoenx/use_cases/generate_target.rb', line 168

def configure_target
	Phoenx.set_target_build_settings_defaults(self.target)
	Phoenx.set_project_build_settings_defaults(@project)
end

#targetObject



177
178
179
# File 'lib/phoenx/use_cases/generate_target.rb', line 177

def target
	return nil
end