Class: PodBuilder::Info

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

Class Method Summary collapse

Class Method Details

.generate_infoObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/pod_builder/info.rb', line 5

def self.generate_info
  restore_path = PodBuilder::basepath("Podfile.restore")
  unless File.exist?(restore_path)
    raise "No Podfile.restore file found"
    return false
  end
  
  podspec_path = PodBuilder::basepath("PodBuilder.podspec")
  unless File.exist?(podspec_path)
    raise "No PodBuilder.podspec file found"
    return false
  end
  
  restore_content = File.read(restore_path)
  
  swift_version = PodBuilder::system_swift_version
  result = {}
  name = nil
  File.read(podspec_path).each_line do |line|
    if (matches = line.match(/s.subspec '(.*)' do \|p\|/)) && matches.size == 2
      name = matches[1]
    elsif (matches = line.match(/p.vendored_frameworks = '(.*)'/)) && matches.size == 2          
      path = matches[1].split("'").first
      plist_path = File.join(PodBuilder::basepath(path), Configuration.framework_plist_filename)

      # fix name if it's a subspec
      if (subspec_items = name.split("_")) && (subspec = subspec_items.last) && subspec_items.count > 1
        if path.include?("/#{subspec}")
          name = name.sub(/_#{subspec}$/, "/#{subspec}")
        end
      end
                
      base = PodBuilder::basepath.gsub(PodBuilder::home + "/", "")
      framework_path = File.join(base, matches[1].split("'").first)
      result[name] = { framework_path: framework_path }

      specs = restore_podspecs(name.split("/").first, restore_content)
      unless specs.count > 0
        raise "pod `#{name}` not found in restore file"
      end

      restore_line = restore_line(name, restore_content)
      version = version_info(restore_line)
      is_static = is_static(restore_line)
      result[name].merge!({ "restore_info": { "version": version, "specs": specs, "is_static": is_static }})
      if swift_version = swift_version(restore_line)
        result[name][:restore_info].merge!({ "swift_version": swift_version })
      end
      
      prebuilt_info = prebuilt_info(plist_path)
      if prebuilt_info.count > 0 
        result[name].merge!({ "prebuilt_info": prebuilt_info })
      end
    end
  end

  return result
end