some improvements i think

This commit is contained in:
2026-01-14 20:15:49 +02:00
parent 6604c67ec5
commit 49adb21b81
14 changed files with 420 additions and 69 deletions

View File

@@ -9,6 +9,7 @@
#include "tier1/interface.h"
#include "tier1/utlstring.h"
#include "tier1/utlvector.h"
#include "tier2/fileformats/json.h"
#include "libgen.h"
#include "ctype.h"
@@ -245,23 +246,33 @@ skipcompile:
void CClangCompiler::GenerateLinterData()
{
CUtlVector<IJSONValue*> jsonValues = {};
FILE* f = V_fopen("compile_commands.json", "wb");
V_fprintf(f, "[\n");
uint32_t i = 0;
for (auto &file: g_clangFiles)
for ( auto &f: g_clangFiles )
{
V_fprintf(f, "\t{\n");
V_fprintf(f, "\t\t\"arguments\": [\n");
for (auto &arg: file.m_szArguments)
V_fprintf(f, "\t\t\t\"%s\",\n",arg.GetString());
V_fseek(f, -2, SEEK_CUR);
V_fprintf(f, "\n\t\t],\n");
V_fprintf(f, "\t\t\"file\": \"%s\",\n", file.m_szName.GetString());
V_fprintf(f, "\t\t\"directory\": \"%s\"\n", filesystem2->BuildDirectory());
V_fprintf(f, "\t},\n");
IJSONObject *pFileObject = JSONManager()->CreateObject();
IJSONValue *pFileValue = JSONManager()->CreateValue();
IJSONArray *pArgumentFiles = JSONManager()->CreateArray();
IJSONValue *pArgumentsValue = JSONManager()->CreateValue();
CUtlVector<IJSONValue*> values;
for (auto &arg: f.m_szArguments)
{
IJSONValue *pFileValue = JSONManager()->CreateValue();
pFileValue->SetStringValue(arg.GetString());
values.AppendTail(pFileValue);
}
pArgumentFiles->SetArray(values.GetSize(), values.GetData());
pArgumentsValue->SetArrayValue(pArgumentFiles);
pFileObject->SetValue("arguments", pArgumentsValue);
pFileValue->SetObjectValue(pFileObject);
jsonValues.AppendTail(pFileValue);
};
V_fseek(f, -2, SEEK_CUR);
V_fprintf(f, "\n]\n");
IJSONArray *pArray = JSONManager()->CreateArray();
pArray->SetArray(jsonValues.GetSize(), jsonValues.GetData());
IJSONValue *pRoot = JSONManager()->CreateValue();
pRoot->SetArrayValue(pArray);
CUtlString szCommands = JSONManager()->WriteString(pRoot);
V_printf("JSON\n%s\n",szCommands.GetString());
V_fclose(f);
};