-
Notifications
You must be signed in to change notification settings - Fork 222
/
package.rb
160 lines (132 loc) · 5.09 KB
/
package.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
require 'tmpdir'
module Pod
class Command
class Package < Command
self.summary = 'Package a podspec into a static library.'
self.arguments = [
CLAide::Argument.new('NAME', true),
CLAide::Argument.new('SOURCE', false)
]
def self.options
[
['--force', 'Overwrite existing files.'],
['--no-mangle', 'Do not mangle symbols of depedendant Pods.'],
['--embedded', 'Generate embedded frameworks.'],
['--library', 'Generate static libraries.'],
['--dynamic', 'Generate dynamic framework.'],
['--exclude-deps', 'Exclude symbols from dependencies.'],
['--configuration', 'Build the specified configuration (e.g. Debug). Defaults to Release'],
['--subspecs', 'Only include the given subspecs'],
['--spec-sources=private,https://github.com/CocoaPods/Specs.git', 'The sources to pull dependant ' \
'pods from (defaults to https://github.com/CocoaPods/Specs.git)']
]
end
def initialize(argv)
@embedded = argv.flag?('embedded')
@force = argv.flag?('force')
@library = argv.flag?('library')
@dynamic = argv.flag?('dynamic')
@mangle = argv.flag?('mangle', true)
@exclude_deps = argv.flag?('exclude-deps', false)
@name = argv.shift_argument
@source = argv.shift_argument
@spec_sources = argv.option('spec-sources', 'https://github.com/CocoaPods/Specs.git').split(',')
subspecs = argv.option('subspecs')
@subspecs = subspecs.split(',') unless subspecs.nil?
@config = argv.option('configuration', 'Release')
@source_dir = Dir.pwd
@spec = spec_with_path(@name)
@spec = spec_with_name(@name) unless @spec
super
end
def validate!
super
help! 'A podspec name or path is required.' unless @spec
help! 'podspec has binary-only depedencies, mangling not possible.' if @mangle && binary_only?(@spec)
help! '--exclude-deps option can only be used for static libraries' if @exclude_deps && @dynamic
end
def run
if @path.nil? || @spec.nil?
help! 'Unable to find a podspec with path or name.'
return
end
target_dir, work_dir = create_working_directory
return if target_dir.nil?
build_package
`mv "#{work_dir}" "#{target_dir}"`
Dir.chdir(@source_dir)
end
private
def build_in_sandbox(platform)
config.installation_root = Pathname.new(Dir.pwd)
config.sandbox_root = 'Pods'
static_sandbox = build_static_sandbox(@dynamic)
static_installer = install_pod(platform.name, static_sandbox)
if @dynamic
dynamic_sandbox = build_dynamic_sandbox(static_sandbox, static_installer)
install_dynamic_pod(dynamic_sandbox, static_sandbox, static_installer)
end
begin
perform_build(platform, static_sandbox, dynamic_sandbox)
ensure # in case the build fails; see Builder#xcodebuild.
Pathname.new(config.sandbox_root).rmtree
FileUtils.rm_f('Podfile.lock')
end
end
def build_package
builder = SpecBuilder.new(@spec, @source, @embedded, @dynamic)
newspec = builder.spec_metadata
@spec.available_platforms.each do |platform|
build_in_sandbox(platform)
newspec += builder.spec_platform(platform)
end
newspec += builder.spec_close
File.open(@spec.name + '.podspec', 'w') { |file| file.write(newspec) }
end
def create_target_directory
target_dir = "#{@source_dir}/#{@spec.name}-#{@spec.version}"
if File.exist? target_dir
if @force
Pathname.new(target_dir).rmtree
else
UI.puts "Target directory '#{target_dir}' already exists."
return nil
end
end
target_dir
end
def create_working_directory
target_dir = create_target_directory
return if target_dir.nil?
work_dir = Dir.tmpdir + '/cocoapods-' + Array.new(8) { rand(36).to_s(36) }.join
Pathname.new(work_dir).mkdir
full_path = Pathname.new(@path)
`cp -r #{full_path.parent} #{work_dir}`
Dir.chdir(work_dir)
[target_dir, work_dir]
end
def perform_build(platform, static_sandbox, dynamic_sandbox)
static_sandbox_root = config.sandbox_root.to_s
if @dynamic
static_sandbox_root = "#{static_sandbox_root}/#{static_sandbox.root.to_s.split('/').last}"
dynamic_sandbox_root = "#{config.sandbox_root}/#{dynamic_sandbox.root.to_s.split('/').last}"
end
builder = Pod::Builder.new(
@source_dir,
static_sandbox_root,
dynamic_sandbox_root,
static_sandbox.public_headers.root,
@spec,
@embedded,
@mangle,
@dynamic,
@config,
@exclude_deps
)
builder.build(platform, @library)
return unless @embedded
builder.link_embedded_resources
end
end
end
end