Skip to content

Commit 0cd7bc4

Browse files
Updating runcpp2 and tutorial to download for current version instead
1 parent bc0a16e commit 0cd7bc4

File tree

3 files changed

+71
-14
lines changed

3 files changed

+71
-14
lines changed

Examples/ClearTutorial.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
3+
rm ./tutorial/*.cpp ./tutorial/*.hpp ./tutorial/*.yaml ./tutorial/main

Examples/InteractiveTutorial.cpp

Lines changed: 59 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Defines: ["ssLOG_USE_SOURCE=1"]
3838
#include <chrono>
3939

4040
std::string runcpp2ExecutablePath = "";
41+
std::string downloadBranch = "heads/master";
4142
bool integrationTest = false;
4243

4344
#define DELAYED_OUTPUT(str) \
@@ -325,12 +326,9 @@ int main(int, char**)
325326
"See https://neko-box-coder.github.io/runcpp2/latest/guides/"
326327
"building_project_sources/ for more details.\n");
327328

328-
//TODO: Remove this when the cache bug is fixed
329-
DELAYED_OUTPUT("`--rebuild` is just resetting the build cache");
330-
331329
DELAYED_OUTPUT("Let's try it");
332330
if(!RunCommandWithPrompt( runcpp2ExecutablePath +
333-
" --build --output ./tutorial --executable --rebuild "
331+
" --build --output ./tutorial --executable "
334332
"tutorial/main.cpp"))
335333
{
336334
return false;
@@ -782,15 +780,15 @@ bool Chapter3_ExternalDependencies()
782780
#ifdef _WIN32
783781
if(!RunCommandWithPrompt( "powershell -Command \""
784782
"Invoke-WebRequest https://github.com/Neko-Box-Coder/runcpp2/raw/"
785-
"refs/heads/master/Examples/Logging.cpp "
783+
"refs/" + downloadBranch + "/Examples/Logging.cpp "
786784
"-OutFile tutorial/Logging.cpp\"", true, false))
787785
{
788786
return false;
789787
}
790788
#else
791789
if(!RunCommandWithPrompt( "curl -L -o tutorial/Logging.cpp "
792-
"https://github.com/Neko-Box-Coder/runcpp2/raw/refs/heads/"
793-
"master/Examples/Logging.cpp"))
790+
"https://github.com/Neko-Box-Coder/runcpp2/raw/refs/" +
791+
downloadBranch + "/Examples/Logging.cpp"))
794792
{
795793
return false;
796794
}
@@ -818,16 +816,16 @@ bool Chapter3_ExternalDependencies()
818816
#ifdef _WIN32
819817
if(!RunCommandWithPrompt( "powershell -Command \""
820818
"Invoke-WebRequest https://github.com/Neko-Box-Coder/runcpp2/raw/"
821-
"refs/heads/master/Examples/SDLWindow.cpp "
819+
"refs/" + downloadBranch + "/Examples/SDLWindow.cpp "
822820
"-OutFile tutorial/SDLWindow.cpp\"", true, false))
823821
{
824822
return false;
825823
}
826824

827825
#else
828826
if(!RunCommandWithPrompt( "curl -L -o tutorial/SDLWindow.cpp "
829-
"https://github.com/Neko-Box-Coder/runcpp2/raw/refs/heads/"
830-
"master/Examples/SDLWindow.cpp"))
827+
"https://github.com/Neko-Box-Coder/runcpp2/raw/refs/" +
828+
downloadBranch + "/Examples/SDLWindow.cpp"))
831829
{
832830
return false;
833831
}
@@ -1080,6 +1078,56 @@ int main(int argc, char* argv[])
10801078

10811079
runcpp2ExecutablePath = exePath.string() + " -l -c " + configPath.string();
10821080
}
1081+
1082+
//Get runcpp2 version
1083+
{
1084+
System2CommandInfo commandInfo = {0};
1085+
commandInfo.RedirectOutput = true;
1086+
SYSTEM2_RESULT result = System2CppRun(runcpp2ExecutablePath + " --version", commandInfo);
1087+
#define CHECK_RESULT() \
1088+
if(result != SYSTEM2_RESULT_SUCCESS) \
1089+
{ \
1090+
ssLOG_ERROR("Failed to get version"); \
1091+
ssLOG_ERROR("SYSTEM2_RESULT: " << result); \
1092+
return 1; \
1093+
}
1094+
1095+
CHECK_RESULT();
1096+
1097+
std::string versionOutput;
1098+
result = System2CppReadFromOutput(commandInfo, versionOutput);
1099+
CHECK_RESULT();
1100+
1101+
int returnCode = 0;
1102+
result = System2CppGetCommandReturnValueSync(commandInfo, returnCode, false);
1103+
CHECK_RESULT();
1104+
1105+
if(returnCode != 0)
1106+
{
1107+
ssLOG_ERROR("Failed to get version with return code: " << returnCode);
1108+
return 1;
1109+
}
1110+
1111+
#undef CHECK_RESULT
1112+
1113+
{
1114+
size_t newlinePos = versionOutput.find("\r");
1115+
if(newlinePos == std::string::npos)
1116+
newlinePos = versionOutput.find("\n");
1117+
if(newlinePos != std::string::npos)
1118+
versionOutput = versionOutput.substr(0, newlinePos);
1119+
}
1120+
1121+
size_t versionStartPos = versionOutput.rfind(" ");
1122+
if(versionStartPos == std::string::npos || ++versionStartPos >= versionOutput.size())
1123+
{
1124+
ssLOG_ERROR("Failed to extract runcpp2 version");
1125+
return 1;
1126+
}
1127+
1128+
downloadBranch = "tags/" + versionOutput.substr(versionStartPos);
1129+
1130+
}
10831131

10841132
DELAYED_OUTPUT("The whole tutorial is about 15 minutes long.");
10851133

@@ -1127,7 +1175,7 @@ int main(int argc, char* argv[])
11271175

11281176
DELAYED_OUTPUT("This concludes the tutorial.");
11291177
DELAYED_OUTPUT("Feel free to check out the documentation for more details.");
1130-
DELAYED_OUTPUT("https://neko-box-coder.github.io/runcpp2/latest/guides/basic_concepts/");
1178+
DELAYED_OUTPUT( "https://neko-box-coder.github.io/runcpp2/master/guides/basic_concepts/");
11311179
DELAYED_OUTPUT("");
11321180
DELAYED_OUTPUT("As well as the examples in the repository.");
11331181
DELAYED_OUTPUT("https://github.com/Neko-Box-Coder/runcpp2/tree/master/Examples");

Src/runcpp2/runcpp2.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -841,10 +841,15 @@ bool runcpp2::DownloadTutorial(char* runcppPath)
841841
break;
842842
}
843843

844+
std::string targetBranch = RUNCPP2_VERSION;
845+
size_t dashPos = targetBranch.find("-");
846+
if(dashPos != std::string::npos)
847+
targetBranch = targetBranch.substr(0, dashPos);
848+
844849
#ifdef _WIN32
845850
if(!RunCommand( "powershell -Command \""
846851
"Invoke-WebRequest https://github.com/Neko-Box-Coder/runcpp2/raw/"
847-
"refs/heads/master/Examples/InteractiveTutorial.cpp "
852+
"refs/tags/" + targetBranch + "/Examples/InteractiveTutorial.cpp "
848853
"-OutFile InteractiveTutorial.cpp\"",
849854
false,
850855
"./",
@@ -855,8 +860,8 @@ bool runcpp2::DownloadTutorial(char* runcppPath)
855860
}
856861
#else
857862
if(!RunCommand( "curl -L -o InteractiveTutorial.cpp "
858-
"https://github.com/Neko-Box-Coder/runcpp2/raw/refs/heads/"
859-
"master/Examples/InteractiveTutorial.cpp",
863+
"https://github.com/Neko-Box-Coder/runcpp2/raw/refs/tags/" +
864+
targetBranch + "/Examples/InteractiveTutorial.cpp",
860865
false,
861866
"./",
862867
dummy,
@@ -866,6 +871,7 @@ bool runcpp2::DownloadTutorial(char* runcppPath)
866871
}
867872
#endif
868873

874+
ssLOG_INFO("targetBranch: " << targetBranch);
869875
ssLOG_BASE("Downloaded InteractiveTutorial.cpp from github.");
870876
ssLOG_BASE("Do `" << runcppPath << " InteractiveTutorial.cpp to start the tutorial.");
871877

0 commit comments

Comments
 (0)