From 676ca3a8366218e56f528a9a4cc6b172f2506339 Mon Sep 17 00:00:00 2001 From: Mark Pizzolato Date: Fri, 28 Apr 2023 09:43:27 -1000 Subject: [PATCH] SCP: Add CheckSourceCode support for Windows builds --- Visual Studio Projects/Post-Build-Event.cmd | 28 ++++++++++++++++++++- sim_fio.c | 6 ++--- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/Visual Studio Projects/Post-Build-Event.cmd b/Visual Studio Projects/Post-Build-Event.cmd index 70c02b3b..53b2cf19 100644 --- a/Visual Studio Projects/Post-Build-Event.cmd +++ b/Visual Studio Projects/Post-Build-Event.cmd @@ -9,6 +9,8 @@ rem this failure is akin to a compile time error the simulator rem should be fixed before it can be used. rem 2) An optional simulator test which is only performed rem if a simulation test script is available. +rem 3) An optional source code analysis to verify project standards +rem have been followed. rem rem There are 2 required parameters to this procedure: rem 1 - The simulator source directory @@ -20,6 +22,12 @@ rem rem These tests will be skipped if there is a file named Post-Build-Event.Skip rem in the same directory as this procedure. rem +rem The source code analysis is only run if there is a file named +rem Post-Build-Event.Run-Source-Check in the same directory as this procedure. +rem When source code analysis is being run, the existence of a file named +rem Post-Build-Event.Run-Source-Check-Switches will cause detailed analysis +rem information to be emitted for all files analyzed. +rem if exist %2 goto _check_skip_tests echo error: Missing simulator binary: %2 @@ -44,7 +52,25 @@ if exist "%_script_path%" goto _got_script set _script_path=..\%1\tests\%_binary_name%_test.ini if exist "%_script_path%" goto _got_script echo Simulator specific tests not found for %_binary_name% simulator. -exit /B 0 +goto _check_source :_got_script %2 "%_script_path%" "%4" + +:_check_source +setlocal enabledelayedexpansion +if not exist "%_script_name%.Run-Source-Check" exit /B 0 +set _project_file=%~dp0%~n2.vcproj +set _project_deps="%~dp0%~n2.deps" +set _project_linedeps="%~dp0%~n2.linedeps" +findstr RelativePath "%_project_file%" | findstr /C:.c | findstr /C:windows-build /V > %_project_deps% +for /F "usebackq tokens=2 delims==" %%f in (`type %_project_deps%`) do @echo %%f>>%_project_linedeps% +set _deps_switches= +if exist "%_script_name%.Run-Source-Check-Switches" set _deps_switches=-DV +set _deps_line= +for /F "usebackq tokens=2 delims==" %%f in (`type %_project_deps%`) do set _deps_line=!_deps_line! %%f +del %_project_deps% +del %_project_linedeps% +echo Checking Source for %~n2 simulator +%2 %_deps_switches% CheckSourceCode %_deps_line% +set _deps_line= diff --git a/sim_fio.c b/sim_fio.c index b3099403..5a0559a6 100644 --- a/sim_fio.c +++ b/sim_fio.c @@ -2334,7 +2334,6 @@ extension = sim_filepath_parts (filepath, "x"); Stats->IsSource = ((0 == strcmp (".c", extension)) || (0 == strcmp (".h", extension))); dir = sim_filepath_parts (directory, "p"); Stats->IsInScpDir = (sim_check_scp_dir != NULL) && (strcmp (dir, sim_check_scp_dir) == 0); -free (dir); if ((!Stats->IsInScpDir) && (sim_check_scp_dir != NULL)) { const char **scp_sub_dir = _check_source_scp_sub_dirs; @@ -2343,13 +2342,14 @@ if ((!Stats->IsInScpDir) && (sim_check_scp_dir != NULL)) { strlcpy (tmp_dir, sim_check_scp_dir, sizeof (tmp_dir)); strlcat (tmp_dir, *scp_sub_dir, sizeof (tmp_dir)); - strlcat (tmp_dir, &directory[strlen (directory) - 1], sizeof (tmp_dir)); - if (strcmp (directory, tmp_dir) == 0) + strlcat (tmp_dir, &dir[strlen (dir) - 1], sizeof (tmp_dir)); + if (strcmp (dir, tmp_dir) == 0) break; ++scp_sub_dir; } Stats->IsInScpDir = (*scp_sub_dir != NULL); } +free (dir); f = fopen (filepath, "rb"); if ((f == NULL) || ((size_t)FileSize != fread (data, 1, (size_t)FileSize, f))) {