From 54732ad8a38bfddf05d6bc51ce79b08c4296365f Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Thu, 27 Feb 2025 14:21:43 -0800 Subject: [PATCH] Use `warn` for printing `#warning` messages in JS libraries Previously we were only writing the message to stderr, and not recording it as an actual warning. After this change, such messages are now reported as warnings and controllable using `-Werror`, etc. --- src/parseTools.mjs | 2 +- test/test_other.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/parseTools.mjs b/src/parseTools.mjs index 7d76ea6cb5d97..8bef1e6a03b83 100644 --- a/src/parseTools.mjs +++ b/src/parseTools.mjs @@ -180,7 +180,7 @@ export function preprocess(filename) { showStack.pop(); } else if (first === '#warning') { if (showCurrentLine()) { - printErr( + warn( `${filename}:${i + 1}: #warning ${trimmed.substring(trimmed.indexOf(' ')).trim()}`, ); } diff --git a/test/test_other.py b/test/test_other.py index 014e2bd49600b..dac24ea5ead4f 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -4919,6 +4919,13 @@ def test_jslib_warnings(self): self.assertNotContained('This warning should not be present!', proc.stderr) self.assertContained('warning_in_js_libraries.js:5: #warning This is a warning string!', proc.stderr) self.assertContained('warning_in_js_libraries.js:7: #warning This is a second warning string!', proc.stderr) + self.assertContained('emcc: warning: warnings in JS library compilation [-Wjs-compiler]', proc.stderr) + + err = self.expect_fail([EMCC, test_file('hello_world.c'), '--js-library', test_file('warning_in_js_libraries.js'), '-Werror']) + self.assertNotContained('This warning should not be present!', err) + self.assertContained('warning_in_js_libraries.js:5: #warning This is a warning string!', err) + self.assertContained('warning_in_js_libraries.js:7: #warning This is a second warning string!', err) + self.assertContained('emcc: error: warnings in JS library compilation [-Wjs-compiler] [-Werror]', err) # Tests using the #error directive in JS library files def test_jslib_errors(self):