9
9
10
10
import assert from 'node:assert' ;
11
11
import * as fs from 'node:fs/promises' ;
12
- import * as path from 'node:path' ;
13
12
import {
14
13
ATEXITS ,
15
14
ATINITS ,
@@ -146,23 +145,27 @@ function shouldPreprocess(fileName) {
146
145
return content . startsWith ( '#preprocess\n' ) || content . startsWith ( '#preprocess\r\n' ) ;
147
146
}
148
147
149
- function getIncludeFile ( fileName , alwaysPreprocess ) {
150
- let result = `// include: ${ fileName } \n` ;
151
- const absFile = path . isAbsolute ( fileName ) ? fileName : localFile ( fileName ) ;
152
- const doPreprocess = alwaysPreprocess || shouldPreprocess ( absFile ) ;
148
+ function getIncludeFile ( fileName , alwaysPreprocess , shortName ) {
149
+ shortName ??= fileName ;
150
+ let result = `// include: ${ shortName } \n` ;
151
+ const doPreprocess = alwaysPreprocess || shouldPreprocess ( fileName ) ;
153
152
if ( doPreprocess ) {
154
- result += processMacros ( preprocess ( absFile ) , fileName ) ;
153
+ result += processMacros ( preprocess ( fileName ) , fileName ) ;
155
154
} else {
156
- result += readFile ( absFile ) ;
155
+ result += readFile ( fileName ) ;
157
156
}
158
- result += `// end include: ${ fileName } \n` ;
157
+ result += `// end include: ${ shortName } \n` ;
159
158
return result ;
160
159
}
161
160
161
+ function getSystemIncludeFile ( fileName ) {
162
+ return getIncludeFile ( localFile ( fileName ) , /*alwaysPreprocess=*/ true , /*shortName=*/ fileName ) ;
163
+ }
164
+
162
165
function preJS ( ) {
163
166
let result = '' ;
164
167
for ( const fileName of PRE_JS_FILES ) {
165
- result += getIncludeFile ( fileName , /*alwaysPreprocess=*/ false ) ;
168
+ result += getIncludeFile ( fileName ) ;
166
169
}
167
170
return result ;
168
171
}
@@ -714,8 +717,12 @@ function(${args}) {
714
717
libraryItems . push ( JS ) ;
715
718
}
716
719
717
- function includeFile ( fileName , alwaysPreprocess = true ) {
718
- writeOutput ( getIncludeFile ( fileName , alwaysPreprocess ) ) ;
720
+ function includeSystemFile ( fileName ) {
721
+ writeOutput ( getSystemIncludeFile ( fileName ) ) ;
722
+ }
723
+
724
+ function includeFile ( fileName ) {
725
+ writeOutput ( getIncludeFile ( fileName ) ) ;
719
726
}
720
727
721
728
function finalCombiner ( ) {
@@ -741,10 +748,10 @@ function(${args}) {
741
748
postSets . push ( ...orderedPostSets ) ;
742
749
743
750
const shellFile = MINIMAL_RUNTIME ? 'shell_minimal.js' : 'shell.js' ;
744
- includeFile ( shellFile ) ;
751
+ includeSystemFile ( shellFile ) ;
745
752
746
753
const preFile = MINIMAL_RUNTIME ? 'preamble_minimal.js' : 'preamble.js' ;
747
- includeFile ( preFile ) ;
754
+ includeSystemFile ( preFile ) ;
748
755
749
756
for ( const item of libraryItems . concat ( postSets ) ) {
750
757
writeOutput ( indentify ( item || '' , 2 ) ) ;
@@ -769,14 +776,14 @@ var proxiedFunctionTable = [
769
776
writeOutput ( '// EMSCRIPTEN_END_FUNCS\n' ) ;
770
777
771
778
const postFile = MINIMAL_RUNTIME ? 'postamble_minimal.js' : 'postamble.js' ;
772
- includeFile ( postFile ) ;
779
+ includeSystemFile ( postFile ) ;
773
780
774
781
for ( const fileName of POST_JS_FILES ) {
775
- includeFile ( fileName , /*alwaysPreprocess=*/ false ) ;
782
+ includeFile ( fileName ) ;
776
783
}
777
784
778
785
if ( MODULARIZE ) {
779
- includeFile ( 'postamble_modularize.js' ) ;
786
+ includeSystemFile ( 'postamble_modularize.js' ) ;
780
787
}
781
788
782
789
if ( errorOccured ( ) ) {
0 commit comments