ninja win: Add support for 'CallingConvention'

Each calling convention decorates C functions in a different way, so we can use
that to test the flag.

BUG=
R=scottmg@chromium.org

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

git-svn-id: http://gyp.googlecode.com/svn/trunk@1984 78cadc50-ecff-11dd-a971-7dbc132099af
diff --git a/pylib/gyp/msvs_emulation.py b/pylib/gyp/msvs_emulation.py
index 5384df1..fa97aaf 100644
--- a/pylib/gyp/msvs_emulation.py
+++ b/pylib/gyp/msvs_emulation.py
@@ -406,6 +406,8 @@
     cl('WholeProgramOptimization', map={'true': '/GL'})
     cl('WarningLevel', prefix='/W')
     cl('WarnAsError', map={'true': '/WX'})
+    cl('CallingConvention',
+        map={'0': 'd', '1': 'r', '2': 'z'}, prefix='/G')
     cl('DebugInformationFormat',
         map={'1': '7', '3': 'i', '4': 'I'}, prefix='/Z')
     cl('RuntimeTypeInfo', map={'true': '/GR', 'false': '/GR-'})
diff --git a/test/win/compiler-flags/calling-convention-cdecl.def b/test/win/compiler-flags/calling-convention-cdecl.def
new file mode 100644
index 0000000..dc1dba0
--- /dev/null
+++ b/test/win/compiler-flags/calling-convention-cdecl.def
@@ -0,0 +1,6 @@
+; Copyright (c) 2014 Google Inc. All rights reserved.
+; Use of this source code is governed by a BSD-style license that can be
+; found in the LICENSE file.
+
+EXPORTS
+  foo
diff --git a/test/win/compiler-flags/calling-convention-fastcall.def b/test/win/compiler-flags/calling-convention-fastcall.def
new file mode 100644
index 0000000..2c61afe
--- /dev/null
+++ b/test/win/compiler-flags/calling-convention-fastcall.def
@@ -0,0 +1,6 @@
+; Copyright (c) 2014 Google Inc. All rights reserved.
+; Use of this source code is governed by a BSD-style license that can be
+; found in the LICENSE file.
+
+EXPORTS
+  @foo@0
diff --git a/test/win/compiler-flags/calling-convention-stdcall.def b/test/win/compiler-flags/calling-convention-stdcall.def
new file mode 100644
index 0000000..6c7e05e
--- /dev/null
+++ b/test/win/compiler-flags/calling-convention-stdcall.def
@@ -0,0 +1,6 @@
+; Copyright (c) 2014 Google Inc. All rights reserved.
+; Use of this source code is governed by a BSD-style license that can be
+; found in the LICENSE file.
+
+EXPORTS
+  _foo@0
diff --git a/test/win/compiler-flags/calling-convention.cc b/test/win/compiler-flags/calling-convention.cc
new file mode 100644
index 0000000..0d78a0c
--- /dev/null
+++ b/test/win/compiler-flags/calling-convention.cc
@@ -0,0 +1,6 @@
+// Copyright (c) 2014 Google Inc. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+extern "C" void foo() {
+}
diff --git a/test/win/compiler-flags/calling-convention.gyp b/test/win/compiler-flags/calling-convention.gyp
new file mode 100644
index 0000000..e2cdd77
--- /dev/null
+++ b/test/win/compiler-flags/calling-convention.gyp
@@ -0,0 +1,47 @@
+# Copyright (c) 2014 Google Inc. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+{
+ 'targets': [
+    {
+      'target_name': 'test_cdecl',
+      'type': 'loadable_module',
+      'msvs_settings': {
+        'VCCLCompilerTool': {
+          'CallingConvention': 0,
+        },
+      },
+      'sources': [
+        'calling-convention.cc',
+        'calling-convention-cdecl.def',
+      ],
+    },
+    {
+      'target_name': 'test_fastcall',
+      'type': 'loadable_module',
+      'msvs_settings': {
+        'VCCLCompilerTool': {
+          'CallingConvention': 1,
+        },
+      },
+      'sources': [
+        'calling-convention.cc',
+        'calling-convention-fastcall.def',
+      ],
+    },
+    {
+      'target_name': 'test_stdcall',
+      'type': 'loadable_module',
+      'msvs_settings': {
+        'VCCLCompilerTool': {
+          'CallingConvention': 2,
+        },
+      },
+      'sources': [
+        'calling-convention.cc',
+        'calling-convention-stdcall.def',
+      ],
+    },
+  ]
+}
diff --git a/test/win/gyptest-cl-calling-convention.py b/test/win/gyptest-cl-calling-convention.py
new file mode 100644
index 0000000..b5fdc47
--- /dev/null
+++ b/test/win/gyptest-cl-calling-convention.py
@@ -0,0 +1,22 @@
+#!/usr/bin/env python
+
+# Copyright (c) 2014 Google Inc. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""
+Make sure calling convention setting is extracted properly.
+"""
+
+import TestGyp
+
+import sys
+
+if sys.platform == 'win32':
+  test = TestGyp.TestGyp(formats=['msvs', 'ninja'])
+
+  CHDIR = 'compiler-flags'
+  test.run_gyp('calling-convention.gyp', chdir=CHDIR)
+  test.build('calling-convention.gyp', test.ALL, chdir=CHDIR)
+
+  test.pass_test()