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