Class: PodBuilder::PodfileItem

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(spec, all_specs, checkout_options) ⇒ PodfileItem

Initialize a new instance

Parameters:

  • spec (Specification)
  • checkout_options (Hash)


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
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/podfile_item.rb', line 95

def initialize(spec, all_specs, checkout_options)
  if overrides = Configuration.spec_overrides[spec.name]
    overrides.each do |k, v|
      spec.root.attributes_hash[k] = v
      if checkout_options.has_key?(spec.name)
        checkout_options[spec.name][k] = v
      end
    end
  end

  @name = spec.name
  @root_name = spec.name.split("/").first

  checkout_options_keys = [@root_name, @name]

  if opts_key = checkout_options_keys.detect { |x| checkout_options.has_key?(x) }
    @repo = checkout_options[opts_key][:git]
    @tag = checkout_options[opts_key][:tag]
    @commit = checkout_options[opts_key][:commit]
    @path = checkout_options[opts_key][:path]
    @branch = checkout_options[opts_key][:branch]
    @is_external = true
  else
    @repo = spec.root.source[:git]
    @tag = spec.root.source[:tag]
    @commit = spec.root.source[:commit]
    @is_external = false
  end    

  @vendored_items = recursive_vendored_items(spec, all_specs)

  @frameworks = []
  @weak_frameworks = []
  @libraries = []
  spec_and_dependencies(spec, all_specs).each do |spec|
    @frameworks += extract_array(spec, "framework")
    @frameworks += extract_array(spec, "frameworks")
    
    @weak_frameworks += extract_array(spec, "weak_framework")
    @weak_frameworks += extract_array(spec, "weak_frameworks")  

    @libraries += extract_array(spec, "library")
    @libraries += extract_array(spec, "libraries")  
  end

  @version = spec.root.version.version
  @available_versions = spec.respond_to?(:spec_source) ? spec.spec_source.versions(@root_name)&.map(&:to_s) : [@version]
  
  @swift_version = spec.root.swift_version&.to_s
  @module_name = spec.root.module_name

  @dependency_names = spec.recursive_dep_names(all_specs)

  @is_static = spec.root.attributes_hash["static_framework"] || false
  @xcconfig = spec.root.attributes_hash["xcconfig"] || {}

  @source_files = source_files_from(spec)
  
  @build_configuration = spec.root.attributes_hash.dig("pod_target_xcconfig", "prebuild_configuration") || "release"
  @build_configuration.downcase!
end

Instance Attribute Details

#available_versionsObject (readonly)

Returns the value of attribute available_versions.



31
32
33
# File 'lib/pod_builder/podfile_item.rb', line 31

def available_versions
  @available_versions
end

#branchString (readonly)

Returns The git branch.

Returns:



11
12
13
# File 'lib/pod_builder/podfile_item.rb', line 11

def branch
  @branch
end

#build_configurationString

Returns The pod’s build configuration.

Returns:

  • (String)

    The pod’s build configuration



67
68
69
# File 'lib/pod_builder/podfile_item.rb', line 67

def build_configuration
  @build_configuration
end

#commitString (readonly)

Returns The pinned commit of the pod, if any.

Returns:

  • (String)

    The pinned commit of the pod, if any



39
40
41
# File 'lib/pod_builder/podfile_item.rb', line 39

def commit
  @commit
end

#dependency_namesArray<String> (readonly)

Returns The pod’s dependency names, if any. Use dependencies() to get the [Array<PodfileItem>].

Returns:

  • (Array<String>)

    The pod’s dependency names, if any. Use dependencies() to get the [Array<PodfileItem>]



51
52
53
# File 'lib/pod_builder/podfile_item.rb', line 51

def dependency_names
  @dependency_names
end

#frameworksString

Returns Framweworks the pod needs to link to.

Returns:

  • (String)

    Framweworks the pod needs to link to



75
76
77
# File 'lib/pod_builder/podfile_item.rb', line 75

def frameworks
  @frameworks
end

#is_externalBool

Returns Is external pod.

Returns:

  • (Bool)

    Is external pod



63
64
65
# File 'lib/pod_builder/podfile_item.rb', line 63

def is_external
  @is_external
end

#is_staticBool (readonly)

Returns True if the pod is shipped as a static framework.

Returns:

  • (Bool)

    True if the pod is shipped as a static framework



55
56
57
# File 'lib/pod_builder/podfile_item.rb', line 55

def is_static
  @is_static
end

#librariesString

Returns Libraries the pod needs to link to.

Returns:

  • (String)

    Libraries the pod needs to link to



83
84
85
# File 'lib/pod_builder/podfile_item.rb', line 83

def libraries
  @libraries
end

#module_nameString (readonly)

Returns The module name.

Returns:

  • (String)

    The module name



43
44
45
# File 'lib/pod_builder/podfile_item.rb', line 43

def module_name
  @module_name
end

#nameString (readonly)

Returns The name of the pod, which might be the subspec name if appicable.

Returns:

  • (String)

    The name of the pod, which might be the subspec name if appicable



19
20
21
# File 'lib/pod_builder/podfile_item.rb', line 19

def name
  @name
end

#pathString

Returns Local path, if any.

Returns:

  • (String)

    Local path, if any



35
36
37
# File 'lib/pod_builder/podfile_item.rb', line 35

def path
  @path
end

#repoString (readonly)

Returns The git repo.

Returns:



7
8
9
# File 'lib/pod_builder/podfile_item.rb', line 7

def repo
  @repo
end

#root_nameString (readonly)

Returns Matches @name unless for subspecs were it stores the name of the root pod.

Returns:

  • (String)

    Matches @name unless for subspecs were it stores the name of the root pod



15
16
17
# File 'lib/pod_builder/podfile_item.rb', line 15

def root_name
  @root_name
end

#source_filesString

Returns source_files.

Returns:



87
88
89
# File 'lib/pod_builder/podfile_item.rb', line 87

def source_files
  @source_files
end

#swift_versionString (readonly)

Returns The swift version if applicable.

Returns:

  • (String)

    The swift version if applicable



47
48
49
# File 'lib/pod_builder/podfile_item.rb', line 47

def swift_version
  @swift_version
end

#tagString (readonly)

Returns The pinned tag of the pod, if any.

Returns:

  • (String)

    The pinned tag of the pod, if any



23
24
25
# File 'lib/pod_builder/podfile_item.rb', line 23

def tag
  @tag
end

#vendored_itemsString

Returns The pod’s vendored items (frameworks and libraries).

Returns:

  • (String)

    The pod’s vendored items (frameworks and libraries)



71
72
73
# File 'lib/pod_builder/podfile_item.rb', line 71

def vendored_items
  @vendored_items
end

#versionString (readonly)

Returns The pinned version of the pod, if any.

Returns:

  • (String)

    The pinned version of the pod, if any



27
28
29
# File 'lib/pod_builder/podfile_item.rb', line 27

def version
  @version
end

#weak_frameworksString

Returns Weak framweworks the pod needs to link to.

Returns:

  • (String)

    Weak framweworks the pod needs to link to



79
80
81
# File 'lib/pod_builder/podfile_item.rb', line 79

def weak_frameworks
  @weak_frameworks
end

#xcconfigArray<Hash> (readonly)

Returns The pod’s xcconfig configuration.

Returns:

  • (Array<Hash>)

    The pod’s xcconfig configuration



59
60
61
# File 'lib/pod_builder/podfile_item.rb', line 59

def xcconfig
  @xcconfig
end

Instance Method Details

#dependencies(available_pods) ⇒ Object



203
204
205
# File 'lib/pod_builder/podfile_item.rb', line 203

def dependencies(available_pods)
  return available_pods.select { |x| @dependency_names.include?(x.name) }
end

#entry(include_version = true, include_pb_entry = true) ⇒ String

Returns The podfile entry.

Returns:

  • (String)

    The podfile entry



236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
# File 'lib/pod_builder/podfile_item.rb', line 236

def entry(include_version = true, include_pb_entry = true)
  e = "pod '#{@name}'"

  unless include_version
    return e
  end

  if is_external
    if @path
      e += ", :path => '#{@path}'"  
    else
      if @repo
        e += ", :git => '#{@repo}'"  
      end
      if @tag
        e += ", :tag => '#{@tag}'"
      end
      if @commit
        e += ", :commit => '#{@commit}'"  
      end
      if @branch
        e += ", :branch => '#{@branch}'"  
      end
    end
  else
    e += ", '=#{@version}'"  
  end

  if include_pb_entry && !is_prebuilt
    plists = Dir.glob(PodBuilder::basepath("Rome/**/#{module_name}.framework/#{Configuration::framework_plist_filename}"))
    if plists.count > 0
      plist = CFPropertyList::List.new(:file => plists.first)
      data = CFPropertyList.native_types(plist.value)
      swift_version = data["swift_version"]
      is_static = data["is_static"] || false
    
      e += " # pb<#{name}> is<#{is_static}>"
      if swift_version
        e += " sv<#{swift_version}>"
      end
    else
      e += " # pb<#{name}>"
    end
  end

  return e
end

#git_hard_checkoutObject



324
325
326
327
328
329
330
331
332
333
334
335
336
337
# File 'lib/pod_builder/podfile_item.rb', line 324

def git_hard_checkout
  prefix = "git fetch --all --tags --prune; git reset --hard"
  if @tag
    return "#{prefix} tags/#{@tag}"
  end
  if @commit
    return "#{prefix} #{@commit}"
  end
  if @branch
    return "#{prefix} origin/#{@branch}"
  end

  return nil
end

#has_common_spec(named) ⇒ Object



320
321
322
# File 'lib/pod_builder/podfile_item.rb', line 320

def has_common_spec(named)
  return root_name == named.split("/").first
end

#has_subspec(named) ⇒ Object



312
313
314
315
316
317
318
# File 'lib/pod_builder/podfile_item.rb', line 312

def has_subspec(named)
  unless !is_subspec
    return false
  end

  return named.split("/").first == name
end

#inspectObject



195
196
197
# File 'lib/pod_builder/podfile_item.rb', line 195

def inspect
  return "#{@name} repo=#{@repo} pinned=#{@tag || @commit} is_static=#{@is_static} deps=#{@dependencies || "[]"}"
end

#is_prebuiltBool

Returns True if it’s a pod that doesn’t provide source code (is already shipped as a prebuilt pod).

Returns:

  • (Bool)

    True if it’s a pod that doesn’t provide source code (is already shipped as a prebuilt pod)



209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/pod_builder/podfile_item.rb', line 209

def is_prebuilt
  # We treat pods to skip like prebuilt ones
  if Configuration.skip_pods.include?(@root_name) || Configuration.skip_pods.include?(@name)
    return true
  end

  # Podspecs aren't always properly written (source_file key is often used instead of header_files)
  # Therefore it can become tricky to understand which pods are already precompiled by boxing a .framework or .a
  vendored_items_paths = vendored_items.map { |x| File.basename(x) }
  embedded_as_vendored = vendored_items_paths.include?("#{@module_name}.framework")
  embedded_as_static_lib = vendored_items_paths.any? { |x| x.match(/#{module_name}.*\\.a/) != nil }
  
  only_headers = @source_files.include?("*.h")
  only_headers |= (source_files.count > 0 && @source_files.all? { |x| x.end_with?(".h") })
  no_sources = (@source_files.count == 0 || only_headers) && @vendored_items.count > 0

  return embedded_as_static_lib || embedded_as_vendored || only_headers || no_sources
end

#is_subspecBool

Returns True if it’s a subspec.

Returns:

  • (Bool)

    True if it’s a subspec



230
231
232
# File 'lib/pod_builder/podfile_item.rb', line 230

def is_subspec
  @root_name != @name
end

#pod_specification(all_poditems, parent_spec = nil) ⇒ Object



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/pod_builder/podfile_item.rb', line 157

def pod_specification(all_poditems, parent_spec = nil)
  spec_raw = {}

  spec_raw["name"] = @name
  spec_raw["module_name"] = @module_name

  spec_raw["source"] = {}
  if repo = @repo
    spec_raw["source"]["git"] = repo
  end
  if tag = @tag
    spec_raw["source"]["tag"] = tag
  end
  if commit = @commit
    spec_raw["source"]["commit"] = commit
  end

  spec_raw["version"] = @version
  if swift_version = @swift_version
    spec_raw["swift_version"] = swift_version
  end

  spec_raw["static_framework"] = is_static

  spec_raw["frameworks"] = @frameworks
  spec_raw["libraries"] = @libraries

  spec_raw["xcconfig"] = @xcconfig

  spec_raw["dependencies"] = @dependency_names.map { |x| [x, []] }.to_h

  spec = Pod::Specification.from_hash(spec_raw, parent_spec)   
  all_subspec_items = all_poditems.select { |x| x.is_subspec && x.root_name == @name }
  spec.subspecs = all_subspec_items.map { |x| x.pod_specification(all_poditems, spec) }

  return spec
end

#podspec_nameObject



284
285
286
# File 'lib/pod_builder/podfile_item.rb', line 284

def podspec_name
  return name.gsub("/", "_")
end

#prebuilt_entry(include_pb_entry = true) ⇒ Object



296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
# File 'lib/pod_builder/podfile_item.rb', line 296

def prebuilt_entry(include_pb_entry = true)
  relative_path = Pathname.new(Configuration.base_path).relative_path_from(Pathname.new(PodBuilder::project_path)).to_s

  if Configuration.subspecs_to_split.include?(name)
    entry = "pod 'PodBuilder/#{podspec_name}', :path => '#{relative_path}'"
  else
    entry = "pod 'PodBuilder/#{root_name}', :path => '#{relative_path}'"
  end

  if include_pb_entry && !is_prebuilt
    entry += " # pb<#{name}>"
  end

  return entry
end

#prebuilt_rel_pathObject



288
289
290
291
292
293
294
# File 'lib/pod_builder/podfile_item.rb', line 288

def prebuilt_rel_path
  if is_subspec && Configuration.subspecs_to_split.include?(name)
    return "#{name}/#{module_name}.framework"
  else
    return "#{module_name}.framework"
  end
end

#to_sObject



199
200
201
# File 'lib/pod_builder/podfile_item.rb', line 199

def to_s
  return @name
end