From 467435aeeaf83485430ad6e55c7213a2df1279ab Mon Sep 17 00:00:00 2001 From: Mathieu Hofman Date: Sun, 30 Jun 2024 05:49:00 +0000 Subject: [PATCH] fix(xsnap): force rebuild if build config changes --- .dockerignore | 1 + packages/xsnap/.gitignore | 1 + packages/xsnap/build.env | 2 +- packages/xsnap/src/build.js | 24 ++++++++++++++++++++++-- packages/xsnap/xsnap-native | 2 +- 5 files changed, 26 insertions(+), 4 deletions(-) diff --git a/.dockerignore b/.dockerignore index 6e6aa7d3e00..97f2dd62b43 100644 --- a/.dockerignore +++ b/.dockerignore @@ -22,6 +22,7 @@ packages/stat-logger **/_agstate .vagrant endo-sha.txt +packages/xsnap/build.config.env # When changing/adding entries here, make sure to search the whole project for # `@@AGORIC_DOCKER_SUBMODULES@@` packages/xsnap/moddable diff --git a/packages/xsnap/.gitignore b/packages/xsnap/.gitignore index 04f5262f86f..2cee34ad100 100644 --- a/packages/xsnap/.gitignore +++ b/packages/xsnap/.gitignore @@ -1,4 +1,5 @@ build +build.config.env dist test/fixture-snap-pool/ test/fixture-snap-shot.xss diff --git a/packages/xsnap/build.env b/packages/xsnap/build.env index cf11308c6fc..b816a3002cd 100644 --- a/packages/xsnap/build.env +++ b/packages/xsnap/build.env @@ -1,4 +1,4 @@ MODDABLE_URL=https://github.com/agoric-labs/moddable.git MODDABLE_COMMIT_HASH=f6c5951fc055e4ca592b9166b9ae3cbb9cca6bf0 XSNAP_NATIVE_URL=https://github.com/agoric-labs/xsnap-pub -XSNAP_NATIVE_COMMIT_HASH=2d8ccb76b8508e490d9e03972bb4c64f402d5135 +XSNAP_NATIVE_COMMIT_HASH=eef9b67da5517ed18ff9e0073b842db20924eae3 diff --git a/packages/xsnap/src/build.js b/packages/xsnap/src/build.js index 3bd1d4c0454..418355405e0 100644 --- a/packages/xsnap/src/build.js +++ b/packages/xsnap/src/build.js @@ -220,6 +220,7 @@ const updateSubmodules = async (showEnv, { env, stdout, spawn, fs }) => { * existsSync: typeof import('fs').existsSync, * rmdirSync: typeof import('fs').rmdirSync, * readFile: typeof import('fs').promises.readFile, + * writeFile: typeof import('fs').promises.writeFile, * }, * os: { * type: typeof import('os').type, @@ -230,6 +231,21 @@ const makeXsnap = async ({ spawn, fs, os }) => { const pjson = await fs.readFile(asset('../package.json'), 'utf-8'); const pkg = JSON.parse(pjson); + const configEnvs = [ + `XSNAP_VERSION=${pkg.version}`, + `CC=cc "-D__has_builtin(x)=1"`, + ]; + + const configEnvFile = asset('../build.config.env'); + const existingConfigEnvs = fs.existsSync(configEnvFile) + ? await fs.readFile(configEnvFile, 'utf-8') + : ''; + + const expectedConfigEnvs = configEnvs.concat('').join('\n'); + if (existingConfigEnvs.trim() !== expectedConfigEnvs.trim()) { + await fs.writeFile(configEnvFile, expectedConfigEnvs); + } + const platform = ModdableSDK.platforms[os.type()]; if (!platform) { throw Error(`Unsupported OS found: ${os.type()}`); @@ -241,8 +257,10 @@ const makeXsnap = async ({ spawn, fs, os }) => { [ `MODDABLE=${ModdableSDK.MODDABLE}`, `GOAL=${goal}`, - `XSNAP_VERSION=${pkg.version}`, - `CC=cc "-D__has_builtin(x)=1"`, + // Any other configuration variables that affect the build output + // should be placed in `configEnvs` to force a rebuild if they change + ...configEnvs, + `EXTRA_DEPS=${configEnvFile}`, '-f', 'xsnap-worker.mk', ], @@ -263,6 +281,7 @@ const makeXsnap = async ({ spawn, fs, os }) => { * existsSync: typeof import('fs').existsSync, * rmdirSync: typeof import('fs').rmdirSync, * readFile: typeof import('fs').promises.readFile, + * writeFile: typeof import('fs').promises.writeFile, * }, * os: { * type: typeof import('os').type, @@ -344,6 +363,7 @@ const run = () => spawn: childProcessTop.spawn, fs: { readFile: fsTop.promises.readFile, + writeFile: fsTop.promises.writeFile, existsSync: fsTop.existsSync, rmdirSync: fsTop.rmdirSync, }, diff --git a/packages/xsnap/xsnap-native b/packages/xsnap/xsnap-native index 2d8ccb76b85..eef9b67da55 160000 --- a/packages/xsnap/xsnap-native +++ b/packages/xsnap/xsnap-native @@ -1 +1 @@ -Subproject commit 2d8ccb76b8508e490d9e03972bb4c64f402d5135 +Subproject commit eef9b67da5517ed18ff9e0073b842db20924eae3