Skip to content

Commit 0f315af

Browse files
WIP
1 parent dbd476b commit 0f315af

File tree

3 files changed

+108
-35
lines changed

3 files changed

+108
-35
lines changed

Src/runcpp2/StringUtil.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ namespace runcpp2
5454
//Check existing string matches
5555
for(int j = 0; j < tempStringsToCheckForSplit.size(); ++j)
5656
{
57-
if( tempStringsToCheckForSplit.at(j).size() >= splitter.size() - 1 ||
57+
if( tempStringsToCheckForSplit.at(j).size() >= splitter.size() ||
5858
stringToSplit.at(i) != splitter.at(tempStringsToCheckForSplit.at(j).size()))
5959
{
6060
tempStringsToCheckForSplit.erase(tempStringsToCheckForSplit.begin() + j);
@@ -66,7 +66,7 @@ namespace runcpp2
6666
tempStringsToCheckForSplit.at(j) += stringToSplit.at(i);
6767

6868
//If there's a match, clear record
69-
if(tempStringsToCheckForSplit.size() == splitter.size())
69+
if(tempStringsToCheckForSplit.at(j).size() == splitter.size())
7070
{
7171
curOutString.erase(curOutString.size() - splitter.size());
7272
outStrings.push_back(curOutString);

Src/runcpp2/main.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -56,22 +56,22 @@ int main(int argc, char* argv[])
5656
}
5757

5858
return 0;
59-
#elif 1
60-
//TODO(NOW): Test string split
61-
62-
std::string testString = "This is a test string to split.";
63-
64-
std::vector<std::string> splittedStrings;
65-
66-
runcpp2::Internal::SplitString( testString,
67-
" ",
68-
splittedStrings);
69-
70-
for(int i = 0; i < splittedStrings.size(); ++i)
71-
{
72-
ssLOG_LINE("splittedStrings[" << i << "]: " << splittedStrings[i]);
73-
}
74-
59+
#elif 0
60+
//Test string split
61+
62+
std::string testString = "This.is.a.test.string.to.split.";
63+
64+
std::vector<std::string> splittedStrings;
65+
66+
runcpp2::Internal::SplitString( testString,
67+
".",
68+
splittedStrings);
69+
70+
for(int i = 0; i < splittedStrings.size(); ++i)
71+
{
72+
ssLOG_LINE("splittedStrings[" << i << "]: " << splittedStrings[i]);
73+
}
74+
return 0;
7575
#endif
7676

7777
std::vector<runcpp2::CompilerProfile> compilerProfiles;

Src/runcpp2/runcpp2.cpp

Lines changed: 90 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#include "runcpp2/ParseUtil.hpp"
44
#include "runcpp2/PlatformUtil.hpp"
5-
5+
#include "runcpp2/StringUtil.hpp"
66
#include "ssLogger/ssLog.hpp"
77
#include "tinydir.h"
88
#include "cfgpath.h"
@@ -748,10 +748,6 @@ bool runcpp2::CopyDependenciesBinaries( const std::string& scriptPath,
748748
return false;
749749
}
750750

751-
//auto dirEntry = ghc::filesystem::directory_entry(searchPath, _);
752-
753-
//auto dirIt = ghc::filesystem::directory_iterator(searchPath, _);
754-
755751
for(auto it : ghc::filesystem::directory_iterator(searchPath, _))
756752
{
757753
if(it.is_directory())
@@ -803,6 +799,12 @@ bool runcpp2::CompileAndLinkScript( const std::string& scriptPath,
803799
const CompilerProfile& profile)
804800
{
805801
//TODO(NOW)
802+
std::string scriptDirectory = ghc::filesystem::path(scriptPath).parent_path().string();
803+
std::string scriptName = ghc::filesystem::path(scriptPath).stem().string();
804+
std::string runcpp2ScriptDir = scriptDirectory + "/.runcpp2";
805+
std::vector<std::string> platformNames = Internal::GetPlatformNames();
806+
807+
806808

807809
std::string compileCommand = profile.Compiler.Executable + " " +
808810
profile.Compiler.CompileArgs;
@@ -819,13 +821,26 @@ bool runcpp2::CompileAndLinkScript( const std::string& scriptPath,
819821

820822
if(scriptInfo.OverrideCompileFlags.find(profile.Name) != scriptInfo.OverrideCompileFlags.end())
821823
{
822-
//std::vector<std::string> compileArgsToRemove = scriptInfo .OverrideCompileFlags
823-
// .at(profile.Name)
824-
// .Remove.
825-
826-
824+
std::vector<std::string> compileArgsToRemove;
825+
Internal::SplitString( scriptInfo.OverrideCompileFlags.at(profile.Name).Remove,
826+
" ",
827+
compileArgsToRemove);
827828

829+
for(int i = 0; i < compileArgsToRemove.size(); ++i)
830+
{
831+
std::size_t foundIndex = compileArgs.find(compileArgsToRemove.at(i));
832+
833+
if(foundIndex != std::string::npos)
834+
{
835+
compileArgs.erase(foundIndex, compileArgsToRemove.at(i).size() + 1);
836+
continue;
837+
}
838+
839+
ssLOG_WARNING("Compile flag to remove not found: " << compileArgsToRemove.at(i));
840+
}
828841

842+
Internal::TrimRight(compileArgs);
843+
compileArgs += " " + scriptInfo.OverrideCompileFlags.at(profile.Name).Append;
829844
}
830845

831846
compileCommand.replace( foundIndex,
@@ -838,8 +853,6 @@ bool runcpp2::CompileAndLinkScript( const std::string& scriptPath,
838853
return false;
839854
}
840855

841-
842-
#if 0
843856
//Replace {InputFile}
844857
const std::string inputFileSubstitution = "{InputFile}";
845858
foundIndex = compileCommand.find(inputFileSubstitution);
@@ -853,10 +866,21 @@ bool runcpp2::CompileAndLinkScript( const std::string& scriptPath,
853866

854867
//Replace {ObjectFile}
855868
const std::string objectFileSubstitution = "{ObjectFile}";
869+
std::string objectFileExt;
870+
871+
for(int i = 0; i < platformNames.size(); ++i)
872+
{
873+
if(profile.ObjectFileExtensions.find(platformNames.at(i)) != profile.ObjectFileExtensions.end())
874+
{
875+
objectFileExt = profile.ObjectFileExtensions.at(platformNames.at(i));
876+
break;
877+
}
878+
}
879+
856880
foundIndex = compileCommand.find(objectFileSubstitution);
857881
if(foundIndex != std::string::npos)
858882
{
859-
std::string objectFileName = scriptDirectory + "/.runcpp2/" + scriptName + "." + objectFileExt;
883+
std::string objectFileName = runcpp2ScriptDir + "/" + scriptName + "." + objectFileExt;
860884
compileCommand.replace(foundIndex, objectFileSubstitution.size(), objectFileName);
861885
}
862886
else
@@ -867,13 +891,62 @@ bool runcpp2::CompileAndLinkScript( const std::string& scriptPath,
867891

868892
//Compile the script
869893
ssLOG_INFO("running compile command: " << compileCommand);
870-
//TODO(NOW): Replace this with system2
871-
if(std::system(compileCommand.c_str()) != 0)
894+
895+
System2CommandInfo compileCommandInfo;
896+
SYSTEM2_RESULT result = System2Run(compileCommand.c_str(), &compileCommandInfo);
897+
898+
if(result != SYSTEM2_RESULT_SUCCESS)
872899
{
873-
ssLOG_ERROR("Failed to run compile script with command: " << compileCommand);
900+
ssLOG_ERROR("System2Run failed with result: " << result);
901+
return false;
902+
}
903+
904+
std::vector<char> output;
905+
output.resize(4096);
906+
output.back() = '\0';
907+
908+
uint32_t byteRead = 0;
909+
910+
do
911+
{
912+
output.resize(output.size() + 4096);
913+
output.back() = '\0';
914+
915+
result = System2ReadFromOutput( &compileCommandInfo,
916+
output.data() + output.size() - 4096,
917+
4096 - 1,
918+
&byteRead);
919+
}
920+
while(result == SYSTEM2_RESULT_READ_NOT_FINISHED);
921+
922+
output.at(byteRead) = '\0';
923+
924+
if(result != SYSTEM2_RESULT_SUCCESS)
925+
{
926+
ssLOG_ERROR("Failed to read from output with result: " << result);
874927
return false;
875928
}
876-
#endif
929+
930+
ssLOG_DEBUG("Compile Output: \n" << output.data());
931+
932+
int statusCode = 0;
933+
result = System2GetCommandReturnValueSync(&compileCommandInfo, &statusCode);
934+
935+
if(result != SYSTEM2_RESULT_SUCCESS)
936+
{
937+
ssLOG_ERROR("System2GetCommandReturnValueSync failed with result: " << result);
938+
return false;
939+
}
940+
941+
if(statusCode != 0)
942+
{
943+
ssLOG_ERROR("Compile command returned with non-zero status code: " << statusCode);
944+
return false;
945+
}
946+
947+
//TODO(NOW): Link
948+
949+
877950
return true;
878951
}
879952

0 commit comments

Comments
 (0)