From 8068c552ab3a41189de9be9d2086c44338be988b Mon Sep 17 00:00:00 2001 From: Bryce Harrington Date: Fri, 10 Jan 2014 13:19:17 -0800 Subject: btool: Fix hitting cmdline limit on XP/Mingw/Msys (Fixes #1251405) Current releases of trunk fail to build on Windows XP because command line length limits are hit. This patch sends only the unique parameters from the "libs" field during the link stage to the command. This saves enough characters so that btool will complete the build. It is not a long term solution, but will allow development to continue on Windows for a while longer, until the underlying problems can be addressed. Patch authored by David Mathog (mathog) Signed-off-by: Bryce Harrington (bzr r12913) --- buildtool.cpp | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) (limited to 'buildtool.cpp') diff --git a/buildtool.cpp b/buildtool.cpp index c6aa6e127..7ef10c87d 100644 --- a/buildtool.cpp +++ b/buildtool.cpp @@ -52,6 +52,8 @@ #include #include +#include +#include #include #include #include @@ -4163,7 +4165,7 @@ bool MakeBase::executeCommand(const String &command, return false; } strcpy(paramBuf, (char *)command.c_str()); - + //# Go to http://msdn2.microsoft.com/en-us/library/ms682499.aspx //# to see how Win32 pipes work @@ -8136,6 +8138,31 @@ public: virtual ~TaskLink() {} + virtual void UniqueParams(std::string& source) { + size_t prev = 0; + size_t next = 0; + std::list thelist; + std::list::iterator it; + std::string tstring=" "; + source +=std::string(" "); // else the last token may be lost + while ((next = source.find_first_of(" ", prev)) != std::string::npos){ + if (next - prev != 0){ + thelist.push_back(source.substr(prev, next - prev)); + } + prev = next + 1; + } + thelist.sort(); + source.clear(); + source +=std::string(" "); + for(it=thelist.begin(); it!=thelist.end();it++){ + if(*it != tstring){ + tstring = *it; + source +=tstring; + source +=std::string(" "); + } + } + } + virtual bool execute() { String command = parent.eval(commandOpt, "g++"); @@ -8177,6 +8204,8 @@ public: doit = true; } cmd.append(" "); + // trim it down to unique elements, reduce command line size + UniqueParams(libs); cmd.append(libs); if (!doit) { @@ -8187,6 +8216,7 @@ public: String outbuf, errbuf; + std::cout << "DEBUG command = " << cmd << std::endl; if (!executeCommand(cmd.c_str(), "", outbuf, errbuf)) { error("LINK problem: %s", errbuf.c_str()); @@ -8488,7 +8518,7 @@ public: String outString, errString; - if (!executeCommand(cmd.c_str(), "", outString, errString)) + if (!executeCommand(cmd.c_str(), "", outString, errString)) { error(" problem: %s", errString.c_str()); return false; @@ -9058,7 +9088,7 @@ public: cmd = command; cmd.append(getNativePath(fullName)); - if (!executeCommand(cmd, "", outbuf, errbuf)) + if (!executeCommand(cmd, "", outbuf, errbuf)) { error(" failed : %s", errbuf.c_str()); return false; -- cgit v1.2.3