xref: /aosp_15_r20/external/angle/build/fuchsia/test/gs_util_wrapper.py (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1# Copyright 2024 The Chromium Authors
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4""" A simple wrapper of running gsutil.py from the depot_tools; all the
5functions in this module are running in a separated process. """
6
7import os
8import subprocess
9import sys
10
11from typing import List
12
13from common import DIR_SRC_ROOT
14
15
16def _find_gsutil() -> str:
17    """ Returns the location of the gsutil.py. """
18    sys.path.append(os.path.join(DIR_SRC_ROOT, 'build'))
19    # Do not pollute the environment, callers should not use find_depot_tools
20    # directly.
21    # pylint: disable=import-error, import-outside-toplevel
22    import find_depot_tools
23    # pylint: enable=import-error, import-outside-toplevel
24    sys.path.pop()
25    return os.path.join(find_depot_tools.DEPOT_TOOLS_PATH, 'gsutil.py')
26
27
28GSUTIL_PATH = _find_gsutil()
29
30
31def run_gsutil(args: List[str]) -> None:
32    """ Runs gsutil with |args| and throws CalledProcessError if the process
33    failed. """
34    return subprocess.run([sys.executable, GSUTIL_PATH] + args, check=True)
35