forked from firebase/firebase-ios-sdk
- Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpod_lib_lint.rb
executable file
·199 lines (163 loc) · 5.32 KB
/
pod_lib_lint.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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#!/usr/bin/env ruby
# Copyright 2019 Google
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
require'cocoapods'
require'set'
# Enable ruby options after 'require' because cocoapods is noisy
$VERBOSE =true# ruby -w
#$DEBUG = true # ruby --debug
defusage()
script=File.basename($0)
STDERR.puts<<~EOF
USAGE: #{script} podspec [options]
podspec is the podspec to lint
options can be any options for pod spec lint
script options:
--no-analyze: don't run Xcode analyze on this podspec
--ignore-local-podspecs: list of podspecs that should not be added to
"--include-podspecs" list. If not specified, then all podspec
dependencies will be passed to "--include-podspecs".
Example: --ignore-local-podspecs=FirebaseInstanceID.podspec,GoogleDataTransport.podspec
EOF
end
defmain(args)
ifargs.size < 1then
usage()
exit(1)
end
STDOUT.sync=true
command=%w(bundleexecpodliblint--sources=https://github.com/firebase/SpecsStaging.git,https://cdn.cocoapods.org/)
# Split arguments that need to be processed by the script itself and passed
# to the pod command.
pod_args=[]
ignore_local_podspecs=[]
analyze=true
args.eachdo |arg|
ifarg =~ /--ignore-local-podspecs=(.*)/
ignore_local_podspecs= $1.split(',')
elsifarg =~ /--no-analyze/
analyze=false
else
pod_args.push(arg)
end
end
podspec_file=pod_args[0]
# Figure out which dependencies are local
deps=find_local_deps(podspec_file,ignore_local_podspecs.to_set)
arg=make_include_podspecs(deps)
command.push(arg)ifarg
command.push('--analyze')ifanalyze
command.push(*pod_args)
putscommand.join(' ')
# Run the lib lint command in a thread.
pod_lint_status=1
t=Thread.newdo
with_removed_social_media_url(podspec_file)do
system(*command)
pod_lint_status= $?.exitstatus
end
end
# Print every minute since linting can run for >10m without output.
number_of_times_checked=0
whilet.alive?do
sleep1.0
number_of_times_checked += 1
if(number_of_times_checked % 60) == 0then
puts"Still working, running for #{number_of_times_checked / 60}min."
end
end
exit(pod_lint_status)
end
# Loads all the specs (inclusing subspecs) from the given podspec file.
defload_specs(podspec_file)
trace('loading',podspec_file)
results=[]
spec=Pod::Spec.from_file(podspec_file)
results.push(spec)
results.push(*spec.subspecs)
returnresults
end
# Finds all dependencies of the given list of specs
defall_deps(specs)
result=Set[]
specs.eachdo |spec|
spec.dependencies.eachdo |dep|
name=dep.name.sub(/\/.*/,'')
result.add(name)
end
end
result=result.to_a
trace(' deps', *result)
returnresult
end
# Given a podspec file, finds all local dependencies that have a local podspec
# in the same directory. Modifies seen to include all seen podspecs, which
# guarantees that a given podspec will only be processed once.
deffind_local_deps(podspec_file,seen=Set[])
# Mark the current podspec seen to prevent a pod from depending upon itself
# (as might happen if a subspec of the pod depends upon another subpsec of
# the pod.
seen.add(File.basename(podspec_file))
results=[]
spec_dir=File.dirname(podspec_file)
specs=load_specs(podspec_file)
deps=all_deps(specs)
deps.eachdo |dep_name|
dep_file=File.join(spec_dir,"#{dep_name}.podspec")
ifFile.exist?(dep_file)then
dep_podspec=File.basename(dep_file)
ifseen.add?(dep_podspec)
# Depend on the podspec we found and any podspecs it depends upon.
results.push(dep_podspec)
results.push(*find_local_deps(dep_file,seen))
end
end
end
returnresults
end
# Returns an --include-podspecs argument that indicates the given deps are
# locally available. Returns nil if deps is empty.
defmake_include_podspecs(deps)
returnnilifdeps.empty?
ifdeps.size == 1then
deps_joined=deps[0]
else
deps_joined="{" + deps.join(',') + "}"
end
return"--include-podspecs=#{deps_joined}"
end
deftrace(*args)
returnif not $DEBUG
STDERR.puts(args.join(' '))
end
# Edits the given podspec file to remove the social_media_url, yields, then
# restores the file to its original condition. Validating of the social URL
# can be very flaky (see #3416). Remove it from spec to let the actual tests
# pass.
defwith_removed_social_media_url(spec)
podspec_content=File.read(spec)
updated_podspec_content=
podspec_content.gsub("s.social_media_url = ","# s.social_media_url = ")
write_file(spec,updated_podspec_content)
yield
ensure
write_file(spec,podspec_content)
end
# Writes the text in +contents+ to the file named by +filename+.
defwrite_file(filename,contents)
File.open(filename,"w")do |file|
file.write(contents)
end
end
main(ARGV)