Skip to content

Commit bbba3d0

Browse files
committed
REXM: ADDED: Web platform logs automated reports -WIP-
1 parent cde917c commit bbba3d0

1 file changed

Lines changed: 81 additions & 1 deletion

File tree

tools/rexm/rexm.c

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1456,6 +1456,21 @@ int main(int argc, char *argv[])
14561456

14571457
rlExampleTesting *testing = (rlExampleTesting *)RL_CALLOC(exBuildListCount, sizeof(rlExampleTesting));
14581458

1459+
#if defined(_WIN32)
1460+
// Set required environment variables
1461+
//putenv(TextFormat("RAYLIB_DIR=%s\\..", exBasePath));
1462+
//_putenv("PATH=%PATH%;C:\\raylib\\w64devkit\\bin");
1463+
//putenv("MAKE=mingw32-make");
1464+
//ChangeDirectory(exBasePath);
1465+
//_putenv("MAKE_PATH=C:\\raylib\\w64devkit\\bin");
1466+
//_putenv("EMSDK_PATH = C:\\raylib\\emsdk");
1467+
//_putenv("PYTHON_PATH=$(EMSDK_PATH)\\python\\3.9.2-nuget_64bit");
1468+
//_putenv("NODE_PATH=$(EMSDK_PATH)\\node\\20.18.0_64bit\\bin");
1469+
//_putenv("PATH=%PATH%;$(MAKE_PATH);$(EMSDK_PATH);$(NODE_PATH);$(PYTHON_PATH)");
1470+
1471+
_putenv("PATH=%PATH%;C:\\raylib\\w64devkit\\bin;C:\\raylib\\emsdk\\python\\3.9.2-nuget_64bit;C:\\raylib\\emsdk\\node\\20.18.0_64bit\\bin");
1472+
#endif
1473+
14591474
for (int i = 0; i < exBuildListCount; i++)
14601475
{
14611476
// Get example name and category
@@ -1474,7 +1489,7 @@ int main(int argc, char *argv[])
14741489
// STEP 3: Run example with arguments: --frames 2 > <example>.out.log
14751490
// STEP 4: Load <example>.out.log and check "WARNING:" messages -> Some could maybe be ignored
14761491
// STEP 5: Generate report with results
1477-
1492+
14781493
// STEP 1: Load example and inject required code
14791494
// PROBLEM: As we need to modify the example source code for building, we need to keep a copy or something
14801495
// WARNING: If we make a copy and something fails, it could not be restored at the end
@@ -1485,6 +1500,71 @@ int main(int argc, char *argv[])
14851500
TextFormat("%s/%s/%s.original.c", exBasePath, exCategory, exName));
14861501
char *srcText = LoadFileText(TextFormat("%s/%s/%s.c", exBasePath, exCategory, exName));
14871502

1503+
#define BUILD_TESTING_WEB
1504+
#if defined(BUILD_TESTING_WEB)
1505+
static const char *mainReplaceText =
1506+
"#include <stdio.h>\n"
1507+
"#include <string.h>\n"
1508+
"#include <stdlib.h>\n"
1509+
"#include <emscripten/emscripten.h>\n\n"
1510+
"static char logText[1024] = {0};\n"
1511+
"static int logTextOffset = 0;\n\n"
1512+
"void CustomTraceLog(int msgType, const char *text, va_list args)\n{\n"
1513+
" switch (msgType)\n {\n"
1514+
" case LOG_INFO: logTextOffset += sprintf(logText + logTextOffset, \"INFO: \"); break;\n"
1515+
" case LOG_ERROR: logTextOffset += sprintf(logText + logTextOffset, \"ERROR: \"); break;\n"
1516+
" case LOG_WARNING: logTextOffset += sprintf(logText + logTextOffset, \"WARNING: \"); break;\n"
1517+
" case LOG_DEBUG: logTextOffset += sprintf(logText + logTextOffset, \"DEBUG: \"); break;\n"
1518+
" default: break;\n }\n"
1519+
" logTextOffset += vsprintf(logText + logTextOffset, text, args);\n"
1520+
" logTextOffset += sprintf(logText + logTextOffset, \"\\n\");\n}\n\n"
1521+
"int main(int argc, char *argv[])\n{\n"
1522+
" SetTraceLogCallback(CustomTraceLog);\n"
1523+
" int requestedTestFrames = 0;\n"
1524+
" int testFramesCount = 0;\n"
1525+
" if ((argc > 1) && (argc == 3) && (strcmp(argv[1], \"--frames\") != 0)) requestedTestFrames = atoi(argv[2]);\n";
1526+
1527+
static const char *returnReplaceText =
1528+
" char outputLogFile[256] = { 0 };\n"
1529+
" TextCopy(outputLogFile, GetFileNameWithoutExt(argv[0]));\n"
1530+
" SaveFileText(outputLogFile, logText);\n"
1531+
" emscripten_run_script(TextFormat(\"saveFileFromMEMFSToDisk('%s','%s')\", outputLogFile, GetFileName(outputLogFile)));\n\n"
1532+
" return 0";
1533+
1534+
char *srcTextUpdated[4] = { 0 };
1535+
srcTextUpdated[0] = TextReplace(srcText, "int main(void)\n{", mainReplaceText);
1536+
srcTextUpdated[1] = TextReplace(srcTextUpdated[0], "WindowShouldClose()", "WindowShouldClose() && (testFramesCount < requestedTestFrames)");
1537+
srcTextUpdated[2] = TextReplace(srcTextUpdated[1], "EndDrawing();", "EndDrawing(); testFramesCount++;");
1538+
srcTextUpdated[3] = TextReplace(srcTextUpdated[2], " return 0", returnReplaceText);
1539+
UnloadFileText(srcText);
1540+
1541+
//SaveFileText(TextFormat("%s/%s/%s.c", exBasePath, exCategory, exName), srcTextUpdated[3]);
1542+
for (int i = 0; i < 4; i++) { MemFree(srcTextUpdated[i]); srcTextUpdated[i] = NULL; }
1543+
1544+
// Build example for PLATFORM_WEB
1545+
// Build: raylib.com/examples/<category>/<category>_example_name.html
1546+
// Build: raylib.com/examples/<category>/<category>_example_name.data
1547+
// Build: raylib.com/examples/<category>/<category>_example_name.wasm
1548+
// Build: raylib.com/examples/<category>/<category>_example_name.js
1549+
#if defined(_WIN32)
1550+
LOG("INFO: [%s] Building example for PLATFORM_WEB (Host: Win32)\n", exName);
1551+
system(TextFormat("mingw32-make -C %s -f Makefile.Web %s/%s PLATFORM=PLATFORM_WEB -B", exBasePath, exCategory, exName));
1552+
#else
1553+
LOG("INFO: [%s] Building example for PLATFORM_WEB (Host: POSIX)\n", exName);
1554+
system(TextFormat("make -C %s -f Makefile.Web %s/%s PLATFORM=PLATFORM_WEB -B", exBasePath, exCategory, exName));
1555+
#endif
1556+
// Restore original source code before continue
1557+
FileCopy(TextFormat("%s/%s/%s.original.c", exBasePath, exCategory, exName),
1558+
TextFormat("%s/%s/%s.c", exBasePath, exCategory, exName));
1559+
FileRemove(TextFormat("%s/%s/%s.original.c", exBasePath, exCategory, exName));
1560+
1561+
// STEP 3: Run example on browser
1562+
ChangeDirectory(TextFormat("%s/%s", exBasePath, exCategory));
1563+
system("start python -m http.server 8080");
1564+
system(TextFormat("start explorer \"http:\\localhost:8080/%s.html", exName));
1565+
1566+
#else // BUILD_TESTING_DESKTOP
1567+
14881568
static const char *mainReplaceText =
14891569
"#include <string.h>\n"
14901570
"#include <stdlib.h>\n"

0 commit comments

Comments
 (0)