File: cipd.py

package info (click to toggle)
chromium 138.0.7204.157-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 6,071,864 kB
  • sloc: cpp: 34,936,859; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,967; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (58 lines) | stat: -rw-r--r-- 2,123 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# Copyright 2024 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Util for fetching recipe bundles from CIPD."""

import logging
import pathlib
import subprocess
import sys

_THIS_DIR = pathlib.Path(__file__).resolve().parent

# Bundles will be placed under //tools/utr/.bundles/.
_CIPD_ROOT_BASE_DIR = _THIS_DIR.joinpath('.bundles')

_CHROME_RECIPE_BUNDLE = (
    'infra_internal/recipe_bundles/chrome-internal.googlesource.com/'
    'chrome/tools/build')
_CHROMIUM_RECIPE_BUNDLE = (
    'infra/recipe_bundles/chromium.googlesource.com/chromium/tools/build')
_RECIPE_BUNDLE_VERSION = 'refs/heads/main'


def fetch_recipe_bundle(project, is_verbose):
  cipd_root_dir = _CIPD_ROOT_BASE_DIR.joinpath(project)
  # Assume cipd client is on PATH. Since we're in a standard Chromium checkout,
  # it should be a safe bet.
  exe = 'cipd.bat' if sys.platform == 'win32' else 'cipd'
  if not cipd_root_dir.exists():
    # Re-using the same cipd "root" that `gclient sync` uses in a checkout leads
    # to interference. (ie: `gclient sync` wiping out the bundle.) So just use
    # our own root for the bundle.
    cmd = [exe, 'init', '-force', str(cipd_root_dir)]
    logging.info('Initializing cipd root for bundle:')
    # Use the "basic_logger" here (and below) to avoid rich from coloring random
    # bits of the printed command.
    logging.getLogger('basic_logger').info(' '.join(cmd))
    subprocess.check_call(cmd)

  recipe_bundle_package = _CHROME_RECIPE_BUNDLE
  if project == 'chromium':
    recipe_bundle_package = _CHROMIUM_RECIPE_BUNDLE
  cmd = [
      exe,
      'install',
      recipe_bundle_package,
      _RECIPE_BUNDLE_VERSION,
      '-root',
      str(cipd_root_dir),
      '-log-level',
      'debug' if is_verbose else 'warning',
  ]
  logging.info('[cyan]Running bundle install command:[/]')
  logging.getLogger('basic_logger').info(' '.join(cmd))
  # The stdout of `cipd install` seems noisy, and all useful logs appear to go
  # to stderr anyway.
  subprocess.check_call(cmd, stdout=subprocess.DEVNULL)
  return cipd_root_dir