-
Notifications
You must be signed in to change notification settings - Fork 215
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Force xsnap rebuild #9618
Force xsnap rebuild #9618
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 |
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -ueo pipefail | ||
|
||
# the xsnap binary lives in a platform-specific directory | ||
unameOut="$(uname -s)" | ||
case "${unameOut}" in | ||
Linux*) platform=lin ;; | ||
Darwin*) platform=mac ;; | ||
*) platform=win ;; | ||
esac | ||
|
||
# extract the xsnap package version from the long version printed by xsnap-worker | ||
"./xsnap-native/xsnap/build/bin/${platform}/release/xsnap-worker" -v | sed -e 's/^xsnap \([^ ]*\) (XS [^)]*)$/\1/g' |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -220,16 +220,34 @@ 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, | ||
* } | ||
* }} io | ||
* @param {object} [options] | ||
* @param {boolean} [options.forceBuild] | ||
*/ | ||
const makeXsnap = async ({ spawn, fs, os }) => { | ||
const makeXsnap = async ({ spawn, fs, os }, { forceBuild = false } = {}) => { | ||
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 (forceBuild || existingConfigEnvs.trim() !== expectedConfigEnvs.trim()) { | ||
await fs.writeFile(configEnvFile, expectedConfigEnvs); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice, so we update There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or if |
||
} | ||
|
||
const platform = ModdableSDK.platforms[os.type()]; | ||
if (!platform) { | ||
throw Error(`Unsupported OS found: ${os.type()}`); | ||
|
@@ -241,8 +259,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 +283,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, | ||
|
@@ -328,7 +349,18 @@ async function main(args, { env, stdout, spawn, fs, os }) { | |
|
||
if (!showEnv) { | ||
if (hasSource) { | ||
await makeXsnap({ spawn, fs, os }); | ||
// Force a rebuild if for some reason the binary is out of date | ||
// Since the make checks may not always detect that situation | ||
let forceBuild = !hasBin; | ||
if (hasBin) { | ||
const npm = makeCLI('npm', { spawn }); | ||
await npm | ||
.run(['run', '-s', 'check-version'], { cwd: asset('..') }) | ||
.catch(() => { | ||
forceBuild = true; | ||
}); | ||
} | ||
await makeXsnap({ spawn, fs, os }, { forceBuild }); | ||
} else if (!hasBin) { | ||
throw new Error( | ||
'XSnap has neither sources nor a pre-built binary. Docker? .dockerignore? npm files?', | ||
|
@@ -344,6 +376,7 @@ const run = () => | |
spawn: childProcessTop.spawn, | ||
fs: { | ||
readFile: fsTop.promises.readFile, | ||
writeFile: fsTop.promises.writeFile, | ||
existsSync: fsTop.existsSync, | ||
rmdirSync: fsTop.rmdirSync, | ||
}, | ||
|
+3 −0 | xsnap/makefiles/lin/xsnap-worker.mk | |
+3 −0 | xsnap/makefiles/mac/xsnap-worker.mk | |
+16 −4 | xsnap/sources/xsnap-worker.c | |
+3 −2 | xsnap/sources/xsnap.c | |
+6 −1 | xsnap/sources/xsnapPlatform.c |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -219,21 +219,12 @@ $do_not_build || ( | |
echo "At least $src is newer than gyp bindings" | ||
(cd "$GOLANG_DIR" && lazy_yarn build:gyp) | ||
} | ||
|
||
# check the built xsnap version against the package version it should be using | ||
(cd "${thisdir}/../packages/xsnap" && npm run -s check-version) || exit 1 | ||
fi | ||
) | ||
|
||
# the xsnap binary lives in a platform-specific directory | ||
unameOut="$(uname -s)" | ||
case "${unameOut}" in | ||
Linux*) platform=lin ;; | ||
Darwin*) platform=mac ;; | ||
*) platform=win ;; | ||
esac | ||
|
||
# check the xsnap version against our baked-in notion of what version we should be using | ||
xsnap_version=$("${thisdir}/../packages/xsnap/xsnap-native/xsnap/build/bin/${platform}/release/xsnap-worker" -n) | ||
[[ "${xsnap_version}" == "${XSNAP_VERSION}" ]] || fatal "xsnap version mismatch; expected ${XSNAP_VERSION}, got ${xsnap_version}" | ||
|
||
Comment on lines
-225
to
-236
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Glad to see this go! 💯 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well arguably it moved |
||
if $only_build; then | ||
echo "Build complete." 1>&2 | ||
exit 0 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good enough, it assumes that
bash
is available, but I'll admit that's likely, and easier than figuring out how to write this in the purelysh
subsetThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well arguably this is already posix 2022 compliant, it's just that most shells still don't support
-o pipefail
in their posix mode.I suppose I could check for the existence of the binary first before trying to invoke it