Skip to content

Commit

Permalink
fix(xsnap): force rebuild if build config changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mhofman committed Jul 1, 2024
1 parent 54b2e2b commit 467435a
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions packages/xsnap/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
build
build.config.env
dist
test/fixture-snap-pool/
test/fixture-snap-shot.xss
2 changes: 1 addition & 1 deletion packages/xsnap/build.env
Original file line number Diff line number Diff line change
@@ -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
24 changes: 22 additions & 2 deletions packages/xsnap/src/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()}`);
Expand All @@ -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',
],
Expand All @@ -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,
Expand Down Expand Up @@ -344,6 +363,7 @@ const run = () =>
spawn: childProcessTop.spawn,
fs: {
readFile: fsTop.promises.readFile,
writeFile: fsTop.promises.writeFile,
existsSync: fsTop.existsSync,
rmdirSync: fsTop.rmdirSync,
},
Expand Down

0 comments on commit 467435a

Please sign in to comment.