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)


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

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 = [@name, @root_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)

  @frameworks = []
  @frameworks += extract_array(spec, "framework")
  @frameworks += extract_array(spec, "frameworks")
  @frameworks += extract_array(spec.root, "framework")
  @frameworks += extract_array(spec.root, "frameworks")

  @weak_frameworks = []
  @weak_frameworks += extract_array(spec, "weak_frameworks")
  @weak_frameworks += extract_array(spec, "weak_frameworks")
  @weak_frameworks += extract_array(spec.root, "weak_frameworks")
  @weak_frameworks += extract_array(spec.root, "weak_frameworks")

  @libraries = []
  @libraries += extract_array(spec, "library")
  @libraries += extract_array(spec, "libraries")
  @libraries += extract_array(spec.root, "library")
  @libraries += extract_array(spec.root, "libraries")

  @version = spec.root.version.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"] || {}

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

Instance Attribute Details

#branch ⇒ String (readonly)

Returns The git branch.

Returns:



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

def branch
  @branch
end

#build_configuration ⇒ String

Returns The pod's build configuration.

Returns:

  • (String) —

    The pod's build configuration



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

def build_configuration
  @build_configuration
end

#commit ⇒ String (readonly)

Returns The pinned commit of the pod, if any.

Returns:

  • (String) —

    The pinned commit of the pod, if any



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

def commit
  @commit
end

#dependency_names ⇒ Array<String> (readonly)

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

Returns:

  • (Array<String>) —

    The pod's dependency names, if any. Use dependencies() to get the [Array]



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

def dependency_names
  @dependency_names
end

#frameworks ⇒ String

Returns Framweworks the pod needs to link to.

Returns:

  • (String) —

    Framweworks the pod needs to link to



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

def frameworks
  @frameworks
end

#has_source_files_key ⇒ Bool

Returns true if the source_files key is present

Returns:

  • (Bool) —

    Returns true if the source_files key is present



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

def has_source_files_key
  @has_source_files_key
end

#is_external ⇒ Bool (readonly)

Returns Is external pod.

Returns:

  • (Bool) —

    Is external pod



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

def is_external
  @is_external
end

#is_static ⇒ Bool (readonly)

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

Returns:

  • (Bool) —

    True if the pod is shipped as a static framework



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

def is_static
  @is_static
end

#libraries ⇒ String

Returns Libraries the pod needs to link to.

Returns:

  • (String) —

    Libraries the pod needs to link to



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

def libraries
  @libraries
end

#module_name ⇒ String (readonly)

Returns The module name.

Returns:

  • (String) —

    The module name



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

def module_name
  @module_name
end

#name ⇒ String (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

#path ⇒ String

Returns Local path, if any.

Returns:

  • (String) —

    Local path, if any



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

def path
  @path
end

#repo ⇒ String (readonly)

Returns The git repo.

Returns:



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

def repo
  @repo
end

#root_name ⇒ String (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

#swift_version ⇒ String (readonly)

Returns The swift version if applicable.

Returns:

  • (String) —

    The swift version if applicable



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

def swift_version
  @swift_version
end

#tag ⇒ String (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_items ⇒ String

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

Returns:

  • (String) —

    The pod's vendored items (frameworks and libraries)



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

def vendored_items
  @vendored_items
end

#version ⇒ String (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_frameworks ⇒ String

Returns Weak framweworks the pod needs to link to.

Returns:

  • (String) —

    Weak framweworks the pod needs to link to



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

def weak_frameworks
  @weak_frameworks
end

#xcconfig ⇒ Array<Hash> (readonly)

Returns The pod's xcconfig configuration.

Returns:

  • (Array<Hash>) —

    The pod's xcconfig configuration



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

def xcconfig
  @xcconfig
end

Instance Method Details

#dependencies(available_pods) ⇒ Object



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

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



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

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
    e += " # pb<#{name}>"
  end

  return e
end

#git_hard_checkout ⇒ Object



305
306
307
308
309
310
311
312
313
314
315
316
317
318
# File 'lib/pod_builder/podfile_item.rb', line 305

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



301
302
303
# File 'lib/pod_builder/podfile_item.rb', line 301

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

#has_subspec(named) ⇒ Object



293
294
295
296
297
298
299
# File 'lib/pod_builder/podfile_item.rb', line 293

def has_subspec(named)
  unless !is_subspec
    return false
  end

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

#inspect ⇒ Object



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

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

#is_prebuilt ⇒ Bool

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)



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

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

  # checking if there's a vendored_item matching the module name is a pretty good guess for a prebuilt pod.
  # Still suboptimal, maybe it should be more appropriate to use FileAccessor and check that no source code is provided (no *.{m,mm,c,cpp,swift, etc})
  if vendored_items.map { |x| File.basename(x) }.include?("#{@module_name}.framework")
    return true
  else
    return !@has_source_files_key && @vendored_items.count > 0
  end
end

#is_subspec ⇒ Bool

Returns True if it's a subspec.

Returns:

  • (Bool) —

    True if it's a subspec



225
226
227
# File 'lib/pod_builder/podfile_item.rb', line 225

def is_subspec
  @root_name != @name
end

#pod_specification(all_poditems, parent_spec = nil) ⇒ Object



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

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_name ⇒ Object



266
267
268
# File 'lib/pod_builder/podfile_item.rb', line 266

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

#prebuilt_entry(include_pb_entry = true) ⇒ Object



278
279
280
281
282
283
284
285
286
287
288
289
290
291
# File 'lib/pod_builder/podfile_item.rb', line 278

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
    entry += " # pb<#{name}>"
  end

  return entry
end

#prebuilt_rel_path ⇒ Object



270
271
272
273
274
275
276
# File 'lib/pod_builder/podfile_item.rb', line 270

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_s ⇒ Object



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

def to_s
  return @name
end