Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix failure to run executable targets on Windows #231

Merged

Conversation

cerfical
Copy link
Contributor

@cerfical cerfical commented May 6, 2024

Fixes #228

@tristan957
Copy link
Contributor

Could you describe how this fixes the issue? Thanks for your contribution

@cerfical
Copy link
Contributor Author

cerfical commented May 6, 2024

Well, the code below parses the environment file meson-vscode.env:

vscode-meson/src/utils.ts

Lines 169 to 178 in 3f4ee1e

_envDict = {};
const data = await fs.promises.readFile(envfile);
for (const i of data.toString().split(/\r?\n/)) {
// Poor man's i.split("=", 1), JS won't return part after first equal sign.
// Value is quoted, remove first and last " char and also possible \r ending.
const index = i.indexOf("=");
const key = i.substring(0, index);
const value = i.slice(index + 2, -1);
_envDict[key] = value;
}

I haven't looked into how exactly the file gets its contents, but I guess that it must contain some kind of environment variables defined as <key>=<value> pairs. Later, the environment is used to initialize a new process responsible for a run task:

new vscode.ProcessExecution(t.filename[0], {
cwd: workspaceState.get<string>("mesonbuild.sourceDir")!,
env: getEnvDict(),
}),

The problem occurs because envFile can contain an empty line (specifically at the end of file), which causes an empty key with an empty value to be inserted into the resulting dict. The implementation then calls a system API to create a process and fails. So for a simple solution, we can just ignore empty lines by filter()'ing them out. Or we could redesign some things, and that requires extra work for such a small issue, so...

@tristan957 tristan957 added this pull request to the merge queue Jun 24, 2024
Merged via the queue into mesonbuild:main with commit f59c628 Jun 24, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Run executable fails on Windows
2 participants