mirror of
https://github.com/kovidgoyal/kitty.git
synced 2026-08-04 14:46:03 +00:00
Only validate newly built files
This commit is contained in:
parent
1492278494
commit
9f4499419c
2 changed files with 36 additions and 33 deletions
|
|
@ -295,7 +295,7 @@ def commands_to_compile_to_glsl(sources: dict[str, SlangFile], build_dir: str, d
|
|||
dest = f'{base_dest}.{v}.glsl'
|
||||
c = list(cmd)
|
||||
if sp.name:
|
||||
dest = f'{base_dest}{sp.filename_insert}.{ep.stage.name}.glsl'
|
||||
dest = f'{base_dest}{sp.filename_insert}.{v}.glsl'
|
||||
c.insert(-1, f'{base_dest}.{sp.name}.slang-module')
|
||||
c += extra_cmd + ['-entry', ep.name, '-stage', ep.stage.name, '-o', dest]
|
||||
output_mtime = safe_mtime(dest)
|
||||
|
|
@ -445,6 +445,9 @@ def compile_builtin_shaders(build_dir: str, dest_dir: str, parallel_run: Paralle
|
|||
# Now run all commands
|
||||
parallel_run(chain(spirv_commands, glsl_commands))
|
||||
fixup_opengl_files(*built_glsl_files)
|
||||
if shutil.which('glslangValidator'):
|
||||
from kitty.shaders.validate_shaders import validate_glsl_files
|
||||
validate_glsl_files(built_glsl_files)
|
||||
|
||||
|
||||
def main() -> None:
|
||||
|
|
@ -462,10 +465,6 @@ def main() -> None:
|
|||
needed.append(Command(desc, cmd, lambda: True))
|
||||
parallel_run(needed)
|
||||
compile_builtin_shaders(sys.argv[-2], sys.argv[-1], prun)
|
||||
if shutil.which('glslangValidator'):
|
||||
from kitty.shaders.validate_shaders import validate_glsl
|
||||
validate_glsl('shaders')
|
||||
|
||||
|
||||
def test_slang_build() -> None:
|
||||
import subprocess
|
||||
|
|
|
|||
|
|
@ -3,38 +3,20 @@ import subprocess
|
|||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
# Map the custom extensions to the required glslangValidator stage strings
|
||||
stage_mapping = {
|
||||
'.vert.glsl': 'vert',
|
||||
'.frag.glsl': 'frag',
|
||||
'.vertex.glsl': 'vert',
|
||||
'.fragment.glsl': 'frag',
|
||||
}
|
||||
|
||||
def validate_glsl(directory_path: str = '.', verbose: bool = False) -> None:
|
||||
'''
|
||||
Validates all GLSL shaders in the specified directory with names matching
|
||||
name.vert.glsl or name.frag.glsl using glslangValidator.
|
||||
'''
|
||||
target_dir = Path(directory_path)
|
||||
|
||||
if not target_dir.is_dir():
|
||||
raise SystemExit(f"Error: Directory '{directory_path}' does not exist.")
|
||||
|
||||
# Map the custom extensions to the required glslangValidator stage strings
|
||||
stage_mapping = {
|
||||
'.vert.glsl': 'vert',
|
||||
'.frag.glsl': 'frag'
|
||||
}
|
||||
|
||||
# Find all files matching the patterns
|
||||
shader_files: list[Path] = []
|
||||
for ext in stage_mapping.keys():
|
||||
shader_files.extend(target_dir.glob(f'*{ext}'))
|
||||
|
||||
if not shader_files:
|
||||
if verbose:
|
||||
print(f"No matching shaders (*.vert.glsl or *.frag.glsl) found in '{target_dir}'.")
|
||||
return
|
||||
|
||||
def validate_glsl_files(shader_files: list[str], verbose: bool = False) -> None:
|
||||
error_count = 0
|
||||
print(f"Scanning directory: {target_dir.resolve()}\n" + "-" * 50)
|
||||
|
||||
# Process each shader file
|
||||
for file_path in sorted(shader_files):
|
||||
for file_path in sorted(Path(f) for f in shader_files):
|
||||
# Identify extension matching suffix
|
||||
matched_ext = next(ext for ext in stage_mapping if file_path.name.endswith(ext))
|
||||
stage = stage_mapping[matched_ext]
|
||||
|
|
@ -61,6 +43,28 @@ def validate_glsl(directory_path: str = '.', verbose: bool = False) -> None:
|
|||
raise SystemExit(f"Failure: {error_count} shader(s) failed validation.")
|
||||
|
||||
|
||||
def validate_glsl_dir(directory_path: str, verbose: bool = False) -> None:
|
||||
'''
|
||||
Validates all GLSL shaders in the specified directory with names matching
|
||||
name.vert.glsl or name.frag.glsl using glslangValidator.
|
||||
'''
|
||||
target_dir = Path(directory_path)
|
||||
|
||||
if not target_dir.is_dir():
|
||||
raise SystemExit(f"Error: Directory '{directory_path}' does not exist.")
|
||||
|
||||
# Find all files matching the patterns
|
||||
shader_files: list[Path] = []
|
||||
for ext in stage_mapping.keys():
|
||||
shader_files.extend(target_dir.glob(f'*{ext}'))
|
||||
|
||||
if not shader_files:
|
||||
if verbose:
|
||||
print(f"No matching shaders (*.vert.glsl or *.frag.glsl) found in '{target_dir}'.")
|
||||
return
|
||||
validate_glsl_files(shader_files)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
dir_to_scan = sys.argv[1] if len(sys.argv) > 1 else 'shaders'
|
||||
validate_glsl(dir_to_scan, verbose=True)
|
||||
validate_glsl_dir(dir_to_scan, verbose=True)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue