Skip to content

Commit

Permalink
Raise an exception on compilation failures in tests but not in the `g…
Browse files Browse the repository at this point in the history
…enerate` script (#16)
  • Loading branch information
ppenenko authored Dec 14, 2024
1 parent 58d560b commit f992eae
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
32 changes: 22 additions & 10 deletions src/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,23 @@ def generate(self, material, primitive):
def compile(self, to_glsl : bool) -> str:
pass

def _compile_shader(shader, to_glsl):
def _compile_shader(
shader,
to_glsl : bool,
ignore_compile_errors : bool
) -> str:
'''
Helper function to compile a shader in a process pool.
Without it, the pool would not be able to pickle the method.
'''
return shader.compile(to_glsl)
return shader.compile(to_glsl, ignore_compile_errors)

class _HlslShader(_Shader):
@abc.abstractmethod
def _get_hlsl_profile():
pass

def compile(self, to_glsl : bool) -> str:
def compile(self, to_glsl : bool, ignore_compile_errors : bool) -> str:
log = io.StringIO()
log, sys.stdout = sys.stdout, log

Expand Down Expand Up @@ -99,7 +103,8 @@ def compile(self, to_glsl : bool) -> str:
output_path = spv_path
)
except subprocess.CalledProcessError as err:
pass
if not ignore_compile_errors:
raise err

log, sys.stdout = sys.stdout, log
return log.getvalue()
Expand Down Expand Up @@ -149,7 +154,7 @@ def _generate(self, shader_file, material, primitive):
)

class _GlslShader(_Shader):
def compile(self, to_glsl : bool) -> str:
def compile(self, to_glsl : bool, ignore_compile_errors : bool ) -> str:
log = io.StringIO()
log, sys.stdout = sys.stdout, log

Expand All @@ -162,7 +167,8 @@ def compile(self, to_glsl : bool) -> str:
output_path = glsl_output_path
)
except subprocess.CalledProcessError as err:
pass
if not ignore_compile_errors:
raise err

log, sys.stdout = sys.stdout, log
return log.getvalue()
Expand Down Expand Up @@ -231,7 +237,8 @@ def generate(
compile : bool,
to_glsl : bool,
skip_codegen : bool,
serial : bool
serial : bool,
ignore_compile_errors : bool
):
if not gltf_dir_path.is_dir():
raise NotADirectoryError(gltf_dir_path)
Expand Down Expand Up @@ -272,14 +279,18 @@ def generate(

if serial:
for shader in shaders:
log = shader.compile(to_glsl = to_glsl)
log = shader.compile(
to_glsl = to_glsl,
ignore_compile_errors = ignore_compile_errors
)
print(log, end = '')
else:
with mp.Pool() as pool:
for log in pool.imap_unordered(
functools.partial(
_compile_shader,
to_glsl = to_glsl
to_glsl = to_glsl,
ignore_compile_errors = ignore_compile_errors
),
shaders
):
Expand Down Expand Up @@ -320,5 +331,6 @@ def generate(
compile = args.compile,
to_glsl = args.to_glsl,
skip_codegen = args.skip_codegen,
serial = args.serial
serial = args.serial,
ignore_compile_errors = True # just collect all errors in stdout
)
3 changes: 2 additions & 1 deletion tests/test_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@ def test_generate(self):
compile = True,
to_glsl = False,
skip_codegen = False,
serial = False
serial = False,
ignore_compile_errors = False
)

0 comments on commit f992eae

Please sign in to comment.