Repository: conan-io/conan

Issue:
vcvars_command ignores sdk version for vcversion <= 14
I was doing:

vcvars = tools.vcvars_command(self.settings,winsdk_version="8.1")

but the 8.1 wasn't getting appended

Looking at the code:

```
if int(compiler_version) > 14:
                vcvars_path = os.path.join(vs_path, "VC/Auxiliary/Build/vcvarsall.bat")
                command = ('set "VSCMD_START_DIR=%%CD%%" && '
                           'call "%s" %s' % (vcvars_path, vcvars_arch))
                if winsdk_version:
                    command += " %s" % winsdk_version
                if vcvars_ver:
                    command += " -vcvars_ver=%s" % vcvars_ver
```

version 14 is excluded for some reason. 

however the sdk does seem supported for v14:

```
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC>vcvarsall.bat /?
Error in script usage. The correct usage is:
    vcvarsall.bat [option]
  or
    vcvarsall.bat [option] store
  or
    vcvarsall.bat [option] [version number]
  or
    vcvarsall.bat [option] store [version number]
where [option] is: x86 | amd64 | arm | x86_amd64 | x86_arm | amd64_x86 | amd64_arm
where [version number] is either the full Windows 10 SDK version number or "8.1" to use the windows 8.1 SDK
:
The store parameter sets environment variables to support
  store (rather than desktop) development.
:
For example:
    vcvarsall.bat x86_amd64
    vcvarsall.bat x86_arm store
    vcvarsall.bat x86_amd64 10.0.10240.0
    vcvarsall.bat x86_arm store 10.0.10240.0
    vcvarsall.bat x64 8.1
    vcvarsall.bat x64 store 8.1
:
Please make sure either Visual Studio or C++ Build SKU is installed.
```
The workaround is to manually append the sdk verison

The sdk version is needed when a newer sdk version is installed...projects can fail to build otherwise.

Either way, it might be nice to output an error/warning if someone specifies a setting which is considered not supported so they know why it has no effect.


Discussion:
Hi @rconde01,

Thanks a lot for looking into this.
We saw those options where available for vcvarsall in VS 2017: https://docs.microsoft.com/en-us/cpp/build/building-on-the-command-line#use-the-developer-tools-in-an-existing-command-window

However, vcvarsall 2015 seemed to not support it looking at its documentation page: https://msdn.microsoft.com/en-us/library/f2ccy3wt.aspx

We'll fix it for next conan release. thanks again!

Resolving patch:
diff --git a/conans/client/tools/win.py b/conans/client/tools/win.py
--- a/conans/client/tools/win.py
+++ b/conans/client/tools/win.py
@@ -249,11 +249,10 @@ def vcvars_command(settings, arch=None, compiler_version=None, force=False, vcva
     if not vcvars_arch:
         raise ConanException('unsupported architecture %s' % arch_setting)
 
-    command = ""
     existing_version = os.environ.get("VisualStudioVersion")
 
     if existing_version:
-        command = "echo Conan:vcvars already set"
+        command = ["echo Conan:vcvars already set"]
         existing_version = existing_version.split(".")[0]
         if existing_version != compiler_version:
             message = "Visual environment already set to %s\n " \
@@ -268,32 +267,32 @@ def vcvars_command(settings, arch=None, compiler_version=None, force=False, vcva
         if not vs_path or not os.path.isdir(vs_path):
             raise ConanException("VS non-existing installation: Visual Studio %s" % str(compiler_version))
         else:
-            vcvars_path = ""
             if int(compiler_version) > 14:
                 vcvars_path = os.path.join(vs_path, "VC/Auxiliary/Build/vcvarsall.bat")
-                command = ('set "VSCMD_START_DIR=%%CD%%" && '
-                           'call "%s" %s' % (vcvars_path, vcvars_arch))
-                if winsdk_version:
-                    command += " %s" % winsdk_version
-                if vcvars_ver:
-                    command += " -vcvars_ver=%s" % vcvars_ver
+                command = ['set "VSCMD_START_DIR=%%CD%%" && '
+                           'call "%s" %s' % (vcvars_path, vcvars_arch)]
             else:
                 vcvars_path = os.path.join(vs_path, "VC/vcvarsall.bat")
-                command = ('call "%s" %s' % (vcvars_path, vcvars_arch))
+                command = ['call "%s" %s' % (vcvars_path, vcvars_arch)]
+        if int(compiler_version) >= 14:
+            if winsdk_version:
+                command.append(winsdk_version)
+            if vcvars_ver:
+                command.append("-vcvars_ver=%s" % vcvars_ver)
 
     if os_setting == 'WindowsStore':
         os_version_setting = settings.get_safe("os.version")
         if os_version_setting == '8.1':
-            command += ' store 8.1'
+            command.append('store 8.1')
         elif os_version_setting == '10.0':
             windows_10_sdk = find_windows_10_sdk()
             if not windows_10_sdk:
                 raise ConanException("cross-compiling for WindowsStore 10 (UWP), "
                                      "but Windows 10 SDK wasn't found")
-            command += ' store ' + windows_10_sdk
+            command.append('store %s' % windows_10_sdk)
         else:
             raise ConanException('unsupported Windows Store version %s' % os_version_setting)
-    return command
+    return " ".join(command)
 
 
 def vcvars_dict(settings, arch=None, compiler_version=None, force=False, filter_known_paths=False,


Test patch:
diff --git a/conans/test/util/vcvars_arch_test.py b/conans/test/util/vcvars_arch_test.py
--- a/conans/test/util/vcvars_arch_test.py
+++ b/conans/test/util/vcvars_arch_test.py
@@ -11,10 +11,10 @@
 
 
 @attr('visual_studio')
+@unittest.skipUnless(platform.system() == "Windows", "Requires Windows")
 class VCVarsArchTest(unittest.TestCase):
+
     def test_arch(self):
-        if platform.system() != "Windows":
-            return
         settings = Settings.loads(default_settings_yml)
         settings.compiler = 'Visual Studio'
         settings.compiler.version = '14'
@@ -45,8 +45,6 @@ def test_arch(self):
             tools.vcvars_command(settings)
 
     def test_arch_override(self):
-        if platform.system() != "Windows":
-            return
         settings = Settings.loads(default_settings_yml)
         settings.compiler = 'Visual Studio'
         settings.compiler.version = '14'
@@ -73,8 +71,6 @@ def test_arch_override(self):
             tools.vcvars_command(settings, arch='mips')
 
     def test_vcvars_ver_override(self):
-        if platform.system() != "Windows":
-            return
         settings = Settings.loads(default_settings_yml)
         settings.compiler = 'Visual Studio'
         settings.compiler.version = '15'
@@ -88,11 +84,9 @@ def test_vcvars_ver_override(self):
 
         command = tools.vcvars_command(settings, vcvars_ver='14.14')
         self.assertIn('vcvarsall.bat', command)
-        self.assertNotIn('-vcvars_ver', command)
+        self.assertIn('-vcvars_ver=14.14', command)
 
     def test_winsdk_version_override(self):
-        if platform.system() != "Windows":
-            return
         settings = Settings.loads(default_settings_yml)
         settings.compiler = 'Visual Studio'
         settings.compiler.version = '15'
@@ -106,4 +100,4 @@ def test_winsdk_version_override(self):
 
         command = tools.vcvars_command(settings, winsdk_version='8.1')
         self.assertIn('vcvarsall.bat', command)
-        self.assertNotIn('8.1', command)
+        self.assertIn('8.1', command)