Commit a9d61576 authored by Fabio Pelosin's avatar Fabio Pelosin

[Target] Cleanup

* rename libraries to #pod_targets
* introduce support for multiple specs in the PodTarget
parent b87c2e82
......@@ -7,16 +7,16 @@ module Pod
#
class AbstractXCConfig
# @return [Target] the library or target represented by this xcconfig.
# @return [Target] the aggregate_target or target represented by this xcconfig.
#
attr_reader :library
attr_reader :aggregate_target
attr_reader :sandbox
# @param [Target] library @see library
# @param [Target] aggregate_target @see aggregate_target
#
def initialize(library)
@library = library
@sandbox = library.sandbox
def initialize(aggregate_target)
@aggregate_target = aggregate_target
@sandbox = aggregate_target.sandbox
end
# @return [Xcodeproj::Config] The generated xcconfig.
......@@ -79,7 +79,7 @@ module Pod
#
DEVELOPER_FRAMEWORKS_SEARCH_PATHS = [
'$(inherited)',
'"$(SDKROOT)/Developer/Library/Frameworks"',
'"$(SDKROOT)/Developer/aggregate_target/Frameworks"',
'"$(DEVELOPER_LIBRARY_DIR)/Frameworks"'
]
......@@ -127,7 +127,7 @@ module Pod
#
def generate
ld_flags = '-ObjC'
if library.target_definition.podfile.set_arc_compatibility_flag?
if aggregate_target.target_definition.podfile.set_arc_compatibility_flag?
ld_flags << ' -fobjc-arc'
end
......@@ -135,11 +135,11 @@ module Pod
'ALWAYS_SEARCH_USER_PATHS' => 'YES',
'OTHER_LDFLAGS' => ld_flags,
'HEADER_SEARCH_PATHS' => quote(sandbox.public_headers.search_paths),
'PODS_ROOT' => library.relative_pods_root,
'PODS_ROOT' => aggregate_target.relative_pods_root,
'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) COCOAPODS=1',
}
library.libraries.each do |lib|
aggregate_target.pod_targets.each do |lib|
consumer_xcconfig(lib.consumer).to_hash.each do |k, v|
prefixed_key = lib.xcconfig_prefix + k
config[k] = "#{config[k]} ${#{prefixed_key}}"
......@@ -147,7 +147,7 @@ module Pod
end
@xcconfig = Xcodeproj::Config.new(config)
@xcconfig.includes = library.libraries.map(&:name)
@xcconfig.includes = aggregate_target.pod_targets.map(&:name)
@xcconfig
end
......@@ -169,10 +169,10 @@ module Pod
# @return [void]
#
def save_as(path)
generate.save_as(path, library.xcconfig_prefix)
generate.save_as(path, aggregate_target.xcconfig_prefix)
end
# Generates the xcconfig for the library.
# Generates the xcconfig for the aggregate_target.
#
# @note The xcconfig file for a public spec target includes the
# standard podspec defined values including libraries,
......@@ -181,7 +181,7 @@ module Pod
# @return [Xcodeproj::Config]
#
def generate
@xcconfig = consumer_xcconfig(library.consumer)
@xcconfig = consumer_xcconfig(aggregate_target.consumer)
@xcconfig
end
......@@ -191,7 +191,7 @@ module Pod
class PrivateSpecXCConfig < AbstractXCConfig
# Generates the xcconfig for the library.
# Generates the xcconfig for the aggregate_target.
#
# @note The private xcconfig file for a spec target includes the public
# namespaced xcconfig file and merges the configuration values
......@@ -201,7 +201,7 @@ module Pod
#
def generate
ld_flags = '-ObjC'
if library.consumer.requires_arc?
if aggregate_target.consumer.requires_arc?
ld_flags << ' -fobjc-arc'
end
......@@ -209,18 +209,18 @@ module Pod
'ALWAYS_SEARCH_USER_PATHS' => 'YES',
'OTHER_LDFLAGS' => ld_flags,
'PODS_ROOT' => '${SRCROOT}',
'HEADER_SEARCH_PATHS' => quote(library.build_headers.search_paths) + ' ' + quote(sandbox.public_headers.search_paths),
'HEADER_SEARCH_PATHS' => quote(aggregate_target.build_headers.search_paths) + ' ' + quote(sandbox.public_headers.search_paths),
'GCC_PREPROCESSOR_DEFINITIONS' => 'COCOAPODS=1',
# 'USE_HEADERMAP' => 'NO'
}
consumer_xcconfig(library.consumer).to_hash.each do |k, v|
prefixed_key = library.xcconfig_prefix + k
consumer_xcconfig(aggregate_target.consumer).to_hash.each do |k, v|
prefixed_key = aggregate_target.xcconfig_prefix + k
config[k] = "#{config[k]} ${#{prefixed_key}}"
end
@xcconfig = Xcodeproj::Config.new(config)
@xcconfig.includes = [library.name]
@xcconfig.includes = [aggregate_target.name]
@xcconfig
end
......
......@@ -189,8 +189,8 @@ module Pod
#
def clean_sandbox
sandbox.public_headers.implode!
libraries.each do |library|
library.build_headers.implode!
pod_targets.each do |pod_target|
pod_target.build_headers.implode!
end
unless sandbox_state.deleted.empty?
......@@ -208,12 +208,12 @@ module Pod
#
def create_file_accessors
targets.each do |target|
target.libraries.each do |library|
pod_root = sandbox.pod_dir(library.spec.root.name)
target.pod_targets.each do |pod_target|
pod_root = sandbox.pod_dir(pod_target.specs.first.root.name)
path_list = Sandbox::PathList.new(pod_root)
file_accessor = Sandbox::FileAccessor.new(path_list, library.spec.consumer(library.platform))
library.file_accessors ||= []
library.file_accessors << file_accessor
file_accessor = Sandbox::FileAccessor.new(path_list, pod_target.specs.first.consumer(pod_target.platform))
pod_target.file_accessors ||= []
pod_target.file_accessors << file_accessor
end
end
end
......@@ -246,10 +246,10 @@ module Pod
#
def install_source_of_pod(pod_name)
specs_by_platform = {}
libraries.each do |library|
if library.spec && library.spec.root.name == pod_name
specs_by_platform[library.platform] ||= []
specs_by_platform[library.platform] << library.spec
libraries.each do |pod_target|
if pod_target.spec && pod_target.spec.root.name == pod_name
specs_by_platform[pod_target.platform] ||= []
specs_by_platform[pod_target.platform] << pod_target.spec
end
end
......@@ -303,20 +303,20 @@ module Pod
# @return [void]
#
def install_file_references
installer = FileReferencesInstaller.new(sandbox, libraries, pods_project)
installer = FileReferencesInstaller.new(sandbox, pod_targets, pods_project)
installer.install!
end
# Installs the library targets of the Pods projects and generates their
# Installs the library targets of the Pods projects and generates their
# support files.
#
# @return [void]
#
def install_libraries
UI.message"- Installing libraries" do
libraries.sort_by(&:name).each do |library|
next if library.target_definition.empty?
target_installer = PodTargetInstaller.new(sandbox, library)
pod_targets.sort_by(&:name).each do |pod_target|
next if pod_target.target_definition.empty?
target_installer = PodTargetInstaller.new(sandbox, pod_target)
target_installer.install!
end
......@@ -337,8 +337,8 @@ module Pod
targets.each do |target|
native_target = pods_project.targets.select { |t| t.name == target.name }.first
products = pods_project.products_group
target.libraries.each do |library|
product = products.files.select { |f| f.path == library.product_name }.first
target.pod_targets.each do |pod_target|
product = products.files.select { |f| f.path == pod_target.product_name }.first
native_target.frameworks_build_phase.add_file_reference(product)
end
end
......@@ -536,7 +536,7 @@ module Pod
# @return [PodRepresentation] The pod representation.
#
def pod_rep(pod)
all_file_accessors = libraries.map(&:file_accessors).flatten.compact
all_file_accessors = pod_targets.map(&:file_accessors).flatten.compact
file_accessors = all_file_accessors.select { |fa| fa.spec.root.name == pod }
Hooks::PodRepresentation.new(pod, file_accessors)
end
......@@ -550,7 +550,7 @@ module Pod
# @return [Array<LibraryRepresentation>]
#
def library_reps
@library_reps ||= libraries.map { |lib| library_rep(lib) }
@library_reps ||= pod_targets.map { |lib| library_rep(lib) }
end
# @return [Array<PodRepresentation>]
......@@ -567,14 +567,14 @@ module Pod
# @return [Array<Library>] The library.
#
def libraries_using_spec(spec)
libraries.select { |lib| lib.spec == spec }
pod_targets.select { |pod_target| pod_target.specs.include?(spec) }
end
# @return [Array<Library>] The libraries generated by the installation
# process.
#
def libraries
targets.map(&:libraries).flatten
def pod_targets
targets.map(&:pod_targets).flatten
end
#-------------------------------------------------------------------------#
......
......@@ -182,10 +182,11 @@ module Pod
target.user_build_configurations = {}
end
# TODO group the specs of each Pod
specs.each do |spec|
spec_target = PodTarget.new(spec, target_definition, sandbox)
spec_target.user_build_configurations = target.user_build_configurations
target.libraries << spec_target
pod_target = PodTarget.new([spec], target_definition, sandbox)
pod_target.user_build_configurations = target.user_build_configurations
target.pod_targets << pod_target
end
end
targets
......
......@@ -189,7 +189,7 @@ module Pod
def create_target_environment_header
path = library.target_environment_header_path
UI.message "- Generating target environment header at #{UI.path(path)}" do
generator = Generator::TargetEnvironmentHeader.new(library.libraries.map { |l| l.spec })
generator = Generator::TargetEnvironmentHeader.new(library.pod_targets.map { |l| l.specs }.flatten)
generator.save_as(path)
add_file_to_support_group(path)
end
......@@ -227,7 +227,7 @@ module Pod
def create_copy_resources_script
path = library.copy_resources_script_path
UI.message "- Generating copy resources script at #{UI.path(path)}" do
file_accessors = library.libraries.map(&:file_accessors).flatten
file_accessors = library.pod_targets.map(&:file_accessors).flatten
resources = file_accessors.map { |accessor| accessor.resources.flatten.map {|res| project.relativize(res)} }.flatten
resources << bridge_support_file if bridge_support_file
generator = Generator::CopyResourcesScript.new(resources, library.platform)
......@@ -245,7 +245,7 @@ module Pod
Generator::Acknowledgements.generators.each do |generator_class|
path = generator_class.path_from_basepath(basepath)
UI.message "- Generating acknowledgements at #{UI.path(path)}" do
file_accessors = library.libraries.map(&:file_accessors).flatten
file_accessors = library.pod_targets.map(&:file_accessors).flatten
generator = generator_class.new(file_accessors)
generator.save_as(path)
add_file_to_support_group(path)
......
module Pod
# The aggregate target is used to cluster the targets of the single Pods. The
# client targets will then depend on this one.
# Stores the information relative to the target used to cluster the targets
# of the single Pods. The client targets will then depend on this one.
#
class AggregateTarget < Target
......@@ -11,11 +11,11 @@ module Pod
def initialize(target_definition, sandbox)
@target_definition = target_definition
@sandbox = sandbox
@libraries = []
@pod_targets = []
@file_accessors = []
end
# @return [String] the label for the library.
# @return [String] the label for the target.
#
def label
target_definition.label.to_s
......@@ -28,7 +28,7 @@ module Pod
#
attr_accessor :client_root
# @return [Pathname] the path of the user project that this library will
# @return [Pathname] the path of the user project that this target will
# integrate as identified by the analyzer.
#
# @note The project instance is not stored to prevent editing different
......@@ -37,14 +37,14 @@ module Pod
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.
# integrated by this target 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
# @return [Xcodeproj::Config] The configuration file of the target.
#
# @note The configuration is generated by the {TargetInstaller} and
# used by {UserProjectIntegrator} to check for any overridden
......@@ -52,11 +52,11 @@ module Pod
#
attr_accessor :xcconfig
# @return [Array<PodTarget>] the dependencies for this target (or library).
# @return [Array<PodTarget>] The dependencies for this target.
#
attr_accessor :libraries
attr_accessor :pod_targets
# @return [Pathname] the absolute path of acknowledgements file.
# @return [Pathname] The absolute path of acknowledgements file.
#
# @note The acknowledgements generators add the extension according to
# the file type.
......@@ -65,7 +65,7 @@ module Pod
support_files_root + "#{label}-acknowledgements"
end
# @return [Pathname] the absolute path of the copy resources script.
# @return [Pathname] The absolute path of the copy resources script.
#
def copy_resources_script_path
support_files_root + "#{label}-resources.sh"
......@@ -78,14 +78,14 @@ module Pod
"${SRCROOT}/#{support_files_root.relative_path_from(client_root)}"
end
# @return [String] the path of the xcconfig file relative to the root of
# @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
# @return [String] The path of the copy resources script relative to the
# root of the user project.
#
def copy_resources_script_relative_path
......@@ -104,7 +104,7 @@ module Pod
# @param [Pathname] path
# A relative path from the root of the sandbox.
#
# @return [String] the computed path.
# @return [String] The computed path.
#
def relative_to_srcroot(path)
path.relative_path_from(client_root).to_s
......
module Pod
# This target is used to compile a single Pod. A pod can have one or more
# activated spec/subspecs.
# Stores the information relative to the target used to compile a single Pod.
# A pod can have one or more activated spec/subspecs.
#
class PodTarget < Target
# @return [Specification] the spec for the target.
#
attr_reader :spec
attr_reader :specs
# @return [HeadersStore] the header directory for the library.
# @return [HeadersStore] the header directory for the target.
#
attr_reader :build_headers
......@@ -17,36 +17,34 @@ module Pod
# @param [TargetDefinition] target_definition @see target_definition
# @param [Sandbox] sandbox @see sandbox
#
def initialize(spec, target_definition, sandbox)
@spec = spec
def initialize(specs, target_definition, sandbox)
@specs = specs
@target_definition = target_definition
@sandbox = sandbox
@build_headers = Sandbox::HeadersStore.new(sandbox, "BuildHeaders")
@file_accessors = []
end
# @return [String] the label for the library.
# @return [String] the label for the target.
#
def label
"#{target_definition.label.to_s}-#{spec.name.gsub('/', '-')}"
"#{target_definition.label.to_s}-#{root_spec.name}"
end
# @return [Specification] the specification for this library.
#
attr_accessor :spec
# @return [Array<Sandbox::FileAccessor>] the file accessors for the
# specifications of this library.
# specifications of this target.
#
attr_accessor :file_accessors
#-------------------------------------------------------------------------#
# @return [Specification::Consumer] the specification consumer for the
# library.
# target.
#
def consumer
spec.consumer(platform)
specs.first.root.consumer(platform)
end
def root_spec
specs.first.root
end
#-------------------------------------------------------------------------#
......
......@@ -4,6 +4,14 @@ module Pod
describe PodTarget do
xit "returns the label for the target" do
end
xit "returns the consumer of the spec" do
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