Skip to content

Commit

Permalink
Merge pull request #9058 from Agoric/ta/builders-cleanup
Browse files Browse the repository at this point in the history
cleanup proposal output from extractor
  • Loading branch information
mergify[bot] authored Mar 11, 2024
2 parents 83b106a + 5520375 commit 21c29e2
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions packages/boot/tools/supports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,13 @@ export const makeProposalExtractor = ({ childProcess, fs }: Powers) => {
const importSpec = spec =>
importMetaResolve(spec, import.meta.url).then(u => new URL(u).pathname);

const runPackageScript = async (outputDir, scriptPath, env) => {
const runPackageScript = (
outputDir: string,
scriptPath: string,
env: NodeJS.ProcessEnv,
) => {
console.info('running package script:', scriptPath);
const out = await childProcess.execFileSync('yarn', ['bin', 'agoric'], {
const out = childProcess.execFileSync('yarn', ['bin', 'agoric'], {
cwd: outputDir,
env,
});
Expand Down Expand Up @@ -150,30 +154,30 @@ export const makeProposalExtractor = ({ childProcess, fs }: Powers) => {
};

const buildAndExtract = async (builderPath: string) => {
const scriptEnv = Object.assign(Object.create(process.env));

const pkgPath = getPkgPath('builders');
const tmpDir = await fsAmbientPromises.mkdtemp(join(pkgPath, 'proposal-'));

const scriptPath = await importSpec(builderPath);
const tmpDir = await fsAmbientPromises.mkdtemp(
join(getPkgPath('builders'), 'proposal-'),
);

// XXX use '@agoric/inter-protocol'?
const out = await runPackageScript(tmpDir, scriptPath, scriptEnv);
const built = parseProposalParts(out.toString());
const built = parseProposalParts(
runPackageScript(
tmpDir,
await importSpec(builderPath),
process.env,
).toString(),
);

const loadAndRmPkgFile = async fileName => {
const filePath = join(tmpDir, fileName);
const content = await fs.readFile(filePath, 'utf8');
await fs.rm(filePath);
return content;
};
const loadPkgFile = fileName => fs.readFile(join(tmpDir, fileName), 'utf8');

const evalsP = Promise.all(
built.evals.map(async ({ permit, script }) => {
const [permits, code] = await Promise.all([
loadAndRmPkgFile(permit),
loadAndRmPkgFile(script),
loadPkgFile(permit),
loadPkgFile(script),
]);
// Fire and forget. There's a chance the Node process could terminate
// before the deletion completes. This is a minor inconvenience to clean
// up manually and not worth slowing down the test execution to prevent.
void fsAmbientPromises.rm(tmpDir, { recursive: true, force: true });
return { json_permits: permits, js_code: code } as CoreEvalSDKType;
}),
);
Expand Down

0 comments on commit 21c29e2

Please sign in to comment.