blob: de4f262469bbeeafa11cd0ce8701e57c2d1bada1 [file] [log] [blame]
Joanna Wang0a590f32023-04-07 17:51:12 +00001#!/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"""
6Creates a new infra_superpoject gclient checkout based on an existing
7infra 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
38import subprocess
39import os
40import sys
41import json
42from pathlib import Path
43
44
45def 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
73if __name__ == '__main__':
74 sys.exit(main(sys.argv[1:]))