Skip to content

Commit

Permalink
Use warn for printing #warning messages in JS libraries (#23786)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sbc100 authored Feb 27, 2025
1 parent c4e39ce commit 5a62c4d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/parseTools.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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()}`,
);
}
Expand Down
7 changes: 7 additions & 0 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 5a62c4d

Please sign in to comment.