aboutsummaryrefslogtreecommitdiff
path: root/scripts/common_codegen.py
diff options
context:
space:
mode:
authorspencer-lunarg <spencer@lunarg.com>2025-12-15 17:06:35 -0500
committerSpencer Fricke <115671160+spencer-lunarg@users.noreply.github.com>2025-12-15 17:52:25 -0500
commit2a288f8284243645a8a50fe5f4c53209fdbd7905 (patch)
treea7ff397e0767ab22f88e2c17642b759c45341198 /scripts/common_codegen.py
parent1e62683bc7b7a46895843b6d67f72cb56b4ba42f (diff)
downloadusermoji-2a288f8284243645a8a50fe5f4c53209fdbd7905.tar.xz
scripts: Fix clang-format not running
Diffstat (limited to 'scripts/common_codegen.py')
-rw-r--r--scripts/common_codegen.py34
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