Commit b7061f76 authored by Fabio Pelosin's avatar Fabio Pelosin

[Xcodeproj] Initial adaptation for refactor.

parent 3e0ea475
......@@ -19,18 +19,8 @@ module Pod
return @project if @project
@project = Pod::Project.new
@project.user_build_configurations = @podfile.user_build_configurations
pods.each do |pod|
# Add all source files to the project grouped by pod
pod.relative_source_files_by_spec.each do |spec, paths|
parent_group = pod.local? ? @project.local_pods : @project.pods
group = @project.add_spec_group(spec.name, parent_group)
paths.each do |path|
group.files.new('path' => path.to_s)
end
end
end
# Add a group to hold all the target support files
@project.main_group.groups.new('name' => 'Targets Support Files')
pods.each { |p| p.add_file_references_to_project(@project) }
pods.each { |p| p.link_headers }
@project
end
......@@ -188,10 +178,8 @@ module Pod
pathname = Pathname.new(sandbox.root + filename)
dummy_source.save_as(pathname)
project_file = project.files.new('path' => filename)
project.group("Targets Support Files") << project_file
target_installer.target.source_build_phases.first << project_file
file = project.new_file(filename, "Targets Support Files")
target_installer.target.source_build_phase.add_file_reference(file)
end
def specs_by_target
......
module Pod
class Installer
# This class is reponsible of creating and configuring the static library
# target in Pods project. Every target is generated from a target
# definition of the Podfile.
#
class TargetInstaller
include Config::Mixin
attr_reader :podfile, :project, :target_definition, :target
attr_accessor :requires_arc
# @return [Podfile]
#
# TODO: is really needed to pass the podfile?
#
attr_reader :podfile
# @return [Project] The Pods project.
#
attr_reader :project
# @return [TargetDefinition] The target definition whoose target needs to
# be generated.
#
attr_reader :target_definition
def initialize(podfile, project, target_definition)
@podfile, @project, @target_definition = podfile, project, target_definition
@podfile = podfile
@project = project
@target_definition = target_definition
end
# @return [void] Creates the target in the Pods project and its support
# files.
#
# @param [Array<LocalPod>] pods The pods are required by the target
# definition of this installer.
#
# @param [Sandbox] sandbox The sanbox where the support files
# should be generated.
#
def install!(pods, sandbox)
self.requires_arc = pods.any? { |pod| pod.requires_arc? }
@target = @project.add_pod_target(@target_definition.label, @target_definition.platform)
source_file_descriptions = []
pods.each { |p| p.add_build_files_to_target(@target) }
support_files_group = @project.support_files_group.new_group(@target_definition.label)
target_support_files.each { |path| support_files_group.new_file(path) }
xcconfig_file = support_files_group.files.find { |f| f.path == @target_definition.xcconfig_name }
configure_build_configurations(xcconfig_file, sandbox)
create_files(pods, sandbox)
end
def xcconfig
@xcconfig ||= Xcodeproj::Config.new({
# @return [PBXNativeTarget] The target generated by the installation
# process.
#
attr_reader :target
# @return [Boold] Wether the any of the pods requires arc.
#
# TODO: This should not be an attribute reader.
#
attr_accessor :requires_arc
attr_reader :xcconfig
# In a workspace this is where the static library headers should be found.
#
def generate_xcconfig(pods, sandbox)
xcconfig = Xcodeproj::Config.new({
'PODS_ROOT' => @target_definition.relative_pods_root,
'PODS_HEADERS_SEARCH_PATHS' => '${PODS_PUBLIC_HEADERS_SEARCH_PATHS}',
'ALWAYS_SEARCH_USER_PATHS' => 'YES', # needed to make EmbedReader build
'OTHER_LDFLAGS' => default_ld_flags
})
xcconfig.merge!('HEADER_SEARCH_PATHS' => '${PODS_HEADERS_SEARCH_PATHS}')
xcconfig.merge!('PODS_BUILD_HEADERS_SEARCH_PATHS' => quoted(sandbox.build_headers.search_paths).join(" "))
xcconfig.merge!('PODS_PUBLIC_HEADERS_SEARCH_PATHS' => quoted(sandbox.public_headers.search_paths).join(" "))
pods.each { |pod| xcconfig.merge!(pod.xcconfig) }
@xcconfig = xcconfig
end
#
#
def copy_resources_script_for(pods)
@copy_resources_script ||= Generator::CopyResourcesScript.new(pods.map { |p| p.relative_resource_files }.flatten)
end
......@@ -57,37 +123,9 @@ module Pod
[:copy_resources_script_name, :prefix_header_name, :xcconfig_name].map { |file| @target_definition.send(file) }
end
# TODO move xcconfig related code into the xcconfig method, like copy_resources_script and generate_bridge_support.
def install!(pods, sandbox)
self.requires_arc = pods.any? { |pod| pod.requires_arc? }
@target = @project.add_pod_target(@target_definition.label, @target_definition.platform)
source_file_descriptions = []
pods.each do |pod|
xcconfig.merge!(pod.xcconfig)
source_file_descriptions += pod.source_file_descriptions
# TODO: this doesn't need to be done here, it has nothing to do with the target
pod.link_headers
end
@target.add_source_files(source_file_descriptions)
xcconfig.merge!('HEADER_SEARCH_PATHS' => '${PODS_HEADERS_SEARCH_PATHS}')
xcconfig.merge!('PODS_BUILD_HEADERS_SEARCH_PATHS' => quoted(sandbox.build_headers.search_paths).join(" "))
xcconfig.merge!('PODS_PUBLIC_HEADERS_SEARCH_PATHS' => quoted(sandbox.public_headers.search_paths).join(" "))
support_files_group = @project.group("Targets Support Files").create_group(@target_definition.label)
support_files_group.create_files(target_support_files)
xcconfig_file = support_files_group.files.where(:path => @target_definition.xcconfig_name)
configure_build_configurations(xcconfig_file, sandbox)
create_files(pods, sandbox)
end
def configure_build_configurations(xcconfig_file, sandbox)
@target.build_configurations.each do |config|
config.base_configuration = xcconfig_file
config.base_configuration_reference = xcconfig_file
config.build_settings['OTHER_LDFLAGS'] = ''
config.build_settings['GCC_PREFIX_HEADER'] = @target_definition.prefix_header_name
config.build_settings['PODS_ROOT'] = '${SRCROOT}'
......@@ -96,6 +134,8 @@ module Pod
end
end
#
#
def create_files(pods, sandbox)
bridge_support_metadata_path = sandbox.root + @target_definition.bridge_support_name
UI.message "- Generating BridgeSupport metadata file at #{UI.path bridge_support_metadata_path}" do
......@@ -104,6 +144,7 @@ module Pod
end if @podfile.generate_bridge_support?
UI.message "- Generating xcconfig file at #{UI.path(sandbox.root + @target_definition.xcconfig_name)}" do
generate_xcconfig(pods, sandbox)
xcconfig.save_as(sandbox.root + @target_definition.xcconfig_name)
@target_definition.xcconfig = xcconfig
end
......
......@@ -138,19 +138,17 @@ module Pod
[user_project.targets.first]
end.reject do |target|
# Reject any target that already has this Pods library in one of its frameworks build phases
target.frameworks_build_phases.any? do |phase|
phase.files.any? { |file| file.name == @target_definition.lib_name }
end
target.frameworks_build_phase.files.any? { |build_file| build_file.file_ref.name == @target_definition.lib_name }
end
end
end
def add_xcconfig_base_configuration
xcconfig = user_project.files.new('path' => @target_definition.xcconfig_relative_path)
xcconfig = user_project.new_file(@target_definition.xcconfig_relative_path)
targets.each do |target|
config_build_names_by_overriden_key = {}
target.build_configurations.each do |config|
config_name = config.attributes["name"]
config_name = config.name
if @target_definition.xcconfig
@target_definition.xcconfig.attributes.each do |key, value|
target_value = config.build_settings[key]
......@@ -161,11 +159,11 @@ module Pod
end
end
config.base_configuration = xcconfig
config.base_configuration_reference = xcconfig
end
config_build_names_by_overriden_key.each do |key, config_build_names|
name = "#{target.attributes["name"]} [#{config_build_names.join(' - ')}]"
name = "#{target.name} [#{config_build_names.join(' - ')}]"
actions = [ "Use the `$(inherited)' flag, or", "Remove the build settings from the target." ]
UI.warn("The target `#{name}' overrides the `#{key}' build setting defined in `#{@target_definition.xcconfig_relative_path}'.", actions)
end
......@@ -173,23 +171,20 @@ module Pod
end
def add_pods_library
group = user_project.group("Frameworks") || user_project.main_group
pods_library = group.files.new_static_library(@target_definition.label)
frameworks = user_project.frameworks_group
pods_library = frameworks.new_static_library(@target_definition.label)
targets.each do |target|
target.frameworks_build_phases.each { |build_phase| build_phase << pods_library }
target.frameworks_build_phase.add_file_reference(pods_library)
end
end
def add_copy_resources_script_phase
targets.each do |target|
phase = target.shell_script_build_phases.new
phase.name = 'Copy Pods Resources'
phase = target.new_shell_script_build_phase('Copy Pods Resources')
phase.shell_script = %{"#{@target_definition.copy_resources_script_relative_path}"\n}
end
end
end
end
end
end
......@@ -166,11 +166,11 @@ module Pod
# @note The Paths are downcased to prevent issues. See #568.
#
def clean_paths
used = used_files.map(&:downcase)
files = Dir.glob(root + "**/*", File::FNM_DOTMATCH).map(&:downcase)
cached_used_paths = used_files
files = Dir.glob(root + "**/*", File::FNM_DOTMATCH)
files.reject! do |candidate|
candidate.end_with?('.', '..') || used.any? do |path|
candidate.end_with?('.', '..') || cached_used_paths.any? do |path|
path.include?(candidate) || candidate.include?(path)
end
end
......@@ -386,7 +386,36 @@ module Pod
result
end
# @!group Target integration
# @!group Project integration
#
# @return [void]
#
def add_file_references_to_project(project)
@file_references_by_spec = {}
parent_group = local? ? project.local_pods : project.pods
relative_source_files_by_spec.each do |spec, paths|
group = project.add_spec_group(spec.name, parent_group)
file_references = []
paths.each do |path|
file_references << group.new_file(path)
end
@file_references_by_spec[spec] = file_references
end
end
#
#
attr_reader :file_references_by_spec
#
#
def add_build_files_to_target(target)
file_references_by_spec.each do |spec, file_reference|
target.add_file_references(file_reference, spec.compiler_flags.strip)
end
end
# @return [void] Copies the pods headers to the sandbox.
#
......@@ -403,26 +432,10 @@ module Pod
end
end
# @param [Xcodeproj::Project::Object::PBXNativeTarget] target
# The target to integrate.
#
# @return [void] Adds the pods source files to a given target.
#
def source_file_descriptions
result = []
source_files_by_spec.each do | spec, files |
compiler_flags = spec.compiler_flags.strip
files.each do |file|
file = relativize_from_sandbox(file)
desc = Xcodeproj::Project::PBXNativeTarget::SourceFileDescription.new(file, compiler_flags, nil)
result << desc
end
end
result
end
# @return Whether the pod requires ARC.
#
# TODO: this should be not used anymore.
#
def requires_arc?
top_specification.requires_arc
end
......
......@@ -12,9 +12,13 @@ end
module Pod
class Project < Xcodeproj::Project
attr_reader :support_files_group
def initialize(*)
super
main_group << groups.new('name' => 'Pods')
new_group('Pods')
@support_files_group = new_group('Targets Support Files')
@user_build_configurations = []
end
......@@ -24,39 +28,42 @@ module Pod
# any build settings themselves, that's left to `add_pod_target`.
user_build_configurations.each do |name, _|
unless build_configurations.map(&:name).include?(name)
build_configurations.new('name' => name)
bc = new(XCBuildConfiguration)
bc.name = name
build_configurations << bc
end
end
end
# Shortcut access to the `Pods' PBXGroup.
def pods
@pods ||= groups.where(:name => 'Pods') || groups.new('name' => 'Pods')
@pods ||= self['Pods'] || new_group('Pods')
end
# Shortcut access to the `Local Pods' PBXGroup.
def local_pods
@local_pods ||= groups.where(:name => 'Local Pods') || groups.new('name' => 'Local Pods')
@local_pods ||= self['Local Pods'] || new_group('Local Pods')
end
# Adds a group as child to the `Pods' group namespacing subspecs.
def add_spec_group(name, parent_group)
groups = parent_group.groups
current_group = parent_group
group = nil
name.split('/').each do |name|
group = groups.where(:name => name) || groups.new('name' => name)
groups = group.groups
group = current_group[name] || current_group.new_group(name)
current_group = group
end
group
end
def add_pod_target(name, platform)
target = targets.new_static_library(platform.name, name)
target = new_target(:static_library, name, platform.name)
settings = {}
if platform.requires_legacy_ios_archs?
settings['ARCHS'] = "armv6 armv7"
end
if platform == :ios && platform.deployment_target
settings['IPHONEOS_DEPLOYMENT_TARGET'] = platform.deployment_target.to_s
end
......@@ -66,9 +73,11 @@ module Pod
@user_build_configurations.each do |name, type|
unless target.build_configurations.map(&:name).include?(name)
config = target.build_configurations.new('name' => name)
bc = new(XCBuildConfiguration)
bc.name = name
target.build_configurations << bc
# Copy the settings from either the Debug or the Release configuration.
config.build_settings = target.build_settings(type.to_s.capitalize).merge(settings)
bc.build_settings = target.build_settings(type.to_s.capitalize).merge(settings)
end
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment