added compile_commands.json

This commit is contained in:
2025-06-03 00:19:45 +03:00
parent 3beb7aad3b
commit 83b18faab8
9 changed files with 98 additions and 14 deletions

View File

@@ -3,6 +3,7 @@
#include "helper.h"
#include "tier1/utlvector.h"
#include "libgen.h"
#include <cstdio>
struct ClangFile_t
{
@@ -54,9 +55,33 @@ CLDProject CCProject::Compile()
proj.objects.AppendTail((CObject){szOutputFile});
ClangFile_t cfile = {};
cfile.m_szName = m_szName;
cfile.m_szName = file;
cfile.m_szArguments = args;
g_clangFiles.AppendTail(cfile);
}
return proj;
}
void CCProject::GenerateCompileCommands()
{
FILE* f = V_fopen("compile_commands.json", "w");
V_fprintf(f, "[\n");
uint32_t i = 0;
for (auto &file: g_clangFiles)
{
V_fprintf(f, "\t{\n");
V_fprintf(f, "\t\t\"arguments\": [\n");
V_fprintf(f, "\t\t\t\"clang\",\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", IFileSystem2::OwnDirectory());
V_fprintf(f, "\t},\n");
};
V_fseek(f, -2, SEEK_CUR);
V_fprintf(f, "\n]\n");
V_fclose(f);
};

View File

@@ -23,11 +23,25 @@ unsigned int CProject::GenerateProjectHash( void )
static char path[1024];
static ssize_t pathSize = readlink("/proc/self/exe", path, sizeof(path) - 1);
static char* pathDir = dirname(path);
char *szPathDir = dirname(path);
char *szBuildDir = 0;
char *IFileSystem2::OwnDirectory()
{
return pathDir;
return szPathDir;
};
char *IFileSystem2::BuildDirectory()
{
return szBuildDir;
};
void IFileSystem2::CopyFile( const char *szDestination, const char *szOrigin )
{
CUtlVector<CUtlString> args = {
CUtlString(szOrigin),
CUtlString(szDestination),
};
IRunner::Run("cp", args);
}
void IFileSystem2::MakeDirectory( const char *psz )
{