win: Fix behaviour of MinimumRequiredVersion

Previous change for ninja set default subsystem to XP, but didn't do
anything for msvs. This broke the 2012 bot which is where the default
changed (I thought it was 2013 previously).

Now, use the MinimumRequiredVersion setting to determine this value,
which works in VS >= 2010 and emulate that in ninja.

Also, add another line to TestGyp.py so that gyptest.py works when
running on VS2013.

R=thakis@chromium.org
BUG=320371

Review URL: https://codereview.chromium.org/67373005

git-svn-id: http://gyp.googlecode.com/svn/trunk@1788 78cadc50-ecff-11dd-a971-7dbc132099af
diff --git a/pylib/gyp/MSVSSettings.py b/pylib/gyp/MSVSSettings.py
index 9e7efff..f93dab9 100644
--- a/pylib/gyp/MSVSSettings.py
+++ b/pylib/gyp/MSVSSettings.py
@@ -812,6 +812,7 @@
       _Enumeration(['AsInvoker',  # /level='asInvoker'
                     'HighestAvailable',  # /level='highestAvailable'
                     'RequireAdministrator']))  # /level='requireAdministrator'
+_Same(_link, 'MinimumRequiredVersion', _string)
 
 
 # Options found in MSVS that have been renamed in MSBuild.
@@ -851,7 +852,6 @@
 _MSBuildOnly(_link, 'SupportNobindOfDelayLoadedDLL', _boolean)  # /DELAY:NOBIND
 _MSBuildOnly(_link, 'TrackerLogDirectory', _folder_name)
 _MSBuildOnly(_link, 'TreatLinkerWarningAsErrors', _boolean)  # /WX
-_MSBuildOnly(_link, 'MinimumRequiredVersion', _string)
 _MSBuildOnly(_link, 'MSDOSStubFileName', _file_name)  # /STUB Visible='false'
 _MSBuildOnly(_link, 'SectionAlignment', _integer)  # /ALIGN
 _MSBuildOnly(_link, 'SpecifySectionAttributes', _string)  # /SECTION
diff --git a/pylib/gyp/msvs_emulation.py b/pylib/gyp/msvs_emulation.py
index c168629..6102c12 100644
--- a/pylib/gyp/msvs_emulation.py
+++ b/pylib/gyp/msvs_emulation.py
@@ -468,14 +468,13 @@
     ld('MapExports', map={'true': '/MAPINFO:EXPORTS'})
     ld('AdditionalOptions', prefix='')
 
-    xp_version = ''
-    # If we're targeting x86, make sure we're targeting XP.
-    if self._Setting(('VCLinkerTool', 'TargetMachine'),
-                     config, default='1') == '1':
-      xp_version = ',5.01'
+    minimum_required_version = self._Setting(
+        ('VCLinkerTool', 'MinimumRequiredVersion'), config, default='')
+    if minimum_required_version:
+      minimum_required_version = ',' + minimum_required_version
     ld('SubSystem',
-       map={'1': 'CONSOLE%s' % xp_version,
-            '2': 'WINDOWS%s' % xp_version},
+       map={'1': 'CONSOLE%s' % minimum_required_version,
+            '2': 'WINDOWS%s' % minimum_required_version},
        prefix='/SUBSYSTEM:')
 
     ld('TerminalServerAware', map={'1': ':NO', '2': ''}, prefix='/TSAWARE')
diff --git a/test/lib/TestGyp.py b/test/lib/TestGyp.py
index 66c5ece..45dcf93 100644
--- a/test/lib/TestGyp.py
+++ b/test/lib/TestGyp.py
@@ -639,6 +639,7 @@
                     for drive in range(ord('C'), ord('Z') + 1)
                     for suffix in ['', ' (x86)']]
   possible_paths = {
+      '2013': r'Microsoft Visual Studio 12.0\Common7\IDE\devenv.com',
       '2012': r'Microsoft Visual Studio 11.0\Common7\IDE\devenv.com',
       '2010': r'Microsoft Visual Studio 10.0\Common7\IDE\devenv.com',
       '2008': r'Microsoft Visual Studio 9.0\Common7\IDE\devenv.com',
diff --git a/test/win/gyptest-link-subsystem.py b/test/win/gyptest-link-subsystem.py
index de3fb79..a94ba36 100644
--- a/test/win/gyptest-link-subsystem.py
+++ b/test/win/gyptest-link-subsystem.py
@@ -23,12 +23,14 @@
   test.build('subsystem.gyp', 'test_windows_ok', chdir=CHDIR)
   test.build('subsystem.gyp', 'test_windows_fail', chdir=CHDIR, status=1)
 
+  test.build('subsystem.gyp', 'test_console_xp', chdir=CHDIR)
+  test.build('subsystem.gyp', 'test_windows_xp', chdir=CHDIR)
   # Make sure we are targeting XP.
   def GetHeaders(exe):
     return test.run_dumpbin('/headers', test.built_file_path(exe, chdir=CHDIR))
-  if '5.01 subsystem version' not in GetHeaders('test_console_ok.exe'):
+  if '5.01 subsystem version' not in GetHeaders('test_console_xp.exe'):
     test.fail_test()
-  if '5.01 subsystem version' not in GetHeaders('test_windows_ok.exe'):
+  if '5.01 subsystem version' not in GetHeaders('test_windows_xp.exe'):
     test.fail_test()
 
   # TODO(scottmg): There are other subsystems (WinCE, etc.) that we don't use.
diff --git a/test/win/linker-flags/subsystem.gyp b/test/win/linker-flags/subsystem.gyp
index ec68e80..63f072a 100644
--- a/test/win/linker-flags/subsystem.gyp
+++ b/test/win/linker-flags/subsystem.gyp
@@ -44,5 +44,27 @@
       },
       'sources': ['hello.cc'],
     },
+    {
+      'target_name': 'test_console_xp',
+      'type': 'executable',
+      'msvs_settings': {
+        'VCLinkerTool': {
+          'SubSystem': '1',
+          'MinimumRequiredVersion': '5.01',  # XP.
+        }
+      },
+      'sources': ['hello.cc'],
+    },
+    {
+      'target_name': 'test_windows_xp',
+      'type': 'executable',
+      'msvs_settings': {
+        'VCLinkerTool': {
+          'SubSystem': '2',
+          'MinimumRequiredVersion': '5.01',  # XP.
+        }
+      },
+      'sources': ['subsystem-windows.cc'],
+    },
   ]
 }