fredericbonnet / cmake-test-explorer

CMake Test Explorer for Visual Studio Code
BSD 3-Clause "New" or "Revised" License
7 stars 11 forks source link

Extra Ctest Env vars: Also support dotenv file #44

Open SpaceIm opened 3 years ago

SpaceIm commented 3 years ago

Currently, CMake test explorer allows to hardcode env vars in cmakeExplorer.extraCtestEnvVars. But there is no way to load env vars from a dotenv file like in C/C++ extension debugging configuration (https://code.visualstudio.com/docs/cpp/launch-json-reference#_environment-variable-definitions-file).

It would be convenient to add this feature. I'm using conan (C/C++ package manager), and I need to initialize several environment variables (PATH, LD_LIBRARY_PATH or DYLD_LIBRARY_PATH basically), before running executables having runtime dependencies. conan can generate a shell to source, a .bat for windows, and a dotenv file. The content of those environment variables can be very complex, it can change after an update of the dependency graph, or a switch between CMake build types, so hardcoding env vars in cmakeExplorer.extraCtestEnvVars is not an option here.

fredericbonnet commented 3 years ago

That's a good idea, I'll add dotenv support in the next version. BTW do you know the order of precedence between environment and envFile? envFile is supported by VS Code directly in debug mode, however it needs special support for run mode [^1] and I want to keep the same semantics for both.

[^1]: reading the dotenv file and passing its content to Node child_process.spawn

SpaceIm commented 3 years ago

@fredericbonnet thanks for considering this feature.

BTW do you know the order of precedence between environment and envFile? envFile is supported by VS Code directly in debug mode

AFAIK it's not supported directly by VSCode, I mean it's specific to each VSCode debugging configuration. For example C/C++ extension supports envFile, node debugging type also, or python extension, but not (yet) CodeLLDB extension. So I guess that order of precedence is implementation specific. I guess envFile could be injected first, then environment since the later is more specific. Anyway both should be injected. If you do something like this: PATH="<somepath>:$PATH" (Unix) or PATH=<somepath>;%PATH% (Windows) in each one, it's additive.

SpaceIm commented 3 years ago

It may help, in C/C++ extension: https://github.com/microsoft/vscode-cpptools/blob/8815aa5d8302822e575fe1c7a7b24f53ee029a51/Extension/src/Debugger/ParsedEnvironmentFile.ts https://github.com/microsoft/vscode-cpptools/blob/8815aa5d8302822e575fe1c7a7b24f53ee029a51/Extension/src/Debugger/configurationProvider.ts#L399-L425