From 23dafd4e6db8398c018b22a37a07c333a422a25e Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Thu, 1 Jul 2021 12:42:03 -0700 Subject: [PATCH] Fixed static lib archiving with paths with spaces --- IDE/src/BuildContext.bf | 36 ++++++++++++++++++++++++++++++++---- IDE/src/IDEUtils.bf | 8 ++++++-- 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/IDE/src/BuildContext.bf b/IDE/src/BuildContext.bf index eb39162d..552decfb 100644 --- a/IDE/src/BuildContext.bf +++ b/IDE/src/BuildContext.bf @@ -194,14 +194,42 @@ namespace IDE arCmds.AppendF("CREATE {}\n", targetPath); + void AddObject(StringView obj) + { + if (obj.IsEmpty) + return; + + if (obj.EndsWith(".lib", .OrdinalIgnoreCase)) + arCmds.AppendF("ADDLIB {}\n", obj); + else + arCmds.AppendF("ADDMOD {}\n", obj); + } + + bool inQuote = false; + int lastEnd = -1; + for (int i < objectsArg.Length) + { + var c = objectsArg[i]; + if (c == '"') + { + if (inQuote) + AddObject(objectsArg.Substring(lastEnd + 1, i - lastEnd - 1)); + inQuote = !inQuote; + lastEnd = i; + } + else if ((c == ' ') && (!inQuote)) + { + AddObject(objectsArg.Substring(lastEnd + 1, i - lastEnd - 1)); + lastEnd = i; + } + } + AddObject(objectsArg.Substring(lastEnd + 1)); + for (let obj in objectsArg.Split(' ')) { if (!obj.IsEmpty) { - if (obj.EndsWith(".lib", .OrdinalIgnoreCase)) - arCmds.AppendF("ADDLIB {}\n", obj); - else - arCmds.AppendF("ADDMOD {}\n", obj); + } } arCmds.AppendF("SAVE\n"); diff --git a/IDE/src/IDEUtils.bf b/IDE/src/IDEUtils.bf index 6f6b957c..7fc29d01 100644 --- a/IDE/src/IDEUtils.bf +++ b/IDE/src/IDEUtils.bf @@ -17,13 +17,17 @@ namespace IDE public const char8 cNativeSlash = Path.DirectorySeparatorChar; public const char8 cOtherSlash = Path.AltDirectorySeparatorChar; - public static void AppendWithOptionalQuotes(String targetStr, String srcFileName) + public static void AppendWithOptionalQuotes(String targetStr, StringView srcFileName) { bool hasSpace = srcFileName.Contains(' '); bool alreadyQuoted = (srcFileName.Length > 0 && srcFileName[0] == '"' && srcFileName[srcFileName.Length - 1] == '"'); if (hasSpace && !alreadyQuoted) - targetStr.Append("\"", srcFileName, "\""); + { + targetStr.Append("\""); + targetStr.Append(srcFileName); + targetStr.Append("\""); + } else targetStr.Append(srcFileName); }