Class: Pod::Command::XCFramework

Inherits:
Pod::Command show all
Includes:
Config::Mixin, PodUtil
Defined in:
lib/cocoapods-xcframework/command/xcframework.rb

Overview

TODO:

Create a PR to add your plugin to CocoaPods/cocoapods.org in the ‘plugins.json` file, once your plugin is released.

This is an example of a cocoapods plugin adding a top-level subcommand to the ‘pod’ command.

You can also create subcommands of existing or new commands. Say you wanted to add a subcommand to ‘list` to show newly deprecated pods, (e.g. `pod list deprecated`), there are a few things that would need to change.

  • move this file to ‘lib/pod/command/list/deprecated.rb` and update the class to exist in the the Pod::Command::List namespace

  • change this class to extend from ‘List` instead of `Command`. This tells the plugin system that it is a subcommand of `list`.

  • edit ‘lib/cocoapods_plugins.rb` to require this file

Class Method Summary collapse

Instance Method Summary collapse

Methods included from PodUtil

#build_static_sandbox, #fix_bundle_file, #fix_header_file, #generic_new_podspec_hash, #installation_root, #installation_root_muti, #muti_config_with_file, #podfile_from_muti_configs, #podfile_from_spec, #spec_with_name, #spec_with_path, #to_native_platform

Constructor Details

#initialize(argv) ⇒ XCFramework

Returns a new instance of XCFramework.



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/cocoapods-xcframework/command/xcframework.rb', line 46

def initialize(argv)
  @name = argv.shift_argument
  @source = argv.shift_argument
  @spec_sources = argv.option('spec-sources', 'https://github.com/CocoaPods/Specs.git').split(',')
  subspecs = argv.option('subspecs')
  @subspecs = subspecs.split(',') unless subspecs.nil?
  @configuration = argv.option('configuration', 'Release')
  @use_modular_headers = argv.option('use-modular-headers', true)
  @force = argv.flag?('force', true)
  @use_static_library = argv.flag?('static-library',true)
  @enable_bitcode = argv.flag?('enable-bitcode',false)
  @symbols = argv.flag?('symbols',true)
  @support_maccatalyst = argv.flag?('support-maccatalyst',true)
  @support_dynamic = argv.flag?('support-dynamic',false)
  @archive_export = argv.flag?('archive-export',true)
  @workspace = argv.option('workspace')
  config.static_library_enable = @use_static_library
  super
end

Class Method Details

.optionsObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/cocoapods-xcframework/command/xcframework.rb', line 29

def self.options 
  [
    ['--no-force',     'Overwrite existing files.'],
    ['--configuration', 'Build the specified configuration (e.g. Debug). Defaults to Release'],
    ['--spec-sources=private,https://github.com/CocoaPods/Specs.git', 'The sources to pull dependent pods from (defaults to https://github.com/CocoaPods/Specs.git)'],
    ['--subspecs', 'Only include the given subspecs'],
    ['--use-modular-headers', 'pakcage uses modular headers during packaging'],
    ['--no-static-library', 'package not use static library'],
    ['--enable-bitcode', 'package enable bitcode'],
    ['--no-symbols', 'package not use symbols'], # 符号表
    ['--no-support-maccatalyst', 'package support generate MacCatalyst'], # 是否支持MacCatalyst方式支持iOS应用在mac平台运行库生成
    ['--no-support-dynamic', 'package support Mach-O dynamically linked shared library'], # 是否支持动态库生成
    ['--no-archive-export', 'xcodebuild archive export'], # 是否支持本地导出,导出dylib动态库
    ['--workspace', 'xcodebuild archive workspace'], # 工程目录
  ].concat super
end

Instance Method Details

#runObject



71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/cocoapods-xcframework/command/xcframework.rb', line 71

def run
  UI.puts "argvs @name:#{@name} @source:#{@source} @spec_sources:#{@spec_sources} @subspecs:#{@subspecs} @archive_export:#{@archive_export} @workspace:#{@workspace}"
  # @archive_export = false # 测试入口
  if @archive_export
    # 生成二进制资源xcodebuild archive,验证过使用xcodebuild archive无法导出macos架构
    puts "local builder xcframework"
    frameworker = LocalBuilder.new(@name, @source, @spec_sources, @subspecs, @configuration, @force, @use_modular_headers, @enable_bitcode, @symbols, @support_maccatalyst, support_macos, @support_dynamic, Dir.pwd, @workspace)
    frameworker.build
  else
    puts "remote builder xcframework"
    frameworker = Frameworker.new(@name, @source, @spec_sources, @subspecs, @configuration, @force, @use_modular_headers, @enable_bitcode, @symbols, @support_maccatalyst, support_macos, @support_dynamic, @workspace)
    frameworker.run
  end
end

#support_bundle_resObject

是否包含资源文件(bundle/resources/resource_bundles)



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/cocoapods-xcframework/command/xcframework.rb', line 87

def support_bundle_res
  spec = spec_with_path(@name)
  begin
    spec_hash = spec.to_hash
    has_resources = false
    resources = spec_hash['resources']
    resource_bundles = spec_hash['resource_bundles']
    vendored_resources = spec_hash['vendored_resources']
    has_resources ||= resources && !resources.empty?
    has_resources ||= resource_bundles && !resource_bundles.empty?
    has_resources ||= vendored_resources && !vendored_resources.empty?
    UI.puts "#{spec.name}(#{spec.version}) resources=#{!resources.nil?} resource_bundles=#{!resource_bundles.nil?} vendored_resources=#{!vendored_resources.nil?} support_bundle_res=#{has_resources}".yellow
    return has_resources
  rescue => e
    UI.puts "check bundle resource failed: #{e}".red
    return false
  end
end

#support_macosObject

是否支持macos架构



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/cocoapods-xcframework/command/xcframework.rb', line 107

def support_macos
  spec = spec_with_path @name
  platforms = []
  begin
    spec_hash = spec.to_hash
    if spec_hash['platforms']
      platforms = spec_hash['platforms'].keys.map(&:to_s)
    elsif spec.platform
      platforms = [spec.platform.name.to_s]
    end
  rescue => e
    UI.puts "read platforms failed: #{e}".red
  end
  support_macos = platforms.include?('osx') || platforms.include?('macos')
  UI.puts "#{spec.name}(#{spec.version}) platforms=#{platforms} support_macos=#{support_macos}".yellow
  return support_macos
end

#validate!Object



66
67
68
69
# File 'lib/cocoapods-xcframework/command/xcframework.rb', line 66

def validate!
  super
  help! 'A Pod name is required.' unless @name
end