Skip to content

Commit 6fd5a1f

Browse files
authored
Avoid converting --pre-js/--post-js files to absolute paths. NFC (#23664)
Now that we change CWD when running `compiler.mjs` (See #23519) we no longer need to convert these to absolute paths in `link.py`. This also makes explicit the difference between system and user includes in `jsifier.mjs`.
1 parent 9c9b3f7 commit 6fd5a1f

File tree

2 files changed

+25
-18
lines changed

2 files changed

+25
-18
lines changed

src/jsifier.mjs

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
import assert from 'node:assert';
1111
import * as fs from 'node:fs/promises';
12-
import * as path from 'node:path';
1312
import {
1413
ATEXITS,
1514
ATINITS,
@@ -146,23 +145,27 @@ function shouldPreprocess(fileName) {
146145
return content.startsWith('#preprocess\n') || content.startsWith('#preprocess\r\n');
147146
}
148147

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);
153152
if (doPreprocess) {
154-
result += processMacros(preprocess(absFile), fileName);
153+
result += processMacros(preprocess(fileName), fileName);
155154
} else {
156-
result += readFile(absFile);
155+
result += readFile(fileName);
157156
}
158-
result += `// end include: ${fileName}\n`;
157+
result += `// end include: ${shortName}\n`;
159158
return result;
160159
}
161160

161+
function getSystemIncludeFile(fileName) {
162+
return getIncludeFile(localFile(fileName), /*alwaysPreprocess=*/ true, /*shortName=*/ fileName);
163+
}
164+
162165
function preJS() {
163166
let result = '';
164167
for (const fileName of PRE_JS_FILES) {
165-
result += getIncludeFile(fileName, /*alwaysPreprocess=*/ false);
168+
result += getIncludeFile(fileName);
166169
}
167170
return result;
168171
}
@@ -714,8 +717,12 @@ function(${args}) {
714717
libraryItems.push(JS);
715718
}
716719

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));
719726
}
720727

721728
function finalCombiner() {
@@ -741,10 +748,10 @@ function(${args}) {
741748
postSets.push(...orderedPostSets);
742749

743750
const shellFile = MINIMAL_RUNTIME ? 'shell_minimal.js' : 'shell.js';
744-
includeFile(shellFile);
751+
includeSystemFile(shellFile);
745752

746753
const preFile = MINIMAL_RUNTIME ? 'preamble_minimal.js' : 'preamble.js';
747-
includeFile(preFile);
754+
includeSystemFile(preFile);
748755

749756
for (const item of libraryItems.concat(postSets)) {
750757
writeOutput(indentify(item || '', 2));
@@ -769,14 +776,14 @@ var proxiedFunctionTable = [
769776
writeOutput('// EMSCRIPTEN_END_FUNCS\n');
770777

771778
const postFile = MINIMAL_RUNTIME ? 'postamble_minimal.js' : 'postamble.js';
772-
includeFile(postFile);
779+
includeSystemFile(postFile);
773780

774781
for (const fileName of POST_JS_FILES) {
775-
includeFile(fileName, /*alwaysPreprocess=*/ false);
782+
includeFile(fileName);
776783
}
777784

778785
if (MODULARIZE) {
779-
includeFile('postamble_modularize.js');
786+
includeSystemFile('postamble_modularize.js');
780787
}
781788

782789
if (errorOccured()) {

tools/link.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1826,8 +1826,8 @@ def get_full_import_name(name):
18261826
if settings.PTHREADS:
18271827
settings.REQUIRED_EXPORTS.append('_emscripten_tls_init')
18281828

1829-
settings.PRE_JS_FILES = [os.path.abspath(f) for f in options.pre_js]
1830-
settings.POST_JS_FILES = [os.path.abspath(f) for f in options.post_js]
1829+
settings.PRE_JS_FILES = options.pre_js
1830+
settings.POST_JS_FILES = options.post_js
18311831

18321832
settings.MINIFY_WHITESPACE = settings.OPT_LEVEL >= 2 and settings.DEBUG_LEVEL == 0 and not options.no_minify
18331833

0 commit comments

Comments
 (0)