diff options
Diffstat (limited to 'scripts/common_codegen.py')
| -rw-r--r-- | scripts/common_codegen.py | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/scripts/common_codegen.py b/scripts/common_codegen.py index 1e4d9700..d44cd643 100644 --- a/scripts/common_codegen.py +++ b/scripts/common_codegen.py @@ -19,6 +19,8 @@ # Author: Mark Lobodzinski <mark@lunarg.com> import os +import sys +import subprocess # Copyright text prefixing all headers (list of strings). prefixStrings = [ @@ -76,7 +78,37 @@ def GetFeatureProtect(interface): if provisional == 'true': return platform_dict['provisional'] +# Returns true if we are running in GitHub actions +# https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables +def IsGHA(): + if 'GITHUB_ACTION' in os.environ: + return True + return False + +# Points to the directory containing the top level CMakeLists.txt +PROJECT_SRC_DIR = os.path.abspath(os.path.join(os.path.split(os.path.abspath(__file__))[0], '..')) +if not os.path.isfile(f'{PROJECT_SRC_DIR}/CMakeLists.txt'): + print(f'PROJECT_SRC_DIR invalid! {PROJECT_SRC_DIR}') + sys.exit(1) # helper to define paths relative to the repo root -def repo_relative(path): +def RepoRelative(path): return os.path.abspath(os.path.join(os.path.dirname(__file__), '..', path)) + +# Runs a command in a directory and returns its return code. +# Directory is project root by default, or a relative path from project root +def RunShellCmd(command, start_dir = PROJECT_SRC_DIR, env=None, verbose=False): + # Flush stdout here. Helps when debugging on CI. + sys.stdout.flush() + + if start_dir != PROJECT_SRC_DIR: + start_dir = RepoRelative(start_dir) + cmd_list = command.split(" ") + + # Helps a lot when debugging CI issues + if IsGHA(): + verbose = True + + if verbose: + print(f'CICMD({cmd_list}, env={env})') + subprocess.check_call(cmd_list, cwd=start_dir, env=env)
\ No newline at end of file |
