X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=buildtool.cpp;h=2b4307ab0f0e2ca6026a7eabc2a4a874d0d32a8b;hb=d6386dbacd747ed71bec974533792a9311d76bfa;hp=fe1a3816f254c6047d338bf8e2cba7a59300f9cd;hpb=4394869d23caf2881abe9a6e959f76feb13cf1b9;p=inkscape.git diff --git a/buildtool.cpp b/buildtool.cpp index fe1a3816f..2b4307ab0 100644 --- a/buildtool.cpp +++ b/buildtool.cpp @@ -39,7 +39,7 @@ * */ -#define BUILDTOOL_VERSION "BuildTool v0.9.5" +#define BUILDTOOL_VERSION "BuildTool v0.9.9" #include #include @@ -207,7 +207,7 @@ TREX_API TRexBool trex_getsubexp(TRex* exp, int n, TRexMatch *subexp); #include //#include "trex.h" -#ifdef _UINCODE +#ifdef _UNICODE #define scisprint iswprint #define scstrlen wcslen #define scprintf wprintf @@ -2745,16 +2745,94 @@ bool URI::parse(const String &str) //######################################################################## //# Stat cache to speed up stat requests //######################################################################## -typedef std::map > statCacheType; +struct StatResult { + int result; + struct stat statInfo; +}; +typedef std::map statCacheType; static statCacheType statCache; static int cachedStat(const String &f, struct stat *s) { - std::pair result = statCache.insert(statCacheType::value_type(f, std::pair())); + //printf("Stat path: %s\n", f.c_str()); + std::pair result = statCache.insert(statCacheType::value_type(f, StatResult())); if (result.second) { - result.first->second.first = stat(f.c_str(), &(result.first->second.second)); + result.first->second.result = stat(f.c_str(), &(result.first->second.statInfo)); } - *s = result.first->second.second; - return result.first->second.first; + *s = result.first->second.statInfo; + return result.first->second.result; } +static void removeFromStatCache(const String f) { + //printf("Removing from cache: %s\n", f.c_str()); + statCache.erase(f); +} + +//######################################################################## +//# Dir cache to speed up dir requests +//######################################################################## +/*struct DirListing { + bool available; + std::vector files; + std::vector dirs; +}; +typedef std::map dirCacheType; +static dirCacheType dirCache; +static const DirListing &cachedDir(String fullDir) +{ + String dirNative = getNativePath(fullDir); + std::pair result = dirCache.insert(dirCacheType::value_type(dirNative, DirListing())); + if (result.second) { + DIR *dir = opendir(dirNative.c_str()); + if (!dir) + { + error("Could not open directory %s : %s", + dirNative.c_str(), strerror(errno)); + result.first->second.available = false; + } + else + { + result.first->second.available = true; + while (true) + { + struct dirent *de = readdir(dir); + if (!de) + break; + + //Get the directory member name + String s = de->d_name; + if (s.size() == 0 || s[0] == '.') + continue; + String childName; + if (dirName.size()>0) + { + childName.append(dirName); + childName.append("/"); + } + childName.append(s); + String fullChild = baseDir; + fullChild.append("/"); + fullChild.append(childName); + + if (isDirectory(fullChild)) + { + //trace("directory: %s", childName.c_str()); + if (!listFiles(baseDir, childName, res)) + return false; + continue; + } + else if (!isRegularFile(fullChild)) + { + error("unknown file:%s", childName.c_str()); + return false; + } + + //all done! + res.push_back(childName); + + } + closedir(dir); + } + } + return result.first->second; +}*/ //######################################################################## //# F I L E S E T @@ -3111,11 +3189,19 @@ protected: /** * If this prefix is seen in a substitution, use as a * pkg-config 'libs' query - * example: + * example: * ${pcl.gtkmm} */ String pclPrefix; + /** + * If this prefix is seen in a substitution, use as a + * Bazaar "bzr revno" query + * example: ??? + * ${bzr.Revision} + */ + String bzrPrefix; + @@ -3259,6 +3345,16 @@ protected: */ bool copyFile(const String &srcFile, const String &destFile); + /** + * Delete a file + */ + bool removeFile(const String &file); + + /** + * Tests if the file exists + */ + bool fileExists(const String &fileName); + /** * Tests if the file exists and is a regular file */ @@ -3544,6 +3640,138 @@ private: int parselen; }; +/** + * Execute the "bzr revno" command and return the result. + * This is a simple, small class. + */ +class BzrRevno : public MakeBase +{ +public: + + /** + * Safe way. Execute "bzr revno" and return the result. + * Safe from changes in format. + */ + bool query(String &res) + { + String cmd = "bzr revno"; + + String outString, errString; + bool ret = executeCommand(cmd.c_str(), "", outString, errString); + if (!ret) + { + error("error executing '%s': %s", cmd.c_str(), errString.c_str()); + return false; + } + res = outString; + return true; + } +}; + +/** + * Execute the "svn info" command and parse the result. + * This is a simple, small class. Define here, because it + * is used by MakeBase implementation methods. + */ +class SvnInfo : public MakeBase +{ +public: + +#if 0 + /** + * Safe way. Execute "svn info --xml" and parse the result. Search for + * elements/attributes. Safe from changes in format. + */ + bool query(const String &name, String &res) + { + String cmd = "svn info --xml"; + + String outString, errString; + bool ret = executeCommand(cmd.c_str(), "", outString, errString); + if (!ret) + { + error("error executing '%s': %s", cmd.c_str(), errString.c_str()); + return false; + } + Parser parser; + Element *elem = parser.parse(outString); + if (!elem) + { + error("error parsing 'svn info' xml result: %s", outString.c_str()); + return false; + } + + res = elem->getTagValue(name); + if (res.size()==0) + { + res = elem->getTagAttribute("entry", name); + } + return true; + } +#else + + + /** + * Universal way. Parse the file directly. Not so safe from + * changes in format. + */ + bool query(const String &name, String &res) + { + String fileName = resolve(".svn/entries"); + String nFileName = getNativePath(fileName); + + std::map properties; + + FILE *f = fopen(nFileName.c_str(), "r"); + if (!f) + { + error("could not open SVN 'entries' file"); + return false; + } + + const char *fieldNames[] = + { + "format-nbr", + "name", + "kind", + "revision", + "url", + "repos", + "schedule", + "text-time", + "checksum", + "committed-date", + "committed-rev", + "last-author", + "has-props", + "has-prop-mods", + "cachable-props", + }; + + for (int i=0 ; i<15 ; i++) + { + inbuf[0] = '\0'; + if (feof(f) || !fgets(inbuf, 255, f)) + break; + properties[fieldNames[i]] = trim(inbuf); + } + fclose(f); + + res = properties[name]; + + return true; + } + +private: + + char inbuf[256]; + +#endif + +}; + + + @@ -3943,13 +4171,18 @@ bool MakeBase::executeCommand(const String &command, return false; } SetHandleInformation(stdoutRead, HANDLE_FLAG_INHERIT, 0); - if (!CreatePipe(&stderrRead, &stderrWrite, &saAttr, 0)) - { - error("executeProgram: could not create pipe"); - delete[] paramBuf; - return false; - } - SetHandleInformation(stderrRead, HANDLE_FLAG_INHERIT, 0); + if (&outbuf != &errbuf) { + if (!CreatePipe(&stderrRead, &stderrWrite, &saAttr, 0)) + { + error("executeProgram: could not create pipe"); + delete[] paramBuf; + return false; + } + SetHandleInformation(stderrRead, HANDLE_FLAG_INHERIT, 0); + } else { + stderrRead = stdoutRead; + stderrWrite = stdoutWrite; + } // Create the process STARTUPINFO siStartupInfo; @@ -3991,7 +4224,7 @@ bool MakeBase::executeCommand(const String &command, error("executeCommand: could not close read pipe"); return false; } - if (!CloseHandle(stderrWrite)) + if (stdoutWrite != stderrWrite && !CloseHandle(stderrWrite)) { error("executeCommand: could not close read pipe"); return false; @@ -4049,7 +4282,7 @@ bool MakeBase::executeCommand(const String &command, error("executeCommand: could not close read pipe"); return false; } - if (!CloseHandle(stderrRead)) + if (stdoutRead != stderrRead && !CloseHandle(stderrRead)) { error("executeCommand: could not close read pipe"); return false; @@ -4209,7 +4442,7 @@ bool MakeBase::listDirectories(const String &baseName, String fullPath = baseName; if (dirName.size()>0) { - fullPath.append("/"); + if (dirName[0]!='/') fullPath.append("/"); fullPath.append(dirName); } DIR *dir = opendir(fullPath.c_str()); @@ -4491,6 +4724,23 @@ bool MakeBase::lookupProperty(const String &propertyName, String &result) return false; result = val; } + else if (bzrPrefix.size() > 0 && + varname.compare(0, bzrPrefix.size(), bzrPrefix) == 0) + { + varname = varname.substr(bzrPrefix.size()); + String val; + //SvnInfo svnInfo; + BzrRevno bzrRevno; + if (varname == "revision") + { + if (!bzrRevno.query(val)) + return ""; + result = "r"+val; + } + /*if (!svnInfo.query(varname, val)) + return false; + result = val;*/ + } else { std::map::iterator iter; @@ -4858,6 +5108,8 @@ bool MakeBase::createDirectory(const String &dirname) cnative, strerror(errno)); return false; } + + removeFromStatCache(nativeDir); return true; } @@ -4920,10 +5172,8 @@ bool MakeBase::removeDirectory(const String &dirName) else { //trace("DEL file: %s", childName.c_str()); - if (remove(cnative)<0) + if (!removeFile(childName)) { - error("error deleting %s : %s", - cnative, strerror(errno)); return false; } } @@ -4939,6 +5189,8 @@ bool MakeBase::removeDirectory(const String &dirName) return false; } + removeFromStatCache(native); + return true; } @@ -4988,6 +5240,7 @@ bool MakeBase::copyFile(const String &srcFile, const String &destFile) FILE *destf = fopen(destNative.c_str(), "wb"); if (!destf) { + fclose(srcf); error("copyFile cannot open %s for writing", srcNative.c_str()); return false; } @@ -5014,11 +5267,91 @@ bool MakeBase::copyFile(const String &srcFile, const String &destFile) #endif /* __WIN32__ */ + removeFromStatCache(destNative); return true; } +/** + * Delete a file + */ +bool MakeBase::removeFile(const String &file) +{ + String native = getNativePath(file); + + if (!fileExists(native)) + { + return true; + } + +#ifdef WIN32 + // On Windows 'remove' will only delete files + + if (remove(native.c_str())<0) + { + if (errno==EACCES) + { + error("File %s is read-only", native.c_str()); + } + else if (errno==ENOENT) + { + error("File %s does not exist or is a directory", native.c_str()); + } + else + { + error("Failed to delete file %s: %s", native.c_str(), strerror(errno)); + } + return false; + } + +#else + + if (!isRegularFile(native)) + { + error("File %s does not exist or is not a regular file", native.c_str()); + return false; + } + + if (remove(native.c_str())<0) + { + if (errno==EACCES) + { + error("File %s is read-only", native.c_str()); + } + else + { + error( + errno==EACCES ? "File %s is read-only" : + errno==ENOENT ? "File %s does not exist or is a directory" : + "Failed to delete file %s: %s", native.c_str()); + } + return false; + } + +#endif + + removeFromStatCache(native); + + return true; +} + + +/** + * Tests if the file exists + */ +bool MakeBase::fileExists(const String &fileName) +{ + String native = getNativePath(fileName); + struct stat finfo; + + //Exists? + if (cachedStat(native, &finfo)<0) + return false; + + return true; +} + /** * Tests if the file exists and is a regular file @@ -5432,9 +5765,6 @@ bool PkgConfig::query(const String &pkgName) } - - - //######################################################################## //# D E P T O O L //######################################################################## @@ -6391,6 +6721,7 @@ public: TASK_COPY, TASK_CXXTEST_PART, TASK_CXXTEST_ROOT, + TASK_CXXTEST_RUN, TASK_DELETE, TASK_ECHO, TASK_JAR, @@ -6767,6 +7098,8 @@ public: } if (errorOccurred && !continueOnError) break; + + removeFromStatCache(getNativePath(destFullName)); } if (f) @@ -7157,6 +7490,7 @@ public: error(" problem: %s", errString.c_str()); return false; } + removeFromStatCache(getNativePath(fullDest)); } return true; @@ -7260,6 +7594,7 @@ public: error(" problem: %s", errString.c_str()); return false; } + removeFromStatCache(getNativePath(fullDest)); } return true; @@ -7298,6 +7633,97 @@ private: }; +/** + * Execute the CxxTest test executable + */ +class TaskCxxTestRun: public Task +{ +public: + + TaskCxxTestRun(MakeBase &par) : Task(par) + { + type = TASK_CXXTEST_RUN; + name = "cxxtestrun"; + } + + virtual ~TaskCxxTestRun() + {} + + virtual bool execute() + { + unsigned int newFiles = 0; + + String workingDir = parent.resolve(parent.eval(workingDirOpt, "inkscape")); + String rawCmd = parent.eval(commandOpt, "build/cxxtests"); + + String cmdExe; + if (fileExists(rawCmd)) { + cmdExe = rawCmd; + } else if (fileExists(rawCmd + ".exe")) { + cmdExe = rawCmd + ".exe"; + } else { + error(" problem: cxxtests executable not found! (command=\"%s\")", rawCmd.c_str()); + } + // Note that the log file names are based on the exact name used to call cxxtests (it uses argv[0] + ".log"/".xml") + if (isNewerThan(cmdExe, rawCmd + ".log") || isNewerThan(cmdExe, rawCmd + ".xml")) newFiles++; + + // Prepend the necessary ../'s + String cmd = rawCmd; + unsigned int workingDirDepth = 0; + bool wasSlash = true; + for(size_t i=0; i0) { + char olddir[1024]; + if (workingDir.size()>0) { + // TODO: Double-check usage of getcwd and handle chdir errors + getcwd(olddir, 1024); + chdir(workingDir.c_str()); + } + + String outString; + if (!executeCommand(cmd.c_str(), "", outString, outString)) + { + error(" problem: %s", outString.c_str()); + return false; + } + + if (workingDir.size()>0) { + // TODO: Handle errors? + chdir(olddir); + } + + removeFromStatCache(getNativePath(cmd + ".log")); + removeFromStatCache(getNativePath(cmd + ".xml")); + } + + return true; + } + + virtual bool parse(Element *elem) + { + if (!parent.getAttribute(elem, "command", commandOpt)) + return false; + if (!parent.getAttribute(elem, "workingdir", workingDirOpt)) + return false; + return true; + } + +private: + + String commandOpt; + String workingDirOpt; + +}; + + /** * */ @@ -7329,7 +7755,6 @@ public: bool verbose = parent.evalBool(verboseOpt, false); bool quiet = parent.evalBool(quietOpt, false); bool failOnError = parent.evalBool(failOnErrorOpt, true); - struct stat finfo; switch (delType) { case DEL_FILE: @@ -7339,24 +7764,9 @@ public: char *fname = (char *)fullName.c_str(); if (!quiet && verbose) taskstatus("path: %s", fname); - //does not exist - if (cachedStat(fullName, &finfo)<0) + if (failOnError && !removeFile(fullName)) { - if (failOnError) - return false; - else - return true; - } - //exists but is not a regular file - if (!S_ISREG(finfo.st_mode)) - { - error(" failed. '%s' exists and is not a regular file", - fname); - return false; - } - if (remove(fname)<0) - { - error(" failed: %s", strerror(errno)); + //error("Could not delete file '%s'", fullName.c_str()); return false; } return true; @@ -7367,8 +7777,11 @@ public: String fullDir = parent.resolve(dirName); if (!quiet && verbose) taskstatus("path: %s", fullDir.c_str()); - if (!removeDirectory(fullDir)) + if (failOnError && !removeDirectory(fullDir)) + { + //error("Could not delete directory '%s'", fullDir.c_str()); return false; + } return true; } } @@ -7498,6 +7911,7 @@ public: execCmd.c_str(), errString.c_str()); return false; } + removeFromStatCache(getNativePath(destfile)); return true; } @@ -7615,6 +8029,8 @@ public: execCmd.c_str(), errString.c_str()); return false; } + // TODO: + //removeFromStatCache(getNativePath(........)); return true; } @@ -7717,6 +8133,7 @@ public: error("LINK problem: %s", errbuf.c_str()); return false; } + removeFromStatCache(getNativePath(fullTarget)); if (symFileName.size()>0) { @@ -7731,6 +8148,7 @@ public: error(" symbol file failed : %s", errbuf.c_str()); return false; } + removeFromStatCache(getNativePath(symFullName)); } if (doStrip) @@ -7743,6 +8161,7 @@ public: error(" failed : %s", errbuf.c_str()); return false; } + removeFromStatCache(getNativePath(fullTarget)); } return true; @@ -7822,13 +8241,14 @@ public: virtual bool execute() { String fileName = parent.eval(fileNameOpt, ""); + bool force = parent.evalBool(forceOpt, false); String text = parent.eval(textOpt, ""); taskstatus("%s", fileName.c_str()); String fullName = parent.resolve(fileName); - if (!isNewerThan(parent.getURI().getPath(), fullName)) + if (!force && !isNewerThan(parent.getURI().getPath(), fullName)) { - //trace("skipped "); + taskstatus("skipped"); return true; } String fullNative = getNativePath(fullName); @@ -7844,6 +8264,7 @@ public: fputc(text[i], f); fputc('\n', f); fclose(f); + removeFromStatCache(fullNative); return true; } @@ -7851,6 +8272,8 @@ public: { if (!parent.getAttribute(elem, "file", fileNameOpt)) return false; + if (!parent.getAttribute(elem, "force", forceOpt)) + return false; if (fileNameOpt.size() == 0) { error(" requires 'file=\"filename\"' attribute"); @@ -7866,6 +8289,7 @@ public: private: String fileNameOpt; + String forceOpt; String textOpt; }; @@ -8010,6 +8434,7 @@ public: error(" problem: %s", errString.c_str()); return false; } + removeFromStatCache(getNativePath(fullDest)); } return true; @@ -8184,6 +8609,8 @@ public: String outbuf, errbuf; if (!executeCommand(cmd, "", outbuf, errbuf)) return false; + // TODO: + //removeFromStatCache(getNativePath(fullDest)); return true; } @@ -8247,6 +8674,7 @@ public: error("RC problem: %s", errString.c_str()); return false; } + removeFromStatCache(getNativePath(fullOut)); return true; } @@ -8372,7 +8800,7 @@ public: error(" problem: %s", errString.c_str()); return false; } - + removeFromStatCache(getNativePath(fullOut)); return true; } @@ -8493,7 +8921,7 @@ public: error(" problem: %s", errString.c_str()); return false; } - + removeFromStatCache(getNativePath(fullOut)); return true; } @@ -8576,6 +9004,7 @@ public: error(" failed : %s", errbuf.c_str()); return false; } + removeFromStatCache(getNativePath(fullName)); return true; } @@ -8641,6 +9070,7 @@ public: nativeFile.c_str(), strerror(ret)); return false; } + removeFromStatCache(nativeFile); return true; } @@ -8704,6 +9134,8 @@ Task *Task::createTask(Element *elem, int lineNr) task = new TaskCxxTestPart(parent); else if (tagName == "cxxtestroot") task = new TaskCxxTestRoot(parent); + else if (tagName == "cxxtestrun") + task = new TaskCxxTestRun(parent); else if (tagName == "delete") task = new TaskDelete(parent); else if (tagName == "echo") @@ -9098,6 +9530,7 @@ void Make::init() pcPrefix = "pc."; pccPrefix = "pcc."; pclPrefix = "pcl."; + bzrPrefix = "bzr."; properties.clear(); for (unsigned int i = 0 ; i < allTasks.size() ; i++) delete allTasks[i]; @@ -9516,6 +9949,16 @@ bool Make::parseProperty(Element *elem) pclPrefix = attrVal; pclPrefix.push_back('.'); } + else if (attrName == "subversion") + { + if (attrVal.find('.') != attrVal.npos) + { + error("bzr prefix cannot have a '.' in it"); + return false; + } + bzrPrefix = attrVal; + bzrPrefix.push_back('.'); + } } return true;