1#!/usr/bin/env bash
2
3# Copyright 2020 The Fuchsia Authors. All rights reserved.
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6
7# Executes the given python executable with PYTHONPATH set and captures
8# its output in a file. The first PYTHON_ARG should probably be the path
9# to a python script that writes something to stdout.
10# This is to let GN use the mesa python scripts that write headers to stdout,
11# and to support a custom PYTHONPATH.
12
13USAGE="Usage: $0 PYTHON_EXE PYTHONPATH OUT_FILE [PYTHON_ARGS...]"
14
15if [[ "$#" -lt "3" ]]; then
16    echo "${USAGE}" 1>&2;
17    exit 1
18fi
19
20PYTHON_EXE=${1}
21shift
22PYTHONPATH=${1}
23shift
24OUT=${1}
25shift
26
27# -S to decrease start-up time by not looking for site packages.
28env PYTHONPATH="${PYTHONPATH}" "${PYTHON_EXE}" -S "$@" > ${OUT}
29exit $?
30