Class: Pod::Builder
- Inherits:
-
Object
- Object
- Pod::Builder
- Defined in:
- lib/cocoapods-packager/builder.rb
Instance Method Summary collapse
- #build(platform, library) ⇒ Object
- #build_framework(platform) ⇒ Object
- #build_library(platform, defines, output) ⇒ Object
- #build_static_lib_for_ios(static_libs, defines, output) ⇒ Object
- #build_static_lib_for_mac(static_libs, output) ⇒ Object
- #build_static_library(platform) ⇒ Object
- #build_with_mangling ⇒ Object
- #compile ⇒ Object
- #copy_headers ⇒ Object
- #copy_license ⇒ Object
- #copy_resources(platform) ⇒ Object
- #create_framework(platform) ⇒ Object
- #dependency_count ⇒ Object
- #expand_paths(path_specs) ⇒ Object
-
#initialize(source_dir, sandbox_root, public_headers_root, spec, embedded, mangle) ⇒ Builder
constructor
A new instance of Builder.
- #link_embedded_resources ⇒ Object
- #static_libs_in_sandbox(build_dir = 'build') ⇒ Object
- #xcodebuild(defines = '', args = '', build_dir = 'build') ⇒ Object
Constructor Details
#initialize(source_dir, sandbox_root, public_headers_root, spec, embedded, mangle) ⇒ Builder
Returns a new instance of Builder.
3 4 5 6 7 8 9 10 |
# File 'lib/cocoapods-packager/builder.rb', line 3 def initialize(source_dir, sandbox_root, public_headers_root, spec, , mangle) @source_dir = source_dir @sandbox_root = sandbox_root @public_headers_root = public_headers_root @spec = spec @embedded = @mangle = mangle end |
Instance Method Details
#build(platform, library) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/cocoapods-packager/builder.rb', line 12 def build(platform, library) if library build_static_library(platform) else build_framework(platform) end end |
#build_framework(platform) ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/cocoapods-packager/builder.rb', line 29 def build_framework(platform) UI.puts('Building framework') defines = compile create_framework(platform.name.to_s) copy_headers build_library(platform, defines, @fwk.versions_path + Pathname.new(@spec.name)) copy_license copy_resources(platform) end |
#build_library(platform, defines, output) ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/cocoapods-packager/builder.rb', line 52 def build_library(platform, defines, output) static_libs = static_libs_in_sandbox if platform.name == :ios build_static_lib_for_ios(static_libs, defines, output) else build_static_lib_for_mac(static_libs, output) end end |
#build_static_lib_for_ios(static_libs, defines, output) ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'lib/cocoapods-packager/builder.rb', line 62 def build_static_lib_for_ios(static_libs, defines, output) `libtool -static -o #{@sandbox_root}/build/package.a #{static_libs.join(' ')}` xcodebuild(defines, '-sdk iphonesimulator', 'build-sim') sim_libs = static_libs_in_sandbox('build-sim') `libtool -static -o #{@sandbox_root}/build-sim/package.a #{sim_libs.join(' ')}` `lipo #{@sandbox_root}/build/package.a #{@sandbox_root}/build-sim/package.a -create -output #{output}` end |
#build_static_lib_for_mac(static_libs, output) ⇒ Object
72 73 74 |
# File 'lib/cocoapods-packager/builder.rb', line 72 def build_static_lib_for_mac(static_libs, output) `libtool -static -o #{output} #{static_libs.join(' ')}` end |
#build_static_library(platform) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/cocoapods-packager/builder.rb', line 20 def build_static_library(platform) UI.puts('Building static library') defines = compile platform_path = Pathname.new(platform.name.to_s) platform_path.mkdir unless platform_path.exist? build_library(platform, defines, platform_path + Pathname.new("lib#{@spec.name}.a")) end |
#build_with_mangling ⇒ Object
76 77 78 79 80 81 82 |
# File 'lib/cocoapods-packager/builder.rb', line 76 def build_with_mangling UI.puts 'Mangling symbols' defines = Symbols.mangle_for_pod_dependencies(@spec.name, @sandbox_root) UI.puts 'Building mangled framework' xcodebuild(defines) return defines end |
#compile ⇒ Object
84 85 86 87 88 89 90 91 92 |
# File 'lib/cocoapods-packager/builder.rb', line 84 def compile xcodebuild if dependency_count > 0 && @mangle return build_with_mangling end '' end |
#copy_headers ⇒ Object
94 95 96 97 98 99 |
# File 'lib/cocoapods-packager/builder.rb', line 94 def copy_headers headers_source_root = "#{@public_headers_root}/#{@spec.name}" Dir.glob("#{headers_source_root}/**/*.h"). each { |h| `ditto #{h} #{@fwk.headers_path}/#{h.sub(headers_source_root, '')}` } end |
#copy_license ⇒ Object
101 102 103 104 105 |
# File 'lib/cocoapods-packager/builder.rb', line 101 def copy_license license_file = @spec.license[:file] license_file = 'LICENSE' unless license_file `cp "#{@sandbox_root}/#{@spec.name}/#{license_file}" .` end |
#copy_resources(platform) ⇒ Object
107 108 109 110 111 112 113 114 115 116 |
# File 'lib/cocoapods-packager/builder.rb', line 107 def copy_resources(platform) `cp -rp #{@sandbox_root}/build/*.bundle #{@fwk.resources_path} 2>&1` resources = (@spec.consumer(platform).resources) if resources.count == 0 @fwk.delete_resources return end `cp -rp #{resources.join(' ')} #{@fwk.resources_path}` end |
#create_framework(platform) ⇒ Object
118 119 120 121 |
# File 'lib/cocoapods-packager/builder.rb', line 118 def create_framework(platform) @fwk = Framework::Tree.new(@spec.name, platform, @embedded) @fwk.make end |
#dependency_count ⇒ Object
123 124 125 126 127 128 129 130 131 |
# File 'lib/cocoapods-packager/builder.rb', line 123 def dependency_count count = @spec.dependencies.count @spec.subspecs.each do |subspec| count += subspec.dependencies.count end count end |
#expand_paths(path_specs) ⇒ Object
133 134 135 136 137 |
# File 'lib/cocoapods-packager/builder.rb', line 133 def (path_specs) path_specs.map do |path_spec| Dir.glob(File.join(@source_dir, path_spec)) end end |
#link_embedded_resources ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/cocoapods-packager/builder.rb', line 40 def target_path = @fwk.root_path + Pathname.new('Resources') target_path.mkdir unless target_path.exist? Dir.glob(@fwk.resources_path.to_s + '/*').each do |resource| resource = Pathname.new(resource).relative_path_from(target_path) `ln -sf #{resource} #{target_path}` end end |
#static_libs_in_sandbox(build_dir = 'build') ⇒ Object
139 140 141 |
# File 'lib/cocoapods-packager/builder.rb', line 139 def static_libs_in_sandbox(build_dir='build') Dir.glob("#{@sandbox_root}/#{build_dir}/libPods-*.a") end |
#xcodebuild(defines = '', args = '', build_dir = 'build') ⇒ Object
143 144 145 |
# File 'lib/cocoapods-packager/builder.rb', line 143 def xcodebuild(defines = '', args = '', build_dir = 'build') `xcodebuild #{defines} CONFIGURATION_BUILD_DIR=#{build_dir} clean build #{args} -configuration Release -target Pods -project #{@sandbox_root}/Pods.xcodeproj 2>&1` end |