nim-lang / nimble

Package manager for the Nim programming language.
https://nim-lang.github.io/nimble/index.html
Other
1.25k stars 190 forks source link

setCommand runs after the `after` block #575

Open haltcase opened 5 years ago

haltcase commented 5 years ago

Given a task b and an after b: ... hook, the after block runs before b. Repro:

https://gist.github.com/citycide/86ddf061c6ada8e0218edaf7119f076e

(Note that you can clone gists as git repos, git clone https://gist.github.com/86ddf061c6ada8e0218edaf7119f076e.git)

# nimble_tasks.nim
when isMainModule:
  echo "Hello, World!"
# nimble_tasks.nimble
version     = "0.1.0"
author      = "citycide"
description = "Nimble task hooks repro"
license     = "MIT"
bin         = @["nimble_tasks"]

requires "nim >= 0.19.0"

template exe (s: string): string =
  if buildOS == "windows": s & ".exe" else: s

after b:
  # this runs before the `b` task is done?
  echo existsFile("nt".exe) # -> false??

task b, "build a thing":
  rmFile "nt".exe
  switch "out", "nt".exe
  switch "define", "release"
  setCommand "c", "nimble_tasks.nim"

» nim -v
Nim Compiler Version 0.19.0 [Windows: amd64]
Compiled at 2018-10-03
Copyright (c) 2006-2018 by Andreas Rumpf

active boot switches: -d:release

» nimble -v
nimble v0.9.0 compiled at 2018-10-03 02:18:38
git hash: af1c1d73c32b6e9fe7a8aecf3768d9f482b18180
haltcase commented 5 years ago

I think this is actually because of setCommand which apparently sets the command to run once the nimscript file is run, not the task. So I'll close this since it's probably working as designed even if it's a bit confusing at first.

dom96 commented 5 years ago

I think this is actually because of setCommand which apparently sets the command to run once the nimscript file is run, not the task.

Huh? That doesn't right at all.

haltcase commented 5 years ago

Not sure if it's ideal but that's how it's currently documented:

https://nim-lang.org/docs/nimscript.html#setCommand%2Cstring%2Cstring

proc setCommand(cmd: string; project = "") {...} Sets the Nim command that should be continued with after this Nimscript has finished.

dom96 commented 5 years ago

Yes, but the code under "task" is only executed that task is executed.

dom96 commented 5 years ago

wow, two words missing in my comments above and I'm puzzled as to what I was actually talking about. I must have been pretty tired :)

This said, I don't particularly like these semantics. It is true that setCommand simply asks Nimble to run a command after the task finishes, but I'm not sure that should also be after the after block is executed.