summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--compiler/commands.nim26
-rw-r--r--tests/compiler/tcmdlinecpuamd64.nim10
-rw-r--r--tests/compiler/tcmdlinecpuamd64.nim.cfg1
-rw-r--r--tests/compiler/tcmdlineoswin.nim14
-rw-r--r--tests/compiler/tcmdlineoswin.nim.cfg1
5 files changed, 38 insertions, 14 deletions
diff --git a/compiler/commands.nim b/compiler/commands.nim
index 249312f50..068fcbc92 100644
--- a/compiler/commands.nim
+++ b/compiler/commands.nim
@@ -627,22 +627,20 @@ proc processSwitch*(switch, arg: string, pass: TCmdLinePass, info: TLineInfo;
     processOnOffSwitchG(conf, {optGenMapping}, arg, pass, info)
   of "os":
     expectArg(conf, switch, arg, pass, info)
-    if pass in {passCmd1, passPP}:
-      let theOS = platform.nameToOS(arg)
-      if theOS == osNone:
-        let osList = platform.listOSnames().join(", ")
-        localError(conf, info, "unknown OS: '$1'. Available options are: $2" % [arg, $osList])
-      elif theOS != conf.target.hostOS:
-        setTarget(conf.target, theOS, conf.target.targetCPU)
+    let theOS = platform.nameToOS(arg)
+    if theOS == osNone:
+      let osList = platform.listOSnames().join(", ")
+      localError(conf, info, "unknown OS: '$1'. Available options are: $2" % [arg, $osList])
+    else:
+      setTarget(conf.target, theOS, conf.target.targetCPU)
   of "cpu":
     expectArg(conf, switch, arg, pass, info)
-    if pass in {passCmd1, passPP}:
-      let cpu = platform.nameToCPU(arg)
-      if cpu == cpuNone:
-        let cpuList = platform.listCPUnames().join(", ")
-        localError(conf, info, "unknown CPU: '$1'. Available options are: $2" % [ arg, cpuList])
-      elif cpu != conf.target.hostCPU:
-        setTarget(conf.target, conf.target.targetOS, cpu)
+    let cpu = platform.nameToCPU(arg)
+    if cpu == cpuNone:
+      let cpuList = platform.listCPUnames().join(", ")
+      localError(conf, info, "unknown CPU: '$1'. Available options are: $2" % [ arg, cpuList])
+    else:
+      setTarget(conf.target, conf.target.targetOS, cpu)
   of "run", "r":
     processOnOffSwitchG(conf, {optRun}, arg, pass, info)
   of "errormax":
diff --git a/tests/compiler/tcmdlinecpuamd64.nim b/tests/compiler/tcmdlinecpuamd64.nim
new file mode 100644
index 000000000..0265e3d94
--- /dev/null
+++ b/tests/compiler/tcmdlinecpuamd64.nim
@@ -0,0 +1,10 @@
+discard """
+  cmd: "nim $target $options --cpu:amd64 $file"
+  disabled: "32bit"
+"""
+
+import strutils
+
+static:
+  #cpu is set to "i386" in tcpuamd64.nim.cfg, but --cpu:amd64 in command line should override it.
+  doAssert cmpIgnoreCase(hostCPU, "amd64") == 0
diff --git a/tests/compiler/tcmdlinecpuamd64.nim.cfg b/tests/compiler/tcmdlinecpuamd64.nim.cfg
new file mode 100644
index 000000000..f2e5064ad
--- /dev/null
+++ b/tests/compiler/tcmdlinecpuamd64.nim.cfg
@@ -0,0 +1 @@
+cpu:i386
diff --git a/tests/compiler/tcmdlineoswin.nim b/tests/compiler/tcmdlineoswin.nim
new file mode 100644
index 000000000..6642c5ac6
--- /dev/null
+++ b/tests/compiler/tcmdlineoswin.nim
@@ -0,0 +1,14 @@
+discard """
+  cmd: "nim $target $options --os:windows $file"
+  disabled: "linux"
+  disabled: "bsd"
+  disabled: "macosx"
+  disabled: "unix"
+  disabled: "posix"
+"""
+
+import strutils
+
+static:
+  #os is set to "linux" in toswin.nim.cfg, but --os:windows in command line should override it.
+  doAssert cmpIgnoreCase(hostOS, "windows") == 0
diff --git a/tests/compiler/tcmdlineoswin.nim.cfg b/tests/compiler/tcmdlineoswin.nim.cfg
new file mode 100644
index 000000000..037f87651
--- /dev/null
+++ b/tests/compiler/tcmdlineoswin.nim.cfg
@@ -0,0 +1 @@
+os:linux