Module: HMap::PBXHelper

Defined in:
lib/hmap/xc/pbx_helper.rb

Class Method Summary collapse

Class Method Details

.build_as_framework?(target) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/hmap/xc/pbx_helper.rb', line 31

def self.build_as_framework?(target)
  target.symbol_type == :framework if target.respond_to?(:symbol_type)
end

.defines_module?(target) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
38
39
40
41
42
43
# File 'lib/hmap/xc/pbx_helper.rb', line 35

def self.defines_module?(target)
  return true if build_as_framework?(target)

  bus = target.build_configuration_list.build_configurations.map do |bu|
    bu.instance_variable_get('@simple_attributes_hash')['buildSettings'] || {}
  end

  bus.any? { |s| s['DEFINES_MODULE'] == 'YES' }
end

.get_groups(xct) ⇒ Object



6
7
8
9
10
# File 'lib/hmap/xc/pbx_helper.rb', line 6

def self.get_groups(xct)
  groups = xct.referrers.select { |e| e.is_a?(Constants::PBXGroup) } || []
  groups += groups.flat_map { |g| get_groups(g) }
  groups.compact
end

.group_paths(xct) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/hmap/xc/pbx_helper.rb', line 12

def self.group_paths(xct)
  gs = get_groups(xct).reverse
  ps = gs.map do |g|
    s_hash = g.instance_variable_get('@simple_attributes_hash')
    s_hash['path'] unless s_hash.nil? && s_hash['sourceTree'] == PBX_GROUP
  end.compact
  File.join(*ps)
end

.project_references(project) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
# File 'lib/hmap/xc/pbx_helper.rb', line 62

def self.project_references(project)
  return if project.nil?

  p_path = File.dirname(project.path)
  project.root_object.project_references.map do |sp|
    ff = sp[:project_ref]
    path = ff.instance_variable_get('@simple_attributes_hash')['path'] || ''
    full_path = File.join(p_path, path)
    Xcodeproj::Project.open(full_path)
  end
end

.projects(*p_paths) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/hmap/xc/pbx_helper.rb', line 45

def self.projects(*p_paths)
  return if p_paths.empty?

  p_paths.flat_map do |pj|
    project = Xcodeproj::Project.open(pj)
    p_path = File.dirname(project.path)
    project.root_object.project_references.map do |sp|
      ff = sp[:project_ref]
      f_hash = ff.instance_variable_get('@simple_attributes_hash')
      g_path = PBXHelper.group_paths(ff) if f_hash['sourceTree'] == PBX_GROUP
      path = f_hash['path'] || ''
      full_path = File.join(p_path, g_path || '', path)
      Xcodeproj::Project.open(full_path)
    end << project
  end
end

.uses_swift?(target) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
24
25
26
27
28
29
# File 'lib/hmap/xc/pbx_helper.rb', line 21

def self.uses_swift?(target)
  source_files = target.build_phases.flat_map do |phase|
    phase.files if phase.is_a?(Constants::PBXSourcesBuildPhase)
  end.compact
  source_files.any? do |file|
    path = file.file_ref.instance_variable_get('@simple_attributes_hash')['path'] || ''
    File.extname(path) == '.swift'
  end
end