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 |
Joanna Wang | c3dd924 | 2023-04-10 16:42:13 +0000 | [diff] [blame] | 40 | import platform |
Joanna Wang | 0a590f3 | 2023-04-07 17:51:12 +0000 | [diff] [blame] | 41 | import sys |
| 42 | import json |
| 43 | from pathlib import Path |
| 44 | |
| 45 | |
| 46 | def main(argv): |
| 47 | assert len(argv) == 1, 'One and only one arg expected.' |
Joanna Wang | c3dd924 | 2023-04-10 16:42:13 +0000 | [diff] [blame] | 48 | assert platform.system() == 'Linux', 'Non-linux OSs not supported yet.' |
Joanna Wang | 0a590f3 | 2023-04-07 17:51:12 +0000 | [diff] [blame] | 49 | destination = argv[0] |
| 50 | |
| 51 | # In case there is '~' in the destination string |
| 52 | destination = os.path.expanduser(destination) |
| 53 | |
| 54 | Path(destination).mkdir(parents=True, exist_ok=True) |
| 55 | |
Joanna Wang | c3dd924 | 2023-04-10 16:42:13 +0000 | [diff] [blame] | 56 | print(f'Copying {os.getcwd()} into {destination}') |
| 57 | cp = subprocess.Popen( |
| 58 | ['cp', '-a', os.path.join(os.getcwd(), '.'), destination], |
| 59 | stdout=subprocess.PIPE, |
| 60 | stderr=subprocess.PIPE) |
Joanna Wang | 0a590f3 | 2023-04-07 17:51:12 +0000 | [diff] [blame] | 61 | cp.wait() |
Joanna Wang | c3dd924 | 2023-04-10 16:42:13 +0000 | [diff] [blame] | 62 | print('Copying complete') |
Joanna Wang | 0a590f3 | 2023-04-07 17:51:12 +0000 | [diff] [blame] | 63 | |
Joanna Wang | c3dd924 | 2023-04-10 16:42:13 +0000 | [diff] [blame] | 64 | print(f'Deleting old {destination}/.gclient file') |
Joanna Wang | 0a590f3 | 2023-04-07 17:51:12 +0000 | [diff] [blame] | 65 | gclient_file = os.path.join(destination, '.gclient') |
| 66 | with open(gclient_file, 'r') as file: |
| 67 | data = file.read() |
| 68 | internal = "infra_internal" in data |
| 69 | |
| 70 | os.remove(gclient_file) |
| 71 | |
Joanna Wang | c3dd924 | 2023-04-10 16:42:13 +0000 | [diff] [blame] | 72 | print('Migrating to infra/infra_superproject') |
Joanna Wang | 0a590f3 | 2023-04-07 17:51:12 +0000 | [diff] [blame] | 73 | cmds = ['fetch', '--force'] |
| 74 | if internal: |
| 75 | cmds.append('infra_internal') |
Joanna Wang | c3dd924 | 2023-04-10 16:42:13 +0000 | [diff] [blame] | 76 | print('including internal code in checkout') |
Joanna Wang | 0a590f3 | 2023-04-07 17:51:12 +0000 | [diff] [blame] | 77 | else: |
| 78 | cmds.append('infra') |
| 79 | fetch = subprocess.Popen(cmds, cwd=destination) |
| 80 | fetch.wait() |
| 81 | |
| 82 | |
| 83 | if __name__ == '__main__': |
| 84 | sys.exit(main(sys.argv[1:])) |