Joanna Wang | 0a590f3 | 2023-04-07 17:51:12 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | # Copyright (c) 2023 The Chromium Authors. All rights reserved. |
| 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
| 5 | """ |
| 6 | Creates a new infra_superpoject gclient checkout based on an existing |
| 7 | infra or infra_internal checkout. |
| 8 | |
| 9 | Usage: |
| 10 | |
| 11 | (1) Commit any WIP changes in all infra repos: |
| 12 | `git commit -a -v -m "another commit" OR `git commit -a -v --amend` |
| 13 | |
| 14 | (2) Run `git rebase-update` and `gclient sync` and ensure all conflicts |
| 15 | are resolved. |
| 16 | |
| 17 | (3) In your gclient root directory (the one that contains a .gclient file), |
| 18 | run: |
| 19 | `python3 path/to/depot_tools/infra_to_superproject.py <destination>` |
| 20 | example: |
| 21 | `cd ~/cr` # gclient root dir |
| 22 | `python3 depot_tools/infra_to_superproject.py ~/cr2` |
| 23 | |
| 24 | (4) `cd <destination>` and check that everything looks like your original |
| 25 | gclient checkout. The file structure should be the same, your branches |
| 26 | and commits in repos should be copied over. |
| 27 | |
| 28 | (5) `sudo rm -rf <old_directory_name>` |
| 29 | example: |
| 30 | `sudo rm -rf cr` |
| 31 | |
| 32 | (6) `mv <destination> <old_directory_name>` |
| 33 | example: |
| 34 | `mv cr2 cr |
| 35 | |
| 36 | """ |
| 37 | |
| 38 | import subprocess |
| 39 | import os |
| 40 | import sys |
| 41 | import json |
| 42 | from pathlib import Path |
| 43 | |
| 44 | |
| 45 | def main(argv): |
| 46 | assert len(argv) == 1, 'One and only one arg expected.' |
| 47 | destination = argv[0] |
| 48 | |
| 49 | # In case there is '~' in the destination string |
| 50 | destination = os.path.expanduser(destination) |
| 51 | |
| 52 | Path(destination).mkdir(parents=True, exist_ok=True) |
| 53 | |
| 54 | cp = subprocess.Popen(['cp', '-a', os.getcwd() + '/.', destination]) |
| 55 | cp.wait() |
| 56 | |
| 57 | gclient_file = os.path.join(destination, '.gclient') |
| 58 | with open(gclient_file, 'r') as file: |
| 59 | data = file.read() |
| 60 | internal = "infra_internal" in data |
| 61 | |
| 62 | os.remove(gclient_file) |
| 63 | |
| 64 | cmds = ['fetch', '--force'] |
| 65 | if internal: |
| 66 | cmds.append('infra_internal') |
| 67 | else: |
| 68 | cmds.append('infra') |
| 69 | fetch = subprocess.Popen(cmds, cwd=destination) |
| 70 | fetch.wait() |
| 71 | |
| 72 | |
| 73 | if __name__ == '__main__': |
| 74 | sys.exit(main(sys.argv[1:])) |