-
Notifications
You must be signed in to change notification settings - Fork 351
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
289 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
module Pod | ||
class BuildType | ||
# @return [Array<Symbol>] known packaging options. | ||
# | ||
KNOWN_PACKAGING_OPTIONS = %i(library framework).freeze | ||
|
||
# @return [Array<Symbol>] known linking options. | ||
# | ||
KNOWN_LINKAGE_OPTIONS = %i(static dynamic).freeze | ||
|
||
# @return [Symbol] the packaging for this build type, one of #KNOWN_PACKAGING_OPTIONS | ||
# | ||
attr_reader :packaging | ||
|
||
# @return [Symbol] the linkage for this build type, one of #KNOWN_LINKAGE_OPTIONS | ||
# | ||
attr_reader :linkage | ||
|
||
attr_reader :hash | ||
|
||
def initialize(linkage: :static, packaging: :library) | ||
unless KNOWN_LINKAGE_OPTIONS.include?(linkage) | ||
raise ArgumentError, "Invalid linkage option #{linkage.inspect}, valid options are #{KNOWN_LINKAGE_OPTIONS.inspect}" | ||
end | ||
unless KNOWN_PACKAGING_OPTIONS.include?(packaging) | ||
raise ArgumentError, "Invalid packaging option #{packaging.inspect}, valid options are #{KNOWN_PACKAGING_OPTIONS.inspect}" | ||
end | ||
@packaging = packaging | ||
@linkage = linkage | ||
@hash = packaging.hash ^ linkage.hash | ||
end | ||
|
||
# @param [Specification] spec | ||
# the specification to infer the build type from | ||
# | ||
# @param [Boolean] host_build_type | ||
# the host target definition build type. | ||
# | ||
# @return [BuildType] the appropriate build type for the given spec, | ||
# also based on host target definition build type. | ||
# | ||
def self.infer_from_spec(spec, host_build_type: BuildType.static_library) | ||
if host_build_type.framework? | ||
root_spec = spec && spec.root | ||
if root_spec && root_spec.static_framework | ||
static_framework | ||
else | ||
host_build_type | ||
end | ||
else | ||
static_library | ||
end | ||
end | ||
|
||
# @return [BuildType] the build type for a dynamic library | ||
def self.dynamic_library | ||
new(:linkage => :dynamic, :packaging => :library) | ||
end | ||
|
||
# @return [BuildType] the build type for a static library | ||
# | ||
def self.static_library | ||
new(:linkage => :static, :packaging => :library) | ||
end | ||
|
||
# @return [BuildType] the build type for a dynamic framework | ||
# | ||
def self.dynamic_framework | ||
new(:linkage => :dynamic, :packaging => :framework) | ||
end | ||
|
||
# @return [BuildType] the build type for a static framework | ||
# | ||
def self.static_framework | ||
new(:linkage => :static, :packaging => :framework) | ||
end | ||
|
||
# @return [Boolean] whether the target is built dynamically | ||
# | ||
def dynamic? | ||
linkage == :dynamic | ||
end | ||
|
||
# @return [Boolean] whether the target is built statically | ||
# | ||
def static? | ||
linkage == :static | ||
end | ||
|
||
# @return [Boolean] whether the target is built as a framework | ||
# | ||
def framework? | ||
packaging == :framework | ||
end | ||
|
||
# @return [Boolean] whether the target is built as a library | ||
# | ||
def library? | ||
packaging == :library | ||
end | ||
|
||
# @return [Boolean] whether the target is built as a dynamic framework | ||
# | ||
def dynamic_framework? | ||
dynamic? && framework? | ||
end | ||
|
||
# @return [Boolean] whether the target is built as a dynamic library | ||
# | ||
def dynamic_library? | ||
dynamic? && library? | ||
end | ||
|
||
# @return [Boolean] whether the target is built as a static framework | ||
# | ||
def static_framework? | ||
static? && framework? | ||
end | ||
|
||
# @return [Boolean] whether the target is built as a static library | ||
# | ||
def static_library? | ||
static? && library? | ||
end | ||
|
||
def to_s | ||
"#{linkage} #{packaging}" | ||
end | ||
|
||
def to_hash | ||
{ :linkage => linkage, :packaging => packaging } | ||
end | ||
|
||
def inspect | ||
"#<#{self.class} linkage=#{linkage} packaging=#{packaging}>" | ||
end | ||
|
||
def ==(other) | ||
linkage == other.linkage && | ||
packaging == other.packaging | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
require File.expand_path('../spec_helper', __FILE__) | ||
|
||
module Pod | ||
describe BuildType do | ||
describe '#initialize' do | ||
it 'returns static library by default' do | ||
BuildType.new.should == BuildType.static_library | ||
end | ||
|
||
it 'allows specifying linkage' do | ||
BuildType.new(:linkage => :dynamic).should == BuildType.dynamic_library | ||
end | ||
|
||
it 'allows specifying packaging' do | ||
BuildType.new(:packaging => :framework).should == BuildType.static_framework | ||
end | ||
|
||
it 'raises when given an unknown linkage' do | ||
-> { BuildType.new(:linkage => :foo) }.should.raise(ArgumentError). | ||
message.should.include? 'Invalid linkage option :foo, valid options are [:static, :dynamic]' | ||
end | ||
end | ||
|
||
describe 'convenience factory methods' do | ||
it '#dynamic_library' do | ||
BuildType.dynamic_library.should == BuildType.new(:linkage => :dynamic, :packaging => :library) | ||
end | ||
|
||
it '#static_library' do | ||
BuildType.static_library.should == BuildType.new(:linkage => :static, :packaging => :library) | ||
end | ||
|
||
it '#dynamic_framework' do | ||
BuildType.dynamic_framework.should == BuildType.new(:linkage => :dynamic, :packaging => :framework) | ||
end | ||
|
||
it '#static_framework' do | ||
BuildType.static_framework.should == BuildType.new(:linkage => :static, :packaging => :framework) | ||
end | ||
end | ||
|
||
describe '.infer_from_spec' do | ||
it 'infers the build type' do | ||
BuildType.infer_from_spec(nil, :host_build_type => BuildType.static_library).should == BuildType.static_library | ||
BuildType.infer_from_spec(nil, :host_build_type => BuildType.dynamic_framework).should == BuildType.dynamic_framework | ||
|
||
BuildType.infer_from_spec(stub('spec', :root => stub('root_spec', :static_framework => true)), :host_build_type => BuildType.static_library). | ||
should == BuildType.static_library | ||
BuildType.infer_from_spec(stub('spec', :root => stub('root_spec', :static_framework => false)), :host_build_type => BuildType.static_library). | ||
should == BuildType.static_library | ||
BuildType.infer_from_spec(stub('spec', :root => stub('root_spec', :static_framework => true)), :host_build_type => BuildType.static_framework). | ||
should == BuildType.static_framework | ||
BuildType.infer_from_spec(stub('spec', :root => stub('root_spec', :static_framework => false)), :host_build_type => BuildType.dynamic_framework). | ||
should == BuildType.dynamic_framework | ||
end | ||
end | ||
|
||
describe '#==' do | ||
it 'compares equal build types as equal' do | ||
BuildType.new(:linkage => :dynamic, :packaging => :library).should == BuildType.new(:linkage => :dynamic, :packaging => :library) | ||
end | ||
|
||
it 'compares unequal build types as unequal' do | ||
BuildType.new(:linkage => :dynamic, :packaging => :framework).should != BuildType.new(:linkage => :dynamic, :packaging => :library) | ||
BuildType.new(:linkage => :static, :packaging => :library).should != BuildType.new(:linkage => :dynamic, :packaging => :library) | ||
end | ||
end | ||
|
||
describe '#to_s' do | ||
it 'returns a readable representation' do | ||
BuildType.static_framework.to_s.should == 'static framework' | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
installation_method: | ||
name: cocoapods | ||
sources: | ||
- https://cdn.cocoapods.org/ | ||
target_definitions: | ||
- abstract: true | ||
children: | ||
- children: | ||
- abstract: false | ||
inheritance: search_paths | ||
name: SampleAppTests | ||
name: SampleApp | ||
uses_frameworks: true | ||
name: Pods |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
installation_method: | ||
name: cocoapods | ||
sources: | ||
- https://cdn.cocoapods.org/ | ||
target_definitions: | ||
- abstract: true | ||
children: | ||
- children: | ||
- abstract: false | ||
inheritance: search_paths | ||
name: SampleAppTests | ||
name: SampleApp | ||
uses_frameworks: | ||
:linkage: :dynamic | ||
:packaging: :framework | ||
name: Pods |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters