Class: PodBuilder::Podspec

Inherits:
Object
  • Object
show all
Defined in:
lib/pod_builder/podspec.rb

Class Method Summary collapse

Class Method Details

.generate(analyzer) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/pod_builder/podspec.rb', line 32

def self.generate(analyzer)  
  puts "Generating PodBuilder's local podspec".yellow
  
  buildable_items = Podfile.podfile_items_at(PodBuilder::basepath("Podfile")).sort_by { |x| x.name }
        
  podspec_items = podspec_items_from(buildable_items)

  platform = analyzer.result.targets.first.platform
  generate_podspec_from(podspec_items, platform)
end

.generate_podspec_from(podspec_items, platform) ⇒ Object



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
# File 'lib/pod_builder/podspec.rb', line 64

def self.generate_podspec_from(podspec_items, platform)
  podspecs = []
  podspec_items.each do |item|
    vendored_frameworks = item.vendored_frameworks.map { |x| vendored_framework_path(x) }.compact.uniq
    
    podspec = "  s.subspec '#{item.name.gsub("/", "_")}' do |p|\n"
    podspec += "    p.vendored_frameworks = '#{vendored_frameworks.join("','")}'\n"
    if item.frameworks.count > 0
      podspec += "    p.frameworks = '#{item.frameworks.join("', '")}'\n"
    end
    if item.libraries.count > 0
      podspec += "    p.libraries = '#{item.libraries.join("', '")}'\n"
    end
    if item.resources.count > 0
      podspec += "    p.resources = '#{item.resources.join("', '")}'\n"
    end
    if item.resources.count > 0
      podspec += "    p.exclude_files = '#{item.exclude_files.join("', '")}'\n"
    end
    if item.xcconfig.keys.count > 0
      podspec += "    p.xcconfig = #{item.xcconfig.to_s}\n"
    end

    podspec += "  end"
    
    podspecs.push(podspec)
  end
  
  cwd = File.dirname(File.expand_path(__FILE__))
  podspec_file = File.read("#{cwd}/templates/build_podspec.template")
  podspec_file.gsub!("%%%podspecs%%%", podspecs.join("\n\n"))
        
  podspec_file.sub!("%%%platform_name%%%", platform.name.to_s)
  podspec_file.sub!("%%%deployment_version%%%", platform.deployment_target.version)
  
  File.write(PodBuilder::basepath("PodBuilder.podspec"), podspec_file)
end

.include?(pod_name) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/pod_builder/podspec.rb', line 43

def self.include?(pod_name)
  podspec_path = PodBuilder::basepath("PodBuilder.podspec")
  unless File.exist?(podspec_path)
    return false
  end

  if Configuration.subspecs_to_split.include?(pod_name)
    pod_name = pod_name.gsub("/", "_")
  else
    pod_name = pod_name.split("/").first
  end

  podspec_content = File.read(podspec_path)

  # (_.*) will include prebuild podnames like s.subspec 'Podname_Subspec' do |p|
  subspec_regex = "s.subspec '#{pod_name}(_.*)?' do |p|" 
  return (podspec_content.match(/#{subspec_regex}/) != nil)
end

.podspec_items_from(buildable_items) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
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
153
154
155
# File 'lib/pod_builder/podspec.rb', line 102

def self.podspec_items_from(buildable_items)
  podspec_items = []

  buildable_items.each do |pod|
    spec_exists = File.exist?(PodBuilder::basepath(vendored_spec_framework_path(pod))) 
    subspec_exists = File.exist?(PodBuilder::basepath(vendored_subspec_framework_path(pod)))
    
    unless spec_exists || subspec_exists
      puts "Skipping #{pod.name}, not prebuilt".blue
      next
    end
    
    pod_name = Configuration.subspecs_to_split.include?(pod.name) ? pod.name : pod.root_name
    unless podspec_item = podspec_items.detect { |x| x.name == pod_name }
      podspec_item = PodspecItem.new
      podspec_items.push(podspec_item)
      podspec_item.name = pod_name
      podspec_item.module_name = pod.module_name
    end
    
    podspec_item.vendored_frameworks += [pod] + pod.dependencies(buildable_items)
    
    podspec_item.frameworks = podspec_item.vendored_frameworks.map { |x| x.frameworks }.flatten.uniq.sort
    podspec_item.weak_frameworks = podspec_item.vendored_frameworks.map { |x| x.weak_frameworks }.flatten.uniq.sort
    podspec_item.libraries = podspec_item.vendored_frameworks.map { |x| x.libraries }.flatten.uniq.sort
    
    static_vendored_frameworks = podspec_item.vendored_frameworks.select { |x| x.is_static }
    
    podspec_item.resources = static_vendored_frameworks.map { |x| "#{vendored_framework_path(x)}/*.{nib,bundle,xcasset,strings,png,jpg,tif,tiff,otf,ttf,ttc,plist,json,caf,wav,p12,momd}" }.flatten.uniq
    podspec_item.exclude_files = static_vendored_frameworks.map { |x| "#{vendored_framework_path(x)}/Info.plist" }.flatten.uniq

    # Merge xcconfigs
    if !pod.xcconfig.empty?
      pod.xcconfig.each do |k, v|
        unless v != "$(inherited)"
          next
        end
        unless k == "OTHER_LDFLAGS"
          next # For the time being limit to OTHER_LDFLAGS key
        end

        if podspec_values = podspec_item.xcconfig[k]
          podspec_values_arr = podspec_values.split(" ")
          podspec_values_arr.push(v)
          v = podspec_values_arr.join(" ")          
        end
        
        podspec_item.xcconfig[k] = v
      end
    end
  end

  return podspec_items
end

.vendored_framework_path(pod) ⇒ Object



157
158
159
160
161
162
163
164
165
# File 'lib/pod_builder/podspec.rb', line 157

def self.vendored_framework_path(pod)
  if File.exist?(PodBuilder::basepath(vendored_subspec_framework_path(pod)))
    return vendored_subspec_framework_path(pod)
  elsif File.exist?(PodBuilder::basepath(vendored_spec_framework_path(pod)))
    return vendored_spec_framework_path(pod)
  end
  
  return nil
end

.vendored_spec_framework_path(pod) ⇒ Object



171
172
173
# File 'lib/pod_builder/podspec.rb', line 171

def self.vendored_spec_framework_path(pod)
  return "Rome/#{pod.module_name}.framework"
end

.vendored_subspec_framework_path(pod) ⇒ Object



167
168
169
# File 'lib/pod_builder/podspec.rb', line 167

def self.vendored_subspec_framework_path(pod)
  return "Rome/#{pod.prebuilt_rel_path}"
end