Skip to content

Commit 58b8e80

Browse files
authored
[embind] Write generated output to a temp file. (#24407)
Instead of writing to stdout, write to a file to avoid any logging output entering the TS definitions or AOT code.
1 parent a576928 commit 58b8e80

File tree

2 files changed

+21
-24
lines changed

2 files changed

+21
-24
lines changed

src/lib/libembind_gen.js

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ var LibraryEmbind = {
446446
if (this.usedEmbindString) {
447447
out.unshift('type EmbindString = ArrayBuffer|Uint8Array|Uint8ClampedArray|Int8Array|string;\n');
448448
}
449-
console.log(out.join(''));
449+
return out.join('');
450450
}
451451
},
452452

@@ -468,10 +468,10 @@ var LibraryEmbind = {
468468
def.printJs(out);
469469
}
470470
out.push('}\n');
471-
console.log(JSON.stringify({
471+
return JSON.stringify({
472472
'invokers': out.join(''),
473473
publicSymbols,
474-
}));
474+
});
475475
}
476476
},
477477

@@ -843,27 +843,27 @@ var LibraryEmbind = {
843843
});
844844
},
845845

846+
$emitOutput__deps: ['$awaitingDependencies', '$throwBindingError', '$getTypeName', '$moduleDefinitions',
846847
#if EMBIND_AOT
847-
$embindEmitAotJs__deps: ['$awaitingDependencies', '$throwBindingError', '$getTypeName', '$moduleDefinitions', '$JsPrinter'],
848-
$embindEmitAotJs__postset: () => { addAtPostCtor('embindEmitAotJs()'); },
849-
$embindEmitAotJs: () => {
848+
'$JsPrinter',
849+
#else
850+
'$TsPrinter',
851+
#endif
852+
],
853+
$emitOutput__postset: () => { addAtPostCtor('emitOutput()'); },
854+
$emitOutput: () => {
850855
for (const typeId in awaitingDependencies) {
851856
throwBindingError(`Missing binding for type: '${getTypeName(typeId)}' typeId: ${typeId}`);
852857
}
858+
#if EMBIND_AOT
853859
const printer = new JsPrinter(moduleDefinitions);
854-
printer.print();
855-
},
856-
#else // EMBIND_AOT
857-
$embindEmitTypes__deps: ['$awaitingDependencies', '$throwBindingError', '$getTypeName', '$moduleDefinitions', '$TsPrinter'],
858-
$embindEmitTypes__postset: () => { addAtPostCtor('embindEmitTypes()'); },
859-
$embindEmitTypes: () => {
860-
for (const typeId in awaitingDependencies) {
861-
throwBindingError(`Missing binding for type: '${getTypeName(typeId)}' typeId: ${typeId}`);
862-
}
860+
#else
863861
const printer = new TsPrinter(moduleDefinitions);
864-
printer.print();
865-
},
866862
#endif
863+
const output = printer.print();
864+
var fs = require('fs');
865+
fs.writeFileSync(process.argv[2], output + '\n');
866+
},
867867

868868
// Stub functions used by eval, but not needed for TS generation:
869869
$makeLegalFunctionName: () => { throw new Error('stub function should not be called'); },
@@ -874,10 +874,6 @@ var LibraryEmbind = {
874874
$PureVirtualError: () => { throw new Error('stub function should not be called'); },
875875
};
876876

877-
#if EMBIND_AOT
878-
extraLibraryFuncs.push('$embindEmitAotJs');
879-
#else
880-
extraLibraryFuncs.push('$embindEmitTypes');
881-
#endif
877+
extraLibraryFuncs.push('$emitOutput');
882878

883879
addToLibrary(LibraryEmbind);

tools/link.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2071,9 +2071,10 @@ def run_embind_gen(options, wasm_target, js_syms, extra_settings):
20712071
if settings.WASM_EXCEPTIONS:
20722072
node_args += shared.node_exception_flags(config.NODE_JS)
20732073
# Run the generated JS file with the proper flags to generate the TypeScript bindings.
2074-
out = shared.run_js_tool(outfile_js, [], node_args, stdout=PIPE)
2074+
output_file = in_temp('embind_generated_output.js')
2075+
shared.run_js_tool(outfile_js, [output_file], node_args)
20752076
settings.restore(original_settings)
2076-
return out
2077+
return read_file(output_file)
20772078

20782079

20792080
@ToolchainProfiler.profile_block('emit tsd')

0 commit comments

Comments
 (0)