Skip to content

Commit bc1b0bf

Browse files
committed
Auto merge of #15308 - vsrs:runnable_env_per_platform, r=HKalbasi
Runnable env per platform This PR adds an option to specify runnables `env` per platform (win32, linux, etc.): ``` { "rust-analyzer.runnables.extraEnv": [ { "platform": "win32", "env": { "SCITER_BIN_FOLDER": "C:\\Projects\\3rd\\sciter-js-sdk\\bin\\windows\\x64", } }, { "platform":["linux","darwin"], "env": { "SCITER_BIN_FOLDER": "/home/vit/Projects/sciter/sciter-js-sdk/bin/linux/x64", } } ] } ```
2 parents b64e5b3 + 08b3b2a commit bc1b0bf

File tree

4 files changed

+50
-6
lines changed

4 files changed

+50
-6
lines changed

docs/user/manual.adoc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -949,6 +949,29 @@ Or it is possible to specify vars more granularly:
949949
You can use any valid regular expression as a mask.
950950
Also note that a full runnable name is something like *run bin_or_example_name*, *test some::mod::test_name* or *test-mod some::mod*, so it is possible to distinguish binaries, single tests, and test modules with this masks: `"^run"`, `"^test "` (the trailing space matters!), and `"^test-mod"` respectively.
951951

952+
If needed, you can set different values for different platforms:
953+
```jsonc
954+
"rust-analyzer.runnables.extraEnv": [
955+
{
956+
"platform": "win32", // windows only
957+
env: {
958+
"APP_DATA": "windows specific data"
959+
}
960+
},
961+
{
962+
"platform": ["linux"],
963+
"env": {
964+
"APP_DATA": "linux data",
965+
}
966+
},
967+
{ // for all platforms
968+
"env": {
969+
"APP_COMMON_DATA": "xxx",
970+
}
971+
}
972+
]
973+
```
974+
952975
==== Compiler feedback from external commands
953976

954977
Instead of relying on the built-in `cargo check`, you can configure Code to run a command in the background and use the `$rustc-watch` problem matcher to generate inline error markers from its output.

editors/code/package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,15 @@
328328
"items": {
329329
"type": "object",
330330
"properties": {
331+
"platform": {
332+
"type": [
333+
"null",
334+
"string",
335+
"array"
336+
],
337+
"default": null,
338+
"markdownDescription": "Platform(s) filter like \"win32\" or [\"linux\", \"win32\"]. See [process.platform](https://nodejs.org/api/process.html#processplatform) values."
339+
},
331340
"mask": {
332341
"type": "string",
333342
"description": "Runnable name mask"

editors/code/src/config.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ import type { Env } from "./client";
66
import { log } from "./util";
77
import { expectNotUndefined, unwrapUndefinable } from "./undefinable";
88

9-
export type RunnableEnvCfg =
10-
| undefined
11-
| Record<string, string>
12-
| { mask?: string; env: Record<string, string> }[];
9+
export type RunnableEnvCfgItem = {
10+
mask?: string;
11+
env: Record<string, string>;
12+
platform?: string | string[];
13+
};
14+
export type RunnableEnvCfg = undefined | Record<string, string> | RunnableEnvCfgItem[];
1315

1416
export class Config {
1517
readonly extensionId = "rust-lang.rust-analyzer";

editors/code/src/run.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as tasks from "./tasks";
55

66
import type { CtxInit } from "./ctx";
77
import { makeDebugConfig } from "./debug";
8-
import type { Config, RunnableEnvCfg } from "./config";
8+
import type { Config, RunnableEnvCfg, RunnableEnvCfgItem } from "./config";
99
import { unwrapUndefinable } from "./undefinable";
1010

1111
const quickPickButtons = [
@@ -112,11 +112,21 @@ export function prepareEnv(
112112
}
113113

114114
Object.assign(env, process.env as { [key: string]: string });
115+
const platform = process.platform;
116+
117+
const checkPlatform = (it: RunnableEnvCfgItem) => {
118+
if (it.platform) {
119+
const platforms = Array.isArray(it.platform) ? it.platform : [it.platform];
120+
return platforms.indexOf(platform) >= 0;
121+
}
122+
return true;
123+
};
115124

116125
if (runnableEnvCfg) {
117126
if (Array.isArray(runnableEnvCfg)) {
118127
for (const it of runnableEnvCfg) {
119-
if (!it.mask || new RegExp(it.mask).test(runnable.label)) {
128+
const masked = !it.mask || new RegExp(it.mask).test(runnable.label);
129+
if (masked && checkPlatform(it)) {
120130
Object.assign(env, it.env);
121131
}
122132
}

0 commit comments

Comments
 (0)