xref: /aosp_15_r20/external/angle/build/fuchsia/test/publish_package.py (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1# Copyright 2022 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"""Implements commands for managing Fuchsia repos via the ffx tool."""
5
6import argparse
7
8from typing import Iterable
9
10from common import run_ffx_command
11
12
13def publish_packages(packages: Iterable[str],
14                     repo: str,
15                     new_repo: bool = False) -> None:
16    """Publish packages to a repo directory, initializing it if necessary."""
17    if new_repo:
18        run_ffx_command(cmd=['repository', 'create', repo])
19
20    args = ['repository', 'publish']
21    for package in packages:
22        args += ['--package-archive', package]
23    args += [repo]
24    run_ffx_command(cmd=args)
25
26
27def register_package_args(parser: argparse.ArgumentParser,
28                          allow_temp_repo: bool = False) -> None:
29    """Register common arguments for package publishing."""
30    package_args = parser.add_argument_group(
31        'package', 'Arguments for package publishing.')
32    package_args.add_argument('--packages',
33                              action='append',
34                              help='Paths of the package archives to install')
35    package_args.add_argument('--repo',
36                              help='Directory packages will be published to.')
37    package_args.add_argument('--purge-repo',
38                              action='store_true',
39                              help='If clear the content in the repo.')
40    if allow_temp_repo:
41        package_args.add_argument(
42            '--no-repo-init',
43            action='store_true',
44            default=False,
45            help='Do not initialize the package repository.')
46