Skip to content
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

[superseded] partially address issue #8217 by running user config.nims if possible #8233

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions compiler/nim.nim
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,23 @@ proc handleCmdLine(cache: IdentCache; conf: ConfigRef) =
conf.projectPath = canonicalizePath(conf, getCurrentDir())
loadConfigs(DefaultConfig, cache, conf) # load all config files
let scriptFile = conf.projectFull.changeFileExt("nims")
const config_nims = "config.nims"
if fileExists(scriptFile):
runNimScript(cache, scriptFile, freshDefines=false, conf)
# 'nim foo.nims' means to just run the NimScript file and do nothing more:
if scriptFile == conf.projectFull: return
elif fileExists(conf.projectPath / "config.nims"):
elif fileExists(conf.projectPath / config_nims):
# directory wide NimScript file
runNimScript(cache, conf.projectPath / "config.nims", freshDefines=false, conf)
runNimScript(cache, conf.projectPath / config_nims, freshDefines=false, conf)
else:
# TODO: would like to apply in some sequence the nims scripts we find but
# if we call `runNimScript` multiple times in errors with:
# ???(0, 0) Error: internal error: n is not nil
if optSkipUserConfigFile notin conf.globalOptions:
let file = getUserConfigPath(config_nims)
if fileExists(file):
runNimScript(cache, file, freshDefines=false, conf)

# now process command line arguments again, because some options in the
# command line can overwite the config file's settings
extccomp.initVars(conf)
Expand Down
2 changes: 1 addition & 1 deletion compiler/nimconf.nim
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ proc readConfigFile(
closeLexer(L)
return true

proc getUserConfigPath(filename: string): string =
proc getUserConfigPath*(filename: string): string =
result = joinPath(getConfigDir(), filename)

proc getSystemConfigPath(conf: ConfigRef; filename: string): string =
Expand Down
1 change: 1 addition & 0 deletions nimsuggest/nimsuggest.nim
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,7 @@ proc processCmdLine*(pass: TCmdLinePass, cmd: string; conf: ConfigRef) =
conf.projectName = a
# if processArgument(pass, p, argsCount): break

# TODO: refactor with nimconf.nim to avoid duplicating complex logic
Copy link
Member

@Araq Araq Jul 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. But I cannot merge a PR that makes things worse, then nimsuggest disagrees with nim's way of reading the configuration.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, pending refactoring via OOP here #8682 (comment)

proc handleCmdLine(cache: IdentCache; conf: ConfigRef) =
condsyms.initDefines(conf.symbols)
defineSymbol conf.symbols, "nimsuggest"
Expand Down