55 lines
1.8 KiB
Python
Executable File
55 lines
1.8 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
# Copyright (C) 2020 Igalia S.L.
|
|
#
|
|
# This program is free software; you can redistribute it and/or
|
|
# modify it under the terms of the GNU Lesser General Public
|
|
# License as published by the Free Software Foundation; either
|
|
# version 2.1 of the License, or (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
# Lesser General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU Lesser General Public
|
|
# License along with this program; if not, write to the
|
|
# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
# Boston, MA 02110-1301, USA.
|
|
|
|
import os
|
|
import subprocess
|
|
import sys
|
|
|
|
scriptdir = os.path.abspath(os.path.dirname(__file__))
|
|
SDK_PROJECT_PATH = os.path.join(scriptdir, "..", "buildstream")
|
|
PIPENV_PIPFILE = os.path.realpath(os.path.join(SDK_PROJECT_PATH, "Pipfile"))
|
|
|
|
def run_pipenv(args: list, **kw) -> subprocess.CompletedProcess:
|
|
local_env = {
|
|
"PIPENV_VENV_IN_PROJECT": "1",
|
|
"PIPENV_PIPFILE": PIPENV_PIPFILE
|
|
}
|
|
kw["env"] = os.environ
|
|
kw["env"].update(local_env)
|
|
return subprocess.run(["pipenv", ] + args, **kw)
|
|
|
|
def ensure_environment():
|
|
result = run_pipenv(["--venv",], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
|
if result.returncode != 0:
|
|
run_pipenv(["install"])
|
|
|
|
def run_bst(args: list) -> subprocess.CompletedProcess:
|
|
return run_pipenv(["run", "bst", "-C", SDK_PROJECT_PATH] + args)
|
|
|
|
def main(args: list) -> int:
|
|
ensure_environment()
|
|
if args[0] == "pipenv":
|
|
run_pipenv(args[1:])
|
|
else:
|
|
run_bst(args)
|
|
return 0
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main(sys.argv[1:]))
|