summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorflywind <xzsflywind@gmail.com>2021-04-01 14:05:04 +0800
committerGitHub <noreply@github.com>2021-04-01 08:05:04 +0200
commit924ab3adea30b8ffe590d1dd08cc3ff23f4881de (patch)
tree1ebd26f158ed64eb5cd567a4b697f033e3885939
parentfe9a37f2a57d0e76984b25c3dfe0fbdc94a30d9e (diff)
downloadNim-924ab3adea30b8ffe590d1dd08cc3ff23f4881de.tar.gz
fix #17190 `nimscript` now accepts arbitrary file extensions for `nim e main.customext` (#17596)
* fix #17190

* cah

* merge

* Update tnimscriptwithnimext.nim

* Update tnimscriptwithmacro.nims

* Apply suggestions from code review

* Delete tnimscriptwithnimext.nim

* Update tests/tools/tnimscriptwithmacro.nims

* fix

* fix

* add a test

* Apply suggestions from code review

Co-authored-by: Timothee Cour <timothee.cour2@gmail.com>

* Apply suggestions from code review

* Update changelog.md

Co-authored-by: Timothee Cour <timothee.cour2@gmail.com>

Co-authored-by: Timothee Cour <timothee.cour2@gmail.com>
Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
-rw-r--r--changelog.md2
-rw-r--r--compiler/main.nim2
-rw-r--r--compiler/nimconf.nim7
-rw-r--r--tests/misc/trunner.nim9
-rw-r--r--tests/newconfig/foo2/mfoo2.customext2
5 files changed, 18 insertions, 4 deletions
diff --git a/changelog.md b/changelog.md
index f6dcee833..900693644 100644
--- a/changelog.md
+++ b/changelog.md
@@ -281,6 +281,8 @@
 - Tuple expressions are now parsed consistently as
   `nnkTupleConstr` node. Will affect macros expecting nodes to be of `nnkPar`.
 
+- `nim e` now accepts arbitrary file extensions for the nimscript file,
+  although `.nims` is still the preferred extension in general.
 
 ## Compiler changes
 
diff --git a/compiler/main.nim b/compiler/main.nim
index b61cdcadb..26a19063f 100644
--- a/compiler/main.nim
+++ b/compiler/main.nim
@@ -342,8 +342,6 @@ proc mainCommand*(graph: ModuleGraph) =
     if conf.projectIsCmd or conf.projectIsStdin: discard
     elif not fileExists(conf.projectFull):
       rawMessage(conf, errGenerated, "NimScript file does not exist: " & conf.projectFull.string)
-    elif not conf.projectFull.string.endsWith(".nims"):
-      rawMessage(conf, errGenerated, "not a NimScript file: " & conf.projectFull.string)
     # main NimScript logic handled in `loadConfigs`.
   of cmdNop: discard
   of cmdJsonscript:
diff --git a/compiler/nimconf.nim b/compiler/nimconf.nim
index 1691e7ccf..b63e5a0ad 100644
--- a/compiler/nimconf.nim
+++ b/compiler/nimconf.nim
@@ -298,11 +298,14 @@ proc loadConfigs*(cfg: RelativeFile; cache: IdentCache; conf: ConfigRef; idgen:
     for filename in configFiles:
       # delayed to here so that `hintConf` is honored
       rawMessage(conf, hintConf, filename.string)
-  if scriptIsProj:
+  if conf.cmd == cmdNimscript:
     showHintConf()
     configFiles.setLen 0
   if conf.cmd != cmdIdeTools:
-    runNimScriptIfExists(scriptFile, isMain = true)
+    if conf.cmd == cmdNimscript:
+      runNimScriptIfExists(conf.projectFull, isMain = true)
+    else:
+      runNimScriptIfExists(scriptFile, isMain = true)
   else:
     if not scriptIsProj:
       runNimScriptIfExists(scriptFile, isMain = true)
diff --git a/tests/misc/trunner.nim b/tests/misc/trunner.nim
index a66177f28..1895eeb97 100644
--- a/tests/misc/trunner.nim
+++ b/tests/misc/trunner.nim
@@ -238,6 +238,15 @@ tests/newconfig/bar/mfoo.nims""".splitLines
       expected.add &"Hint: used config file '{b}' [Conf]\n"
     doAssert outp.endsWith expected, outp & "\n" & expected
 
+  block: # mfoo2.customext
+    let filename = testsDir / "newconfig/foo2/mfoo2.customext"
+    let cmd = fmt"{nim} e --hint:conf {filename}"
+    let (outp, exitCode) = execCmdEx(cmd, options = {poStdErrToStdOut})
+    doAssert exitCode == 0
+    var expected = &"Hint: used config file '{filename}' [Conf]\n"
+    doAssert outp.endsWith "123" & "\n" & expected
+
+
   block: # nim --eval
     let opt = "--hints:off"
     check fmt"""{nim} {opt} --eval:"echo defined(nimscript)"""".execCmdEx == ("true\n", 0)
diff --git a/tests/newconfig/foo2/mfoo2.customext b/tests/newconfig/foo2/mfoo2.customext
new file mode 100644
index 000000000..66c8b1d15
--- /dev/null
+++ b/tests/newconfig/foo2/mfoo2.customext
@@ -0,0 +1,2 @@
+doAssert defined(nimscript)
+echo "123"