Skip to content

Commit

Permalink
feat: update proxy binaries on self-update
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher Arndt <[email protected]>
  • Loading branch information
SpotlightKid committed Jan 3, 2025
1 parent e71f941 commit 332653b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 17 deletions.
4 changes: 4 additions & 0 deletions src/choosenim.nim
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ proc updateSelf(params: CliParams) =
display("Info:", "Updated choosenim to version " & $version,
Success, HighPriority)

# Any Nim installation currently activated by choosenim?
if $getCurrentVersion(params) != "":
discard installProxies(params)

proc update(params: CliParams) =
if params.commands.len != 2:
raise newException(ChooseNimError,
Expand Down
44 changes: 27 additions & 17 deletions src/choosenimpkg/switcher.nim
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,31 @@ proc writeProxy(bin: string, params: CliParams) =
display("Hint:", "Ensure that '$1' is before '$2' in the PATH env var." %
[params.getBinDir(), fromPATH.splitFile.dir], Warning, HighPriority)

proc installProxies*(params: CliParams): bool =
## Install or update proxy executables.
##
## Returns `true` when any proxies were newly installed or updated,
## `false` otherwise.
var proxiesToInstall = @proxies

# Handle MingW proxies.
when defined(windows):
if not isDefaultCCInPath(params):
let mingwBin = getMingwBin(params)
if not fileExists(mingwBin / "gcc".addFileExt(ExeExt)):
let msg = "No 'gcc' binary found in '$1'." % mingwBin
raise newException(ChooseNimError, msg)

proxiesToInstall.add(mingwProxies)

if not params.areProxiesInstalled(proxiesToInstall):
# Create the proxy executables.
for proxy in proxiesToInstall:
writeProxy(proxy, params)
return true

return false

proc switchToPath(filepath: string, params: CliParams): bool =
## Switches to the specified file path that should point to the root of
## the Nim repo.
Expand All @@ -254,30 +279,15 @@ proc switchToPath(filepath: string, params: CliParams): bool =
"running `choosenim \"#v0.16.0\"` or similar.",
Warning, HighPriority)

var proxiesToInstall = @proxies
# Handle MingW proxies.
when defined(windows):
if not isDefaultCCInPath(params):
let mingwBin = getMingwBin(params)
if not fileExists(mingwBin / "gcc".addFileExt(ExeExt)):
let msg = "No 'gcc' binary found in '$1'." % mingwBin
raise newException(ChooseNimError, msg)

proxiesToInstall.add(mingwProxies)

# Return early if this version is already selected.
let selectedPath = params.getSelectedPath()
let proxiesInstalled = params.areProxiesInstalled(proxiesToInstall)
if selectedPath == filepath and proxiesInstalled:

if selectedPath == filepath and not installProxies(params):
return false
else:
# Write selected path to "current file".
writeFile(params.getCurrentFile(), filepath)

# Create the proxy executables.
for proxy in proxiesToInstall:
writeProxy(proxy, params)

when defined(windows):
if not isNimbleBinInPath(params):
display("Hint:", "Use 'choosenim <version/channel> --firstInstall' to add\n" &
Expand Down

0 comments on commit 332653b

Please sign in to comment.