Commit b7061f76 authored by Fabio Pelosin's avatar Fabio Pelosin

[Xcodeproj] Initial adaptation for refactor.

parent 3e0ea475
...@@ -19,18 +19,8 @@ module Pod ...@@ -19,18 +19,8 @@ module Pod
return @project if @project return @project if @project
@project = Pod::Project.new @project = Pod::Project.new
@project.user_build_configurations = @podfile.user_build_configurations @project.user_build_configurations = @podfile.user_build_configurations
pods.each do |pod| pods.each { |p| p.add_file_references_to_project(@project) }
# Add all source files to the project grouped by pod pods.each { |p| p.link_headers }
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')
@project @project
end end
...@@ -188,10 +178,8 @@ module Pod ...@@ -188,10 +178,8 @@ module Pod
pathname = Pathname.new(sandbox.root + filename) pathname = Pathname.new(sandbox.root + filename)
dummy_source.save_as(pathname) dummy_source.save_as(pathname)
project_file = project.files.new('path' => filename) file = project.new_file(filename, "Targets Support Files")
project.group("Targets Support Files") << project_file target_installer.target.source_build_phase.add_file_reference(file)
target_installer.target.source_build_phases.first << project_file
end end
def specs_by_target def specs_by_target
......
module Pod module Pod
class Installer 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 class TargetInstaller
include Config::Mixin include Config::Mixin
attr_reader :podfile, :project, :target_definition, :target # @return [Podfile]
attr_accessor :requires_arc #
# 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) def initialize(podfile, project, target_definition)
@podfile, @project, @target_definition = podfile, project, target_definition @podfile = podfile
@project = project
@target_definition = target_definition
end end
def xcconfig # @return [void] Creates the target in the Pods project and its support
@xcconfig ||= Xcodeproj::Config.new({ # files.
# In a workspace this is where the static library headers should be found. #
# @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
# @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_ROOT' => @target_definition.relative_pods_root,
'PODS_HEADERS_SEARCH_PATHS' => '${PODS_PUBLIC_HEADERS_SEARCH_PATHS}', 'PODS_HEADERS_SEARCH_PATHS' => '${PODS_PUBLIC_HEADERS_SEARCH_PATHS}',
'ALWAYS_SEARCH_USER_PATHS' => 'YES', # needed to make EmbedReader build 'ALWAYS_SEARCH_USER_PATHS' => 'YES', # needed to make EmbedReader build
'OTHER_LDFLAGS' => default_ld_flags '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 end
#
#
def copy_resources_script_for(pods) def copy_resources_script_for(pods)
@copy_resources_script ||= Generator::CopyResourcesScript.new(pods.map { |p| p.relative_resource_files }.flatten) @copy_resources_script ||= Generator::CopyResourcesScript.new(pods.map { |p| p.relative_resource_files }.flatten)
end end
...@@ -57,37 +123,9 @@ module Pod ...@@ -57,37 +123,9 @@ module Pod
[:copy_resources_script_name, :prefix_header_name, :xcconfig_name].map { |file| @target_definition.send(file) } [:copy_resources_script_name, :prefix_header_name, :xcconfig_name].map { |file| @target_definition.send(file) }
end 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) def configure_build_configurations(xcconfig_file, sandbox)
@target.build_configurations.each do |config| @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['OTHER_LDFLAGS'] = ''
config.build_settings['GCC_PREFIX_HEADER'] = @target_definition.prefix_header_name config.build_settings['GCC_PREFIX_HEADER'] = @target_definition.prefix_header_name
config.build_settings['PODS_ROOT'] = '${SRCROOT}' config.build_settings['PODS_ROOT'] = '${SRCROOT}'
...@@ -96,6 +134,8 @@ module Pod ...@@ -96,6 +134,8 @@ module Pod
end end
end end
#
#
def create_files(pods, sandbox) def create_files(pods, sandbox)
bridge_support_metadata_path = sandbox.root + @target_definition.bridge_support_name 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 UI.message "- Generating BridgeSupport metadata file at #{UI.path bridge_support_metadata_path}" do
...@@ -104,6 +144,7 @@ module Pod ...@@ -104,6 +144,7 @@ module Pod
end if @podfile.generate_bridge_support? end if @podfile.generate_bridge_support?
UI.message "- Generating xcconfig file at #{UI.path(sandbox.root + @target_definition.xcconfig_name)}" do 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) xcconfig.save_as(sandbox.root + @target_definition.xcconfig_name)
@target_definition.xcconfig = xcconfig @target_definition.xcconfig = xcconfig
end end
......
...@@ -137,20 +137,18 @@ module Pod ...@@ -137,20 +137,18 @@ module Pod
# Default to the first, which in a simple project is probably an app target. # Default to the first, which in a simple project is probably an app target.
[user_project.targets.first] [user_project.targets.first]
end.reject do |target| end.reject do |target|
# Reject any target that already has this Pods library in one of its frameworks build phases # Reject any target that already has this Pods library in one of its frameworks build phases
target.frameworks_build_phases.any? do |phase| target.frameworks_build_phase.files.any? { |build_file| build_file.file_ref.name == @target_definition.lib_name }
phase.files.any? { |file| file.name == @target_definition.lib_name }
end
end
end end
end
end end
def add_xcconfig_base_configuration 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| targets.each do |target|
config_build_names_by_overriden_key = {} config_build_names_by_overriden_key = {}
target.build_configurations.each do |config| target.build_configurations.each do |config|
config_name = config.attributes["name"] config_name = config.name
if @target_definition.xcconfig if @target_definition.xcconfig
@target_definition.xcconfig.attributes.each do |key, value| @target_definition.xcconfig.attributes.each do |key, value|
target_value = config.build_settings[key] target_value = config.build_settings[key]
...@@ -161,11 +159,11 @@ module Pod ...@@ -161,11 +159,11 @@ module Pod
end end
end end
config.base_configuration = xcconfig config.base_configuration_reference = xcconfig
end end
config_build_names_by_overriden_key.each do |key, config_build_names| 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." ] 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) UI.warn("The target `#{name}' overrides the `#{key}' build setting defined in `#{@target_definition.xcconfig_relative_path}'.", actions)
end end
...@@ -173,23 +171,20 @@ module Pod ...@@ -173,23 +171,20 @@ module Pod
end end
def add_pods_library def add_pods_library
group = user_project.group("Frameworks") || user_project.main_group frameworks = user_project.frameworks_group
pods_library = group.files.new_static_library(@target_definition.label) pods_library = frameworks.new_static_library(@target_definition.label)
targets.each do |target| 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
end end
def add_copy_resources_script_phase def add_copy_resources_script_phase
targets.each do |target| targets.each do |target|
phase = target.shell_script_build_phases.new phase = target.new_shell_script_build_phase('Copy Pods Resources')
phase.name = 'Copy Pods Resources'
phase.shell_script = %{"#{@target_definition.copy_resources_script_relative_path}"\n} phase.shell_script = %{"#{@target_definition.copy_resources_script_relative_path}"\n}
end end
end end
end end
end end
end end
end end
...@@ -166,11 +166,11 @@ module Pod ...@@ -166,11 +166,11 @@ module Pod
# @note The Paths are downcased to prevent issues. See #568. # @note The Paths are downcased to prevent issues. See #568.
# #
def clean_paths def clean_paths
used = used_files.map(&:downcase) cached_used_paths = used_files
files = Dir.glob(root + "**/*", File::FNM_DOTMATCH).map(&:downcase) files = Dir.glob(root + "**/*", File::FNM_DOTMATCH)
files.reject! do |candidate| 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) path.include?(candidate) || candidate.include?(path)
end end
end end
...@@ -386,7 +386,36 @@ module Pod ...@@ -386,7 +386,36 @@ module Pod
result result
end 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. # @return [void] Copies the pods headers to the sandbox.
# #
...@@ -403,26 +432,10 @@ module Pod ...@@ -403,26 +432,10 @@ module Pod
end end
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. # @return Whether the pod requires ARC.
# #
# TODO: this should be not used anymore.
#
def requires_arc? def requires_arc?
top_specification.requires_arc top_specification.requires_arc
end end
......
...@@ -12,9 +12,13 @@ end ...@@ -12,9 +12,13 @@ end
module Pod module Pod
class Project < Xcodeproj::Project class Project < Xcodeproj::Project
attr_reader :support_files_group
def initialize(*) def initialize(*)
super super
main_group << groups.new('name' => 'Pods') new_group('Pods')
@support_files_group = new_group('Targets Support Files')
@user_build_configurations = [] @user_build_configurations = []
end end
...@@ -24,39 +28,42 @@ module Pod ...@@ -24,39 +28,42 @@ module Pod
# any build settings themselves, that's left to `add_pod_target`. # any build settings themselves, that's left to `add_pod_target`.
user_build_configurations.each do |name, _| user_build_configurations.each do |name, _|
unless build_configurations.map(&:name).include?(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 end
end end
# Shortcut access to the `Pods' PBXGroup. # Shortcut access to the `Pods' PBXGroup.
def pods def pods
@pods ||= groups.where(:name => 'Pods') || groups.new('name' => 'Pods') @pods ||= self['Pods'] || new_group('Pods')
end end
# Shortcut access to the `Local Pods' PBXGroup. # Shortcut access to the `Local Pods' PBXGroup.
def local_pods 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 end
# Adds a group as child to the `Pods' group namespacing subspecs. # Adds a group as child to the `Pods' group namespacing subspecs.
def add_spec_group(name, parent_group) def add_spec_group(name, parent_group)
groups = parent_group.groups current_group = parent_group
group = nil group = nil
name.split('/').each do |name| name.split('/').each do |name|
group = groups.where(:name => name) || groups.new('name' => name) group = current_group[name] || current_group.new_group(name)
groups = group.groups current_group = group
end end
group group
end end
def add_pod_target(name, platform) def add_pod_target(name, platform)
target = targets.new_static_library(platform.name, name) target = new_target(:static_library, name, platform.name)
settings = {} settings = {}
if platform.requires_legacy_ios_archs? if platform.requires_legacy_ios_archs?
settings['ARCHS'] = "armv6 armv7" settings['ARCHS'] = "armv6 armv7"
end end
if platform == :ios && platform.deployment_target if platform == :ios && platform.deployment_target
settings['IPHONEOS_DEPLOYMENT_TARGET'] = platform.deployment_target.to_s settings['IPHONEOS_DEPLOYMENT_TARGET'] = platform.deployment_target.to_s
end end
...@@ -66,9 +73,11 @@ module Pod ...@@ -66,9 +73,11 @@ module Pod
@user_build_configurations.each do |name, type| @user_build_configurations.each do |name, type|
unless target.build_configurations.map(&:name).include?(name) 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. # 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
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