Browse Source

Fix Linux build after Windows change

windows-support
Macoy Madson 6 months ago
parent
commit
0c7cfb3ffa
9 changed files with 31 additions and 20 deletions
  1. +2
    -2
      src/Build.cpp
  2. +0
    -1
      src/Converters.cpp
  3. +0
    -1
      src/Evaluator.cpp
  4. +4
    -4
      src/FileUtilities.cpp
  5. +1
    -1
      src/Main.cpp
  6. +6
    -6
      src/ModuleManager.cpp
  7. +1
    -1
      src/RunProcess.cpp
  8. +17
    -3
      src/Utilities.hpp
  9. +0
    -1
      src/Writer.cpp

+ 2
- 2
src/Build.cpp View File

@ -37,13 +37,13 @@ void makeObjectOutputArgument(char* buffer, int bufferSize, const char* objectNa
void makeDynamicLibraryOutputArgument(char* buffer, int bufferSize, const char* libraryName,
const char* buildExecutable)
{
if (_stricmp(buildExecutable, "cl.exe") == 0)
if (StrCompareIgnoreCase(buildExecutable, "cl.exe") == 0)
{
Log("error: attempting to build dynamic library using cl.exe. You must use link.exe "
"instead\n");
SafeSnprinf(buffer, bufferSize, "%s", libraryName);
}
else if (_stricmp(buildExecutable, "link.exe") == 0)
else if (StrCompareIgnoreCase(buildExecutable, "link.exe") == 0)
{
SafeSnprinf(buffer, bufferSize, "/OUT:\"%s\"", libraryName);
}


+ 0
- 1
src/Converters.cpp View File

@ -3,7 +3,6 @@
#include "Tokenizer.hpp"
#include "Utilities.hpp"
// TODO: safe version of strcat
#include <ctype.h>
#include <stdio.h>
#include <string.h>


+ 0
- 1
src/Evaluator.cpp View File

@ -13,7 +13,6 @@
#include "Utilities.hpp"
#include "Writer.hpp"
// TODO: safe version of strcat
#include <stdio.h>
#include <string.h>


+ 4
- 4
src/FileUtilities.cpp View File

@ -161,7 +161,7 @@ void makeDirectory(const char* path)
void getDirectoryFromPath(const char* path, char* bufferOut, int bufferSize)
{
#ifdef UNIX
char* pathCopy = strdup(path);
char* pathCopy = StrDuplicate(path);
const char* dirName = dirname(pathCopy);
SafeSnprinf(bufferOut, bufferSize, "%s", dirName);
free(pathCopy);
@ -183,7 +183,7 @@ void getDirectoryFromPath(const char* path, char* bufferOut, int bufferSize)
void getFilenameFromPath(const char* path, char* bufferOut, int bufferSize)
{
#ifdef UNIX
char* pathCopy = strdup(path);
char* pathCopy = StrDuplicate(path);
const char* fileName = basename(pathCopy);
SafeSnprinf(bufferOut, bufferSize, "%s", fileName);
free(pathCopy);
@ -205,8 +205,8 @@ void makePathRelativeToFile(const char* filePath, const char* referencedFilePath
{
getDirectoryFromPath(filePath, bufferOut, bufferSize);
// TODO: Need to make this safe!
strcat_s(bufferOut, bufferSize, "/");
strcat_s(bufferOut, bufferSize, referencedFilePath);
StrCatSafe(bufferOut, bufferSize, "/");
StrCatSafe(bufferOut, bufferSize, referencedFilePath);
}
const char* makeAbsolutePath_Allocated(const char* fromDirectory, const char* filePath)


+ 1
- 1
src/Main.cpp View File

@ -254,7 +254,7 @@ int main(int numArguments, char* arguments[])
// Need to use absolute path when executing
const char* executablePath = makeAbsolutePath_Allocated(nullptr, output.c_str());
arguments.fileToExecute = executablePath;
const char* commandLineArguments[] = {_strdup(arguments.fileToExecute), nullptr};
const char* commandLineArguments[] = {StrDuplicate(arguments.fileToExecute), nullptr};
arguments.arguments = commandLineArguments;
char workingDirectory[MAX_PATH_LENGTH] = {0};
getDirectoryFromPath(arguments.fileToExecute, workingDirectory,


+ 6
- 6
src/ModuleManager.cpp View File

@ -331,7 +331,7 @@ bool moduleManagerAddEvaluateFile(ModuleManager& manager, const char* filename,
char safePathBuffer[MAX_PATH_LENGTH] = {0};
makeSafeFilename(safePathBuffer, sizeof(safePathBuffer), resolvedPath);
const char* normalizedFilename = _strdup(safePathBuffer);
const char* normalizedFilename = StrDuplicate(safePathBuffer);
// Enabling this makes all file:line messages really long. For now, I'll keep it as relative to
// current working directory of this executable.
// const char* normalizedFilename = makeAbsolutePath_Allocated(".", filename);
@ -798,7 +798,7 @@ static bool commandEqualsCachedCommand(ModuleManager& manager, const char* artif
{
uint32_t newCommandCrc = 0;
if (logging.commandCrcs)
Logf("\"");
Log("\"");
for (const char** currentArg = commandArguments; *currentArg; ++currentArg)
{
crc32(*currentArg, strlen(*currentArg), &newCommandCrc);
@ -806,7 +806,7 @@ static bool commandEqualsCachedCommand(ModuleManager& manager, const char* artif
Logf("%s ", *currentArg);
}
if (logging.commandCrcs)
Logf("\"\n");
Log("\"\n");
if (crcOut)
*crcOut = newCommandCrc;
@ -976,7 +976,7 @@ bool moduleManagerBuild(ModuleManager& manager, std::vector<std::string>& builtO
// Annoying exception for MSVC not having spaces between some arguments
std::string* objectOutput = &object->filename;
std::string objectOutputOverride;
if (_stricmp(buildCommand.fileToExecute.c_str(), "CL.exe") == 0)
if (StrCompareIgnoreCase(buildCommand.fileToExecute.c_str(), "CL.exe") == 0)
{
char msvcObjectOutput[MAX_PATH_LENGTH] = {0};
makeObjectOutputArgument(msvcObjectOutput, sizeof(msvcObjectOutput),
@ -1163,14 +1163,14 @@ bool moduleManagerBuild(ModuleManager& manager, std::vector<std::string>& builtO
// Annoying exception for MSVC not having spaces between some arguments
std::string* executableOutput = &outputExecutableName;
std::string executableOutputOverride;
if (_stricmp(linkCommand.fileToExecute.c_str(), "cl.exe") == 0)
if (StrCompareIgnoreCase(linkCommand.fileToExecute.c_str(), "cl.exe") == 0)
{
char msvcExecutableOutput[MAX_PATH_LENGTH] = {0};
PrintfBuffer(msvcExecutableOutput, "/Fe\"%s\"", outputExecutableName.c_str());
executableOutputOverride = msvcExecutableOutput;
executableOutput = &executableOutputOverride;
}
else if (_stricmp(linkCommand.fileToExecute.c_str(), "link.exe") == 0)
else if (StrCompareIgnoreCase(linkCommand.fileToExecute.c_str(), "link.exe") == 0)
{
char msvcExecutableOutput[MAX_PATH_LENGTH] = {0};
PrintfBuffer(msvcExecutableOutput, "/out:\"%s\"", outputExecutableName.c_str());


+ 1
- 1
src/RunProcess.cpp View File

@ -128,7 +128,7 @@ int runProcess(const RunProcessArguments& arguments, int* statusOut)
int i = 0;
for (const char** arg = arguments.arguments; *arg != nullptr; ++arg)
{
nonConstArguments[i] = strdup(*arg);
nonConstArguments[i] = StrDuplicate(*arg);
++i;
}


+ 17
- 3
src/Utilities.hpp View File

@ -4,6 +4,8 @@
#include <cstdio> // sprintf
#include <string>
#include <strings.h>
#define MAX_NAME_LENGTH 64
#define MAX_PATH_LENGTH 128
@ -14,8 +16,8 @@
void printIndentToDepth(int depth);
// Print to stderr. Could be for reporting errors too; it's up to you to add "error:'
#define Logf(format, ...) fprintf(stderr, format, __VA_ARGS__);
#define Log(format) fprintf(stderr, format);
#define Logf(format, ...) fprintf(stderr, format, __VA_ARGS__)
#define Log(format) fprintf(stderr, format)
// TODO: de-macroize
#define SafeSnprinf(buffer, size, format, ...) \
@ -26,12 +28,24 @@ void printIndentToDepth(int depth);
#define PrintfBuffer(buffer, format, ...) SafeSnprinf(buffer, sizeof(buffer), format, __VA_ARGS__)
// TODO Replace with strcat()
// TODO Replace with strcat()?
#define PrintBuffer(buffer, output) SafeSnprinf(buffer, sizeof(buffer), "%s", output)
bool writeCharToBuffer(char c, char** at, char* bufferStart, int bufferSize);
bool writeStringToBuffer(const char* str, char** at, char* bufferStart, int bufferSize);
#ifdef WINDOWS
#define StrCatSafe(bufferOut, bufferSize, strToAppend) strcat_s(bufferOut, bufferSize, strToAppend)
#define StrDuplicate(str) _strdup(str)
#define StrCompareIgnoreCase(strA, strB) strcasecmp(strA, strB)
#else
// TODO: Safe version
#define StrCatSafe(bufferOut, bufferSize, strToAppend) \
strncat(bufferOut, strToAppend, bufferSize - 1)
#define StrDuplicate(str) strdup(str)
#define StrCompareIgnoreCase(strA, strB) strcasecmp(strA, strB)
#endif
// TODO De-macroize these? It could be useful to keep as macros if I add __LINE__ etc. (to answer
// questions like "where is this error coming from?")


+ 0
- 1
src/Writer.cpp View File

@ -7,7 +7,6 @@
#include "Tokenizer.hpp"
#include "Utilities.hpp"
// TODO: safe version of strcat
#include <stdarg.h> // va_start
#include <stdio.h>
#include <string.h>


Loading…
Cancel
Save