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