xref: /aosp_15_r20/external/executorch/.ci/docker/common/utils.sh (revision 523fa7a60841cd1ecfb9cc4201f1ca8b03ed023a)
1#!/bin/bash
2# Copyright (c) Meta Platforms, Inc. and affiliates.
3# All rights reserved.
4#
5# This source code is licensed under the BSD-style license found in the
6# LICENSE file in the root directory of this source tree.
7
8as_ci_user() {
9  # NB: unsetting the environment variables works around a conda bug
10  #     https://github.com/conda/conda/issues/6576
11  # NB: Pass on PATH and LD_LIBRARY_PATH to sudo invocation
12  # NB: This must be run from a directory that the user has access to
13  sudo -E -H -u ci-user env -u SUDO_UID -u SUDO_GID -u SUDO_COMMAND -u SUDO_USER env "PATH=${PATH}" "LD_LIBRARY_PATH=${LD_LIBRARY_PATH:-}" "$@"
14}
15
16conda_install() {
17  # Ensure that the install command don't upgrade/downgrade Python
18  # This should be called as
19  #   conda_install pkg1 pkg2 ... [-c channel]
20  as_ci_user conda install -q -n "py_${PYTHON_VERSION}" -y python="${PYTHON_VERSION}" "$@"
21}
22
23conda_run() {
24  as_ci_user conda run -n "py_${PYTHON_VERSION}" --no-capture-output "$@"
25}
26
27pip_install() {
28  as_ci_user conda run -n "py_${PYTHON_VERSION}" pip install --progress-bar off "$@"
29}
30