|
| 1 | +#!/usr/bin/env python3 |
| 2 | +# Copyright (c) The Bitcoin Core developers |
| 3 | +# Distributed under the MIT software license, see the accompanying |
| 4 | +# file COPYING or https://opensource.org/license/mit/. |
| 5 | + |
| 6 | +import os |
| 7 | +import shlex |
| 8 | +import subprocess |
| 9 | +import sys |
| 10 | + |
| 11 | + |
| 12 | +def run(cmd, **kwargs): |
| 13 | + print("+ " + shlex.join(cmd), flush=True) |
| 14 | + try: |
| 15 | + return subprocess.run(cmd, check=True, **kwargs) |
| 16 | + except Exception as e: |
| 17 | + sys.exit(e) |
| 18 | + |
| 19 | + |
| 20 | +def main(): |
| 21 | + print("Export only allowed settings:") |
| 22 | + settings = run( |
| 23 | + ["bash", "-c", "grep export ./ci/test/00_setup_env*.sh"], |
| 24 | + stdout=subprocess.PIPE, |
| 25 | + text=True, |
| 26 | + encoding="utf8", |
| 27 | + ).stdout.splitlines() |
| 28 | + settings = set(l.split("=")[0].split("export ")[1] for l in settings) |
| 29 | + # Add this one manually, because it is the only one set inside the |
| 30 | + # container that also allows external overwrites |
| 31 | + settings.add("BASE_BUILD_DIR") |
| 32 | + |
| 33 | + # Append $USER to /tmp/env to support multi-user systems and $CONTAINER_NAME |
| 34 | + # to allow support starting multiple runs simultaneously by the same user. |
| 35 | + env_file = "/tmp/env-{u}-{c}".format( |
| 36 | + u=os.getenv("USER"), |
| 37 | + c=os.getenv("CONTAINER_NAME"), |
| 38 | + ) |
| 39 | + with open(env_file, "w", encoding="utf8") as file: |
| 40 | + for k, v in os.environ.items(): |
| 41 | + if k in settings: |
| 42 | + file.write(f"{k}={v}\n") |
| 43 | + run(["cat", env_file]) |
| 44 | + |
| 45 | + run(["./ci/test/02_run_container.sh"]) # run the remainder |
| 46 | + |
| 47 | + |
| 48 | +if __name__ == "__main__": |
| 49 | + main() |
0 commit comments