aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/common_codegen.py34
-rwxr-xr-xscripts/generate_source.py6
2 files changed, 36 insertions, 4 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
diff --git a/scripts/generate_source.py b/scripts/generate_source.py
index 82bc213e..59314533 100755
--- a/scripts/generate_source.py
+++ b/scripts/generate_source.py
@@ -177,7 +177,7 @@ def main(argv):
group.add_argument('-o', action='store', dest='directory', help='Create target and related files in specified directory')
args = parser.parse_args(argv)
- repo_dir = common_codegen.repo_relative('.')
+ repo_dir = common_codegen.RepoRelative('.')
registry = os.path.abspath(os.path.join(args.registry, 'vk.xml'))
video_registry = os.path.abspath(os.path.join(args.registry, 'video.xml'))
@@ -255,7 +255,7 @@ def main(argv):
# write out the header version used to generate the code to a checked in CMake file
if args.generated_version:
json_files = []
- json_files.append(common_codegen.repo_relative('icd/VkICD_mock_icd.json.in'))
+ json_files.append(common_codegen.RepoRelative('icd/VkICD_mock_icd.json.in'))
for json_file in json_files:
with open(json_file) as f:
data = json.load(f)
@@ -266,7 +266,7 @@ def main(argv):
f.write(json.dumps(data, indent=4))
# Update the CMake project version
- with open(common_codegen.repo_relative('CMakeLists.txt'), "r+") as f:
+ with open(common_codegen.RepoRelative('CMakeLists.txt'), "r+") as f:
data = f.read()
f.seek(0)
f.write(re.sub("project.*VERSION.*", f"project(Vulkan-Tools VERSION {args.generated_version})", data))