Skip to content
This repository was archived by the owner on Nov 18, 2022. It is now read-only.

Commit 808917c

Browse files
committed
Prefer spawning rustup in a shell
This is equally (un)safe but also allows one to include ~ in the "rust-client.rustupPath" config value
1 parent 0f71788 commit 808917c

File tree

3 files changed

+26
-25
lines changed

3 files changed

+26
-25
lines changed

src/extension.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -346,10 +346,9 @@ class ClientWorkspace {
346346

347347
const rustcPrintSysroot = () =>
348348
this.config.rustupDisabled
349-
? wslWrapper.execFile('rustc', ['--print', 'sysroot'], { env })
350-
: wslWrapper.execFile(
351-
this.config.rustupPath,
352-
['run', this.config.channel, 'rustc', '--print', 'sysroot'],
349+
? wslWrapper.exec('rustc --print sysroot', { env })
350+
: wslWrapper.exec(
351+
`${this.config.rustupPath} run ${this.config.channel} rustc --print sysroot`,
353352
{ env },
354353
);
355354

@@ -419,7 +418,11 @@ class ClientWorkspace {
419418
console.info(`running without rustup: ${rlsPath}`);
420419
const env = await makeRlsEnv();
421420

422-
childProcess = child_process.spawn(rlsPath, [], { env, cwd });
421+
childProcess = child_process.spawn(rlsPath, [], {
422+
env,
423+
cwd,
424+
shell: true,
425+
});
423426
} else {
424427
console.info(`running with rustup: ${rlsPath}`);
425428
const config = this.config.rustupConfig();
@@ -436,7 +439,7 @@ class ClientWorkspace {
436439
childProcess = withWsl(config.useWSL).spawn(
437440
config.path,
438441
['run', config.channel, rlsPath],
439-
{ env, cwd },
442+
{ env, cwd, shell: true },
440443
);
441444
}
442445

src/rustup.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ export async function rustupUpdate(config: RustupConfig) {
2424
startSpinner('RLS', 'Updating…');
2525

2626
try {
27-
const { stdout } = await withWsl(config.useWSL).execFile(config.path, [
28-
'update',
29-
]);
27+
const { stdout } = await withWsl(config.useWSL).exec(
28+
`${config.path} update`,
29+
);
3030

3131
// This test is imperfect because if the user has multiple toolchains installed, they
3232
// might have one updated and one unchanged. But I don't want to go too far down the
@@ -83,10 +83,9 @@ export async function checkForRls(config: RustupConfig) {
8383

8484
async function hasToolchain(config: RustupConfig): Promise<boolean> {
8585
try {
86-
const { stdout } = await withWsl(config.useWSL).execFile(config.path, [
87-
'toolchain',
88-
'list',
89-
]);
86+
const { stdout } = await withWsl(config.useWSL).exec(
87+
`${config.path} toolchain list`,
88+
);
9089
return stdout.includes(config.channel);
9190
} catch (e) {
9291
console.log(e);
@@ -130,7 +129,7 @@ async function tryToInstallToolchain(config: RustupConfig) {
130129
*/
131130
async function listComponents(config: RustupConfig): Promise<string[]> {
132131
return withWsl(config.useWSL)
133-
.execFile(config.path, ['component', 'list', '--toolchain', config.channel])
132+
.exec(`${config.path} component list --toolchain ${config.channel}`)
134133
.then(({ stdout }) =>
135134
stdout
136135
.toString()
@@ -226,9 +225,8 @@ export function parseActiveToolchain(rustupOutput: string): string {
226225

227226
export async function getVersion(config: RustupConfig): Promise<string> {
228227
const versionRegex = /rustup ([0-9]+\.[0-9]+\.[0-9]+)/;
229-
const execFile = withWsl(config.useWSL).execFile;
230228

231-
const output = await execFile(config.path, ['--version']);
229+
const output = await withWsl(config.useWSL).exec(`${config.path} --version`);
232230
const versionMatch = output.stdout.toString().match(versionRegex);
233231
if (versionMatch && versionMatch.length >= 2) {
234232
return versionMatch[1];
@@ -259,7 +257,7 @@ export function getActiveChannel(wsPath: string, config: RustupConfig): string {
259257
try {
260258
// `rustup show active-toolchain` is available since rustup 1.12.0
261259
activeChannel = withWsl(config.useWSL)
262-
.execFileSync(config.path, ['show', 'active-toolchain'], { cwd: wsPath })
260+
.execSync(`${config.path} show active-toolchain`, { cwd: wsPath })
263261
.toString()
264262
.trim();
265263
// Since rustup 1.17.0 if the active toolchain is the default, we're told
@@ -270,7 +268,7 @@ export function getActiveChannel(wsPath: string, config: RustupConfig): string {
270268
} catch (e) {
271269
// Possibly an old rustup version, so try rustup show
272270
const showOutput = withWsl(config.useWSL)
273-
.execFileSync(config.path, ['show'], { cwd: wsPath })
271+
.execSync(`${config.path} show`, { cwd: wsPath })
274272
.toString();
275273
activeChannel = parseActiveToolchain(showOutput);
276274
}

src/utils/child_process.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import * as util from 'util';
33

44
import { modifyParametersForWSL } from './wslpath';
55

6-
const execFileAsync = util.promisify(child_process.execFile);
6+
const execAsync = util.promisify(child_process.exec);
77

88
export interface SpawnFunctions {
9-
execFile: typeof execFileAsync;
10-
execFileSync: typeof child_process.execFileSync;
9+
exec: typeof execAsync;
10+
execSync: typeof child_process.execSync;
1111
spawn: typeof child_process.spawn;
1212
modifyArgs: (
1313
command: string,
@@ -18,14 +18,14 @@ export interface SpawnFunctions {
1818
export function withWsl(withWsl: boolean): SpawnFunctions {
1919
return withWsl
2020
? {
21-
execFile: withWslModifiedParameters(execFileAsync),
22-
execFileSync: withWslModifiedParameters(child_process.execFileSync),
21+
exec: withWslModifiedParameters(execAsync),
22+
execSync: withWslModifiedParameters(child_process.execSync),
2323
spawn: withWslModifiedParameters(child_process.spawn),
2424
modifyArgs: modifyParametersForWSL,
2525
}
2626
: {
27-
execFile: execFileAsync,
28-
execFileSync: child_process.execFileSync,
27+
exec: execAsync,
28+
execSync: child_process.execSync,
2929
spawn: child_process.spawn,
3030
modifyArgs: (command: string, args: string[]) => ({ command, args }),
3131
};

0 commit comments

Comments
 (0)