Skip to content

Commit 5d63441

Browse files
authored
Feature/update podfile (#169)
have a python script to update podfile
1 parent b0583c5 commit 5d63441

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed

scripts/gha/build_testapps.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,18 @@ def _build_ios(
437437
dir_util.copy_tree(framework_src_path, framework_dest_path)
438438
framework_paths.append(framework_dest_path)
439439

440+
podfile_tool_path = os.path.join(
441+
root_dir, "scripts", "gha", "integration_testing", "update_podfile.py")
442+
sdk_podfile_path = os.path.join(
443+
root_dir, "ios_pod", "Podfile")
444+
app_podfile_path = os.path.join(
445+
project_dir, "Podfile")
446+
podfile_patcher_args = [
447+
"python", podfile_tool_path,
448+
"--sdk_podfile", sdk_podfile_path,
449+
"--app_podfile", app_podfile_path
450+
]
451+
_run(podfile_patcher_args)
440452
_run(["pod", "install"])
441453

442454
entitlements_path = os.path.join(
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Copyright 2020 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
r""" Update integration testapps' Podfiles to match the SDK's Podfile.
16+
Usage:
17+
python update_podfile.py --sdk_podfile ios_pod/Podfile \
18+
--app_podfile admob/integration_test/Podfile
19+
"""
20+
21+
from absl import app
22+
from absl import flags
23+
import re
24+
import fileinput
25+
26+
FLAGS = flags.FLAGS
27+
28+
flags.DEFINE_string(
29+
"sdk_podfile", None, "Path to CPP SDK's iOS podfile.",
30+
short_name="s")
31+
flags.DEFINE_string(
32+
"app_podfile", None, "Path to integration testapp's iOS podfile.",
33+
short_name="a")
34+
35+
36+
def main(argv):
37+
if len(argv) > 1:
38+
raise app.UsageError("Too many command-line arguments.")
39+
40+
sdk_podfile = FLAGS.sdk_podfile
41+
app_podfile = FLAGS.app_podfile
42+
43+
# split lines in Podfile by ' ' and ','
44+
split_pattern = ' |,'
45+
46+
# dict to store podName & podVersion from sdk's podfile
47+
pod_dict = {}
48+
with open(sdk_podfile) as f:
49+
for line in f:
50+
tokens = re.split(split_pattern, line)
51+
tokens = list(filter(None, tokens))
52+
if tokens[0] == 'pod':
53+
pod_dict[tokens[1]] = tokens[2]
54+
55+
# update podVersion in app's podfile
56+
new_lines = []
57+
with open(app_podfile) as f:
58+
for line in f:
59+
tokens = re.split(split_pattern, line)
60+
tokens = list(filter(None, tokens))
61+
if tokens[0] == 'pod' and tokens[1] in pod_dict:
62+
new_lines.append(line.replace(tokens[2], pod_dict[tokens[1]]))
63+
else:
64+
new_lines.append(line)
65+
66+
with open(app_podfile, "w") as out_file:
67+
out_file.writelines(new_lines)
68+
69+
70+
if __name__ == "__main__":
71+
flags.mark_flag_as_required("sdk_podfile")
72+
flags.mark_flag_as_required("app_podfile")
73+
app.run(main)

0 commit comments

Comments
 (0)