Browse Source

Fix CRC parsing, correct first arg

* I had to add another command exception to properly fill in the first
argument after it is overridden via env vars.
* I was parsing CRCs incorrectly, which caused rebuilds every time.
* Free command line
windows-support
Macoy Madson 6 months ago
parent
commit
395b99941e
2 changed files with 53 additions and 10 deletions
  1. +7
    -2
      src/ModuleManager.cpp
  2. +46
    -8
      src/RunProcess.cpp

+ 7
- 2
src/ModuleManager.cpp View File

@ -1,7 +1,6 @@
#include "ModuleManager.hpp"
#include <string.h>
#include <cstring>
#include "Converters.hpp"
@ -684,10 +683,16 @@ static bool commandEqualsCachedCommand(ModuleManager& manager, const char* artif
const char** commandArguments, uint32_t* crcOut)
{
uint32_t newCommandCrc = 0;
if (logging.commandCrcs)
Logf("\"");
for (const char** currentArg = commandArguments; *currentArg; ++currentArg)
{
crc32(*currentArg, strlen(*currentArg), &newCommandCrc);
if (logging.commandCrcs)
Logf("%s ", *currentArg);
}
if (logging.commandCrcs)
Logf("\"\n");
if (crcOut)
*crcOut = newCommandCrc;
@ -1210,7 +1215,7 @@ static bool moduleManagerReadCacheFile(ModuleManager& manager)
char* endPtr;
manager.cachedCommandCrcs[(*tokens)[artifactIndex].contents] =
strtol((*tokens)[crcIndex].contents.c_str(), &endPtr, /*base=*/10);
static_cast<uint32_t>(std::stoul((*tokens)[crcIndex].contents));
}
else
{


+ 46
- 8
src/RunProcess.cpp View File

@ -282,28 +282,63 @@ int runProcess(const RunProcessArguments& arguments, int* statusOut)
const char* fileToExecute =
fileToExecuteOverride[0] ? fileToExecuteOverride : arguments.fileToExecute;
// TODO: Make command line use fileToExecuteOverride if necessary!
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
char* commandLineString = nullptr;
{
size_t commandLineLength = 0;
bool isFirstArg = true;
for (const char** arg = arguments.arguments; *arg != nullptr; ++arg)
{
commandLineLength += strlen(*arg);
if (isFirstArg)
{
commandLineLength += strlen(fileToExecute);
// Room for quotes
commandLineLength += 2;
isFirstArg = false;
}
else
commandLineLength += strlen(*arg);
// Room for space
commandLineLength += 1;
}
commandLineString = (char*)calloc(commandLineLength, sizeof(char));
commandLineString[commandLineLength] = '\0';
commandLineString[commandLineLength - 1] = '\0';
char* writeHead = commandLineString;
isFirstArg = true;
for (const char** arg = arguments.arguments; *arg != nullptr; ++arg)
{
if (!writeStringToBuffer(*arg, &writeHead, commandLineString, commandLineLength))
// Support executable with spaces in path
if (isFirstArg)
{
Log("error: ran out of space to write command\n");
free(commandLineString);
return 1;
isFirstArg = false;
if (!writeCharToBuffer('"', &writeHead, commandLineString, commandLineLength))
{
Log("error: ran out of space to write command\n");
free(commandLineString);
return 1;
}
if (!writeStringToBuffer(fileToExecute, &writeHead, commandLineString,
commandLineLength))
{
Log("error: ran out of space to write command\n");
free(commandLineString);
return 1;
}
if (!writeCharToBuffer('"', &writeHead, commandLineString, commandLineLength))
{
Log("error: ran out of space to write command\n");
free(commandLineString);
return 1;
}
}
else
{
if (!writeStringToBuffer(*arg, &writeHead, commandLineString, commandLineLength))
{
Log("error: ran out of space to write command\n");
free(commandLineString);
return 1;
}
}
if (*(arg + 1) != nullptr)
@ -339,6 +374,7 @@ int runProcess(const RunProcessArguments& arguments, int* statusOut)
&startupInfo, // Pointer to STARTUPINFO structure
processInfo)) // Pointer to PROCESS_INFORMATION structure
{
free(commandLineString);
int errorCode = GetLastError();
if (errorCode == ERROR_FILE_NOT_FOUND)
{
@ -356,6 +392,8 @@ int runProcess(const RunProcessArguments& arguments, int* statusOut)
return 1;
}
free(commandLineString);
Log("Executed successfully\n");
std::string command = "";


Loading…
Cancel
Save