Class: Pod::SpecBuilder
- Inherits:
-
Object
- Object
- Pod::SpecBuilder
- Defined in:
- lib/cocoapods-packagerthk/spec_builder.rb
Instance Method Summary collapse
- #framework_path ⇒ Object
-
#initialize(spec, source, embedded, dynamic, generate_spec) ⇒ SpecBuilder
constructor
A new instance of SpecBuilder.
- #spec_close ⇒ Object
- #spec_metadata ⇒ Object
- #spec_platform(platform) ⇒ Object
- #spec_sources_pattern(generate_spec) ⇒ Object
- #spec_sources_pattern_subpsec(subspec) ⇒ Object
Constructor Details
#initialize(spec, source, embedded, dynamic, generate_spec) ⇒ SpecBuilder
Returns a new instance of SpecBuilder.
3 4 5 6 7 8 9 10 |
# File 'lib/cocoapods-packagerthk/spec_builder.rb', line 3 def initialize(spec, source, , dynamic, generate_spec) @spec = spec @source = source.nil? ? '{ :path => \'.\' }' : source = @dynamic = dynamic @is_generate_spec = generate_spec @generate_spec = "" end |
Instance Method Details
#framework_path ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/cocoapods-packagerthk/spec_builder.rb', line 12 def framework_path if @spec.name + '.embeddedframework' + '/' + @spec.name + '.framework' else @spec.name + '.framework' end end |
#spec_close ⇒ Object
132 133 134 |
# File 'lib/cocoapods-packagerthk/spec_builder.rb', line 132 def spec_close "end\n" end |
#spec_metadata ⇒ Object
127 128 129 130 |
# File 'lib/cocoapods-packagerthk/spec_builder.rb', line 127 def spec = spec_header spec end |
#spec_platform(platform) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/cocoapods-packagerthk/spec_builder.rb', line 20 def spec_platform(platform) fwk_base = platform.name.to_s + '/' + framework_path spec = " s.\#{platform.name}.deployment_target = '\#{platform.deployment_target}'\n s.\#{platform.name}.vendored_framework = '\#{fwk_base}'\n" %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
41 42 43 44 45 46 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 |
# File 'lib/cocoapods-packagerthk/spec_builder.rb', line 41 def spec_sources_pattern(generate_spec) # 添加Source Pattern spec = "\n if ENV['IS_SOURCE'] || ENV[\"\\\#{s.name}_SOURCE\"]\ns.source = { :git => '\#{@spec.attributes_hash['source']['git']}', :commit => \"\#{@spec.attributes_hash['source']['commit']}\" }\n" %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 += " else\ns.source = { :git => '[email protected]:iosfeaturelibraries/frameworkrepo.git', :commit => 'xxx'}\ns.source_files = \"\\\#{s.name}-\\\#{s.version}/ios/\\\#{s.name}.framework/Headers/*.h\"\ns.public_header_files = \"\\\#{s.name}-\\\#{s.version}/ios/\\\#{s.name}.framework/Headers/*.h\"\ns.ios.vendored_framework = \"\\\#{s.name}-\\\#{s.version}/ios/\\\#{s.name}.framework\"\n end\n" # cur_work_dir = Dir::getwd # Dir.chdir('/Users/joe.cheng/cocoapods-debug') # File.open('debug' + '.podspec', 'w') { |file| file.write(spec) } # Dir.chdir(cur_work_dir) spec end |
#spec_sources_pattern_subpsec(subspec) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/cocoapods-packagerthk/spec_builder.rb', line 88 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" %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 |