summaryrefslogtreecommitdiffstats
path: root/buildtool.cpp
diff options
context:
space:
mode:
authorJohan B. C. Engelen <jbc.engelen@swissonline.ch>2012-03-14 21:30:59 +0000
committerJohan B. C. Engelen <j.b.c.engelen@alumnus.utwente.nl>2012-03-14 21:30:59 +0000
commit024767db143b4fdb172258ae5bb318b9dd4f819a (patch)
tree3051b4046e4f896bf7c9009d31c0ddc8ee38023a /buildtool.cpp
parentTranslations. Adding Latvian to the interface preferences. (diff)
downloadinkscape-024767db143b4fdb172258ae5bb318b9dd4f819a.tar.gz
inkscape-024767db143b4fdb172258ae5bb318b9dd4f819a.zip
buildtool: allow parallel builds with btool -j :)
(bzr r11087)
Diffstat (limited to 'buildtool.cpp')
-rw-r--r--buildtool.cpp96
1 files changed, 77 insertions, 19 deletions
diff --git a/buildtool.cpp b/buildtool.cpp
index 7d2ca7912..bc04d6815 100644
--- a/buildtool.cpp
+++ b/buildtool.cpp
@@ -4,6 +4,7 @@
* Authors:
* Bob Jamison
* Jasper van de Gronde
+ * Johan Engelen
*
* Copyright (C) 2006-2008 Bob Jamison
*
@@ -25,7 +26,7 @@
/**
* To use this file, compile with:
* <pre>
- * g++ -O3 buildtool.cpp -o btool.exe
+ * g++ -O3 buildtool.cpp -o btool.exe -fopenmp
* (or whatever your compiler might be)
* Then
* btool
@@ -35,11 +36,11 @@
* Note: if you are using MinGW, and a not very recent version of it,
* gettimeofday() might be missing. If so, just build this file with
* this command:
- * g++ -O3 -DNEED_GETTIMEOFDAY buildtool.cpp -o btool.exe
+ * g++ -O3 -DNEED_GETTIMEOFDAY buildtool.cpp -o btool.exe -fopenmp
*
*/
-#define BUILDTOOL_VERSION "BuildTool v0.9.9"
+#define BUILDTOOL_VERSION "BuildTool v0.9.9multi"
#include <stdio.h>
#include <fcntl.h>
@@ -62,6 +63,9 @@
#include <windows.h>
#endif
+#ifdef _OPENMP
+#include <omp.h>
+#endif
#include <errno.h>
@@ -3080,6 +3084,12 @@ public:
{ uri.parse(uristr); }
/**
+ * Set the number of threads that can be used
+ */
+ void setNumThreads(const int num)
+ { numThreads = num; }
+
+ /**
* Resolve another path relative to this one
*/
String resolve(const String &otherPath);
@@ -3098,6 +3108,13 @@ public:
bool evalBool(const String &s, bool defaultVal);
/**
+ * replace variable refs like ${a} with their values
+ * return the value parsed as an integer
+ * Assume that the string has already been syntax validated
+ */
+ int evalInt(const String &s, int defaultVal);
+
+ /**
* Get an element attribute, performing substitutions if necessary
*/
bool getAttribute(Element *elem, const String &name, String &result);
@@ -3161,7 +3178,12 @@ protected:
* The path to the file associated with this object
*/
URI uri;
-
+
+ /**
+ * The number of threads that can be used
+ */
+ static int numThreads;
+
/**
* If this prefix is seen in a substitution, use an environment
* variable.
@@ -3406,7 +3428,7 @@ private:
};
-
+int MakeBase::numThreads = 1;
/**
* Define the pkg-config class here, since it will be used in MakeBase method
@@ -4867,6 +4889,15 @@ bool MakeBase::evalBool(const String &s, bool defaultVal)
return false;
}
+int MakeBase::evalInt(const String &s, int defaultVal)
+{
+ if (s.size()==0) {
+ return defaultVal;
+ }
+ int val = atoi(s.c_str());
+ // perhaps some error checking, but... bah! waste of time
+ return val;
+}
/**
* Get a string attribute, testing it for proper syntax and
@@ -6957,11 +6988,16 @@ public:
/**
* Compile each of the C files that need it
*/
- bool errorOccurred = false;
- std::vector<String> cfiles;
- for (viter=deps.begin() ; viter!=deps.end() ; viter++)
- {
- DepRec dep = *viter;
+ bool errorOccurred = false;
+
+#ifdef _OPENMP
+ taskstatus("compile with %d threads in parallel", numThreads);
+# pragma omp parallel for num_threads(numThreads)
+#endif
+
+ for (unsigned int fi = 0; fi < deps.size() ; ++fi)
+ {
+ DepRec dep = deps[fi];
//## Select command
String sfx = dep.suffix;
@@ -6974,22 +7010,27 @@ public:
String destPath = dest;
String srcPath = source;
if (dep.path.size()>0)
- {
+ {
destPath.append("/");
destPath.append(dep.path);
srcPath.append("/");
srcPath.append(dep.path);
- }
+ }
//## Make sure destination directory exists
if (!createDirectory(destPath))
{
- if (f)
- {
- fclose(f);
+ taskstatus("problem creating folder: %s", destPath.c_str());
+ errorOccurred = true;
+#ifdef _OPENMP // figure out a way to break the loop here with OpenMP
+ continue; // terminate this for-loop
+#else
+ if (f) {
+ fclose(f);
}
return false;
+#endif
}
-
+
//## Check whether it needs to be done
String destName;
if (destPath.size()>0)
@@ -7102,11 +7143,15 @@ public:
error("problem compiling: %s", errString.c_str());
errorOccurred = true;
}
- if (errorOccurred && !continueOnError)
+
+ if (errorOccurred && !continueOnError) {
+#ifndef _OPENMP // figure out a way to break the loop here with OpenMP
break;
+#endif
+ }
removeFromStatCache(getNativePath(destFullName));
- }
+ }
if (f)
{
@@ -10301,7 +10346,7 @@ static bool parseOptions(int argc, char **argv)
}
else if (arg == "-f" || arg == "-file")
{
- if (i>=argc)
+ if (i>=argc-1)
{
usage(argc, argv);
return false;
@@ -10309,6 +10354,19 @@ static bool parseOptions(int argc, char **argv)
i++; //eat option
make.setURI(argv[i]);
}
+ else if (arg == "-j")
+ {
+ if (i>=argc-1) { // if -j is given as last argument
+ make.setNumThreads(20); // default to some high value
+ } else {
+ i++; //eat option
+ if (argv[i] && (*argv[i] == '-')) { // if -j is followed by another '-...' option
+ make.setNumThreads(20); // default to some high value
+ } else {
+ make.setNumThreads(atoi(argv[i]));
+ }
+ }
+ }
else if (arg.size()>2 && sequ(arg, "-D"))
{
String s = arg.substr(2, arg.size());