Commit 1d51f821 authored by Jeremy Slater's avatar Jeremy Slater

Add per-spec static library targets

Static library targets are created for each combination of user-target
and spec dependency.  This addresses issue #841, although likely not 
entirely.
parent 358b4d85
......@@ -6,6 +6,10 @@ module Pod
#
class XCConfig
# @return [Library] the library represented by this xcconfig.
#
attr_reader :library
# @return [Sandbox] the sandbox where the Pods project is installed.
#
attr_reader :sandbox
......@@ -24,7 +28,8 @@ module Pod
# @param [Array<LocalPod>] pods @see pods
# @param [String] relative_pods_root @see relative_pods_root
#
def initialize(sandbox, spec_consumers, relative_pods_root)
def initialize(library, sandbox, spec_consumers, relative_pods_root)
@library = library
@sandbox = sandbox
@spec_consumers = spec_consumers
@relative_pods_root = relative_pods_root
......@@ -56,7 +61,7 @@ module Pod
'HEADER_SEARCH_PATHS' => '${PODS_HEADERS_SEARCH_PATHS}',
'PODS_ROOT' => relative_pods_root,
'PODS_HEADERS_SEARCH_PATHS' => '${PODS_PUBLIC_HEADERS_SEARCH_PATHS}',
'PODS_BUILD_HEADERS_SEARCH_PATHS' => quote(sandbox.build_headers.search_paths),
'PODS_BUILD_HEADERS_SEARCH_PATHS' => quote(library.build_headers.search_paths),
'PODS_PUBLIC_HEADERS_SEARCH_PATHS' => quote(sandbox.public_headers.search_paths),
'GCC_PREPROCESSOR_DEFINITIONS' => 'COCOAPODS=1'
})
......@@ -77,7 +82,8 @@ module Pod
#
def self.pods_project_settings
{ 'PODS_ROOT' => '${SRCROOT}',
'PODS_HEADERS_SEARCH_PATHS' => '${PODS_BUILD_HEADERS_SEARCH_PATHS}' }
'PODS_HEADERS_SEARCH_PATHS' => '${PODS_BUILD_HEADERS_SEARCH_PATHS} ${PODS_PUBLIC_HEADERS_SEARCH_PATHS}',
'USE_HEADERMAP' => 'NO' }
end
# Generates and saves the xcconfig to the given path.
......
......@@ -51,10 +51,11 @@ module Pod
@result.podfile_state = generate_podfile_state
@locked_dependencies = generate_version_locking_dependencies
@result.libraries = generated_libraries
compute_target_platforms
fetch_external_sources if allow_fetches
@result.specs_by_target = resolve_dependencies
@result.specifications = generate_specifications
@result.libraries = generated_libraries
@result.sandbox_state = generate_sandbox_state
@result
end
......@@ -158,42 +159,41 @@ module Pod
# Creates the models that represent the libraries generated by CocoaPods.
#
# @note The libraries are generated before the resolution process
# because it might be necessary to infer the platform from the
# user targets, which in turns requires to identify the user
# project.
#
# @note The specification of the libraries are added in the
# {#resolve_dependencies} step.
#
# @return [Array<Libraries>] the generated libraries.
#
def generated_libraries
libraries = []
podfile.target_definition_list.each do |target_definition|
lib = Library.new(target_definition)
lib.support_files_root = sandbox.library_support_files_dir(lib.name)
if config.integrate_targets?
project_path = compute_user_project_path(target_definition)
user_project = Xcodeproj::Project.new(project_path)
targets = compute_user_project_targets(target_definition, user_project)
result.specs_by_target.each do |target_definition, specs|
specs.each do |spec|
lib_target = Podfile::TargetDefinition.from_hash(target_definition.to_hash, target_definition.parent)
if target_definition.name == 'Pods'
lib_target.name = spec.name.gsub('/', '-')
else
lib_target.name = "#{target_definition.name}-#{spec.name.gsub('/', '-')}"
end
lib.user_project_path = project_path
lib.client_root = project_path.dirname
lib.user_target_uuids = targets.map(&:uuid)
lib.user_build_configurations = compute_user_build_configurations(target_definition, targets)
lib.platform = compute_platform_for_target_definition(target_definition, targets)
else
unless target_definition.platform
raise Informative, "It is necessary to specify the platform in the Podfile if not integrating."
lib = Library.new(lib_target, sandbox)
lib.support_files_root = sandbox.library_support_files_dir(lib.name)
if config.integrate_targets?
project_path = compute_user_project_path(target_definition)
user_project = Xcodeproj::Project.new(project_path)
targets = compute_user_project_targets(target_definition, user_project)
lib.user_project_path = project_path
lib.client_root = project_path.dirname
lib.user_target_uuids = targets.map(&:uuid)
lib.user_build_configurations = compute_user_build_configurations(lib_target, targets)
lib.platform = lib_target.platform
lib.specs = [spec]
else
lib.client_root = config.installation_root
lib.user_target_uuids = []
lib.user_build_configurations = {}
lib.platform = lib_target.platform
end
lib.client_root = config.installation_root
lib.user_target_uuids = []
lib.user_build_configurations = {}
lib.platform = target_definition.platform
libraries << lib
end
libraries << lib
end
libraries
end
......@@ -263,8 +263,6 @@ module Pod
# Converts the Podfile in a list of specifications grouped by target.
#
# @note In this step the specs are added to the libraries.
#
# @note As some dependencies might have external sources the resolver
# is aware of the {Sandbox} and interacts with it to download the
# podspecs of the external sources. This is necessary because the
......@@ -284,17 +282,10 @@ module Pod
#
def resolve_dependencies
specs_by_target = nil
UI.section "Resolving dependencies of #{UI.path podfile.defined_in_file}" do
resolver = Resolver.new(sandbox, podfile, locked_dependencies)
specs_by_target = resolver.resolve
end
specs_by_target.each do |target_definition, specs|
lib = result.libraries.find { |l| l.target_definition == target_definition}
lib.specs = specs
end
specs_by_target
end
......@@ -449,6 +440,29 @@ module Pod
Platform.new(name, deployment_target)
end
# Precompute the platforms for each target_definition in the Podfile
#
# @note The platforms are computed and added to each target_definition
# because it might be necessary to infer the platform from the
# user targets.
#
# @return [void]
#
def compute_target_platforms
podfile.target_definition_list.each do |target_definition|
if config.integrate_targets?
project_path = compute_user_project_path(target_definition)
user_project = Xcodeproj::Project.new(project_path)
targets = compute_user_project_targets(target_definition, user_project)
platform = compute_platform_for_target_definition(target_definition, targets)
else
unless target_definition.platform
raise Informative, "It is necessary to specify the platform in the Podfile if not integrating."
end
end
end
end
#-----------------------------------------------------------------------#
class AnalysisResult
......
......@@ -121,6 +121,17 @@ module Pod
sandbox.public_headers.add_files(namespaced_path, files)
end
end
libraries.each do |library|
library.file_accessors.each do |file_accessor|
headers_sandbox = Pathname.new(file_accessor.spec.root.name)
library.build_headers.add_search_path(headers_sandbox)
header_mappings(headers_sandbox, file_accessor, file_accessor.headers).each do |namespaced_path, files|
sandbox.build_headers.add_files(namespaced_path, files)
end
end
end
end
end
......
......@@ -140,7 +140,7 @@ module Pod
def create_xcconfig_file
path = library.xcconfig_path
UI.message "- Generating xcconfig file at #{UI.path(path)}" do
gen = Generator::XCConfig.new(sandbox, spec_consumers, library.relative_pods_root)
gen = Generator::XCConfig.new(library, sandbox, spec_consumers, library.relative_pods_root)
gen.set_arc_compatibility_flag = target_definition.podfile.set_arc_compatibility_flag?
gen.save_as(path)
library.xcconfig = gen.xcconfig
......
......@@ -13,11 +13,16 @@ module Pod
#
attr_reader :target_definition
# @return [HeadersStore] the header directory for the Pods libraries.
#
attr_reader :build_headers
# @param [TargetDefinition] target_definition @see target_definition
# @param [PBXNativeTarget] target @see target
#
def initialize(target_definition)
def initialize(target_definition, sandbox)
@target_definition = target_definition
@build_headers = Sandbox::HeadersStore.new(sandbox, "BuildHeaders")
end
# @return [String] the label for the library.
......
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