-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
make config.nims behave like nim.cfg in terms of where these scripts are searched / run #8682
Conversation
friendly ping |
Can you make it run system |
e1da01a
to
c3423fd
Compare
done PTAL |
c3423fd
to
9f1283c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Look at my remarks.
compiler/nim.nim
Outdated
if fileExists(scriptFile): | ||
runNimScript(cache, scriptFile, freshDefines=false, conf) | ||
|
||
proc runNimScriptIfExists(scriptFile:string)= |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Space after the colon: Just like in written English.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
compiler/nim.nim
Outdated
# merge this complex logic with `loadConfigs` | ||
# check whether these should be controlled via | ||
# optSkipConfigFile, optSkipUserConfigFile | ||
let config_nims = "config.nims" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a const
and the Nim compiler doesn't use under_scores.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
compiler/nim.nim
Outdated
elif fileExists(conf.projectPath / "config.nims"): | ||
# directory wide NimScript file | ||
runNimScript(cache, conf.projectPath / "config.nims", freshDefines=false, conf) | ||
if fileExists(scriptFile) and scriptFile == conf.projectFull: return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this have a fileExists
check? If the same as conf.projectFull
do return. And this should probably use cmpPaths
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this have a fileExists check? If the same as conf.projectFull do return
it's needed; with your suggestion, nim c foo.nims
would exit without error when foo.nims
doesn't exist; with this PR (and in fact preexisting to this PR), it would give an error
And this should probably use cmpPaths
done
9f1283c
to
7b8e420
Compare
PTAL |
@Araq friendly ping |
Sorry, one more thing to do: Patch |
7b8e420
to
3b8caa8
Compare
/cc @Araq PTAL
done: did a refactoring using OOP, which removed a lot of duplicate (and out of sync!) code. after this PR, it will also unblock #8233 which was blocking on your comment here
In future PR, if needed, nimfix can also reuse cmdlinehelper to avoid being out of sync (it's been out of sync for some time; I'd rather not do the change in this PR as it's already out of sync with compiler/nim.nim) |
3b8caa8
to
59184ca
Compare
compiler/nim.nim
Outdated
proc handleCmdLine(cache: IdentCache; conf: ConfigRef) = | ||
condsyms.initDefines(conf.symbols) | ||
let self = ProgNim(name: "nim_compiler") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NOTE: this PR adds
defineSymbol conf.symbols, "nim_compiler"
for symmetry with what's done in numsuggest and nimfix which add "numsuggest" and "nimfix" respectively
compiler/cmdlinehelper.nim
Outdated
|
||
proc processCmdLineAndProjectPath*(self: ProgBase, conf: ConfigRef) = | ||
self.processCmdLine(passCmd1, "", conf) | ||
if conf.projectName == "-": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this branch was missing prior to this PR for nimsuggest
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And yet ... nimsuggest does not support to read the main file from stdin!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
except OSError: | ||
conf.projectFull = conf.projectName | ||
let p = splitFile(conf.projectFull) | ||
let dir = if p.dir.len > 0: p.dir else: getCurrentDir() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was missing prior to this PR for nimsuggest
# 'nim foo.nims' means to just run the NimScript file and do nothing more: | ||
if fileExists(scriptFile) and scriptFile.cmpPaths(conf.projectFull) == 0: | ||
return false | ||
else: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a bit more complex that I'd hope, but that's to keep semantics from before this PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is also hard to review because of the large diffs, who knows what features/changes were made. Maybe split it up in two PRs, one that only adds these new place where to hide config files, one that refactors the code duplication.
compiler/cmdlinehelper.nim
Outdated
if fileExists(scriptFile): | ||
runNimScript(cache, scriptFile, freshDefines=false, conf) | ||
|
||
# TODO: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't write what's left TODO we have enough of this in the compiler, do it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
compiler/cmdlinehelper.nim
Outdated
condsyms.initDefines(conf.symbols) | ||
defineSymbol conf.symbols, self.name | ||
|
||
proc processCmdLineAndProjectPath*(self: ProgBase, conf: ConfigRef) = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of this OOP approach, give processCmdLineAndProjectPath
two callbacks or - probably better- make it a template.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done with 2 callbacks
compiler/nim.nim
Outdated
@@ -37,7 +37,9 @@ proc prependCurDir(f: string): string = | |||
else: | |||
result = f | |||
|
|||
proc processCmdLine(pass: TCmdLinePass, cmd: string; config: ConfigRef) = | |||
type ProgNim=ref object of ProgBase |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Empty subclass means you don't need any inheritance/OOP here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done, changed it to not use OOP
nimsuggest/nimsuggest.nim
Outdated
@@ -487,7 +487,9 @@ proc mainThread(graph: ModuleGraph) = | |||
var | |||
inputThread: Thread[ThreadParams] | |||
|
|||
proc mainCommand(graph: ModuleGraph) = | |||
type ProgNimsuggest=ref object of ProgBase |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Empty subclass means you don't need any inheritance/OOP here.
BTW Spaces around the '='. Just like you saw it everywhere else in Nim's whole codebase.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
8b8f445
to
be30af0
Compare
/cc @Araq
I kept different commits at strategic points and for that purpose, you can select the commit range in review, see image
https://github.com/nim-lang/Nim/pull/8682/files/b76d7f1a916b080a69c588c5675afde7575d2445 (1st 4 commits)
https://github.com/nim-lang/Nim/pull/8682/files/b76d7f1a916b080a69c588c5675afde7575d2445..be30af0ccc960a7e6c1a77d9093e1327beef8ef3 (last 2 commits) alternatively, this also helps: |
compiler/cmdlinehelper.nim
Outdated
std/os | ||
|
||
type NimProg* = ref object | ||
name*: string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this field and pass name
as a parameter to initDefinesProg
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
compiler/cmdlinehelper.nim
Outdated
compiler/[options, idents, nimconf, scriptconfig, extccomp, commands, msgs, lineinfos, modulegraphs, condsyms], | ||
std/os | ||
|
||
type NimProg* = ref object |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type
NimProg* = ref object
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
/cc @Araq PTAL |
3072a93
to
facf529
Compare
|
facf529
to
3ad8f80
Compare
/cc @Araq PTAL |
@timotheecour Just wanted to thank you heartily for this PR :D |
Related: nim-lang#8682 Also mention the "nim help" command to list all available tasks.
glad to hear, thanks :-) |
Related: #8682 Also mention the "nim help" command to list all available tasks.
Related: nim-lang#8682 Also mention the "nim help" command to list all available tasks.
Related: nim-lang#8682 Also mention the "nim help" command to list all available tasks.
Related: #8682 Also mention the "nim help" command to list all available tasks.
/cc @Araq
these are controlled by `optSkipConfigFile