Commit c31b4b76 authored by Marius Rackwitz's avatar Marius Rackwitz

Support framework as type for generated target

parent 18abf36f
......@@ -189,6 +189,7 @@ module Pod
user_project = Xcodeproj::Project.open(project_path)
native_targets = compute_user_project_targets(target_definition, user_project)
target.host_requires_framework |= compute_user_project_targets_require_framework(native_targets)
target.user_project_path = project_path
target.client_root = project_path.dirname
target.user_target_uuids = native_targets.map(&:uuid)
......@@ -211,6 +212,7 @@ module Pod
# Create a target for each spec group and add it to the aggregate target
grouped_specs.each do |pod_specs|
pod_target = PodTarget.new(pod_specs, target_definition, sandbox)
pod_target.host_requires_framework |= target.host_requires_framework
if config.integrate_targets?
pod_target.user_build_configurations = target.user_build_configurations
pod_target.archs = @archs_by_target_def[target_definition]
......@@ -518,6 +520,22 @@ module Pod
end
end
# Checks if any of the targets for the {TargetDefinition} computed before
# by #compute_user_project_targets require to be build as a framework due
# the presence of Swift source code in any of the source build phases.
#
# @param [Array<PBXNativeTarget>] native_targets
# the targets which are checked for presence of Swift source code
#
# @return [Boolean] Whether the user project targets to integrate into
# uses Swift
#
def compute_user_project_targets_require_framework(native_targets)
native_targets.any? do |target|
target.source_build_phase.files.any? { |f| f.file_ref.last_known_file_type == 'sourcecode.swift' }
end
end
# @return [Hash{String=>Symbol}] A hash representing the user build
# configurations where each key corresponds to the name of a
# configuration and its value to its type (`:debug` or `:release`).
......
......@@ -36,10 +36,11 @@ module Pod
# @return [void]
#
def add_target
product_type = target.requires_framework? ? :framework : :static_library
name = target.label
platform = target.platform.name
deployment_target = target.platform.deployment_target.to_s
@native_target = project.new_target(:static_library, name, platform, deployment_target)
@native_target = project.new_target(product_type, name, platform, deployment_target)
target.user_build_configurations.each do |bc_name, type|
configuration = @native_target.add_build_configuration(bc_name, type)
......
......@@ -15,6 +15,12 @@ module Pod
#
attr_reader :sandbox
# @return [Boolean] Whether the target needs to be implemented as a framework.
# Computed by analyzer.
#
attr_accessor :host_requires_framework
alias_method :host_requires_framework?, :host_requires_framework
# @return [String] the name of the library.
#
def name
......@@ -41,6 +47,20 @@ module Pod
#-------------------------------------------------------------------------#
# @return [Boolean] whether the generated target need to be implemented
# as a framework
#
# @note This applies either if Swift was used by the host, which was checked
# eagerly by the analyzer before, or in the given target or its
# dependents, which can only be checked after the specs were been
# fetched.
#
def requires_framework?
host_requires_framework? || uses_swift?
end
#-------------------------------------------------------------------------#
# @!group Information storage
# @return [Hash{String=>Symbol}] A hash representing the user build
......
......@@ -127,6 +127,26 @@ module Pod
it 'returns that it does not use swift' do
@target.uses_swift?.should == false
end
describe 'Host requires frameworks' do
before do
@target.host_requires_framework = true
end
it 'returns that it requires being built as framework' do
@target.requires_framework?.should == true
end
end
describe 'Host does not requires frameworks' do
it 'returns :static_library as product type' do
@target.product_type.should == :static_library
end
it 'returns that it does not require being built as framework' do
@target.requires_framework?.should == false
end
end
end
describe 'With frameworks' do
......@@ -139,6 +159,10 @@ module Pod
it 'returns that it uses swift' do
@target.uses_swift?.should == true
end
it 'returns that it requires being built as framework' do
@target.requires_framework?.should == true
end
end
end
end
......
......@@ -111,6 +111,22 @@ module Pod
it 'returns that it does not use swift' do
@pod_target.uses_swift?.should == false
end
describe 'Host requires frameworks' do
before do
@pod_target.host_requires_framework = true
end
it 'returns that it requires being built as framework' do
@pod_target.requires_framework?.should == true
end
end
describe 'Host does not requires frameworks' do
it 'returns that it does not require being built as framework' do
@pod_target.requires_framework?.should == false
end
end
end
describe 'With frameworks' do
......@@ -121,6 +137,10 @@ module Pod
it 'returns that it uses swift' do
@pod_target.uses_swift?.should == true
end
it 'returns that it requires being built as framework' do
@pod_target.requires_framework?.should == true
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