From e37d3575d92cb34f7e7cd012aa0b2f3ee2134fc0 Mon Sep 17 00:00:00 2001 From: Kris Kowal Date: Wed, 20 Mar 2024 13:56:11 -0700 Subject: [PATCH] fix(xsnap): Revert failed attempt to expedite xsnap builds This reverts commit 3e5581b68307038a4a8ec3078c992d04f9d38ab2. --- packages/xsnap/package.json | 13 ++---- packages/xsnap/scripts/test-package.sh | 21 --------- packages/xsnap/src/build.js | 65 ++------------------------ 3 files changed, 7 insertions(+), 92 deletions(-) delete mode 100644 packages/xsnap/scripts/test-package.sh diff --git a/packages/xsnap/package.json b/packages/xsnap/package.json index 2c34f5299e3..8b271de3fc6 100644 --- a/packages/xsnap/package.json +++ b/packages/xsnap/package.json @@ -13,10 +13,10 @@ "scripts": { "repl": "node src/xsrepl.js", "build:bin": "if test -d ./test; then node src/build.js; else yarn build:from-env; fi", - "build:env": "if test -d ./test; then node src/build.js --show-env > build.env; fi", + "build:env": "test -d ./test && node src/build.js --show-env > build.env", "build:from-env": "{ cat build.env; echo node src/build.js; } | xargs env", "build": "yarn build:bin && yarn build:env", - "postinstall": "node src/build.js", + "postinstall": "yarn build:from-env", "clean": "rm -rf xsnap-native/xsnap/build", "lint": "run-s --continue-on-error lint:*", "lint:js": "eslint 'src/**/*.js' 'test/**/*.js' api.js", @@ -50,14 +50,7 @@ "LICENSE*", "api.js", "build.env", - "moddable/modules/data", - "moddable/xs/includes", - "moddable/xs/makefiles", - "moddable/xs/platforms/*.h", - "moddable/xs/sources", - "src", - "xsnap-native/xsnap/makefiles", - "xsnap-native/xsnap/sources" + "src" ], "publishConfig": { "access": "public" diff --git a/packages/xsnap/scripts/test-package.sh b/packages/xsnap/scripts/test-package.sh deleted file mode 100644 index c6ef5c8e800..00000000000 --- a/packages/xsnap/scripts/test-package.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -# Verifies that files in package.json covers everything xsnap needs to compile -# from sources out of an npm package. -set -xueo pipefail - -TEMP=$(mktemp -d) -# function cleanup() { -# rm -rf "$TEMP" -# } -# trap cleanup EXIT - -yarn pack -f "$TEMP/package.tar" -( - cd "$TEMP" - tar xvf package.tar - cd package - yarn - time yarn build - time yarn build - time yarn build -) diff --git a/packages/xsnap/src/build.js b/packages/xsnap/src/build.js index 7f39c85e602..b2b95361581 100644 --- a/packages/xsnap/src/build.js +++ b/packages/xsnap/src/build.js @@ -149,9 +149,12 @@ const makeSubmodule = (path, repoUrl, { git }) => { * rmdirSync: typeof import('fs').rmdirSync, * readFile: typeof import('fs').promises.readFile, * }, + * os: { + * type: typeof import('os').type, + * } * }} io */ -const updateSubmodules = async (args, { env, stdout, spawn, fs }) => { +async function main(args, { env, stdout, spawn, fs, os }) { const git = makeCLI('git', { spawn }); // When changing/adding entries here, make sure to search the whole project @@ -211,22 +214,7 @@ const updateSubmodules = async (args, { env, stdout, spawn, fs }) => { await submodule.init(); } } -}; -/** - * @param {{ - * spawn: typeof import('child_process').spawn, - * fs: { - * existsSync: typeof import('fs').existsSync, - * rmdirSync: typeof import('fs').rmdirSync, - * readFile: typeof import('fs').promises.readFile, - * }, - * os: { - * type: typeof import('os').type, - * } - * }} io - */ -const makeXsnap = async ({ spawn, fs, os }) => { const pjson = await fs.readFile(asset('../package.json'), 'utf-8'); const pkg = JSON.parse(pjson); @@ -251,51 +239,6 @@ const makeXsnap = async ({ spawn, fs, os }) => { }, ); } -}; - -/** - * @param {string[]} args - * @param {{ - * env: Record, - * stdout: typeof process.stdout, - * spawn: typeof import('child_process').spawn, - * fs: { - * existsSync: typeof import('fs').existsSync, - * rmdirSync: typeof import('fs').rmdirSync, - * readFile: typeof import('fs').promises.readFile, - * }, - * os: { - * type: typeof import('os').type, - * } - * }} io - */ -async function main(args, { env, stdout, spawn, fs, os }) { - // I solemnly swear I will do no synchronous work followed by a variable - // number turns of the event loop. - await null; - - // If this is a working copy of xsnap in a checkout of agoric-sdk, we need to - // either clone or update submodules. - // Otherwise, we are running from an extracted npm tarball in a dependent - // package's node_modules, in which case we should just `make` with the - // `moddable` directory provided by npm. - // This will avoid rebuilding native xsnap in the common case for end users. - // - // | moddable/ | moddable/.git | working copy | - // | --------- | ------------- | ------------ | - // | ABSENT | ABSENT | YES | - // | ABSENT | EXISTS | * | - // | EXISTS | ABSENT | NO | - // | EXISTS | EXISTS | YES | - // - // We short-circuit after a single stat if moddable/.git exists because that - // implies that moddable/ exists. - const isWorkingCopy = - fs.existsSync('moddable/.git') || !fs.existsSync('moddable'); - if (isWorkingCopy) { - await updateSubmodules(args, { env, stdout, spawn, fs }); - } - await makeXsnap({ spawn, fs, os }); } const run = () =>