diff options
| author | spencer-lunarg <spencer@lunarg.com> | 2025-12-15 17:06:35 -0500 |
|---|---|---|
| committer | Spencer Fricke <115671160+spencer-lunarg@users.noreply.github.com> | 2025-12-15 17:52:25 -0500 |
| commit | 2a288f8284243645a8a50fe5f4c53209fdbd7905 (patch) | |
| tree | a7ff397e0767ab22f88e2c17642b759c45341198 /scripts | |
| parent | 1e62683bc7b7a46895843b6d67f72cb56b4ba42f (diff) | |
| download | usermoji-2a288f8284243645a8a50fe5f4c53209fdbd7905.tar.xz | |
scripts: Fix clang-format not running
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/common_codegen.py | 34 | ||||
| -rwxr-xr-x | scripts/generate_source.py | 6 |
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)) |
