support for static analyzers other than visual studio

This commit is contained in:
Anatol Belski 2014-03-01 20:15:10 +01:00
parent 0bbacd8678
commit cf90bd92bf
2 changed files with 41 additions and 3 deletions

View 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");
}
}

View File

@ -26,6 +26,8 @@ var FSO = WScript.CreateObject("Scripting.FileSystemObject");
var MFO = null;
var SYSTEM_DRIVE = WshShell.Environment("Process").Item("SystemDrive");
var PROGRAM_FILES = WshShell.Environment("Process").Item("ProgramFiles");
var PROGRAM_FILESx86 = WshShell.Environment("Process").Item("ProgramFiles(x86)");
var VCINSTALLDIR = WshShell.Environment("Process").Item("VCINSTALLDIR");
var DSP_FLAGS = new Array();
var PHP_SRC_DIR=FSO.GetParentFolderName(WScript.ScriptFullName);
@ -1388,6 +1390,11 @@ function ADD_SOURCES(dir, file_list, target, obj_dir)
}
} else {
MFO.WriteLine(sub_build + obj + ": " + dir + "\\" + src);
if (PHP_ANALYZER == "pvs") {
MFO.WriteLine("\t@\"$(PVS_STUDIO)\" --cl-params $(" + flags + ") $(CFLAGS) $(" + bd_flags_name + ") /c " + dir + "\\" + src + " --source-file " + dir + "\\" + src
+ " --cfg PVS-Studio.conf ");
}
MFO.WriteLine("\t@$(CC) $(" + flags + ") $(CFLAGS) $(" + bd_flags_name + ") /c " + dir + "\\" + src + " /Fo" + sub_build + obj);
}
}
@ -1555,8 +1562,10 @@ function write_summary()
} else {
ar[4] = ['Optimization', PHP_DEBUG == "yes" ? "disabled" : "PGO disabled"];
}
if (PHP_STATIC_ANALYZE == "yes") {
if (PHP_ANALYZER == "vs") {
ar[5] = ['Static analyzer', 'Visual Studio'];
} else if (PHP_ANALYZER == "pvs") {
ar[5] = ['Static analyzer', 'PVS-Studio'];
} else {
ar[5] = ['Static analyzer', 'disabled'];
}