|
| 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