]> granicus.if.org Git - php/commitdiff
support for static analyzers other than visual studio
authorAnatol Belski <ab@php.net>
Sat, 1 Mar 2014 19:15:10 +0000 (20:15 +0100)
committerAnatol Belski <ab@php.net>
Sat, 1 Mar 2014 19:15:10 +0000 (20:15 +0100)
win32/build/config.w32
win32/build/confutils.js

index 0caa3c66f77119809a01dd4c0d5a47b368dbcd17..4d2451b5afaa0479a314b1f9f370c2fdc8615837 100644 (file)
@@ -444,8 +444,37 @@ if (PHP_SECURITY_FLAGS == "yes") {
        ADD_FLAG("LDFLAGS", "/NXCOMPAT /DYNAMICBASE ");
 }
 
-ARG_ENABLE("static-analyze", "Enable the VC compiler static analyze", "no");
-if (PHP_STATIC_ANALYZE == "yes") {
+/* XXX add and implement clang keyword for clang analyzer */
+ARG_WITH("analyzer", "Enable static analyzer. Pass vs for Visual Studio, pvs for PVS-Studio", "no");
+if (PHP_ANALYZER == "vs") {
        ADD_FLAG("CFLAGS", " /analyze ");
        ADD_FLAG("CFLAGS", " /wd6308 ");
+} else if (PHP_ANALYZER == "pvs") {
+       var pvs_studio = false;
+
+       if (FSO.FileExists(PROGRAM_FILES + "\\PVS-Studio\\x64\\PVS-Studio.exe")) {
+               pvs_studio = PROGRAM_FILES + "\\PVS-Studio\\x86\\PVS-Studio.exe";
+       } else if (FSO.FileExists(PROGRAM_FILESx86 + "\\PVS-Studio\\x64\\PVS-Studio.exe")) {
+               pvs_studio = PROGRAM_FILESx86 + "\\PVS-Studio\\x64\\PVS-Studio.exe";
+       }
+
+       if (!pvs_studio) {
+               WARNING("Couldn't find PVS-Studio binaries, static analyze was disabled");
+               PHP_ANALYZER = "no";
+       } else {
+               var pvscfg = FSO.CreateTextFile("PVS-Studio.conf", true);
+               DEFINE("PVS_STUDIO", pvs_studio);
+
+               pvscfg.WriteLine("exclude-path = " + VCINSTALLDIR);
+               if (FSO.FolderExists(PROGRAM_FILESx86 + "\\windows kits\\")) {
+                       pvscfg.WriteLine("exclude-path = " + PROGRAM_FILESx86 + "\\windows kits\\");
+               } else if (FSO.FolderExists(PROGRAM_FILES + "\\windows kits\\")) {
+                       pvscfg.WriteLine("exclude-path = " + PROGRAM_FILES + "\\windows kits\\");
+               }
+               pvscfg.WriteLine("vcinstalldir = " + VCINSTALLDIR);
+               pvscfg.WriteLine("platform = " + (X64 ? 'x64' : 'Win32'));
+               pvscfg.WriteLine("preprocessor = visualcpp");
+               pvscfg.WriteLine("language = C");
+       }
 }
+
index e674964078bfcd572357c64ce0b8a99c905054aa..5ccdfa11aaa14b553042dc3b8f7234f39f264dce 100644 (file)
@@ -26,6 +26,8 @@ var FSO = WScript.CreateObject("Scripting.FileSystemObject");
 var MFO = null;\r
 var SYSTEM_DRIVE = WshShell.Environment("Process").Item("SystemDrive");\r
 var PROGRAM_FILES = WshShell.Environment("Process").Item("ProgramFiles");\r
+var PROGRAM_FILESx86 = WshShell.Environment("Process").Item("ProgramFiles(x86)");\r
+var VCINSTALLDIR = WshShell.Environment("Process").Item("VCINSTALLDIR");\r
 var DSP_FLAGS = new Array();\r
 var PHP_SRC_DIR=FSO.GetParentFolderName(WScript.ScriptFullName);\r
 \r
@@ -1388,6 +1390,11 @@ function ADD_SOURCES(dir, file_list, target, obj_dir)
                        }\r
                } else {\r
                        MFO.WriteLine(sub_build + obj + ": " + dir + "\\" + src);\r
+\r
+                       if (PHP_ANALYZER == "pvs") {\r
+                               MFO.WriteLine("\t@\"$(PVS_STUDIO)\" --cl-params $(" + flags + ") $(CFLAGS) $(" + bd_flags_name + ") /c " + dir + "\\" + src + " --source-file "  + dir + "\\" + src\r
+                                       + " --cfg PVS-Studio.conf ");\r
+                       }\r
                        MFO.WriteLine("\t@$(CC) $(" + flags + ") $(CFLAGS) $(" + bd_flags_name + ") /c " + dir + "\\" + src + " /Fo" + sub_build + obj);\r
                }\r
        }\r
@@ -1555,8 +1562,10 @@ function write_summary()
        } else {\r
                ar[4] = ['Optimization', PHP_DEBUG == "yes" ? "disabled" : "PGO disabled"];\r
        }\r
-       if (PHP_STATIC_ANALYZE == "yes") {\r
+       if (PHP_ANALYZER == "vs") {\r
                ar[5] = ['Static analyzer', 'Visual Studio'];\r
+       } else if (PHP_ANALYZER == "pvs") {\r
+               ar[5] = ['Static analyzer', 'PVS-Studio'];\r
        } else {\r
                ar[5] = ['Static analyzer', 'disabled'];\r
        }\r