Prechádzať zdrojové kódy

Support for building xcframework

onevcat 6 rokov pred
rodič
commit
0309f389d6
3 zmenil súbory, kde vykonal 118 pridanie a 60 odobranie
  1. 2 1
      Gemfile
  2. 4 0
      Gemfile.lock
  3. 112 59
      fastlane/Fastfile

+ 2 - 1
Gemfile

@@ -4,4 +4,5 @@ source "https://rubygems.org"
 
 gem "fastlane"
 gem "jazzy"
-gem "cocoapods", "~> 1.8.beta"
+gem "cocoapods", "~> 1.8.beta"
+gem "xcode-install"

+ 4 - 0
Gemfile.lock

@@ -219,6 +219,9 @@ GEM
     word_wrap (1.0.0)
     xcinvoke (0.3.0)
       liferaft (~> 0.0.6)
+    xcode-install (2.6.1)
+      claide (>= 0.9.1, < 1.1.0)
+      fastlane (>= 2.1.0, < 3.0.0)
     xcodeproj (1.12.0)
       CFPropertyList (>= 2.3.3, < 4.0)
       atomos (~> 0.1.3)
@@ -237,6 +240,7 @@ DEPENDENCIES
   cocoapods (~> 1.8.beta)
   fastlane
   jazzy
+  xcode-install
 
 BUNDLED WITH
    2.0.2

+ 112 - 59
fastlane/Fastfile

@@ -9,103 +9,156 @@ platform :ios do
     test(destination: "platform=macOS", swift_version: "5.0")
     test(destination: "platform=iOS Simulator,name=iPhone 8", swift_version: "5.0")
     test(destination: "platform=tvOS Simulator,name=Apple TV", swift_version: "5.0")
-
+    
     test(destination: "platform=macOS", swift_version: "4.2")
     test(destination: "platform=iOS Simulator,name=iPhone 8", swift_version: "4.2")
     test(destination: "platform=tvOS Simulator,name=Apple TV", swift_version: "4.2")
-
+    
     test(destination: "platform=macOS", swift_version: "4.0")
     test(destination: "platform=iOS Simulator,name=iPhone 8", swift_version: "4.0")
     test(destination: "platform=tvOS Simulator,name=Apple TV", swift_version: "4.0")
   end
-
+  
   lane :test do |options|
     _test(options)
   end
-
+  
   private_lane :_test do |options|
     scan(
-        scheme: "Kingfisher", 
-        clean: true, 
-        xcargs: "SWIFT_VERSION=#{options[:swift_version]}",
-        destination: options[:destination]
+      scheme: "Kingfisher", 
+      clean: true, 
+      xcargs: "SWIFT_VERSION=#{options[:swift_version]}",
+      destination: options[:destination]
     )
   end
-
+  
   lane :test_ci do
     test(destination: ENV["DESTINATION"], swift_version: ENV["SWIFT_VERSION"])
   end
   
   desc "Lint"
   lane :lint do
-      carthage(command: "build", no_skip_current: true)
-      pod_lib_lint
+    carthage(command: "build", no_skip_current: true)
+    pod_lib_lint
   end
-
+  
   desc "Release new version"
   lane :release do |options|
-      target_version = options[:version]
-      raise "The version is missed. Use `fastlane release version:{version_number}`.`" if target_version.nil?
-
-      ensure_git_branch
-      ensure_git_status_clean
-      
-      tests
-      lint
-      carthage(command: "archive", frameworks: ["Kingfisher"])
-      
-      sync_build_number_to_git
-      increment_version_number(version_number: target_version)
-      version_bump_podspec(path: "Kingfisher.podspec", version_number: target_version)
-
-      log = extract_current_change_log(version: target_version)
-      release_log = update_change_log(log: log)
-
-      doc(version: target_version)
-
-      git_commit_all(message: "Bump version to #{target_version}")
-      
-      Actions.sh("git tag -s #{target_version} -m ''")
-
-      push_to_git_remote
-
-      set_github_release(
+    target_version = options[:version]
+    raise "The version is missed. Use `fastlane release version:{version_number}`.`" if target_version.nil?
+    
+    ensure_git_branch
+    ensure_git_status_clean
+    
+    tests
+    lint
+
+    sync_build_number_to_git
+    increment_version_number(version_number: target_version)
+    version_bump_podspec(path: "Kingfisher.podspec", version_number: target_version)
+    
+    log = extract_current_change_log(version: target_version)
+    release_log = update_change_log(log: log)
+    
+    doc(version: target_version)
+    
+    git_commit_all(message: "Bump version to #{target_version}")
+    
+    Actions.sh("git tag -s #{target_version} -m ''")
+    
+    push_to_git_remote
+    
+    xcframework
+    set_github_release(
       repository_name: "onevcat/Kingfisher",
       api_token: ENV['GITHUB_TOKEN'],
       name: release_log[:title],
       tag_name: target_version,
       description: release_log[:text],
-      upload_assets: ["Kingfisher.framework.zip"]
-      )
-
-      pod_push
+      upload_assets: ["build/Kingfisher-#{target_version}.zip"]
+    )
+    
+    pod_push
   end
-
+  
   lane :podpush do
     pod_push
   end
-
+  
   lane :doc do |options|
-      target_version = options[:version]
-      Actions.sh("cd .. && jazzy \
-                        --clean \
-                        -x USE_SWIFT_RESPONSE_FILE=NO \
-                        --author \"Wei Wang\" \
-                        --author_url https://onevcat.com \
-                        --github_url https://github.com/onevcat/Kingfisher \
-                        --github-file-prefix https://github.com/onevcat/Kingfisher/tree/#{target_version} \
-                        --module-version #{target_version} \
-                        --module Kingfisher \
-                        --root-url http://onevcat.github.io/Kingfisher/ \
-                        --output docs/ \
-                        --theme fullwidth")
+    target_version = options[:version]
+    Actions.sh("cd .. && jazzy \
+      --clean \
+      -x USE_SWIFT_RESPONSE_FILE=NO \
+      --author \"Wei Wang\" \
+      --author_url https://onevcat.com \
+      --github_url https://github.com/onevcat/Kingfisher \
+      --github-file-prefix https://github.com/onevcat/Kingfisher/tree/#{target_version} \
+      --module-version #{target_version} \
+      --module Kingfisher \
+      --root-url http://onevcat.github.io/Kingfisher/ \
+      --output docs/ \
+      --theme fullwidth")
+  end
+  
+  lane :xcframework do |options|
+    target_version = "Kingfisher-#{options[:version]}"
+    supporting_root = "../build/#{target_version}/Supporting Files"
+    xcversion(version: "~> 11.0")
+    FileUtils.rm_rf '../build'
+    
+    frameworks = []
+    
+    ["macosx",
+     "iphoneos", 
+     "iphonesimulator", 
+     "appletvos", 
+     "appletvsimulator", 
+     "watchos", 
+     "watchsimulator"
+    ].each do |sdk|
+      archive_path = "build/Kingfisher-#{sdk}.xcarchive"
+      xcodebuild(
+        archive: true,
+        archive_path: archive_path,
+        scheme: "Kingfisher",
+        sdk: sdk,
+        build_settings: {
+          "BUILD_LIBRARY_FOR_DISTRIBUTION" => "YES",
+          "SKIP_INSTALL" => "NO"
+        }
+      )
+      frameworks.push("#{archive_path}/Products/Library/Frameworks/Kingfisher.framework")
+
+      dSYM_path = "../#{archive_path}/dSYMs/Kingfisher.framework.dSYM"
+      FileUtils.mkdir_p("#{supporting_root}/#{sdk}/dSYMs/")
+      FileUtils.cp_r(dSYM_path, "#{supporting_root}/#{sdk}/dSYMs/Kingfisher.framework.dSYM")
+
+      bitcode_symbol_map_path = "../#{archive_path}/BCSymbolMaps/"
+      if Dir.exist?(bitcode_symbol_map_path)
+        FileUtils.mkdir_p("#{supporting_root}/#{sdk}/BCSymbolMaps/")
+        FileUtils.cp_r(bitcode_symbol_map_path, "#{supporting_root}/#{sdk}")
+      end
+    end
+    # `xcodebuild` action in fastlane does not support `-create-xcframework` arg yet.
+    # Change it back to use fastlane action later when it is prepared.
+    framework_args = frameworks.map { |framework_path| "-framework '#{framework_path}'"}
+    args = "-create-xcframework #{framework_args.join(" ")} -output 'build/#{target_version}/Kingfisher.xcframework'"
+    Dir.chdir("..") do
+      Action.sh "xcodebuild #{args}"
+    end
+
+    zip(
+      path: "build/#{target_version}",
+      output_path: "build/#{target_version}.zip"
+    )
   end
 
   after_all do |lane|
-
+  
   end
 
   error do |lane, exception|
-
+  
   end
 end