Commit 3d3ab979 authored by Fabio Pelosin's avatar Fabio Pelosin

[Target] Refactor file structure

parent 9b3de5a8
......@@ -44,8 +44,9 @@ module Pod
autoload :ExternalSources, 'cocoapods/external_sources'
autoload :Installer, 'cocoapods/installer'
autoload :SourcesManager, 'cocoapods/sources_manager'
autoload :PodTarget, 'cocoapods/target'
autoload :SpecTarget, 'cocoapods/target'
autoload :Target, 'cocoapods/target'
autoload :PodTarget, 'cocoapods/target/pod_target'
autoload :SpecTarget, 'cocoapods/target/spec_target'
autoload :Project, 'cocoapods/project'
autoload :Resolver, 'cocoapods/resolver'
autoload :Sandbox, 'cocoapods/sandbox'
......@@ -54,11 +55,11 @@ module Pod
module Generator
autoload :Acknowledgements, 'cocoapods/generator/acknowledgements'
autoload :Markdown, 'cocoapods/generator/acknowledgements/markdown'
autoload :Plist, 'cocoapods/generator/acknowledgements/plist'
autoload :BridgeSupport, 'cocoapods/generator/bridge_support'
autoload :CopyResourcesScript, 'cocoapods/generator/copy_resources_script'
autoload :DummySource, 'cocoapods/generator/dummy_source'
autoload :Markdown, 'cocoapods/generator/acknowledgements/markdown'
autoload :Plist, 'cocoapods/generator/acknowledgements/plist'
autoload :PrefixHeader, 'cocoapods/generator/prefix_header'
autoload :TargetEnvironmentHeader, 'cocoapods/generator/target_environment_header'
autoload :PodXCConfig, 'cocoapods/generator/xcconfig'
......
......@@ -6,7 +6,7 @@ module Pod
# working with a target in the Podfile and it's dependent libraries.
# This class is used to represent both the targets and their libraries.
#
class AbstractTarget
class Target
# @return [PBXNativeTarget] the target definition of the Podfile that
# generated this target.
......@@ -105,169 +105,7 @@ module Pod
support_files_root + "#{label}-dummy.m"
end
end
#---------------------------------------------------------------------------#
class PodTarget < AbstractTarget
# @param [TargetDefinition] target_definition @see target_definition
# @param [Sandbox] sandbox @see sandbox
#
def initialize(target_definition, sandbox)
@target_definition = target_definition
@sandbox = sandbox
@libraries = []
@file_accessors = []
end
# @return [String] the label for the library.
#
def label
target_definition.label.to_s
end
# @return [Pathname] the folder where the client is stored used for
# computing the relative paths. If integrating it should be the
# folder where the user project is stored, otherwise it should
# be the installation root.
#
attr_accessor :client_root
# @return [Pathname] the path of the user project that this library will
# integrate as identified by the analyzer.
#
# @note The project instance is not stored to prevent editing different
# instances.
#
attr_accessor :user_project_path
# @return [String] the list of the UUIDs of the user targets that will be
# integrated by this library as identified by the analizer.
#
# @note The target instances are not stored to prevent editing different
# instances.
#
attr_accessor :user_target_uuids
# @return [Xcodeproj::Config] the configuration file of the library
#
# @note The configuration is generated by the {TargetInstaller} and
# used by {UserProjectIntegrator} to check for any overridden
# values.
#
attr_accessor :xcconfig
# @return [Array<SpecTarget>] the dependencies for this target (or library).
#
attr_accessor :libraries
# @return [Pathname] the absolute path of acknowledgements file.
#
# @note The acknowledgements generators add the extension according to
# the file type.
#
def acknowledgements_basepath
support_files_root + "#{label}-acknowledgements"
end
# @return [Pathname] the absolute path of the copy resources script.
#
def copy_resources_script_path
support_files_root + "#{label}-resources.sh"
end
# @return [String] The xcconfig path of the root from the `$(SRCROOT)`
# variable of the user's project.
#
def relative_pods_root
"${SRCROOT}/#{support_files_root.relative_path_from(client_root)}"
end
# @return [String] the path of the xcconfig file relative to the root of
# the user project.
#
def xcconfig_relative_path
relative_to_srcroot(xcconfig_path).to_s
end
# @return [String] the path of the copy resources script relative to the
# root of the user project.
#
def copy_resources_script_relative_path
"${SRCROOT}/#{relative_to_srcroot(copy_resources_script_path)}"
end
#-------------------------------------------------------------------------#
# @!group Private Helpers
private
# Computes the relative path of a sandboxed file from the `$(SRCROOT)`
# variable of the user's project.
#
# @param [Pathname] path
# A relative path from the root of the sandbox.
#
# @return [String] the computed path.
#
def relative_to_srcroot(path)
path.relative_path_from(client_root).to_s
end
end
#---------------------------------------------------------------------------#
class SpecTarget < AbstractTarget
# @return [Specification] the spec for the target.
#
attr_reader :spec
# @return [HeadersStore] the header directory for the library.
#
attr_reader :build_headers
# @param [Specification] spec @see spec
# @param [TargetDefinition] target_definition @see target_definition
# @param [Sandbox] sandbox @see sandbox
#
def initialize(spec, target_definition, sandbox)
@spec = spec
@target_definition = target_definition
@sandbox = sandbox
@build_headers = Sandbox::HeadersStore.new(sandbox, "BuildHeaders")
@file_accessors = []
end
# @return [String] the label for the library.
#
def label
"#{target_definition.label.to_s}-#{spec.name.gsub('/', '-')}"
end
# @return [Specification] the specification for this library.
#
attr_accessor :spec
# @return [Array<Sandbox::FileAccessor>] the file accessors for the
# specifications of this library.
#
attr_accessor :file_accessors
#--------------------------------------#
# @return [Specification::Consumer] the specification consumer for the
# library.
#
def consumer
spec.consumer(platform)
end
end
#---------------------------------------------------------------------------#
end
module Pod
class PodTarget < Target
# @param [TargetDefinition] target_definition @see target_definition
# @param [Sandbox] sandbox @see sandbox
#
def initialize(target_definition, sandbox)
@target_definition = target_definition
@sandbox = sandbox
@libraries = []
@file_accessors = []
end
# @return [String] the label for the library.
#
def label
target_definition.label.to_s
end
# @return [Pathname] the folder where the client is stored used for
# computing the relative paths. If integrating it should be the
# folder where the user project is stored, otherwise it should
# be the installation root.
#
attr_accessor :client_root
# @return [Pathname] the path of the user project that this library will
# integrate as identified by the analyzer.
#
# @note The project instance is not stored to prevent editing different
# instances.
#
attr_accessor :user_project_path
# @return [String] the list of the UUIDs of the user targets that will be
# integrated by this library as identified by the analizer.
#
# @note The target instances are not stored to prevent editing different
# instances.
#
attr_accessor :user_target_uuids
# @return [Xcodeproj::Config] the configuration file of the library
#
# @note The configuration is generated by the {TargetInstaller} and
# used by {UserProjectIntegrator} to check for any overridden
# values.
#
attr_accessor :xcconfig
# @return [Array<SpecTarget>] the dependencies for this target (or library).
#
attr_accessor :libraries
# @return [Pathname] the absolute path of acknowledgements file.
#
# @note The acknowledgements generators add the extension according to
# the file type.
#
def acknowledgements_basepath
support_files_root + "#{label}-acknowledgements"
end
# @return [Pathname] the absolute path of the copy resources script.
#
def copy_resources_script_path
support_files_root + "#{label}-resources.sh"
end
# @return [String] The xcconfig path of the root from the `$(SRCROOT)`
# variable of the user's project.
#
def relative_pods_root
"${SRCROOT}/#{support_files_root.relative_path_from(client_root)}"
end
# @return [String] the path of the xcconfig file relative to the root of
# the user project.
#
def xcconfig_relative_path
relative_to_srcroot(xcconfig_path).to_s
end
# @return [String] the path of the copy resources script relative to the
# root of the user project.
#
def copy_resources_script_relative_path
"${SRCROOT}/#{relative_to_srcroot(copy_resources_script_path)}"
end
#-------------------------------------------------------------------------#
# @!group Private Helpers
private
# Computes the relative path of a sandboxed file from the `$(SRCROOT)`
# variable of the user's project.
#
# @param [Pathname] path
# A relative path from the root of the sandbox.
#
# @return [String] the computed path.
#
def relative_to_srcroot(path)
path.relative_path_from(client_root).to_s
end
#-------------------------------------------------------------------------#
end
end
module Pod
class SpecTarget < Target
# @return [Specification] the spec for the target.
#
attr_reader :spec
# @return [HeadersStore] the header directory for the library.
#
attr_reader :build_headers
# @param [Specification] spec @see spec
# @param [TargetDefinition] target_definition @see target_definition
# @param [Sandbox] sandbox @see sandbox
#
def initialize(spec, target_definition, sandbox)
@spec = spec
@target_definition = target_definition
@sandbox = sandbox
@build_headers = Sandbox::HeadersStore.new(sandbox, "BuildHeaders")
@file_accessors = []
end
# @return [String] the label for the library.
#
def label
"#{target_definition.label.to_s}-#{spec.name.gsub('/', '-')}"
end
# @return [Specification] the specification for this library.
#
attr_accessor :spec
# @return [Array<Sandbox::FileAccessor>] the file accessors for the
# specifications of this library.
#
attr_accessor :file_accessors
#-------------------------------------------------------------------------#
# @return [Specification::Consumer] the specification consumer for the
# library.
#
def consumer
spec.consumer(platform)
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