-
-
Notifications
You must be signed in to change notification settings - Fork 30.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…127506) Modifies the python.sh script to work on macOS, and adapt to recent emscripten changes.
- Loading branch information
Showing
4 changed files
with
51 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,47 @@ | ||
import EmscriptenModule from "./python.mjs"; | ||
import { dirname } from 'node:path'; | ||
import { fileURLToPath } from 'node:url'; | ||
import fs from "node:fs"; | ||
|
||
if (process?.versions?.node) { | ||
const nodeVersion = Number(process.versions.node.split(".", 1)[0]); | ||
if (nodeVersion < 18) { | ||
process.stderr.write( | ||
`Node version must be >= 18, got version ${process.version}\n`, | ||
); | ||
process.exit(1); | ||
process.stderr.write( | ||
`Node version must be >= 18, got version ${process.version}\n`, | ||
); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
function rootDirsToMount(Module) { | ||
return fs | ||
.readdirSync("/") | ||
.filter((dir) => !["dev", "lib", "proc"].includes(dir)) | ||
.map((dir) => "/" + dir); | ||
} | ||
|
||
function mountDirectories(Module) { | ||
for (const dir of rootDirsToMount(Module)) { | ||
Module.FS.mkdirTree(dir); | ||
Module.FS.mount(Module.FS.filesystems.NODEFS, { root: dir }, dir); | ||
} | ||
} | ||
|
||
const thisProgram = "--this-program="; | ||
const thisProgramIndex = process.argv.findIndex((x) => | ||
x.startsWith(thisProgram), | ||
); | ||
|
||
const settings = { | ||
preRun(Module) { | ||
const __dirname = dirname(fileURLToPath(import.meta.url)); | ||
Module.FS.mkdirTree("/lib/"); | ||
Module.FS.mount(Module.FS.filesystems.NODEFS, { root: __dirname + "/lib/" }, "/lib/"); | ||
mountDirectories(Module); | ||
Module.FS.chdir(process.cwd()); | ||
Object.assign(Module.ENV, process.env); | ||
}, | ||
// The first three arguments are: "node", path to this file, path to | ||
// python.sh. After that come the arguments the user passed to python.sh. | ||
arguments: process.argv.slice(3), | ||
// Ensure that sys.executable, sys._base_executable, etc point to python.sh | ||
// not to this file. To properly handle symlinks, python.sh needs to compute | ||
// its own path. | ||
thisProgram: process.argv[2], | ||
thisProgram: process.argv[thisProgramIndex], | ||
// After python.sh come the arguments thatthe user passed to python.sh. | ||
arguments: process.argv.slice(thisProgramIndex + 1), | ||
}; | ||
|
||
await EmscriptenModule(settings); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters