work on implementing xtool
This commit is contained in:
81
fpc/library/swift.cpp
Normal file
81
fpc/library/swift.cpp
Normal file
@@ -0,0 +1,81 @@
|
||||
#include "swift.h"
|
||||
|
||||
CUtlString ISwiftCompiler::GetOutputObjectName( SwiftProject_t *pProject, unsigned int hash, CUtlString szFileName )
|
||||
{
|
||||
CUtlString szTarget = pProject->m_target.GetTriplet();
|
||||
|
||||
return CUtlString(
|
||||
"%s/%s/swift/%u_%s/%s/%s%s",
|
||||
FPC_TEMPORAL_DIRNAME,
|
||||
szTarget.GetString(),
|
||||
hash,
|
||||
pProject->m_szName.GetString(),
|
||||
filesystem2->BuildDirectory(),
|
||||
szFileName.GetString(),
|
||||
GetOutputObjectFormat());
|
||||
};
|
||||
|
||||
CUtlVector<CUtlString> ISwiftCompiler::BuildCommandLine( SwiftProject_t *pProject, const char *szFileName, const char *szOutputFileName )
|
||||
{
|
||||
|
||||
CUtlVector<CUtlString> cmd;
|
||||
|
||||
EnableDebugSymbols(cmd);
|
||||
if (pProject->bFPIC)
|
||||
EnablePIC(cmd);
|
||||
if (pProject->bFPIE)
|
||||
EnablePIE(cmd);
|
||||
SetTarget(cmd, pProject);
|
||||
SetOutputFile(cmd, szOutputFileName);
|
||||
SetSysroot(cmd, pProject, NULL);
|
||||
CompileFile(cmd, szFileName);
|
||||
for (auto ¯o: pProject->macros)
|
||||
Macro(cmd, macro.szName, macro.szValue.GetString());
|
||||
for (auto &dir: pProject->includeDirectories)
|
||||
IncludeDirectory(cmd, dir);
|
||||
|
||||
return cmd;
|
||||
}
|
||||
|
||||
LinkProject_t ISwiftCompiler::Compile( SwiftProject_t *pProject )
|
||||
{
|
||||
if (pProject->m_szName == 0)
|
||||
{
|
||||
Plat_FatalErrorFunc("m_szName must be present\n");
|
||||
}
|
||||
|
||||
LinkProject_t proj = {};
|
||||
proj.m_szName = pProject->m_szName;
|
||||
proj.m_target = pProject->m_target;
|
||||
proj.m_androidmanifest = pProject->m_androidmanifest;
|
||||
unsigned int hash = pProject->GenerateProjectHash();
|
||||
|
||||
|
||||
// Get output directories
|
||||
for (auto &file: pProject->files)
|
||||
{
|
||||
CUtlString szOutputFile = GetOutputObjectName(pProject, hash, file);
|
||||
CUtlString szOutputDir = szOutputFile.GetDirectory();
|
||||
filesystem2->MakeDirectory(szOutputDir);
|
||||
}
|
||||
|
||||
// Run CC
|
||||
for (auto &file: pProject->files)
|
||||
{
|
||||
CUtlString szOutputFile = GetOutputObjectName(pProject, hash, file);
|
||||
CUtlVector<CUtlString> args;
|
||||
|
||||
args = BuildCommandLine(pProject, file, szOutputFile);
|
||||
if (!filesystem2->ShouldRecompile(file, szOutputFile))
|
||||
goto skipcompile;
|
||||
else
|
||||
V_printf(" SWIFT %s\n", file.GetString());
|
||||
runner->Run(GetCompilerExecutable(pProject), args);
|
||||
skipcompile:
|
||||
proj.objects.AppendTail((Object_t){szOutputFile});
|
||||
}
|
||||
runner->Wait();
|
||||
return proj;
|
||||
}
|
||||
|
||||
ISwiftCompiler *swiftcompiler = NULL;
|
||||
Reference in New Issue
Block a user