Class: GoNative::Plugins::IOS::BuildFramework
- Inherits:
-
Object
- Object
- GoNative::Plugins::IOS::BuildFramework
- Extended by:
- DSL::Serviceable
- Defined in:
- lib/gonative/plugins/ios/build_framework.rb
Constant Summary collapse
- BUILD_TEMPLATE_DIRECTORY_PATH =
File.(File.join(__dir__, '../../../..', 'templates', 'build', 'ios'))
Instance Attribute Summary collapse
-
#archs ⇒ Object
readonly
Returns the value of attribute archs.
-
#persist_build_dir ⇒ Object
readonly
Returns the value of attribute persist_build_dir.
-
#plugin_name ⇒ Object
readonly
Returns the value of attribute plugin_name.
Instance Method Summary collapse
- #add_classes(target, group) ⇒ Object
- #add_frameworks(target, group) ⇒ Object
- #add_headers(target, group) ⇒ Object
- #build_framework! ⇒ Object
- #call ⇒ Object
- #cd_build_dir ⇒ Object
- #chmod_frameworks_script! ⇒ Object
- #create_framework_proj ⇒ Object
- #deployment_target ⇒ Object
-
#initialize(podspec, archs, persist_build_dir) ⇒ BuildFramework
constructor
A new instance of BuildFramework.
- #move_template_files! ⇒ Object
- #run_pod_install ⇒ Object
- #setup_build_dir ⇒ Object
- #spec ⇒ Object
Constructor Details
#initialize(podspec, archs, persist_build_dir) ⇒ BuildFramework
Returns a new instance of BuildFramework.
19 20 21 22 23 24 25 |
# File 'lib/gonative/plugins/ios/build_framework.rb', line 19 def initialize(podspec, archs, persist_build_dir) raise Error, 'No podspec exists.' unless File.exist?(podspec) @plugin_name = File.basename(podspec, '.podspec') @archs = archs.gsub(',', ' ') @persist_build_dir = persist_build_dir end |
Instance Attribute Details
#archs ⇒ Object (readonly)
Returns the value of attribute archs.
17 18 19 |
# File 'lib/gonative/plugins/ios/build_framework.rb', line 17 def archs @archs end |
#persist_build_dir ⇒ Object (readonly)
Returns the value of attribute persist_build_dir.
17 18 19 |
# File 'lib/gonative/plugins/ios/build_framework.rb', line 17 def persist_build_dir @persist_build_dir end |
#plugin_name ⇒ Object (readonly)
Returns the value of attribute plugin_name.
17 18 19 |
# File 'lib/gonative/plugins/ios/build_framework.rb', line 17 def plugin_name @plugin_name end |
Instance Method Details
#add_classes(target, group) ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/gonative/plugins/ios/build_framework.rb', line 72 def add_classes(target, group) classes_group = group.new_group('Classes', 'Classes') references = Dir.glob("../#{plugin_name}/Classes/**/*.{m,swift}").map do |file| classes_group.new_file("../../#{file}") end target.add_file_references(references) end |
#add_frameworks(target, group) ⇒ Object
80 81 82 83 84 85 86 87 88 |
# File 'lib/gonative/plugins/ios/build_framework.rb', line 80 def add_frameworks(target, group) frameworks_group = group.new_group('Frameworks', 'Frameworks') references = Dir.glob("../#{plugin_name}/Frameworks/*.{framework,xcframework}").map do |file| frameworks_group.new_file("../../#{file}") end return unless references.length references.each { |ref| target.frameworks_build_phase.add_file_reference(ref) } end |
#add_headers(target, group) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/gonative/plugins/ios/build_framework.rb', line 90 def add_headers(target, group) headers_group = group.new_group('Headers', 'Headers') references = Dir.glob("../#{plugin_name}/Classes/**/*.h").map do |file| headers_group.new_file("../../#{file}") end header_files = target.add_file_references(references) header_files << target.headers_build_phase.add_file_reference(group.new_file("../#{plugin_name}-umbrella.h")) header_files.each do |header| header.settings = { 'ATTRIBUTES' => ['Public'] } end end |
#build_framework! ⇒ Object
123 124 125 126 127 128 |
# File 'lib/gonative/plugins/ios/build_framework.rb', line 123 def build_framework! Utils::UI.info 'Building framework' return if system('sh create-framework.sh >/dev/null 2>/dev/null') raise Error, 'Error building framework. Please run the create-framework file manually to fix any errors' end |
#call ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/gonative/plugins/ios/build_framework.rb', line 27 def call created_build_dir = cd_build_dir setup_build_dir if created_build_dir build_framework! ensure FileUtils.cd('..') FileUtils.rm_rf('build') unless persist_build_dir end |
#cd_build_dir ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/gonative/plugins/ios/build_framework.rb', line 36 def cd_build_dir build_dir = File.join(FileUtils.pwd, 'build') return false if File.exist?(build_dir) FileUtils.mkdir(build_dir) FileUtils.cd(build_dir) true end |
#chmod_frameworks_script! ⇒ Object
119 120 121 |
# File 'lib/gonative/plugins/ios/build_framework.rb', line 119 def chmod_frameworks_script! FileUtils.chmod 0755, 'create-framework.sh' end |
#create_framework_proj ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/gonative/plugins/ios/build_framework.rb', line 52 def create_framework_proj proj = Xcodeproj::Project.new(FileUtils.pwd) target = proj.new_target(:framework, plugin_name.to_s, :ios, deployment_target) main_group = proj.new_group(plugin_name, plugin_name) add_classes(target, main_group) add_frameworks(target, main_group) add_headers(target, main_group) target.build_configurations.each do |config| config.build_settings['INFOPLIST_FILE'] = 'Info.plist' config.build_settings['MARKETING_VERSION'] = spec.version config.build_settings['MODULEMAP_FILE'] = "#{plugin_name}.modulemap" config.build_settings['PRODUCT_BUNDLE_IDENTIFIER'] = "org.cocoapods.#{plugin_name}" config.build_settings['DEBUG_INFORMATION_FORMAT'] = 'dwarf-with-dsym' end proj.save("#{plugin_name}.xcodeproj") end |
#deployment_target ⇒ Object
130 131 132 |
# File 'lib/gonative/plugins/ios/build_framework.rb', line 130 def deployment_target spec.deployment_target('ios') || '15.5' end |
#move_template_files! ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/gonative/plugins/ios/build_framework.rb', line 102 def move_template_files! plugin_dependencies = spec.dependencies.map do |d| ["pod '#{d.name}'", "'#{d.requirement}'"].compact.join(', ') end * "\n\t" FileUtils.cp_r("#{BUILD_TEMPLATE_DIRECTORY_PATH}/.", '.') headers = Dir.glob("../#{plugin_name}/Classes/**/*.h").map { |f| "#import \"#{File.basename(f)}\"" } * "\n" Utils::TemplateInflator.new(plugin_name: plugin_name, plugin_dependencies: plugin_dependencies, plugin_headers: headers, archs: archs, deployment_target: deployment_target).call end |
#run_pod_install ⇒ Object
115 116 117 |
# File 'lib/gonative/plugins/ios/build_framework.rb', line 115 def run_pod_install system 'pod install' end |
#setup_build_dir ⇒ Object
45 46 47 48 49 50 |
# File 'lib/gonative/plugins/ios/build_framework.rb', line 45 def setup_build_dir create_framework_proj move_template_files! run_pod_install chmod_frameworks_script! end |
#spec ⇒ Object
134 135 136 |
# File 'lib/gonative/plugins/ios/build_framework.rb', line 134 def spec @spec ||= Pod::Specification.from_file("../#{plugin_name}.podspec") end |