Skip to content

Commit 8b8ca76

Browse files
wilhuffpaulb777
authored andcommitted
Rewrite pod_lib_lint as a ruby script (#3075)
* Find pod lib lint dependencies locally * Trigger travis for pod_lib_lint * Fix no local deps case * Add a script to print the local dependencies of a given podspec file. (#3072) * Make pod_local_deps.rb into pod_lib_lint.rb * Remove old pod_lib_lint.sh * Update usages of pod_lib_lint.sh to pod_lib_lint.rb * Add tracing to pod_lib_lint.rb * Only keep basenames in the seen set * Mark the current podspec seen * Handle the no deps case correctly
1 parent 836435d commit 8b8ca76

File tree

4 files changed

+170
-96
lines changed

4 files changed

+170
-96
lines changed

.travis.yml

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,18 @@ jobs:
3939
before_install:
4040
- ./scripts/if_changed.sh ./scripts/install_prereqs.sh
4141
script:
42-
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.sh FirebaseCore.podspec
43-
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.sh FirebaseCore.podspec --use-libraries
44-
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.sh FirebaseCore.podspec --use-modular-headers
42+
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.rb FirebaseCore.podspec
43+
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.rb FirebaseCore.podspec --use-libraries
44+
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.rb FirebaseCore.podspec --use-modular-headers
4545

4646
- stage: test
4747
env:
4848
- PROJECT=InstanceID PLATFORM=iOS METHOD=pod-lib-lint
4949
before_install:
5050
- ./scripts/if_changed.sh ./scripts/install_prereqs.sh
5151
script:
52-
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.sh FirebaseInstanceID.podspec --platforms=ios
53-
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.sh FirebaseInstanceID.podspec --platforms=tvos
52+
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.rb FirebaseInstanceID.podspec --platforms=ios
53+
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.rb FirebaseInstanceID.podspec --platforms=tvos
5454

5555
- stage: test
5656
env:
@@ -60,9 +60,9 @@ jobs:
6060
script:
6161
- travis_retry ./scripts/if_changed.sh ./scripts/build.sh $PROJECT $PLATFORM
6262
# The pod lib lint tests are fast enough that it's not worth a separate stage.
63-
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.sh FirebaseStorage.podspec --skip-tests
64-
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.sh FirebaseStorage.podspec --use-libraries --skip-tests
65-
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.sh FirebaseStorage.podspec --use-modular-headers --skip-tests
63+
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.rb FirebaseStorage.podspec --skip-tests
64+
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.rb FirebaseStorage.podspec --use-libraries --skip-tests
65+
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.rb FirebaseStorage.podspec --use-modular-headers --skip-tests
6666

6767
- stage: test
6868
env:
@@ -72,19 +72,19 @@ jobs:
7272
script:
7373
- travis_retry ./scripts/if_changed.sh ./scripts/build.sh $PROJECT $PLATFORM
7474
# The pod lib lint tests are fast enough that it's not worth a separate stage.
75-
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.sh FirebaseDatabase.podspec --skip-tests
76-
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.sh FirebaseDatabase.podspec --use-libraries --skip-tests
77-
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.sh FirebaseDatabase.podspec --use-modular-headers --skip-tests
75+
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.rb FirebaseDatabase.podspec --skip-tests
76+
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.rb FirebaseDatabase.podspec --use-libraries --skip-tests
77+
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.rb FirebaseDatabase.podspec --use-modular-headers --skip-tests
7878

7979
- stage: test
8080
env:
8181
- PROJECT=Functions PLATFORM=iOS METHOD=pod-lib-lint
8282
before_install:
8383
- ./scripts/if_changed.sh ./scripts/install_prereqs.sh
8484
script:
85-
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.sh FirebaseFunctions.podspec
86-
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.sh FirebaseFunctions.podspec --use-libraries
87-
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.sh FirebaseFunctions.podspec --use-modular-headers
85+
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.rb FirebaseFunctions.podspec
86+
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.rb FirebaseFunctions.podspec --use-libraries
87+
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.rb FirebaseFunctions.podspec --use-modular-headers
8888

8989
- stage: test
9090
env:
@@ -109,14 +109,14 @@ jobs:
109109
before_install:
110110
- ./scripts/if_changed.sh ./scripts/install_prereqs.sh
111111
script:
112-
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.sh GoogleUtilities.podspec
113-
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.sh FirebaseAnalyticsInterop.podspec
114-
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.sh FirebaseAuth.podspec
115-
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.sh FirebaseAuthInterop.podspec
116-
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.sh FirebaseDynamicLinks.podspec
117-
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.sh FirebaseMessaging.podspec
118-
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.sh FirebaseInAppMessaging.podspec
119-
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.sh FirebaseInAppMessagingDisplay.podspec
112+
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.rb GoogleUtilities.podspec
113+
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.rb FirebaseAnalyticsInterop.podspec
114+
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.rb FirebaseAuth.podspec
115+
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.rb FirebaseAuthInterop.podspec
116+
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.rb FirebaseDynamicLinks.podspec
117+
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.rb FirebaseMessaging.podspec
118+
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.rb FirebaseInAppMessaging.podspec
119+
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.rb FirebaseInAppMessagingDisplay.podspec
120120

121121
- stage: test
122122
env:
@@ -126,7 +126,7 @@ jobs:
126126
script:
127127
# Eliminate the one warning from BoringSSL when CocoaPods 1.6.0 is available.
128128
# The travis_wait is necessary because the command takes more than 10 minutes.
129-
- travis_wait 30 ./scripts/if_changed.sh ./scripts/pod_lib_lint.sh FirebaseFirestore.podspec --platforms=ios --allow-warnings --no-subspecs
129+
- travis_wait 30 ./scripts/if_changed.sh ./scripts/pod_lib_lint.rb FirebaseFirestore.podspec --platforms=ios --allow-warnings --no-subspecs
130130

131131
# pod lib lint to check build and warnings for static library build - only on cron jobs
132132
- stage: test
@@ -136,19 +136,19 @@ jobs:
136136
before_install:
137137
- ./scripts/install_prereqs.sh
138138
script:
139-
- travis_retry ./scripts/pod_lib_lint.sh GoogleUtilities.podspec --use-libraries
140-
- travis_retry ./scripts/pod_lib_lint.sh FirebaseAnalyticsInterop.podspec --use-libraries
141-
- travis_retry ./scripts/pod_lib_lint.sh FirebaseAuth.podspec --use-libraries
142-
- travis_retry ./scripts/pod_lib_lint.sh FirebaseAuthInterop.podspec --use-libraries
143-
- travis_retry ./scripts/pod_lib_lint.sh FirebaseDynamicLinks.podspec --use-libraries
139+
- travis_retry ./scripts/pod_lib_lint.rb GoogleUtilities.podspec --use-libraries
140+
- travis_retry ./scripts/pod_lib_lint.rb FirebaseAnalyticsInterop.podspec --use-libraries
141+
- travis_retry ./scripts/pod_lib_lint.rb FirebaseAuth.podspec --use-libraries
142+
- travis_retry ./scripts/pod_lib_lint.rb FirebaseAuthInterop.podspec --use-libraries
143+
- travis_retry ./scripts/pod_lib_lint.rb FirebaseDynamicLinks.podspec --use-libraries
144144
# The Protobuf dependency of FirebaseMessaging has warnings with --use-libraries
145-
- travis_retry ./scripts/pod_lib_lint.sh FirebaseMessaging.podspec --use-libraries --allow-warnings
146-
- travis_retry ./scripts/pod_lib_lint.sh FirebaseInAppMessaging.podspec --use-libraries
147-
- travis_retry ./scripts/pod_lib_lint.sh FirebaseInAppMessagingDisplay.podspec --use-libraries
148-
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.sh FirebaseInstanceID.podspec --use-libraries --platforms=ios
149-
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.sh FirebaseInstanceID.podspec --use-libraries --platforms=tvos
150-
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.sh FirebaseInstanceID.podspec --use-modular-headers --platforms=ios
151-
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.sh FirebaseInstanceID.podspec --use-modular-headers --platforms=tvos
145+
- travis_retry ./scripts/pod_lib_lint.rb FirebaseMessaging.podspec --use-libraries --allow-warnings
146+
- travis_retry ./scripts/pod_lib_lint.rb FirebaseInAppMessaging.podspec --use-libraries
147+
- travis_retry ./scripts/pod_lib_lint.rb FirebaseInAppMessagingDisplay.podspec --use-libraries
148+
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.rb FirebaseInstanceID.podspec --use-libraries --platforms=ios
149+
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.rb FirebaseInstanceID.podspec --use-libraries --platforms=tvos
150+
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.rb FirebaseInstanceID.podspec --use-modular-headers --platforms=ios
151+
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.rb FirebaseInstanceID.podspec --use-modular-headers --platforms=tvos
152152

153153
- stage: test
154154
if: type = cron
@@ -159,7 +159,7 @@ jobs:
159159
script:
160160
# TBD - non-portable path warnings
161161
# The travis_wait is necessary because the command takes more than 10 minutes.
162-
- travis_wait 45 ./scripts/pod_lib_lint.sh FirebaseFirestore.podspec --use-libraries --allow-warnings --no-subspecs
162+
- travis_wait 45 ./scripts/pod_lib_lint.rb FirebaseFirestore.podspec --use-libraries --allow-warnings --no-subspecs
163163

164164
# GoogleDataTransport unit tests and pod linting using the default Xcode version.
165165
- stage: test
@@ -169,7 +169,7 @@ jobs:
169169
- ./scripts/if_changed.sh ./scripts/install_prereqs.sh
170170
script:
171171
- travis_retry ./scripts/if_changed.sh ./scripts/build.sh $PROJECT $PLATFORM
172-
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.sh GoogleDataTransport.podspec
172+
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.rb GoogleDataTransport.podspec
173173

174174
# GoogleDataTransport integration tests using the default Xcode version.
175175
- stage: test
@@ -188,7 +188,7 @@ jobs:
188188
- ./scripts/if_changed.sh ./scripts/install_prereqs.sh
189189
script:
190190
- ./scripts/if_changed.sh ./scripts/build.sh $PROJECT $PLATFORM
191-
- ./scripts/if_changed.sh ./scripts/pod_lib_lint.sh GoogleDataTransportCCTSupport.podspec
191+
- ./scripts/if_changed.sh ./scripts/pod_lib_lint.rb GoogleDataTransportCCTSupport.podspec
192192

193193
# Daily test for symbol collisions between Firebase and CocoaPods.
194194
- stage: test

scripts/if_changed.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ fi
125125
# Always rebuild if Travis configuration and/or build scripts changed.
126126
check_changes '^.travis.yml'
127127
check_changes '^Gemfile.lock'
128-
check_changes '^scripts/(build|if_changed|install_prereqs).sh'
128+
check_changes '^scripts/(build|if_changed|install_prereqs|pod_lib_lint).(rb|sh)'
129129

130130
if [[ "$run" == true ]]; then
131131
"$@"

scripts/pod_lib_lint.rb

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
#!/usr/bin/env ruby
2+
3+
# Copyright 2019 Google
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
require 'cocoapods'
18+
require 'set'
19+
20+
# Enable ruby options after 'require' because cocoapods is noisy
21+
$VERBOSE = true # ruby -w
22+
#$DEBUG = true # ruby --debug
23+
24+
def usage()
25+
script = File.basename($0)
26+
STDERR.puts <<~EOF
27+
USAGE: #{script} podspec [options]
28+
29+
podspec is the podspec to lint
30+
31+
options can be any options for pod spec lint
32+
EOF
33+
end
34+
35+
def main(args)
36+
if args.size < 1 then
37+
usage()
38+
exit(1)
39+
end
40+
41+
command = %w(bundle exec pod lib lint)
42+
43+
# Figure out which dependencies are local
44+
podspec_file = args[0]
45+
deps = find_local_deps(podspec_file)
46+
arg = make_include_podspecs(deps)
47+
command.push(arg) if arg
48+
49+
command.push(*args)
50+
puts command.join(' ')
51+
exec(*command)
52+
end
53+
54+
# Loads all the specs (inclusing subspecs) from the given podspec file.
55+
def load_specs(podspec_file)
56+
trace('loading', podspec_file)
57+
results = []
58+
59+
spec = Pod::Spec.from_file(podspec_file)
60+
results.push(spec)
61+
62+
results.push(*spec.subspecs)
63+
return results
64+
end
65+
66+
# Finds all dependencies of the given list of specs
67+
def all_deps(specs)
68+
result = Set[]
69+
70+
specs.each do |spec|
71+
spec.dependencies.each do |dep|
72+
name = dep.name.sub(/\/.*/, '')
73+
result.add(name)
74+
end
75+
end
76+
77+
result = result.to_a
78+
trace(' deps', *result)
79+
return result
80+
end
81+
82+
# Given a podspec file, finds all local dependencies that have a local podspec
83+
# in the same directory. Modifies seen to include all seen podspecs, which
84+
# guarantees that a given podspec will only be processed once.
85+
def find_local_deps(podspec_file, seen = Set[])
86+
# Mark the current podspec seen to prevent a pod from depending upon itself
87+
# (as might happen if a subspec of the pod depends upon another subpsec of
88+
# the pod.
89+
seen.add(File.basename(podspec_file))
90+
91+
results = []
92+
spec_dir = File.dirname(podspec_file)
93+
94+
specs = load_specs(podspec_file)
95+
deps = all_deps(specs)
96+
97+
deps.each do |dep_name|
98+
dep_file = File.join(spec_dir, "#{dep_name}.podspec")
99+
if File.exist?(dep_file) then
100+
dep_podspec = File.basename(dep_file)
101+
if seen.add?(dep_podspec)
102+
# Depend on the podspec we found and any podspecs it depends upon.
103+
results.push(dep_podspec)
104+
results.push(*find_local_deps(dep_file, seen))
105+
end
106+
end
107+
end
108+
109+
return results
110+
end
111+
112+
# Returns an --include-podspecs argument that indicates the given deps are
113+
# locally available. Returns nil if deps is empty.
114+
def make_include_podspecs(deps)
115+
return nil if deps.empty?
116+
117+
if deps.size == 1 then
118+
deps_joined = deps[0]
119+
else
120+
deps_joined = "{" + deps.join(',') + "}"
121+
end
122+
return "--include-podspecs=#{deps_joined}"
123+
end
124+
125+
def trace(*args)
126+
return if not $DEBUG
127+
128+
STDERR.puts(args.join(' '))
129+
end
130+
131+
main(ARGV)

scripts/pod_lib_lint.sh

Lines changed: 0 additions & 57 deletions
This file was deleted.

0 commit comments

Comments
 (0)