nim-lang / choosenim

Official tool for easily installing and managing multiple versions of the Nim programming language.
BSD 3-Clause "New" or "Revised" License
36 stars 7 forks source link

—getNimbleDir prints out debug info and brakes installation script #50

Open federico-lox opened 2 weeks ago

federico-lox commented 2 weeks ago

I’m setting the NIMBLE_DIR environment variable, and it seems that choosenim --getNimbleDir, which is used in the installation script to get the value, prints out debug info data when it doesn’t seem to be expected in the output, breaking the invitation of cp to move the downloaded binary to its permanent destination:

choosenim-init: Downloading choosenim-0.8.9_linux_amd64
Info: Using the environment variable: NIMBLE_DIR='/home/runner/Nim-stable/.nimble'
Info: Using the environment variable: NIMBLE_DIR='/home/runner/Nim-stable/.nimble'
Info: Version 2.2.0 already selected
cp: cannot create regular file ''$'\033''[32m'$'\033' '[1mInfo: '$'\033''[0m'$'\033'' [OmUsing the environment variable: NIMBLE_DIR='\''/home/runner/Nim-stable/.nimble'\'''$'\n\033''[32m'$
'\033'' [1mInfo: '$'\033''[0m'$'\033'' [OmUsing the environment variable: NIMBLE_DIR='\''/ho me/runner/Nim-stable/.nimble'\'''$'\n''/home/run ner/Nim-stable/.nimble/bin/choosenim': No such file or directory

I’m running on NixOS 24.05 and with bash 5.2.26 and it’s reproducible on the latest version of the script downloaded directly from this repo.

SpotlightKid commented 2 weeks ago

You mean --getNimbleBin, which is used by the init.sh script.

But the output is from setNimbleDir, which is imported from nimblepkg.options and is called by newCliParams, so in any case.

federico-lox commented 2 weeks ago

@SpotlightKid Yes, the is an artefact of iOS autocompletion. Fixed in OP.

It’s invoked here: https://github.com/nim-lang/choosenim/blob/162d73d07f05b16cc41f3542ee6a9133508d8daf/scripts/choosenim-unix-init.sh#L83

# Copy choosenim binary to Nimble bin.
local nimbleBinDir= '"$temp_prefix/$filename" --getNimbleBin'

That invocation doesn’t seem to account for the command outputting “Info: …” debug lines when NIMBLE_DIR is set for the environment.

SpotlightKid commented 2 weeks ago

@SpotlightKid Yes, the is an artefact of iOS autocompletion. Fixed in OP.

My correction wasn't about the --, but that the option is --getNimbleBin, not --getNimbleDir. :smile:

The "Info: ..." output goes to stdout, so it is captured by the shell backticks in the line you cited, there is no way to prevent that. So either nimble needs to be fixed to don't output those lines or the init.sh script needs to use another way to determine the nimble bin dir.

The output is not triggered by the --getNimbleBin option, but solely by the presence of the NIMBLE_DIR env variable. E.g. try:

NIMBLE_DIR=/tmp/foo choosenim --help | head

which outputs:

      Info: Using the environment variable: NIMBLE_DIR='/tmp/foo'
      Info: Using the environment variable: NIMBLE_DIR='/tmp/foo'
choosenim: The Nim toolchain installer.

Choose a job. Choose a mortgage. Choose life. Choose Nim.

Usage:
  choosenim <version/path/channel>

Example: