Skip to content

Commit cf90bd9

Browse files
committed
support for static analyzers other than visual studio
1 parent 0bbacd8 commit cf90bd9

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

win32/build/config.w32

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,8 +444,37 @@ if (PHP_SECURITY_FLAGS == "yes") {
444444
ADD_FLAG("LDFLAGS", "/NXCOMPAT /DYNAMICBASE ");
445445
}
446446

447-
ARG_ENABLE("static-analyze", "Enable the VC compiler static analyze", "no");
448-
if (PHP_STATIC_ANALYZE == "yes") {
447+
/* XXX add and implement clang keyword for clang analyzer */
448+
ARG_WITH("analyzer", "Enable static analyzer. Pass vs for Visual Studio, pvs for PVS-Studio", "no");
449+
if (PHP_ANALYZER == "vs") {
449450
ADD_FLAG("CFLAGS", " /analyze ");
450451
ADD_FLAG("CFLAGS", " /wd6308 ");
452+
} else if (PHP_ANALYZER == "pvs") {
453+
var pvs_studio = false;
454+
455+
if (FSO.FileExists(PROGRAM_FILES + "\\PVS-Studio\\x64\\PVS-Studio.exe")) {
456+
pvs_studio = PROGRAM_FILES + "\\PVS-Studio\\x86\\PVS-Studio.exe";
457+
} else if (FSO.FileExists(PROGRAM_FILESx86 + "\\PVS-Studio\\x64\\PVS-Studio.exe")) {
458+
pvs_studio = PROGRAM_FILESx86 + "\\PVS-Studio\\x64\\PVS-Studio.exe";
459+
}
460+
461+
if (!pvs_studio) {
462+
WARNING("Couldn't find PVS-Studio binaries, static analyze was disabled");
463+
PHP_ANALYZER = "no";
464+
} else {
465+
var pvscfg = FSO.CreateTextFile("PVS-Studio.conf", true);
466+
DEFINE("PVS_STUDIO", pvs_studio);
467+
468+
pvscfg.WriteLine("exclude-path = " + VCINSTALLDIR);
469+
if (FSO.FolderExists(PROGRAM_FILESx86 + "\\windows kits\\")) {
470+
pvscfg.WriteLine("exclude-path = " + PROGRAM_FILESx86 + "\\windows kits\\");
471+
} else if (FSO.FolderExists(PROGRAM_FILES + "\\windows kits\\")) {
472+
pvscfg.WriteLine("exclude-path = " + PROGRAM_FILES + "\\windows kits\\");
473+
}
474+
pvscfg.WriteLine("vcinstalldir = " + VCINSTALLDIR);
475+
pvscfg.WriteLine("platform = " + (X64 ? 'x64' : 'Win32'));
476+
pvscfg.WriteLine("preprocessor = visualcpp");
477+
pvscfg.WriteLine("language = C");
478+
}
451479
}
480+

win32/build/confutils.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ var FSO = WScript.CreateObject("Scripting.FileSystemObject");
2626
var MFO = null;
2727
var SYSTEM_DRIVE = WshShell.Environment("Process").Item("SystemDrive");
2828
var PROGRAM_FILES = WshShell.Environment("Process").Item("ProgramFiles");
29+
var PROGRAM_FILESx86 = WshShell.Environment("Process").Item("ProgramFiles(x86)");
30+
var VCINSTALLDIR = WshShell.Environment("Process").Item("VCINSTALLDIR");
2931
var DSP_FLAGS = new Array();
3032
var PHP_SRC_DIR=FSO.GetParentFolderName(WScript.ScriptFullName);
3133

@@ -1388,6 +1390,11 @@ function ADD_SOURCES(dir, file_list, target, obj_dir)
13881390
}
13891391
} else {
13901392
MFO.WriteLine(sub_build + obj + ": " + dir + "\\" + src);
1393+
1394+
if (PHP_ANALYZER == "pvs") {
1395+
MFO.WriteLine("\t@\"$(PVS_STUDIO)\" --cl-params $(" + flags + ") $(CFLAGS) $(" + bd_flags_name + ") /c " + dir + "\\" + src + " --source-file " + dir + "\\" + src
1396+
+ " --cfg PVS-Studio.conf ");
1397+
}
13911398
MFO.WriteLine("\t@$(CC) $(" + flags + ") $(CFLAGS) $(" + bd_flags_name + ") /c " + dir + "\\" + src + " /Fo" + sub_build + obj);
13921399
}
13931400
}
@@ -1555,8 +1562,10 @@ function write_summary()
15551562
} else {
15561563
ar[4] = ['Optimization', PHP_DEBUG == "yes" ? "disabled" : "PGO disabled"];
15571564
}
1558-
if (PHP_STATIC_ANALYZE == "yes") {
1565+
if (PHP_ANALYZER == "vs") {
15591566
ar[5] = ['Static analyzer', 'Visual Studio'];
1567+
} else if (PHP_ANALYZER == "pvs") {
1568+
ar[5] = ['Static analyzer', 'PVS-Studio'];
15601569
} else {
15611570
ar[5] = ['Static analyzer', 'disabled'];
15621571
}

0 commit comments

Comments
 (0)