Skip to content

Commit db85b9a

Browse files
authored
oslc -Werror (#862)
This flag to oslc will treat all warnings issued as if they were errors.
1 parent b036b11 commit db85b9a

8 files changed

Lines changed: 40 additions & 5 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ TESTSUITE ( aastep allowconnect-err and-or-not-synonyms
310310
vararray-connect vararray-default
311311
vararray-deserialize vararray-param
312312
vecctr vector
313-
wavelength_color xml )
313+
wavelength_color Werror xml )
314314

315315
# Only run field3d-related tests if the local OIIO was built with f3d support.
316316
EXECUTE_PROCESS ( COMMAND ${OPENIMAGEIO_BIN}/oiiotool --help

src/liboslcomp/oslcomp.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ OSLCompilerImpl::OSLCompilerImpl (ErrorHandler *errhandler)
129129
m_err(false), m_symtab(*this),
130130
m_current_typespec(TypeDesc::UNKNOWN), m_current_output(false),
131131
m_verbose(false), m_quiet(false), m_debug(false),
132-
m_preprocess_only(false), m_optimizelevel(1),
132+
m_preprocess_only(false), m_err_on_warning(false), m_optimizelevel(1),
133133
m_next_temp(0), m_next_const(0),
134134
m_osofile(NULL),
135135
m_total_nesting(0), m_loop_nesting(0), m_derivsym(NULL),
@@ -409,6 +409,8 @@ OSLCompilerImpl::read_compile_options (const std::vector<std::string> &options,
409409
m_optimizelevel = 1;
410410
} else if (options[i] == "-O2") {
411411
m_optimizelevel = 2;
412+
} else if (options[i] == "-Werror") {
413+
m_err_on_warning = true;
412414
} else if (options[i].c_str()[0] == '-' && options[i].size() > 2) {
413415
// options meant for the preprocessor
414416
if (options[i].c_str()[1] == 'D' || options[i].c_str()[1] == 'U')

src/liboslcomp/oslcomp_pvt.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ class OSLCompilerImpl {
119119
{
120120
ASSERT (format.size());
121121
std::string msg = OIIO::Strutil::format (format, args...);
122+
if (m_err_on_warning) {
123+
error (filename, line, "%s", msg);
124+
return;
125+
}
122126
if (filename.size())
123127
m_errhandler->warning ("%s:%d: warning: %s", filename, line, msg);
124128
else
@@ -447,6 +451,7 @@ class OSLCompilerImpl {
447451
bool m_quiet; ///< Quiet mode
448452
bool m_debug; ///< Debug mode
449453
bool m_preprocess_only; ///< Preprocess only?
454+
bool m_err_on_warning; ///< Treat warnings as errors?
450455
int m_optimizelevel; ///< Optimization level
451456
OpcodeVec m_ircode; ///< Generated IR code
452457
SymbolPtrVec m_opargs; ///< Arguments for all instructions

src/oslc/oslcmain.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ static OSLC_ErrorHandler default_oslc_error_handler;
108108

109109

110110

111-
112111
int
113112
main (int argc, const char *argv[])
114113
{
@@ -139,7 +138,9 @@ main (int argc, const char *argv[])
139138
! strcmp (argv[a], "-d") ||
140139
! strcmp (argv[a], "-E") ||
141140
! strcmp (argv[a], "-O") || ! strcmp (argv[a], "-O0") ||
142-
! strcmp (argv[a], "-O1") || ! strcmp (argv[a], "-O2")) {
141+
! strcmp (argv[a], "-O1") || ! strcmp (argv[a], "-O2") ||
142+
! strcmp (argv[a], "-Werror")
143+
) {
143144
// Valid command-line argument
144145
args.emplace_back(argv[a]);
145146
quiet |= (strcmp (argv[a], "-q") == 0);

testsuite/Werror/ref/out.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
test.osl:8: error: Ambiguous call to 'func ()'
2+
Chosen function is:
3+
test.osl:4 vector func ()
4+
Other candidates are:
5+
test.osl:3 normal func ()
6+
FAILED test.osl

testsuite/Werror/run.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env python
2+
3+
# This shader would ordinarily issue a warning.
4+
# With -Werror, it should be upgraded to an error.
5+
6+
failureok = 1 # this test is expected to have oslc errors
7+
oslcargs = "-Werror"
8+
9+
# No need, the shader in this dir are always compiled
10+
#command = oslc("test.osl")
11+

testsuite/Werror/test.osl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Engineer an ambiguous case that should be a warning
2+
3+
normal func () { return 1; }
4+
vector func () { return 2; }
5+
6+
shader test ()
7+
{
8+
point p = func();
9+
}

testsuite/runtest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
failthresh = 0.004
5252
hardfail = 0.01
5353
failpercent = 0.02
54+
oslcargs = ""
5455

5556
image_extensions = [ ".tif", ".tx", ".exr", ".jpg", ".png", ".rla",
5657
".dpx", ".iff", ".psd" ]
@@ -144,7 +145,7 @@ def oiio_app (app):
144145
# Construct a command that will compile the shader file, appending output to
145146
# the file "out.txt".
146147
def oslc (args) :
147-
return (osl_app("oslc") + args + " >> out.txt 2>&1 ;\n")
148+
return (osl_app("oslc") + oslcargs + " " + args + " >> out.txt 2>&1 ;\n")
148149

149150

150151
# Construct a command that will run oslinfo, appending output to

0 commit comments

Comments
 (0)