Skip to content

Avoid replacing env-var ZEPHYR_SDK_INSTALL_DIR, etc. #189

@flisboac

Description

@flisboac

Would it be possible to avoid replacing the ZEPHYR_SDK_INSTALL_DIR, ZEPHYR_BASE, etc., environment variables, if they're already configured for the environment?

I have a VSCode Workspace template that's based around Devcontainers. I do all my work inside a Docker container, which is built based on the needs of the Zephyr project I'm working on ATM, and therefore already has all the necessary tools installed at system or West-venv level. It has exactly the versions needed for SDK and tools, and whatnot.

In other words, in some cases, there's no need for another tool to assume control of those Zephyr-related env-vars. It would be nice to have the option to disable manipulation of env-vars, or at least give the option to force a specific value for some of them in settings.json.

In my case, specifically:

  • My Zephyr app declares dependency to a specific Zephyr version in its west.yml.
  • ZEPHYR_BASE is configured to be the Zephyr cloned by west init. This allows me to open (in VSCode, etc.) and use the exact Zephyr version my application needs;
  • ZEPHYR_SDK_INSTALL_DIR points to a Zephyr SDK installed as part of the Docker image's build process. Its version is fixed in the Dockerfile.

In a way, my environment is prepared to automate as much of the boring stuff as possible. The intention is for any developer to just clone, run a command or two and open the project in VSCode, and nothing more. If preference is given to some Zephyr-related extension, they're free to install and use, as long as the extension is capable of identifying what the environment provides, and uses it as much as possible.

So, this is the motivation, for my case specifically. However, the direct manipulation of ZEPHYR_SDK_INSTALL_DIR and other Zephyr-related environment variables in the Terminal breaks many use-cases, even related to other extensions:

Image

Looking into Zephyr IDE's source code, I see that ZEPHYR_SDK_INSTALL_DIR is set to be replaced, at this part of the extension's code:

context.environmentVariableCollection.replace("ZEPHYR_SDK_INSTALL_DIR", getToolchainDir(), { applyAtProcessCreation: true, applyAtShellIntegration: true });

And getToolchainDir() is somewhat hardcoded, and the folder it points to may not even be in a layout expected for an user of Zephyr SDK (I mean, which references ZEPHYR_SDK_INSTALL_DIR... I think?):

export function getToolsDir() {
let toolsdir = path.join(os.homedir(), toolsfoldername);
const configuration = vscode.workspace.getConfiguration();
let toolsDirFromFile: string | undefined = configuration.get("zephyr-ide.tools_directory");
if (toolsDirFromFile) {
toolsdir = toolsDirFromFile;
}
// Ensure directory exists before returning
try {
if (!fs.pathExistsSync(toolsdir)) {
fs.ensureDirSync(toolsdir);
}
} catch (e) {
console.error("Failed to ensure tools directory exists:", toolsdir, e);
}
return toolsdir;
}
export function getToolchainDir() {
return path.join(getToolsDir(), "toolchains");
}

So, is there a way to make this behavior optional, or at least configurable to some extent? (Not only for ZEPHYR_SDK_INSTALL_DIR, but for ZEPHYR_BASE and any other env-var that Zephyr IDE intends to manage)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions