create-release-package.rb 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #!/usr/bin/env ruby
  2. require 'fileutils'
  3. require 'pathname'
  4. require 'tmpdir'
  5. raise 'usage: create-release-package.rb destination_path version [xcode_versions]' unless ARGV.length >= 3
  6. DESTINATION = Pathname(ARGV[0])
  7. VERSION = ARGV[1]
  8. XCODE_VERSIONS = ARGV[2..]
  9. ROOT = Pathname(__FILE__).+('../..').expand_path
  10. BUILD_SH = Pathname(__FILE__).+('../../build.sh').expand_path
  11. PLATFORMS = %w{osx ios watchos tvos catalyst}
  12. VERBOSE = false
  13. def sh(*args)
  14. puts "executing: #{args.join(' ')}" if VERBOSE
  15. system(*args, VERBOSE ? {} : {:out => '/dev/null'}) || exit(1)
  16. end
  17. def platforms(xcode_version)
  18. if xcode_version.start_with? '15'
  19. %w{osx ios watchos tvos catalyst visionos}
  20. else
  21. %w{osx ios watchos tvos catalyst}
  22. end
  23. end
  24. def create_xcframework(root, xcode_version, configuration, name)
  25. prefix = "#{root}/#{xcode_version}"
  26. output = "#{prefix}/#{configuration}/#{name}.xcframework"
  27. files = Dir.glob "#{prefix}/#{configuration}/*/#{name}.xcframework/*/#{name}.framework"
  28. sh 'xcodebuild', '-create-xcframework', '-allow-internal-distribution',
  29. '-output', output, *files.flat_map {|f| ['-framework', f]}
  30. end
  31. def zip(name, *files)
  32. path = (DESTINATION + name).to_path
  33. FileUtils.rm_f path
  34. sh 'zip', '--symlinks', '-r', path, *files
  35. end
  36. puts "Packaging version #{VERSION} for Xcode versions #{XCODE_VERSIONS.join(', ')}"
  37. FileUtils.mkdir_p DESTINATION
  38. Dir.mktmpdir do |tmp|
  39. # The default temp directory is in /var, which is a symlink to /private/var
  40. # xcodebuild's relative path resolution breaks due to this and we need to
  41. # give it the fully resolved path
  42. tmp = File.realpath tmp
  43. for version in XCODE_VERSIONS
  44. puts "Extracting source binaries for Xcode #{version}"
  45. FileUtils.mkdir_p "#{tmp}/#{version}"
  46. Dir.chdir("#{tmp}/#{version}") do
  47. for platform in platforms(version)
  48. sh 'unzip', "#{ROOT}/realm-#{platform}-#{version}.zip"
  49. end
  50. end
  51. end
  52. for version in XCODE_VERSIONS
  53. puts "Creating Swift XCFrameworks for Xcode #{version}"
  54. create_xcframework tmp, version, 'Release', 'RealmSwift'
  55. end
  56. puts 'Creating Obj-C XCFrameworks'
  57. objc_xcode_version = XCODE_VERSIONS.last
  58. create_xcframework tmp, objc_xcode_version, 'Release', 'Realm'
  59. create_xcframework tmp, objc_xcode_version, 'Static', 'Realm'
  60. puts 'Creating release package'
  61. package_dir = "#{tmp}/realm-swift-#{VERSION}"
  62. FileUtils.mkdir_p package_dir
  63. sh 'cp', "#{ROOT}/LICENSE", package_dir
  64. sh 'unzip', "#{ROOT}/realm-examples.zip", '-d', package_dir
  65. for lang in %w(objc swift)
  66. File.write "#{package_dir}/#{lang}-docs.webloc", %Q{
  67. <?xml version="1.0" encoding="UTF-8"?>
  68. <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
  69. <plist version="1.0">
  70. <dict>
  71. <key>URL</key>
  72. <string>https://www.mongodb.com/docs/realm-sdks/${lang}/${version}</string>
  73. </dict>
  74. </plist>
  75. }
  76. end
  77. sh 'cp', '-Rca', "#{tmp}/#{objc_xcode_version}/Release/Realm.xcframework", "#{package_dir}"
  78. FileUtils.mkdir_p "#{package_dir}/static"
  79. sh 'cp', '-Rca', "#{tmp}/#{objc_xcode_version}/Static/Realm.xcframework", "#{package_dir}/static"
  80. for version in XCODE_VERSIONS
  81. FileUtils.mkdir_p "#{package_dir}/#{version}"
  82. sh 'cp', '-Rca', "#{tmp}/#{version}/Release/RealmSwift.xcframework", "#{package_dir}/#{version}"
  83. end
  84. Dir.chdir(tmp) do
  85. zip "realm-swift-#{VERSION}.zip", "realm-swift-#{VERSION}"
  86. end
  87. puts 'Creating SPM release zips'
  88. Dir.chdir "#{tmp}/#{objc_xcode_version}/Release" do
  89. zip 'Realm.spm.zip', "Realm.xcframework"
  90. end
  91. for version in XCODE_VERSIONS
  92. Dir.chdir "#{tmp}/#{version}/Release" do
  93. zip "RealmSwift@#{version}.spm.zip", 'RealmSwift.xcframework'
  94. end
  95. end
  96. puts 'Creating Carthage release zip'
  97. Dir.mktmpdir do |tmp2|
  98. Dir.chdir(tmp2) do
  99. sh 'cp', '-Rca', "#{tmp}/#{objc_xcode_version}/Release/Realm.xcframework", tmp2
  100. sh 'cp', '-Rca', "#{tmp}/#{objc_xcode_version}/Release/RealmSwift.xcframework", tmp2
  101. zip 'Carthage.xcframework.zip', 'Realm.xcframework', 'RealmSwift.xcframework'
  102. end
  103. end
  104. end