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, target_definitions, checkout_options, supported_platforms) ⇒ PodfileItem

Initialize a new instance

Parameters:

  • spec (Specification)
  • checkout_options (Hash)


156
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
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
# File 'lib/pod_builder/podfile_item.rb', line 156

def initialize(spec, all_specs, target_definitions, checkout_options, supported_platforms)
  @name = spec.name
  @root_name = spec.name.split("/").first

  @checksum = spec.checksum

  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]
    @podspec_path = checkout_options[opts_key][:podspec]
    @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

  @defines_module = nil # nil is not specified
  if override = spec.attributes_hash.dig("pod_target_xcconfig", "DEFINES_MODULE")
    @defines_module = (override == "YES")
  end

  @vendored_frameworks = extract_vendored_frameworks(spec, all_specs)
  @vendored_libraries = extract_vendored_libraries(spec, all_specs)

  @frameworks = []
  @weak_frameworks = []
  @libraries = []

  @frameworks += extract_array(spec.attributes_hash, "framework")
  @frameworks += extract_array(spec.attributes_hash, "frameworks")
  supported_platforms.each do |platform|
    @frameworks += extract_array(spec.attributes_hash[platform], "framework")
    @frameworks += extract_array(spec.attributes_hash[platform], "frameworks")
  end

  @weak_frameworks += extract_array(spec.attributes_hash, "weak_framework")
  @weak_frameworks += extract_array(spec.attributes_hash, "weak_frameworks")
  supported_platforms.each do |platform|
    @weak_frameworks += extract_array(spec.attributes_hash[platform], "weak_framework")
    @weak_frameworks += extract_array(spec.attributes_hash[platform], "weak_frameworks")
  end

  @libraries += extract_array(spec.attributes_hash, "library")
  @libraries += extract_array(spec.attributes_hash, "libraries")
  supported_platforms.each do |platform|
    @libraries += extract_array(spec.attributes_hash[platform], "library")
    @libraries += extract_array(spec.attributes_hash[platform], "libraries")
  end

  @header_dir = spec.attributes_hash["header_dir"]

  @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

  @default_subspecs = extract_array(spec.attributes_hash, "default_subspecs")
  if default_subspec = spec.attributes_hash["default_subspec"]
    @default_subspecs.push(default_subspec)
  end

  if @name == @root_name && @default_subspecs.empty?
    @default_subspecs += all_specs.select { |t| t.name.include?("/") && t.name.split("/").first == @root_name }.map { |t| t.name.split("/").last }
  end

  @dependency_names = spec.attributes_hash.fetch("dependencies", {}).keys + default_subspecs.map { |t| "#{@root_name}/#{t}" }
  supported_platforms.each do |platform|
    @dependency_names += (spec.attributes_hash.dig(platform, "dependencies") || {}).keys
  end
  @dependency_names.uniq!

  @external_dependency_names = @dependency_names.select { |t| !t.start_with?(root_name) }

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

  if spec.attributes_hash.has_key?("script_phases")
    Configuration.skip_pods += [name, root_name]
    Configuration.skip_pods.uniq!
    puts "Will skip '#{root_name}' which defines script_phase in podspec".blue
  end

  default_subspecs_specs ||= begin
      subspecs = all_specs.select { |t| t.name.split("/").first == @root_name }
      subspecs.select { |t| @default_subspecs.include?(t.name.split("/").last) }
    end
  root_spec = all_specs.detect { |t| t.name == @root_name } || spec
  @source_files = source_files_from([spec, root_spec] + default_subspecs_specs)

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

  default_license = "MIT"
  @license = spec.root.attributes_hash.fetch("license", { "type" => "#{default_license}" })["type"] || default_license
  @summary = spec.root.attributes_hash.fetch("summary", "A summary for #{@name}")
  @source = spec.root.attributes_hash.fetch("source", { "git" => "https://github.com/Subito-it/PodBuilder.git" })
  @authors = spec.root.attributes_hash.fetch("authors", { "PodBuilder" => "[email protected]" })
  @homepage = spec.root.attributes_hash.fetch("homepage", "https://github.com/Subito-it/PodBuilder")

  if Configuration.build_xcframeworks_all
    build_as_xcframework = !Configuration.build_xcframeworks_exclude.include?(@root_name)
  else
    build_as_xcframework = Configuration.build_xcframeworks_include.include?(@root_name)
  end
  @build_xcframework = build_as_xcframework

  @is_prebuilt = extract_is_prebuilt(spec, all_specs, checkout_options, supported_platforms)
  @inhibit_warnings = target_definitions.any? { |t| t.inhibits_warnings_for_pod?(@name) }
end

Instance Attribute Details

#authorsHash

Returns Authors.

Returns:

  • (Hash)

    Authors



124
125
126
# File 'lib/pod_builder/podfile_item.rb', line 124

def authors
  @authors
end

#available_versionsObject (readonly)

Returns the value of attribute available_versions.



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

def available_versions
  @available_versions
end

#branchString (readonly)

Returns The git branch.

Returns:



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

def branch
  @branch
end

#build_configurationString

Returns The pod’s build configuration.

Returns:

  • (String)

    The pod’s build configuration



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

def build_configuration
  @build_configuration
end

#build_xcframeworkBool

Returns Should build as xcframework.

Returns:

  • (Bool)

    Should build as xcframework



140
141
142
# File 'lib/pod_builder/podfile_item.rb', line 140

def build_xcframework
  @build_xcframework
end

#checksumString (readonly)

Returns A checksum for the spec.

Returns:

  • (String)

    A checksum for the spec



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

def checksum
  @checksum
end

#commitString (readonly)

Returns The pinned commit of the pod, if any.

Returns:

  • (String)

    The pinned commit of the pod, if any



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

def commit
  @commit
end

#default_subspecsArray<String>

Returns Default subspecs.

Returns:

  • (Array<String>)

    Default subspecs



132
133
134
# File 'lib/pod_builder/podfile_item.rb', line 132

def default_subspecs
  @default_subspecs
end

#defines_moduleBool

Returns Defines module.

Returns:

  • (Bool)

    Defines module



136
137
138
# File 'lib/pod_builder/podfile_item.rb', line 136

def defines_module
  @defines_module
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>]



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

def dependency_names
  @dependency_names
end

#external_dependency_namesArray<String> (readonly)

Returns The pod’s external dependency names (excluding subspecs), if any.

Returns:

  • (Array<String>)

    The pod’s external dependency names (excluding subspecs), if any



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

def external_dependency_names
  @external_dependency_names
end

#frameworksString

Returns Framweworks the pod needs to link to.

Returns:

  • (String)

    Framweworks the pod needs to link to



96
97
98
# File 'lib/pod_builder/podfile_item.rb', line 96

def frameworks
  @frameworks
end

#header_dirString

Returns Header directory name.

Returns:

  • (String)

    Header directory name



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

def header_dir
  @header_dir
end

#homepageString

Returns Homepage.

Returns:



128
129
130
# File 'lib/pod_builder/podfile_item.rb', line 128

def homepage
  @homepage
end

#inhibit_warningsBool

Returns True if warnings should be inhibited for the pod.

Returns:

  • (Bool)

    True if warnings should be inhibited for the pod



148
149
150
# File 'lib/pod_builder/podfile_item.rb', line 148

def inhibit_warnings
  @inhibit_warnings
end

#is_externalBool

Returns Is external pod.

Returns:

  • (Bool)

    Is external pod



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

def is_external
  @is_external
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)



144
145
146
# File 'lib/pod_builder/podfile_item.rb', line 144

def is_prebuilt
  @is_prebuilt
end

#is_staticBool (readonly)

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

Returns:

  • (Bool)

    True if the pod is shipped as a static binary



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

def is_static
  @is_static
end

#librariesString

Returns Libraries the pod needs to link to.

Returns:

  • (String)

    Libraries the pod needs to link to



104
105
106
# File 'lib/pod_builder/podfile_item.rb', line 104

def libraries
  @libraries
end

#licenseString

Returns License.

Returns:



112
113
114
# File 'lib/pod_builder/podfile_item.rb', line 112

def license
  @license
end

#module_nameString (readonly)

Returns The module name.

Returns:

  • (String)

    The module name



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

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



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

def name
  @name
end

#pathString

Returns Local path, if any.

Returns:

  • (String)

    Local path, if any



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

def path
  @path
end

#podspec_pathString

Returns Local podspec path, if any.

Returns:

  • (String)

    Local podspec path, if any



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

def podspec_path
  @podspec_path
end

#repoString (readonly)

Returns The git repo.

Returns:



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

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



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

def root_name
  @root_name
end

#sourceHash

Returns Source.

Returns:

  • (Hash)

    Source



120
121
122
# File 'lib/pod_builder/podfile_item.rb', line 120

def source
  @source
end

#source_filesString

Returns Source_files.

Returns:



108
109
110
# File 'lib/pod_builder/podfile_item.rb', line 108

def source_files
  @source_files
end

#summaryString

Returns Summary.

Returns:



116
117
118
# File 'lib/pod_builder/podfile_item.rb', line 116

def summary
  @summary
end

#swift_versionString (readonly)

Returns The swift version if applicable.

Returns:

  • (String)

    The swift version if applicable



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

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



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

def tag
  @tag
end

#vendored_frameworksString

Returns The pod’s vendored frameworks.

Returns:

  • (String)

    The pod’s vendored frameworks



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

def vendored_frameworks
  @vendored_frameworks
end

#vendored_librariesString

Returns The pod’s vendored libraries.

Returns:

  • (String)

    The pod’s vendored libraries



92
93
94
# File 'lib/pod_builder/podfile_item.rb', line 92

def vendored_libraries
  @vendored_libraries
end

#versionString (readonly)

Returns The pinned version of the pod, if any.

Returns:

  • (String)

    The pinned version of the pod, if any



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

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



100
101
102
# File 'lib/pod_builder/podfile_item.rb', line 100

def weak_frameworks
  @weak_frameworks
end

#xcconfigArray<Hash> (readonly)

Returns The pod’s xcconfig configuration.

Returns:

  • (Array<Hash>)

    The pod’s xcconfig configuration



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

def xcconfig
  @xcconfig
end

Instance Method Details

#dependencies(available_pods) ⇒ Object



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

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



375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
# File 'lib/pod_builder/podfile_item.rb', line 375

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

  e_suffix = ""
  if !is_prebuilt && inhibit_warnings
    e_suffix = ", :inhibit_warnings => true"
  end

  unless include_version
    return e + e_suffix
  end

  if is_external
    if @path
      e += ", :path => '#{@path}'"
    elsif @podspec_path
      e += ", :podspec => '#{@podspec_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

  e += e_suffix

  if include_pb_entry && !is_prebuilt
    prebuilt_info_path = PodBuilder::prebuiltpath("#{root_name}/#{Configuration::prebuilt_info_filename}")
    if File.exist?(prebuilt_info_path)
      data = JSON.parse(File.read(prebuilt_info_path))
      swift_version = data["swift_version"]
      is_static = data["is_static"] || false

      e += "#{prebuilt_marker()} is<#{is_static}>"
      if swift_version
        e += " sv<#{swift_version}>"
      end
    else
      e += prebuilt_marker()
    end
  end

  return e
end

#has_common_spec(named) ⇒ Object



472
473
474
# File 'lib/pod_builder/podfile_item.rb', line 472

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

#has_subspec(named) ⇒ Object



464
465
466
467
468
469
470
# File 'lib/pod_builder/podfile_item.rb', line 464

def has_subspec(named)
  unless !is_subspec
    return false
  end

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

#inspectObject



312
313
314
# File 'lib/pod_builder/podfile_item.rb', line 312

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

#is_development_podBool

Returns True if it’s a development pod.

Returns:

  • (Bool)

    True if it’s a development pod



369
370
371
# File 'lib/pod_builder/podfile_item.rb', line 369

def is_development_pod
  @path != nil
end

#is_subspecBool

Returns True if it’s a subspec.

Returns:

  • (Bool)

    True if it’s a subspec



363
364
365
# File 'lib/pod_builder/podfile_item.rb', line 363

def is_subspec
  @root_name != @name
end

#pod_specification(all_poditems, parent_spec = nil) ⇒ Object



274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
# File 'lib/pod_builder/podfile_item.rb', line 274

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



431
432
433
# File 'lib/pod_builder/podfile_item.rb', line 431

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

#prebuilt_entry(include_pb_entry = true, absolute_path = false) ⇒ Object



448
449
450
451
452
453
454
455
456
457
458
# File 'lib/pod_builder/podfile_item.rb', line 448

def prebuilt_entry(include_pb_entry = true, absolute_path = false)
  podspec_dirname = File.dirname(prebuilt_podspec_path(absolute_path = absolute_path))

  entry = "pod '#{name}', :path => '#{podspec_dirname}'"

  if include_pb_entry && !is_prebuilt
    entry += prebuilt_marker()
  end

  return entry
end

#prebuilt_markerObject



460
461
462
# File 'lib/pod_builder/podfile_item.rb', line 460

def prebuilt_marker
  return " # pb<#{name}>"
end

#prebuilt_podspec_path(absolute_path = true) ⇒ Object



439
440
441
442
443
444
445
446
# File 'lib/pod_builder/podfile_item.rb', line 439

def prebuilt_podspec_path(absolute_path = true)
  podspec_path = PodBuilder::prebuiltpath("#{@root_name}/#{@root_name}.podspec")
  if absolute_path
    return podspec_path
  else
    pod_path = Pathname.new(podspec_path).relative_path_from(Pathname.new(PodBuilder::basepath)).to_s
  end
end

#prebuilt_rel_pathObject



435
436
437
# File 'lib/pod_builder/podfile_item.rb', line 435

def prebuilt_rel_path
  return "#{module_name}.framework"
end

#recursive_dependencies(available_pods) ⇒ Object



324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
# File 'lib/pod_builder/podfile_item.rb', line 324

def recursive_dependencies(available_pods)
  names = [name]

  deps = []
  last_count = -1
  while deps.count != last_count
    last_count = deps.count

    updated_names = []
    names.each do |name|
      if pod = available_pods.detect { |t| t.name == name }
        deps.push(pod)
        updated_names += pod.dependency_names
      end
    end

    names = updated_names.uniq

    deps.uniq!
  end

  root_names = deps.map(&:root_name).uniq

  # We need to build all other common subspecs to properly build the item
  # Ex.
  # PodA depends on DepA/subspec1
  # PodB depends on DepA/subspec2
  #
  # When building PodA we need to build both DepA subspecs because they might
  # contain different code
  deps += available_pods.select { |t| root_names.include?(t.root_name) && t.root_name != t.name }

  deps.uniq!

  return deps
end

#to_sObject



316
317
318
# File 'lib/pod_builder/podfile_item.rb', line 316

def to_s
  return @name
end