|
| 1 | +require "xcodeproj" |
| 2 | + |
| 3 | +PACKAGE_NAME = "RxKeyboard" |
| 4 | + |
| 5 | +module Pod |
| 6 | + class OS |
| 7 | + attr_accessor :deployment_target |
| 8 | + end |
| 9 | + |
| 10 | + class Spec |
| 11 | + attr_accessor :version |
| 12 | + attr_accessor :ios |
| 13 | + attr_accessor :osx |
| 14 | + attr_accessor :tvos |
| 15 | + attr_accessor :watchos |
| 16 | + |
| 17 | + def initialize |
| 18 | + @ios = OS.new |
| 19 | + @osx = OS.new |
| 20 | + @tvos = OS.new |
| 21 | + @watchos = OS.new |
| 22 | + yield self if block_given? |
| 23 | + end |
| 24 | + |
| 25 | + def method_missing(*args) |
| 26 | + end |
| 27 | + end |
| 28 | +end |
| 29 | + |
| 30 | +def read_podspec |
| 31 | + podspec_path = "#{PACKAGE_NAME}.podspec" |
| 32 | + podspec_content = open(podspec_path).read |
| 33 | + podspec = eval podspec_content |
| 34 | + return podspec |
| 35 | +end |
| 36 | + |
| 37 | +def run(command) |
| 38 | + puts command |
| 39 | + r = `#{command} 2>&1`.strip |
| 40 | + puts r if r and r.length > 0 |
| 41 | + return r |
| 42 | +end |
| 43 | + |
| 44 | +def prepare_xcconfig |
| 45 | + @config = "Config.xcconfig" |
| 46 | + podspec = read_podspec() |
| 47 | + ios_version = podspec.ios.deployment_target |
| 48 | + macos_version = podspec.osx.deployment_target |
| 49 | + tvos_version = podspec.tvos.deployment_target |
| 50 | + watchos_version = podspec.watchos.deployment_target |
| 51 | + |
| 52 | + def add_config(key, value) |
| 53 | + run "echo '#{key} = #{value}' >> #{@config}" |
| 54 | + end |
| 55 | + |
| 56 | + run "test -e #{@config} && rm #{@config}" |
| 57 | + add_config("IPHONEOS_DEPLOYMENT_TARGET", ios_version) if ios_version |
| 58 | + add_config("MACOSX_DEPLOYMENT_TARGET", macos_version) if macos_version |
| 59 | + add_config("TVOS_DEPLOYMENT_TARGET", tvos_version) if tvos_version |
| 60 | + add_config("WATCHOS_DEPLOYMENT_TARGET", watchos_version) if watchos_version |
| 61 | +end |
| 62 | + |
| 63 | +def modify_info |
| 64 | + def plistbuddy(info, command) |
| 65 | + return "/usr/libexec/PlistBuddy -c \"#{command}\" #{info}" |
| 66 | + end |
| 67 | + |
| 68 | + def plist_set(info, key, value) |
| 69 | + r = run plistbuddy(info, "Set #{key} #{value}") |
| 70 | + if r.include? "Not Exist" |
| 71 | + run plistbuddy(info, "Add #{key} string #{value}") |
| 72 | + end |
| 73 | + end |
| 74 | + |
| 75 | + podspec = read_podspec() |
| 76 | + version = podspec.version |
| 77 | + ios_version = podspec.ios.deployment_target |
| 78 | + macos_version = podspec.osx.deployment_target |
| 79 | + tvos_version = podspec.tvos.deployment_target |
| 80 | + watchos_version = podspec.watchos.deployment_target |
| 81 | + |
| 82 | + framework = "#{PACKAGE_NAME}.framework" |
| 83 | + ios_info = "./Carthage/Build/iOS/#{framework}/Info.plist" |
| 84 | + macos_info = "./Carthage/Build/Mac/#{framework}/Resources/Info.plist" |
| 85 | + tvos_info = "./Carthage/Build/tvOS/#{framework}/Info.plist" |
| 86 | + watchos_info = "./Carthage/Build/watchOS/#{framework}/Info.plist" |
| 87 | + |
| 88 | + plist_set(ios_info, "CFBundleVersion", version) if ios_version |
| 89 | + plist_set(macos_info, "CFBundleVersion", version) if macos_version |
| 90 | + plist_set(tvos_info, "CFBundleVersion", version) if tvos_version |
| 91 | + plist_set(watchos_info, "CFBundleVersion", version) if watchos_version |
| 92 | +end |
| 93 | + |
| 94 | +def remove_framework(target_name, framework_name) |
| 95 | + project = Xcodeproj::Project.open("#{PACKAGE_NAME}.xcodeproj") or return |
| 96 | + target = project.targets.find { |t| t.name == target_name } or return |
| 97 | + phase = target.build_phases.find { |p| |
| 98 | + p.kind_of?(Xcodeproj::Project::Object::PBXFrameworksBuildPhase) |
| 99 | + } or return |
| 100 | + file = phase.files_references.find { |f| |
| 101 | + f.path == framework_name |
| 102 | + } or return |
| 103 | + phase.remove_file_reference(file) |
| 104 | + project.save |
| 105 | +end |
| 106 | + |
| 107 | +case ARGV.first |
| 108 | +when "prepare_xcconfig" |
| 109 | + prepare_xcconfig() |
| 110 | + |
| 111 | +when "modify_info" |
| 112 | + modify_info() |
| 113 | + |
| 114 | +when "remove_unnecessary_frameworks" |
| 115 | + remove_framework(PACKAGE_NAME, "RxBlocking.framework") |
| 116 | + remove_framework(PACKAGE_NAME, "RxCocoaRuntime.framework") |
| 117 | +end |
0 commit comments