This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Adding to the $PATH on MacOS for nRF9160 SDK, nRF Connect v3.6.1 - Toolchain Manager "Open Terminal" button

I think this is a very simple answer but I can't find out where the file is to edit for this.

From the nRF Connect v3.6.1 - Toolchain Manager there is a drop down and "Open Terminal" command right?

I want to know where it is setting the paths from, when I installed nrfjprog it installed it in /usr/local/bin BUT it is not in the path.

This does not use my normal bash profile when I open the terminal through the Toolchain Manager, how so I add to this path?

This is what I see now in the terminal when I start it, I want to add /usr/local/bin to it...

Last login: Thu Jan 7 11:52:33 on ttys001
cd /opt/nordic/ncs/v1.4.1 ; export PATH=/opt/nordic/ncs/v1.4.1/toolchain/bin:/usr/bin:/bin:/usr/sbin:/sbin ; export GIT_EXEC_PATH=/opt/nordic/ncs/v1.4.1/toolchain/Cellar/git/2.26.2/libexec/git-core ; export ZEPHYR_TOOLCHAIN_VARIANT=gnuarmemb ; export GNUARMEMB_TOOLCHAIN_PATH=/opt/nordic/ncs/v1.4.1/toolchain ; clear
xxxx@xxxx ~ % cd /opt/nordic/ncs/v1.4.1 ; export PATH=/opt/nordic/ncs/v1.4.1/toolchain/bin:/usr/bin:/bin:/usr/sbin:/sbin ; export GIT_EXEC_PATH=/opt/nordic/ncs/v1.4.1/toolchain/Cellar/git/2.26.2/libexec/git-core ; export ZEPHYR_TOOLCHAIN_VARIANT=gnuarmemb ; export GNUARMEMB_TOOLCHAIN_PATH=/opt/nordic/ncs/v1.4.1/toolchain ; clear

xxxx@xxxx ~ % echo $PATH
/opt/nordic/ncs/v1.4.1/toolchain/bin:/usr/bin:/bin:/usr/sbin:/sbin

After making these changes do I have to restart anything (aka is anything cached) ?

Parents
  • Hi,

    When you open a terminal in Toolchain Manager, you're actually opening git-bash.exe, which is found in your toolchain folder. As you've noticed, opening this bash shell sets up the correct environment. For more information about how this is done, you should take a look at v1.4.1/toolchain/git-cmd.cmd and /v1.4.1/toolchain/cmd/env.cmd. There you'll find how this is set up.

    Another possibility if you want to build things from command line is to check out the guide on installing NCS manually.

    Best regards,

    Marte

  • Hi,

    I do not have a computer with macOS available to check this right now, but it should be a file in your toolchain folder that is being executed when you open SES or a terminal through Toolchain Manager. You can open the toolchain folder by clicking on the arrow next to "Open IDE" in Toolchain Manager and selecting "Open toolchain directory". Can you please tell me which files are located in this folder in your case?

    Best regards,

    Marte

  • There is no toolchain/cmd directory. There are no relevant .sh files in toolchain (or the rest of the SDK)...

  • Hi,

    As cmd is a Windows file (Windows Command Script), you will not have any cmd files or directories on macOS.

    It seems I was mistaken in my previous replies. I believed Toolchain Manager behaved similarly on macOS as on Windows in such a way that when you opened SES or a terminal through Toolchain Manager it executed a file that did everything, such as setting up the environment variables and opening SES or the terminal. Instead, it is the Toolchain Manager itself that sets up the environment variables on macOS.

    So for opening SES using "Open IDE" in Toolchain Manager, you should look at this file (the link is to a file on github, and not a download). On line 222 you see the code for opening SES, where the relevant part on macOS is the 'darwin' case in the switch:

            case 'darwin': {
                const realStudioPath = fs.readlinkSync(
                    `${toolchainDir}/segger_embedded_studio/SEGGER Embedded Studio.app`
                );
                exec(
                    `open "${toolchainDir}/segger_embedded_studio/${realStudioPath}"`,
                    {
                        env: {
                            PATH: `${toolchainDir}/bin:${remote.process.env.PATH}`,
                            ZEPHYR_TOOLCHAIN_VARIANT: 'gnuarmemb',
                            GNUARMEMB_TOOLCHAIN_PATH: toolchainDir,
                        },
                        cwd,
                    },
                    execCallback
                );
                break;
            }

    There you see that it sets the path, ZEPHYR_TOOLCHAIN_VARIANT and GNUARMEMB_TOOLCHAIN_PATH, as well as opens SES.

    For terminal, you should look at this file, where the code for opening the terminal is on line 89. Again, the code for macOS can be identified by darwin, and is the following:

        darwin: toolchainDir => {
            logger.info('Open terminal');
            usageData.sendUsageData(
                EventAction.OPEN_TERMINAL,
                `${process.platform}; ${process.arch}`
            );
            const gitversion = readdirSync(`${toolchainDir}/Cellar/git`).pop();
            const env = [
                `export PATH=${toolchainDir}/bin:$PATH`,
                `export GIT_EXEC_PATH=${toolchainDir}/Cellar/git/${gitversion}/libexec/git-core`,
                'export ZEPHYR_TOOLCHAIN_VARIANT=gnuarmemb',
                `export GNUARMEMB_TOOLCHAIN_PATH=${toolchainDir}`,
            ];
            exec(
                `
    osascript <<END
    tell application "Terminal"
        do script "cd ${path.dirname(toolchainDir)} ; ${env.join(' ; ')} ; clear"
        activate
    end tell
    END
                `,
                execCallback
            );
        },

    You see that this also sets the environment variables and opens the terminal.

    If you compare these with what is found for Windows (the 'win32' case in the first file, and openBash and openCmd in the second one), you see that on Windows, the environment variables are not set here by the Toolchain Manager, but instead it runs some files that set these.

    As I mentioned earlier, another option is to look at how the build environment is set up when you install NCS manually. You can find how to do this here.

    Best regards,

    Marte

Reply
  • Hi,

    As cmd is a Windows file (Windows Command Script), you will not have any cmd files or directories on macOS.

    It seems I was mistaken in my previous replies. I believed Toolchain Manager behaved similarly on macOS as on Windows in such a way that when you opened SES or a terminal through Toolchain Manager it executed a file that did everything, such as setting up the environment variables and opening SES or the terminal. Instead, it is the Toolchain Manager itself that sets up the environment variables on macOS.

    So for opening SES using "Open IDE" in Toolchain Manager, you should look at this file (the link is to a file on github, and not a download). On line 222 you see the code for opening SES, where the relevant part on macOS is the 'darwin' case in the switch:

            case 'darwin': {
                const realStudioPath = fs.readlinkSync(
                    `${toolchainDir}/segger_embedded_studio/SEGGER Embedded Studio.app`
                );
                exec(
                    `open "${toolchainDir}/segger_embedded_studio/${realStudioPath}"`,
                    {
                        env: {
                            PATH: `${toolchainDir}/bin:${remote.process.env.PATH}`,
                            ZEPHYR_TOOLCHAIN_VARIANT: 'gnuarmemb',
                            GNUARMEMB_TOOLCHAIN_PATH: toolchainDir,
                        },
                        cwd,
                    },
                    execCallback
                );
                break;
            }

    There you see that it sets the path, ZEPHYR_TOOLCHAIN_VARIANT and GNUARMEMB_TOOLCHAIN_PATH, as well as opens SES.

    For terminal, you should look at this file, where the code for opening the terminal is on line 89. Again, the code for macOS can be identified by darwin, and is the following:

        darwin: toolchainDir => {
            logger.info('Open terminal');
            usageData.sendUsageData(
                EventAction.OPEN_TERMINAL,
                `${process.platform}; ${process.arch}`
            );
            const gitversion = readdirSync(`${toolchainDir}/Cellar/git`).pop();
            const env = [
                `export PATH=${toolchainDir}/bin:$PATH`,
                `export GIT_EXEC_PATH=${toolchainDir}/Cellar/git/${gitversion}/libexec/git-core`,
                'export ZEPHYR_TOOLCHAIN_VARIANT=gnuarmemb',
                `export GNUARMEMB_TOOLCHAIN_PATH=${toolchainDir}`,
            ];
            exec(
                `
    osascript <<END
    tell application "Terminal"
        do script "cd ${path.dirname(toolchainDir)} ; ${env.join(' ; ')} ; clear"
        activate
    end tell
    END
                `,
                execCallback
            );
        },

    You see that this also sets the environment variables and opens the terminal.

    If you compare these with what is found for Windows (the 'win32' case in the first file, and openBash and openCmd in the second one), you see that on Windows, the environment variables are not set here by the Toolchain Manager, but instead it runs some files that set these.

    As I mentioned earlier, another option is to look at how the build environment is set up when you install NCS manually. You can find how to do this here.

    Best regards,

    Marte

Children
No Data
Related