Skip to content

Commit 01da194

Browse files
committed
fix(agoric-cli): use SDK binaries rather than relying on $PATH
1 parent ad96231 commit 01da194

File tree

3 files changed

+26
-13
lines changed

3 files changed

+26
-13
lines changed

packages/agoric-cli/lib/cosmos.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import chalk from 'chalk';
2-
import { makePspawn } from './helpers.js';
2+
import { makePspawn, getSDKBinaries } from './helpers.js';
33

44
export default async function cosmosMain(progname, rawArgs, powers, opts) {
55
const IMAGE = `agoric/agoric-sdk`;
@@ -21,7 +21,8 @@ export default async function cosmosMain(progname, rawArgs, powers, opts) {
2121

2222
function helper(args, hopts = undefined) {
2323
if (opts.sdk) {
24-
return pspawn('ag-cosmos-helper', args, hopts);
24+
const { cosmosHelper } = getSDKBinaries();
25+
return pspawn(cosmosHelper, args, hopts);
2526
}
2627

2728
// Don't allocate a TTY if we're not talking to one.

packages/agoric-cli/lib/helpers.js

+15-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,24 @@
33

44
/** @typedef {import('child_process').ChildProcess} ChildProcess */
55

6+
export const getSDKBinaries = () => {
7+
const myUrl = import.meta.url;
8+
return {
9+
agSolo: new URL('../../solo/src/entrypoint.js', myUrl).pathname,
10+
cosmosChain: new URL('../../cosmic-swingset/bin/ag-chain-cosmos', myUrl)
11+
.pathname,
12+
cosmosHelper: new URL(
13+
'../../../golang/cosmos/build/ag-cosmos-helper',
14+
myUrl,
15+
).pathname,
16+
};
17+
};
18+
619
/**
720
* Create a promisified spawn function with the following built-in parameters.
821
*
922
* @param {Object} param0
10-
* @param {Record<string, string>} [param0.env] the default environment
23+
* @param {Record<string, string | undefined>} [param0.env] the default environment
1124
* @param {*} [param0.chalk] a colorizer
1225
* @param {Console} [param0.log] a console object
1326
* @param {(cmd: string, cargs: Array<string>, opts: any) => ChildProcess}param0.spawn the spawn function
@@ -26,7 +39,7 @@ export const makePspawn = ({
2639
* @param {Object} param2
2740
* @param {string | [string, string, string]} [param2.stdio] standard IO
2841
* specification
29-
* @param {Record<string, string>} [param2.env] environment
42+
* @param {Record<string, string | undefined>} [param2.env] environment
3043
* @returns {Promise<number> & { childProcess: ChildProcess }}} promise for
3144
* exit status. The return result has a `childProcess` property to obtain
3245
* control over the running process

packages/agoric-cli/lib/start.js

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/* global process setTimeout */
2-
import path from 'path';
32
import chalk from 'chalk';
43
import { createHash } from 'crypto';
54

@@ -11,10 +10,7 @@ import {
1110
finishCosmosApp,
1211
} from './chain-config.js';
1312

14-
import { makePspawn } from './helpers.js';
15-
16-
const filename = new URL(import.meta.url).pathname;
17-
const dirname = path.dirname(filename);
13+
import { makePspawn, getSDKBinaries } from './helpers.js';
1814

1915
const PROVISION_COINS = `100000000${STAKING_DENOM},50000000000${CENTRAL_DENOM},100provisionpass,100sendpacketpass`;
2016
const DELEGATE0_COINS = `50000000${STAKING_DENOM}`;
@@ -49,8 +45,9 @@ export default async function startMain(progname, rawArgs, powers, opts) {
4945

5046
let keysSpawn;
5147
if (opts.sdk) {
48+
const { cosmosHelper } = getSDKBinaries();
5249
keysSpawn = (args, ...rest) =>
53-
pspawn('ag-cosmos-helper', [`--home=_agstate/keys`, ...args], ...rest);
50+
pspawn(cosmosHelper, [`--home=_agstate/keys`, ...args], ...rest);
5451
} else {
5552
keysSpawn = (args, ...rest) =>
5653
pspawn(
@@ -116,7 +113,7 @@ export default async function startMain(progname, rawArgs, powers, opts) {
116113

117114
let agSolo;
118115
if (opts.sdk) {
119-
agSolo = path.resolve(dirname, '../../solo/src/entrypoint.js');
116+
({ agSolo } = getSDKBinaries());
120117
} else {
121118
agSolo = `ag-solo`;
122119
}
@@ -201,8 +198,10 @@ export default async function startMain(progname, rawArgs, powers, opts) {
201198

202199
let chainSpawn;
203200
if (popts.sdk) {
204-
chainSpawn = (args, spawnOpts = undefined) =>
205-
pspawn('ag-chain-cosmos', [...args, `--home=${agServer}`], spawnOpts);
201+
const { cosmosChain } = getSDKBinaries();
202+
chainSpawn = (args, spawnOpts = undefined) => {
203+
return pspawn(cosmosChain, [...args, `--home=${agServer}`], spawnOpts);
204+
};
206205
} else {
207206
chainSpawn = (args, spawnOpts = undefined, dockerArgs = []) =>
208207
pspawn(

0 commit comments

Comments
 (0)