Skip to content

Commit 8c3fe4d

Browse files
authored
Handle JS compiler warning in python (#17365)
This makes `-Werror` work for JS compiler warnings just like it does for others. Also, consistently use `err` over `out` when reporting warnings. Also, avoid adding the `warning;` prefix when calling `warn` in the JS compiler, since its inject automatically.
1 parent bc452a1 commit 8c3fe4d

11 files changed

+28
-13
lines changed

ChangeLog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ See docs/process.md for more on how version tagging works.
2020

2121
3.1.16
2222
------
23+
- Warnings generated by the JS compiler (compiler.js) are now propagated back
24+
to the emcc compiler driver which means that `-Werror` builds will now fail
25+
in the presence of JS compiler warnings. As usual `-Wno-js-compiler` and
26+
`-Wno-error=js-compiler)` can be used to control these warnings. (#17365)
2327
- When JS library functions are included as part of `EXPORTED_RUNTIME_METHODS`
2428
it is no longer necessary to also add them to
2529
`DEFAULT_LIBRARY_FUNCS_TO_INCLUDE`. This change allows us to transition

emscripten.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,9 @@ def emscript(in_wasm, out_wasm, outfile_js, memfile):
354354

355355
forwarded_json = json.loads(forwarded_data)
356356

357+
if forwarded_json['warnings']:
358+
diagnostics.warning('js-compiler', 'warnings in JS library compilation')
359+
357360
pre, post = glue.split('// EMSCRIPTEN_END_FUNCS')
358361

359362
if settings.ASSERTIONS:

src/jsifier.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,7 @@ function ${name}(${args}) {
530530

531531
print('\n//FORWARDED_DATA:' + JSON.stringify({
532532
libraryFunctions: libraryFunctions,
533+
warnings: warnings,
533534
ATINITS: ATINITS.join('\n'),
534535
ATMAINS: ATMAINS.join('\n'),
535536
ATEXITS: ATEXITS.join('\n'),

src/library_browser.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,12 @@ var LibraryBrowser = {
112112
Browser.hasBlobConstructor = true;
113113
} catch(e) {
114114
Browser.hasBlobConstructor = false;
115-
out("warning: no blob constructor, cannot create blobs with mimetypes");
115+
err("warning: no blob constructor, cannot create blobs with mimetypes");
116116
}
117-
Browser.BlobBuilder = typeof MozBlobBuilder != "undefined" ? MozBlobBuilder : (typeof WebKitBlobBuilder != "undefined" ? WebKitBlobBuilder : (!Browser.hasBlobConstructor ? out("warning: no BlobBuilder") : null));
117+
Browser.BlobBuilder = typeof MozBlobBuilder != "undefined" ? MozBlobBuilder : (typeof WebKitBlobBuilder != "undefined" ? WebKitBlobBuilder : (!Browser.hasBlobConstructor ? err("warning: no BlobBuilder") : null));
118118
Browser.URLObject = typeof window != "undefined" ? (window.URL ? window.URL : window.webkitURL) : undefined;
119119
if (!Module.noImageDecoding && typeof Browser.URLObject == 'undefined') {
120-
out("warning: Browser does not support creating object URLs. Built-in browser image decoding will not be available.");
120+
err("warning: Browser does not support creating object URLs. Built-in browser image decoding will not be available.");
121121
Module.noImageDecoding = true;
122122
}
123123

@@ -207,7 +207,7 @@ var LibraryBrowser = {
207207
audio.addEventListener('canplaythrough', function() { finish(audio) }, false); // use addEventListener due to chromium bug 124926
208208
audio.onerror = function audio_onerror(event) {
209209
if (done) return;
210-
out('warning: browser could not fully decode audio ' + name + ', trying slower base64 approach');
210+
err('warning: browser could not fully decode audio ' + name + ', trying slower base64 approach');
211211
function encode64(data) {
212212
var BASE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
213213
var PAD = '=';

src/library_sdl.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2584,7 +2584,7 @@ var LibrarySDL = {
25842584
var curtime = SDL.audioContext['currentTime'];
25852585
#if ASSERTIONS
25862586
if (curtime > SDL.audio.nextPlayTime && SDL.audio.nextPlayTime != 0) {
2587-
out('warning: Audio callback had starved sending audio by ' + (curtime - SDL.audio.nextPlayTime) + ' seconds.');
2587+
err('warning: Audio callback had starved sending audio by ' + (curtime - SDL.audio.nextPlayTime) + ' seconds.');
25882588
}
25892589
#endif
25902590
// Don't ever start buffer playbacks earlier from current time than a given constant 'SDL.audio.bufferingDelay', since a browser

src/modules.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ function exportRuntime() {
531531
const runtimeElementsSet = new Set(runtimeElements);
532532
for (const name of EXPORTED_RUNTIME_METHODS_SET) {
533533
if (!runtimeElementsSet.has(name)) {
534-
printErr(`warning: invalid item in EXPORTED_RUNTIME_METHODS: ${name}`);
534+
warn(`invalid item in EXPORTED_RUNTIME_METHODS: ${name}`);
535535
}
536536
}
537537
}

src/parseTools.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ function preprocess(text, filenameHint) {
8080
const first = trimmed.split(' ', 1)[0];
8181
if (first == '#if' || first == '#ifdef' || first == '#elif') {
8282
if (first == '#ifdef') {
83-
warn('warning: use of #ifdef in js library. Use #if instead.');
83+
warn('use of #ifdef in js library. Use #if instead.');
8484
}
8585
if (first == '#elif') {
8686
const curr = showStack.pop();
@@ -825,7 +825,7 @@ function makeDynCall(sig, funcPtr) {
825825

826826

827827
if (funcPtr === undefined) {
828-
printErr(`warning: ${currentlyParsedFilename}: \
828+
warn(`${currentlyParsedFilename}: \
829829
Legacy use of {{{ makeDynCall("${sig}") }}}(funcPtr, arg1, arg2, ...). \
830830
Starting from Emscripten 2.0.2 (Aug 31st 2020), syntax for makeDynCall has changed. \
831831
New syntax is {{{ makeDynCall("${sig}", "funcPtr") }}}(arg1, arg2, ...). \

src/utility.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ function assert(a, msg) {
4848
}
4949
}
5050

51+
global.warnings = false;
52+
5153
function warn(a, msg) {
54+
global.warnings = true;
5255
if (!msg) {
5356
msg = a;
5457
a = false;
@@ -67,7 +70,7 @@ function warnOnce(a, msg) {
6770
if (!warnOnce.msgs) warnOnce.msgs = {};
6871
if (msg in warnOnce.msgs) return;
6972
warnOnce.msgs[msg] = true;
70-
printErr('warning: ' + msg);
73+
warn(msg);
7174
}
7275
}
7376

tests/test_browser.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3307,10 +3307,13 @@ def test_sdl2_mixer_music(self, formats, flags, music_name):
33073307

33083308
@requires_graphics_hardware
33093309
def test_cocos2d_hello(self):
3310+
# cocos2d build contains a bunch of warnings about tiff symbols being missing at link time:
3311+
# e.g. warning: undefined symbol: TIFFClientOpen
33103312
cocos2d_root = os.path.join(ports.Ports.get_build_dir(), 'cocos2d')
33113313
preload_file = os.path.join(cocos2d_root, 'samples', 'HelloCpp', 'Resources') + '@'
33123314
self.btest('cocos2d_hello.cpp', reference='cocos2d_hello.png', reference_slack=1,
33133315
args=['-sUSE_COCOS2D=3', '-sERROR_ON_UNDEFINED_SYMBOLS=0',
3316+
'-Wno-js-compiler',
33143317
'--preload-file', preload_file, '--use-preload-plugins',
33153318
'-Wno-inconsistent-missing-override'],
33163319
message='You should see Cocos2d logo')

tests/test_webgl_context_attributes_common.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -289,18 +289,18 @@ extern int webglAlphaSupported(void);
289289
static void checkContextAttributesSupport() {
290290
if (!webglAntialiasSupported()) {
291291
resultAA = true;
292-
EM_ASM(out('warning: no antialiasing\n'));
292+
EM_ASM(err('warning: no antialiasing\n'));
293293
}
294294
if (!webglDepthSupported()) {
295295
resultDepth = true;
296-
EM_ASM(out('warning: no depth\n'));
296+
EM_ASM(err('warning: no depth\n'));
297297
}
298298
if (!webglStencilSupported()) {
299299
resultStencil = true;
300-
EM_ASM(out('warning: no stencil\n'));
300+
EM_ASM(err('warning: no stencil\n'));
301301
}
302302
if (!webglAlphaSupported()) {
303303
resultAlpha = true;
304-
EM_ASM(out('warning: no alpha\n'));
304+
EM_ASM(err('warning: no alpha\n'));
305305
}
306306
}

0 commit comments

Comments
 (0)