Top Level Namespace

Defined Under Namespace

Modules: CBin, Pod Classes: PodUpdateConfig

Instance Method Summary collapse

Instance Method Details

#get_podfile_lockObject

获取服务端podfile.lock文件



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
63
64
65
66
# File 'lib/cocoapods-meitu-bin/source_provider_hook.rb', line 9

def get_podfile_lock
  begin
    # 默认是获取要获取服务端podfile.lock文件
    is_load_podfile_lock = true
    # MEITU_LOAD_CACHE_PODFILE_LOCK 为false时不获取服务端podfile.lock文件
    if ENV['MEITU_LOAD_CACHE_PODFILE_LOCK'] && ENV['MEITU_LOAD_CACHE_PODFILE_LOCK'] == 'false'
      is_load_podfile_lock = false
    end
    # 判断是否有update参数 时不获取服务端podfile.lock文件
    ARGV.each do |arg|
      if arg == 'update'
        is_load_podfile_lock = false
      end
    end
    # podfile.lock文件下载和使用逻辑
    if is_load_podfile_lock
      #获取 PODFILE CHECKSUM 用来判断服务端是否存在该podfile.lock
      checksum = Pod::Config.instance.podfile.checksum
      puts checksum
      # zip下载地址
      curl = "https://xiuxiu-dl-meitu-com.obs.cn-north-4.myhuaweicloud.com/ios/binary/MTXX/#{checksum}/podfile.lock.zip"
      # 判断zip文件是否存在 存在下载并解压
      if system("curl -o /dev/null -s -w %{http_code} #{curl} | grep 200")
        puts "获取服务端存储的podfile.lcok文件".green
        #下载并解压的podfile.zip文件
        if system("curl -O #{curl}") && system("unzip -o podfile.lock.zip")
          Pod::UI.puts "下载并解压podfile.lcok文件成功".green
          `rm -rf podfile.lock.zip`
          # 设置获取到的podfile.lock对象
          PodUpdateConfig.set_lockfile( Pod::Config.instance.installation_root + 'Podfile.lock')
          #获取analyzer
          analyzer = Pod::Installer::Analyzer.new(
            Pod::Config.instance.sandbox,
            Pod::Config.instance.podfile,
            PodUpdateConfig.lockfile
          )
          analyzer.analyze(true)

          #获取analyzer中所有git 且branch 指向的pod
          Pod::Config.instance.podfile.dependencies.map do |dependency|
            if dependency.external_source && dependency.external_source[:git] && (dependency.external_source[:branch] || (dependency.external_source.size == 1))
              #brash 指定的组件添加到全局PodUpdateConfig配置中,执行pod install 需要更新的分支最新提交
              PodUpdateConfig.add_value(dependency.name)
            end
          end
        else
          puts "获取podfile.lcok文件失败"
          `rm -rf podfile.lock.zip`
        end
      end
    end
  rescue => error
    puts error
    puts "podfile.lcok相关发生异常"
    `rm -rf podfile.lock.zip`
    `rm -rf podfile.lock`
  end
end

#upload_podfile_lockObject

上传podfile.lock文件到服务端



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/cocoapods-meitu-bin/source_provider_hook.rb', line 69

def upload_podfile_lock
  begin
    checksum = Pod::Config.instance.podfile.checksum
    curl = "https://xiuxiu-dl-meitu-com.obs.cn-north-4.myhuaweicloud.com/ios/binary/MTXX/#{checksum}/podfile.lock.zip"
    # 服务端不存在该podfiel.lock文件才上传,避免频繁上报同一个文件
    if !system("curl -o /dev/null -s -w %{http_code} #{curl} | grep 200")
      Pod::UI.puts "上报podfile.lcok文件到服务端".green
      puts checksum
      if system("zip  podfile.lock.zip Podfile.lock") && system("curl -F \"name=MTXX\" -F \"version=#{checksum}\" -F \"file=@#{Pathname.pwd}/podfile.lock.zip\" http://nezha.community.cloud.meitu.com/file/upload.json")
        Pod::UI.puts "上报podfile.lcok文件到服务端成功".green
        `rm -rf podfile.lock.zip`
      else
        Pod::UI.puts "上报podfile.lcok文件到服务端失败".red
        `rm -rf podfile.lock.zip`
      end
    end

  rescue => error
     puts "上传podfile.lcok文件失败".red
    `rm -rf podfile.zip`
  end
end