From 0a590f3e185c9541feeb75c5fd3b1bb68ffc0362 Mon Sep 17 00:00:00 2001 From: Joanna Wang Date: Fri, 7 Apr 2023 17:51:12 +0000 Subject: [PATCH] Add gclient conversion script. Bug: 1415507 Change-Id: I6e8c59f0089bd8108be5967245d47effd96b4036 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4402816 Commit-Queue: Joanna Wang Reviewed-by: Gavin Mak --- fetch_configs/infra.py | 1 + infra_to_superproject.py | 74 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 infra_to_superproject.py diff --git a/fetch_configs/infra.py b/fetch_configs/infra.py index efa50af93..08afd562d 100644 --- a/fetch_configs/infra.py +++ b/fetch_configs/infra.py @@ -17,6 +17,7 @@ class Infra(config_util.Config): return { 'alias': { 'config': 'infra_superproject', + 'props': [], }, } diff --git a/infra_to_superproject.py b/infra_to_superproject.py new file mode 100644 index 000000000..de4f26246 --- /dev/null +++ b/infra_to_superproject.py @@ -0,0 +1,74 @@ +#!/usr/bin/env python3 +# Copyright (c) 2023 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. +""" +Creates a new infra_superpoject gclient checkout based on an existing +infra or infra_internal checkout. + + Usage: + + (1) Commit any WIP changes in all infra repos: + `git commit -a -v -m "another commit" OR `git commit -a -v --amend` + + (2) Run `git rebase-update` and `gclient sync` and ensure all conflicts + are resolved. + + (3) In your gclient root directory (the one that contains a .gclient file), + run: + `python3 path/to/depot_tools/infra_to_superproject.py ` + example: + `cd ~/cr` # gclient root dir + `python3 depot_tools/infra_to_superproject.py ~/cr2` + + (4) `cd ` and check that everything looks like your original + gclient checkout. The file structure should be the same, your branches + and commits in repos should be copied over. + + (5) `sudo rm -rf ` + example: + `sudo rm -rf cr` + + (6) `mv ` + example: + `mv cr2 cr + +""" + +import subprocess +import os +import sys +import json +from pathlib import Path + + +def main(argv): + assert len(argv) == 1, 'One and only one arg expected.' + destination = argv[0] + + # In case there is '~' in the destination string + destination = os.path.expanduser(destination) + + Path(destination).mkdir(parents=True, exist_ok=True) + + cp = subprocess.Popen(['cp', '-a', os.getcwd() + '/.', destination]) + cp.wait() + + gclient_file = os.path.join(destination, '.gclient') + with open(gclient_file, 'r') as file: + data = file.read() + internal = "infra_internal" in data + + os.remove(gclient_file) + + cmds = ['fetch', '--force'] + if internal: + cmds.append('infra_internal') + else: + cmds.append('infra') + fetch = subprocess.Popen(cmds, cwd=destination) + fetch.wait() + + +if __name__ == '__main__': + sys.exit(main(sys.argv[1:]))