Class: Pindo::MacAppResignHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/pindo/module/xcode/mac_app_resign_helper.rb

Constant Summary collapse

BUNDLE_EXTENSIONS =
%w[.app .appex .framework .xpc .bundle .plugin].freeze
PROFILE_BUNDLE_EXTENSIONS =

需要内嵌描述文件的可执行 bundle(含独立 Bundle ID), .framework / .bundle / .plugin 属于共享代码,不单独内嵌 profile。

%w[.app .appex .xpc].freeze
MACHO_MAGICS =
[
  "\xFE\xED\xFA\xCE", "\xCE\xFA\xED\xFE", "\xFE\xED\xFA\xCF",
  "\xCF\xFA\xED\xFE", "\xCA\xFE\xBA\xBE", "\xBE\xBA\xFE\xCA",
  "\xCA\xFE\xBA\xBF", "\xBF\xBA\xFE\xCA"
].map(&:b).freeze

Class Method Summary collapse

Class Method Details

.resign_app(app_path:, bundle_id:, signing_identity:, profiles: []) ⇒ Object



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
# File 'lib/pindo/module/xcode/mac_app_resign_helper.rb', line 19

def resign_app(app_path:, bundle_id:, signing_identity:, profiles: [])
  validate_input!(app_path, signing_identity)
  output_path = resigned_path(app_path)
  FileUtils.rm_rf(output_path)
  FileUtils.cp_r(app_path, output_path, preserve: true)

  resolved_bundle_id = resolve_bundle_id(output_path, bundle_id)
  puts "\n▶ macOS App 重签名"
  puts "  输入: #{app_path}"
  puts "  输出: #{output_path}"
  puts "  Bundle ID: #{bundle_id}#{resolved_bundle_id}" if bundle_id != resolved_bundle_id
  puts "  Bundle ID: #{resolved_bundle_id}" if bundle_id == resolved_bundle_id
  puts "  签名身份: #{signing_identity}"
  update_main_bundle_id(output_path, resolved_bundle_id)

  Dir.mktmpdir('pindo-macos-entitlements-') do |tmp_dir|
    nested_paths = signable_paths(output_path)
    puts "  嵌套组件: #{nested_paths.length}"
    nested_paths.each_with_index do |path, index|
      puts "  [#{index + 1}/#{nested_paths.length}] 签名: #{relative_path(path, output_path)}"
      sign_component(path, output_path, signing_identity, profiles, tmp_dir, index)
    end
    puts "  签名主 App: #{File.basename(output_path)}"
    sign_component(output_path, output_path, signing_identity, profiles, tmp_dir, 'main',
                   bundle_id: resolved_bundle_id)
  end

  puts "  验证签名: codesign --verify --strict"
  verify!(output_path)
  puts "  ✓ macOS App 签名验证通过"
  output_path
rescue StandardError
  FileUtils.rm_rf(output_path) if output_path && File.exist?(output_path)
  raise
end