Skip to content

Commit

Permalink
xs-vat-worker: solve xs compartmap constraints
Browse files Browse the repository at this point in the history
  - remove .js from "modules" section of xs manifest
  - remove .js when building compartment map from endo manifest
  • Loading branch information
dckc committed Aug 9, 2020
1 parent 294fd6a commit 638a85e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 19 deletions.
26 changes: 13 additions & 13 deletions packages/xs-vat-worker/compartmap.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,26 +123,26 @@
"node_modules/0_MKDIR": "$(ROOT)/node_modules/0_MKDIR",
"node_modules/@agoric/0_MKDIR": "$(ROOT)/node_modules/@agoric/0_MKDIR",
"node_modules/@agoric/assert/0_MKDIR": "$(ROOT)/node_modules/@agoric/assert/0_MKDIR",
"node_modules/@agoric/assert/src/assert.js": "$(ROOT)/node_modules/@agoric/assert/src/assert",
"node_modules/@agoric/assert/src/types.js": "$(ROOT)/node_modules/@agoric/assert/src/types",
"node_modules/@agoric/assert/src/assert": "$(ROOT)/node_modules/@agoric/assert/src/assert",
"node_modules/@agoric/assert/src/types": "$(ROOT)/node_modules/@agoric/assert/src/types",
"node_modules/@agoric/eventual-send/0_MKDIR": "$(ROOT)/node_modules/@agoric/eventual-send/0_MKDIR",
"node_modules/@agoric/eventual-send/src/E.js": "$(ROOT)/node_modules/@agoric/eventual-send/src/E",
"node_modules/@agoric/eventual-send/src/index.js": "$(ROOT)/node_modules/@agoric/eventual-send/src/index",
"node_modules/@agoric/eventual-send/src/E": "$(ROOT)/node_modules/@agoric/eventual-send/src/E",
"node_modules/@agoric/eventual-send/src/index": "$(ROOT)/node_modules/@agoric/eventual-send/src/index",
"node_modules/@agoric/import-bundle/0_MKDIR": "$(ROOT)/node_modules/@agoric/import-bundle/0_MKDIR",
"node_modules/@agoric/import-bundle/src/compartment-wrapper.js": "$(ROOT)/node_modules/@agoric/import-bundle/src/compartment-wrapper",
"node_modules/@agoric/import-bundle/src/index.js": "$(ROOT)/node_modules/@agoric/import-bundle/src/index",
"node_modules/@agoric/marshal/marshal.js": "$(ROOT)/node_modules/@agoric/marshal/marshal",
"node_modules/@agoric/import-bundle/src/compartment-wrapper": "$(ROOT)/node_modules/@agoric/import-bundle/src/compartment-wrapper",
"node_modules/@agoric/import-bundle/src/index": "$(ROOT)/node_modules/@agoric/import-bundle/src/index",
"node_modules/@agoric/marshal/marshal": "$(ROOT)/node_modules/@agoric/marshal/marshal",
"node_modules/@agoric/nat/0_MKDIR": "$(ROOT)/node_modules/@agoric/nat/0_MKDIR",
"node_modules/@agoric/nat/dist/nat.esm.js": "$(ROOT)/node_modules/@agoric/nat/dist/nat.esm",
"node_modules/@agoric/nat/dist/nat.esm": "$(ROOT)/node_modules/@agoric/nat/dist/nat.esm",
"node_modules/@agoric/produce-promise/0_MKDIR": "$(ROOT)/node_modules/@agoric/produce-promise/0_MKDIR",
"node_modules/@agoric/produce-promise/src/producePromise.js": "$(ROOT)/node_modules/@agoric/produce-promise/src/producePromise",
"node_modules/@agoric/produce-promise/src/producePromise": "$(ROOT)/node_modules/@agoric/produce-promise/src/producePromise",
"node_modules/@agoric/swingset-vat/0_MKDIR": "$(ROOT)/node_modules/@agoric/swingset-vat/0_MKDIR",
"node_modules/@agoric/swingset-vat/src/0_MKDIR": "$(ROOT)/node_modules/@agoric/swingset-vat/src/0_MKDIR",
"node_modules/@agoric/swingset-vat/src/capdata.js": "$(ROOT)/node_modules/@agoric/swingset-vat/src/capdata",
"node_modules/@agoric/swingset-vat/src/kernel/liveSlots.js": "$(ROOT)/node_modules/@agoric/swingset-vat/src/kernel/liveSlots",
"node_modules/@agoric/swingset-vat/src/parseVatSlots.js": "$(ROOT)/node_modules/@agoric/swingset-vat/src/parseVatSlots",
"node_modules/@agoric/swingset-vat/src/capdata": "$(ROOT)/node_modules/@agoric/swingset-vat/src/capdata",
"node_modules/@agoric/swingset-vat/src/kernel/liveSlots": "$(ROOT)/node_modules/@agoric/swingset-vat/src/kernel/liveSlots",
"node_modules/@agoric/swingset-vat/src/parseVatSlots": "$(ROOT)/node_modules/@agoric/swingset-vat/src/parseVatSlots",
"packages/0_MKDIR": "$(ROOT)/packages/0_MKDIR",
"packages/xs-vat-worker/0_MKDIR": "$(ROOT)/packages/xs-vat-worker/0_MKDIR",
"packages/xs-vat-worker/src/vatWorker.js": "$(ROOT)/packages/xs-vat-worker/src/vatWorker"
"packages/xs-vat-worker/src/vatWorker": "$(ROOT)/packages/xs-vat-worker/src/vatWorker"
}
}
22 changes: 17 additions & 5 deletions packages/xs-vat-worker/start-xs.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,26 @@ function mainCompartment(Compartment) {
const cache = {};
return k => cache[k] || (cache[k] = f(k));
};
const join = (parent, child) => `${parent}${child.replace(/^\.\//, '')}`;
const unjs = spec => spec.replace(/\.js$/, '');
const unrel = spec => spec.replace(/^\.\//, '/');
const join = (base, ref) => `${base}${unjs(ref.slice(2))}`;
const pkgCompartment = memoize(loc => {
const intraPkg = ref => {
console.log('intraPkg', { loc, ref });
return [ref, join(loc, ref)];
return [unjs(unrel(ref).slice(1)), join(loc, ref)];
};
function interPkg([specifier, { compartment, module }]) {
console.log('interPkg', { loc, specifier, compartment, module });
const pc = pkgCompartment(compartment);
return [specifier, pc.importNow(module)];
const fullSpecifier = unjs(module.slice(2));
// const fullSpecifier = join(compartment, module);
console.log('interPkg', {
loc,
specifier,
compartment,
module,
fullSpecifier,
});
return [specifier, pc.importNow(fullSpecifier)];
}
const { contents, modules } = compartmap.compartments[loc];
const cmap = fromEntries([
Expand All @@ -75,8 +85,10 @@ export default async function main() {
const outStream = new Writer(OUTFD);

const c1 = mainCompartment(tweakCompartmentAPI(xsCompartment));
const vw = await c1.import('./src/vatWorker.js');
console.log('about to import vatWorker');
const vw = await c1.import('src/vatWorker');

console.log('about to run vatWorker.main...');
return vw.main({
setImmediate: callback => {
Timer.set(callback);
Expand Down
2 changes: 1 addition & 1 deletion packages/xs-vat-worker/tools/findmods.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ async function walk(workspace, start, exclude, { fsp, cabinet, fileURL }) {
.map(m => inW(m))
.map(m => [m, ...ancestors(m).map(d => `${d}/0_MKDIR`)])
.flat()
.map(m => [m, `$(ROOT)/${unjs(m)}`])
.map(m => [unjs(m), `$(ROOT)/${unjs(m)}`])
.sort(),
);
const mainPkg = await pkgOf(start);
Expand Down

0 comments on commit 638a85e

Please sign in to comment.