Browse files

ninja windows: add flag support for code analysis (aka PREfast)

Also add test for same for both MSVS and ninja. This test is
only enabled on VS2012 for now. Theoretically, it could be
be enabled for VS2010 Premium too, but few people have that
installed, and we don't currently have a way to gate on that,
so just turn it on for 2012 (non-Express) where it's always
available.
Review URL: https://codereview.chromium.org/11236042

git-svn-id: http://gyp.googlecode.com/svn/trunk@1522 78cadc50-ecff-11dd-a971-7dbc132099af
  • Loading branch information...
1 parent 5e23f8c commit b5084b9b9bf95491ca350f1f1d15e517b40b9918 scottmg@chromium.org committed Oct 23, 2012
View
1 pylib/gyp/msvs_emulation.py
@@ -302,6 +302,7 @@ def GetCflags(self, config):
cl('RuntimeLibrary',
map={'0': 'T', '1': 'Td', '2': 'D', '3': 'Dd'}, prefix='/M')
cl('ExceptionHandling', map={'1': 'sc','2': 'a'}, prefix='/EH')
+ cl('EnablePREfast', map={'true': '/analyze'})
cl('AdditionalOptions', prefix='')
# ninja handles parallelism by itself, don't have the compiler do it too.
cflags = filter(lambda x: not x.startswith('/MP'), cflags)
View
6 test/lib/TestGyp.py
@@ -620,9 +620,11 @@ def FindVisualStudioInstallation():
search %PATH% and %PATHEXT% for a devenv.{exe,bat,...} executable.
Failing that, we search for likely deployment paths.
"""
- possible_roots = ['C:\\Program Files (x86)', 'C:\\Program Files',
- 'E:\\Program Files (x86)', 'E:\\Program Files']
+ possible_roots = ['%s:\\Program Files%s' % (chr(drive), suffix)
+ for drive in range(ord('C'), ord('Z') + 1)
+ for suffix in ['', ' (x86)']]
possible_paths = {
+ '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',
'2005': r'Microsoft Visual Studio 8\Common7\IDE\devenv.com'}
View
40 test/win/compiler-flags/analysis.gyp
@@ -0,0 +1,40 @@
+# Copyright (c) 2012 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_analysis_on',
+ 'type': 'executable',
+ 'msvs_settings': {
+ 'VCCLCompilerTool': {
+ 'EnablePREfast': 'true',
+ 'WarnAsError': 'true',
+ },
+ },
+ 'sources': ['uninit.cc'],
+ },
+ {
+ 'target_name': 'test_analysis_off',
+ 'type': 'executable',
+ 'msvs_settings': {
+ 'VCCLCompilerTool': {
+ 'EnablePREfast': 'false',
+ 'WarnAsError': 'true',
+ },
+ },
+ 'sources': ['uninit.cc'],
+ },
+ {
+ 'target_name': 'test_analysis_unspec',
+ 'type': 'executable',
+ 'sources': ['uninit.cc'],
+ 'msvs_settings': {
+ 'VCCLCompilerTool': {
+ 'WarnAsError': 'true',
+ },
+ },
+ },
+ ]
+}
View
13 test/win/compiler-flags/uninit.cc
@@ -0,0 +1,13 @@
+// Copyright (c) 2012 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.
+
+// Should trigger C6001: using uninitialized memory <variable> for |i|.
+int f(bool b) {
+ int i;
+ if (b)
+ i = 0;
+ return i;
+}
+
+int main() {}
View
30 test/win/gyptest-cl-analysis.py
@@ -0,0 +1,30 @@
+#!/usr/bin/env python
+
+# Copyright (c) 2012 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 PREfast (code analysis) setting is extracted properly.
+"""
+
+import TestGyp
+
+import os
+import sys
+
+if (sys.platform == 'win32' and
+ int(os.environ.get('GYP_MSVS_VERSION', 0)) >= 2012):
+ test = TestGyp.TestGyp(formats=['msvs', 'ninja'])
+
+ CHDIR = 'compiler-flags'
+ test.run_gyp('analysis.gyp', chdir=CHDIR)
+
+ # Analysis enabled, should fail.
+ test.build('analysis.gyp', 'test_analysis_on', chdir=CHDIR, status=1)
+
+ # Analysis not enabled, or unspecified, should pass.
+ test.build('analysis.gyp', 'test_analysis_off', chdir=CHDIR)
+ test.build('analysis.gyp', 'test_analysis_unspec', chdir=CHDIR)
+
+ test.pass_test()

0 comments on commit b5084b9

Please sign in to comment.