Class: XCCache::SPM::XCFramework
- Defined in:
- lib/xccache/spm/xcframework/metadata.rb,
lib/xccache/spm/xcframework/xcframework.rb
Defined Under Namespace
Classes: Metadata
Instance Attribute Summary collapse
-
#slices ⇒ Object
readonly
Returns the value of attribute slices.
Attributes inherited from Buildable
#config, #library_evolution, #module_name, #name, #path, #pkg_desc, #pkg_dir, #sdk, #sdks, #tmpdir
Instance Method Summary collapse
- #build(merge_slices: false, **_options) ⇒ Object
- #create_xcframework(options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ XCFramework
constructor
A new instance of XCFramework.
Methods inherited from Buildable
#pkg_target, #swift_build, #swift_build_args
Constructor Details
#initialize(options = {}) ⇒ XCFramework
Returns a new instance of XCFramework.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/xccache/spm/xcframework/xcframework.rb', line 8 def initialize( = {}) super @slices ||= @sdks.map do |sdk| FrameworkSlice.new( **, sdks: [sdk], path: Dir.prepare(tmpdir / sdk.triple / "#{module_name}.framework"), ) end end |
Instance Attribute Details
#slices ⇒ Object (readonly)
Returns the value of attribute slices.
6 7 8 |
# File 'lib/xccache/spm/xcframework/xcframework.rb', line 6 def slices @slices end |
Instance Method Details
#build(merge_slices: false, **_options) ⇒ 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 |
# File 'lib/xccache/spm/xcframework/xcframework.rb', line 19 def build(merge_slices: false, **) tmp_new_path = tmpdir / "new.xcframework" tmp_existing_path = tmpdir / "existing.framework" slices.each(&:build) UI.section("Creating #{name}.xcframework from slices") do create_xcframework(from: slices.map(&:path), to: tmp_new_path) end path.copy(to: tmp_existing_path) if path.exist? && merge_slices path.rmtree if path.exist? if merge_slices && tmp_existing_path.exist? UI.section("Merging #{name}.xcframework with existing slices") do framework_paths = [tmp_new_path, tmp_existing_path] .flat_map { |p| p.glob("*/*.framework") } .uniq { |p| p.parent.basename.to_s } # uniq by id (ex. ios-arm64), preferred new ones create_xcframework(from: framework_paths, to: path) end else path.parent.mkpath tmp_new_path.copy(to: path) end UI.info("-> XCFramework: #{path.to_s.dark}") end |
#create_xcframework(options = {}) ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/xccache/spm/xcframework/xcframework.rb', line 46 def create_xcframework( = {}) cmd = ["xcodebuild", "-create-xcframework"] cmd << "-allow-internal-distribution" unless library_evolution? cmd << "-output" << [:to] [:from].each { |p| cmd << "-framework" << p } cmd << "> /dev/null" # Only care about errors Sh.run(cmd) end |