Class: Pod::SpecficationBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods-packageall/command/spec_builder.rb

Instance Method Summary collapse

Constructor Details

#initialize(spec, source, embedded, dynamic, generate_spec) ⇒ SpecficationBuilder

Returns a new instance of SpecficationBuilder.



3
4
5
6
7
8
9
10
# File 'lib/cocoapods-packageall/command/spec_builder.rb', line 3

def initialize(spec, source, embedded, dynamic, generate_spec)
  @spec = spec
  @source = source.nil? ? '{ :path => \'.\' }' : source
  @embedded = embedded
  @dynamic = dynamic
  @is_generate_spec = generate_spec
  @generate_spec = ""
end

Instance Method Details

#framework_pathObject



18
19
20
21
22
23
24
# File 'lib/cocoapods-packageall/command/spec_builder.rb', line 18

def framework_path
  if @embedded
    @spec.name + '.embeddedframework' + '/' + @spec.name + '.framework'
  else
    @spec.name + '.framework'
  end
end

#set_has_resource(has) ⇒ Object



12
13
14
15
16
# File 'lib/cocoapods-packageall/command/spec_builder.rb', line 12

def set_has_resource(has)
  if has
    @has_resource = true
  end
end

#spec_closeObject



159
160
161
# File 'lib/cocoapods-packageall/command/spec_builder.rb', line 159

def spec_close
  "end\n"
end

#spec_metadataObject



154
155
156
157
# File 'lib/cocoapods-packageall/command/spec_builder.rb', line 154

def 
  spec = spec_header
  spec
end

#spec_platform(platform) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/cocoapods-packageall/command/spec_builder.rb', line 26

def spec_platform(platform)
  fwk_base = platform.name.to_s + '/' + framework_path
  spec = <<RB
  s.#{platform.name}.deployment_target    = '#{platform.deployment_target}'
  s.#{platform.name}.vendored_framework   = '#{fwk_base}'
RB

  %w(frameworks weak_frameworks libraries requires_arc xcconfig).each do |attribute|
    attributes_hash = @spec.attributes_hash[platform.name.to_s]
    next if attributes_hash.nil?
    value = attributes_hash[attribute]
    next if value.nil?

    value = "'#{value}'" if value.class == String
    spec += "  s.#{platform.name}.#{attribute} = #{value}\n"
  end
  spec

  
end

#spec_sources_pattern(generate_spec) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/cocoapods-packageall/command/spec_builder.rb', line 47

def spec_sources_pattern(generate_spec)
  # 添加Source Pattern
  spec = <<RB
  if ENV['IS_SOURCE'] || ENV["\#{s.name}_SOURCE"]
RB
  
  set_has_resource(@spec.attributes_hash['resource_bundles'])
  if @spec.attributes_hash['source']['tag']
    spec += <<RB
s.source           = { :git => '#{@spec.attributes_hash['source']['git']}', :tag => "#{@spec.attributes_hash['source']['tag']}" }
RB
  elsif @spec.attributes_hash['source']['commit']
    spec += <<RB
s.source           = { :git => '#{@spec.attributes_hash['source']['git']}', :commit => "#{@spec.attributes_hash['source']['commit']}" }
RB
  else
    spec += <<RB
s.source           = { :git => '#{@spec.attributes_hash['source']}'}
RB
  end


    %w(source_files public_header_files resources frameworks resource_bundles dependencies).each do |attribute|
    value = @spec.attributes_hash[attribute]
    next if value.nil?
      if attribute == 'dependencies'
        value.each { |key,hashvalue|
        if hashvalue.empty?
          spec += "    s.dependency \'#{key}\'\n"
        else
          spec += "    s.dependency \'#{key}\', \'#{hashvalue[0]}\'\n"
        end
        }
      else
          value = value.dump if value.class == String
          spec += "    s.#{attribute} = #{value}\n"
      end
    end
    #添加subspec (递归添加)
    @generate_spec = spec
    @spec.subspecs.each do |subspec|
      spec_sources_pattern_subpsec(subspec)
    end
    spec = @generate_spec

  # 添加Framwork Pattern
  spec += <<RB
  else
s.source           = { :git => '[email protected]:iosfeaturelibraries/frameworkrepo.git', :commit => '6fd6924'}
s.ios.deployment_target    = '9.0'
s.ios.vendored_framework   = '#{@spec.name}-#{@spec.version.to_s}/ios/#{@spec.name}.framework'
RB
if @has_resource
  spec += <<RB
s.resources = ["#{@spec.name}-#{@spec.version.to_s}/ios/#{@spec.name}.framework/Resources/*.bundle"]
RB
end

spec += <<RB
  end
RB


  spec
end

#spec_sources_pattern_subpsec(subspec) ⇒ Object



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/cocoapods-packageall/command/spec_builder.rb', line 113

def spec_sources_pattern_subpsec(subspec)
    name = subspec.attributes_hash['name']
    level = subspec.name.split('/').count
    curSpec = "s" * (level - 1)
    space = "  " * (level - 2)
    nextSpec = curSpec + "s"
    @generate_spec += space
    @generate_spec += "    #{curSpec}.subspec \'#{name}\' do |#{nextSpec}|\n"
    
    set_has_resource(subspec.attributes_hash['resource_bundles'])

    %w(source_files public_header_files resources frameworks resource_bundles dependencies).each do |attribute|
      value = subspec.attributes_hash[attribute]
      next if value.nil?
      @generate_spec += space
      if attribute == 'dependencies'
        value.each { |key,hashvalue|
        if hashvalue.empty?
          @generate_spec += "      #{nextSpec}.dependency \'#{key}\'\n"
        else
          @generate_spec += "      #{nextSpec}.dependency \'#{key}\', \'#{hashvalue[0]}\'\n"
        end
        }
      else
        value = value.dump if value.class == String
        @generate_spec += "      #{nextSpec}.#{attribute} = #{value}\n"
      end
    end

    if subspec.subspecs.empty?
      @generate_spec += space
      @generate_spec += "    end\n"
    else
      #添加subspec
      subspec.subspecs.each do |subsubspec|
        spec_sources_pattern_subpsec(subsubspec)
      end
      @generate_spec += "    end\n"
    end
end