##// END OF EJS Templates
added experimental compacting to avoid generation of hundreds of files that all include the same stuff...
florianlink -
r92:f97ec94c87a9
parent child
Show More
@@ -1388,33 +1388,6 static void writeHelperFunctions(QTextStream &stream, const AbstractMetaClass *m
1388 1388 << "}" << endl << endl;
1389 1389 }
1390 1390
1391 void writeQtScriptQtBindingsLicense(QTextStream &stream)
1392 {
1393 stream
1394 << "/****************************************************************************" << endl
1395 << "**" << endl
1396 << "** Copyright (C) 2008 Trolltech ASA. All rights reserved." << endl
1397 << "**" << endl
1398 << "** This file is part of the Qt Script Qt Bindings project on Trolltech Labs." << endl
1399 << "**" << endl
1400 << "** This file may be used under the terms of the GNU General Public" << endl
1401 << "** License version 2.0 as published by the Free Software Foundation" << endl
1402 << "** and appearing in the file LICENSE.GPL included in the packaging of" << endl
1403 << "** this file. Please review the following information to ensure GNU" << endl
1404 << "** General Public Licensing requirements will be met:" << endl
1405 << "** http://www.trolltech.com/products/qt/opensource.html" << endl
1406 << "**" << endl
1407 << "** If you are unsure which license is appropriate for your use, please" << endl
1408 << "** review the following information:" << endl
1409 << "** http://www.trolltech.com/products/qt/licensing.html or contact the" << endl
1410 << "** sales department at sales@trolltech.com." << endl
1411 << "**" << endl
1412 << "** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE" << endl
1413 << "** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE." << endl
1414 << "**" << endl
1415 << "****************************************************************************/" << endl
1416 << endl;
1417 }
1418 1391
1419 1392 /*!
1420 1393 Finds the functions in \a meta_class that we actually want to
@@ -1465,9 +1438,6 static void writeFunctionSignaturesString(QTextStream &s, const AbstractMetaFunc
1465 1438 */
1466 1439 void ClassGenerator::write(QTextStream &stream, const AbstractMetaClass *meta_class)
1467 1440 {
1468 if (FileOut::license)
1469 writeQtScriptQtBindingsLicense(stream);
1470
1471 1441 // write common includes
1472 1442 stream << "#include <QtScript/QScriptEngine>" << endl;
1473 1443 stream << "#include <QtScript/QScriptContext>" << endl;
@@ -40,6 +40,7
40 40 ****************************************************************************/
41 41
42 42 #include "prigenerator.h"
43 #include "shellgenerator.h"
43 44 #include "reporthandler.h"
44 45 #include "fileout.h"
45 46
@@ -53,6 +54,63 void PriGenerator::addSource(const QString &folder, const QString &source)
53 54 priHash[folder].sources << source;
54 55 }
55 56
57 static void collectAndRemoveFile(QTextStream& stream, const QString& file) {
58 QFile f(file);
59 if (f.open(QIODevice::ReadOnly | QIODevice::Text)) {
60 QString s = QString::fromLatin1(f.readAll());
61 if (file.endsWith(".cpp")) {
62 // remove first line include
63 s = s.mid(s.indexOf('\n')+1);
64 }
65 stream << s;
66 f.close();
67 QFile::remove(file);
68 }
69 }
70
71 static QString combineIncludes(const QString& text) {
72 QStringList lines = text.split('\n');
73 QSet<QString> includes;
74 QString result;
75 foreach(QString line, lines) {
76 if (line.startsWith("#include")) {
77 includes.insert(line);
78 } else if (line.startsWith("#")) {
79 // skip preprocessor stuff
80 } else {
81 result += line + "\n";
82 }
83 }
84 QStringList includeList = includes.toList();
85 qSort(includeList);
86 result = includeList.join("\n") + result;
87 return result;
88 }
89
90 static QStringList compactFiles(const QStringList& list, const QString& ext, const QString& dir, const QString& prefix) {
91 QStringList outList;
92 int count = list.count();
93 int fileNum = 0;
94 while (count>0) {
95 QString outFileName = prefix + QString::number(fileNum) + ext;
96 FileOut file(dir + "/" + outFileName);
97 if (ext == ".cpp") {
98 file.stream << "#include \"" + prefix + QString::number(fileNum) + ".h\"\n";
99 }
100 outList << outFileName;
101 QString allText;
102 QTextStream ts(&allText);
103 for (int i = 0; i<MAX_CLASSES_PER_FILE && count>0; i++) {
104 collectAndRemoveFile(ts, dir + "/" + list.at(list.length()-count));
105 count--;
106 }
107 allText = combineIncludes(allText);
108 file.stream << allText;
109 fileNum++;
110 }
111 return outList;
112 }
113
56 114 void PriGenerator::generate()
57 115 {
58 116 QHashIterator<QString, Pri> pri(priHash);
@@ -63,17 +121,30 void PriGenerator::generate()
63 121 continue;
64 122
65 123 QString folder = pri.key();
66 FileOut file(m_out_dir + "/generated_cpp/" + folder + "/" + folder + ".pri");
67 file.stream << "HEADERS += \\\n";
124 folder.replace('\\','/');
125 folder = folder.left(folder.indexOf('/'));
126
68 127 qSort(list.begin(), list.end());
128 FileOut file(m_out_dir + "/generated_cpp/" + pri.key());
129
130 // strange idea to do the file compacting so late, but it is the most effective way without patching the generator a lot
131 bool compact = true;
132 if (compact) {
133 list = compactFiles(list, ".h", m_out_dir + "/generated_cpp/" + folder, folder);
134 }
135
136 file.stream << "HEADERS += \\\n";
69 137 foreach (const QString &entry, list) {
70 file.stream << " $$PWD/" << entry << " \\\n";
138 file.stream << " $$PWD/" << entry << " \\\n";
71 139 }
72 140
73 141 file.stream << "\n";
74 142 file.stream << "SOURCES += \\\n";
75 143 list = pri.value().sources;
76 144 qSort(list.begin(), list.end());
145 if (compact) {
146 list = compactFiles(list, ".cpp", m_out_dir + "/generated_cpp/" + folder, folder);
147 }
77 148 foreach (const QString &entry, list) {
78 149 file.stream << " $$PWD/" << entry << " \\\n";
79 150 }
@@ -51,8 +51,6 void SetupGenerator::addClass(const AbstractMetaClass *cls)
51 51 packHash[cls->package()].append(cls);
52 52 }
53 53
54 void writeQtScriptQtBindingsLicense(QTextStream &stream);
55
56 54 void maybeDeclareMetaType(QTextStream &stream, const QString &typeName,
57 55 QSet<QString> &registeredTypeNames);
58 56 bool hasDefaultConstructor(const AbstractMetaClass *meta_class);
@@ -113,13 +111,10 void SetupGenerator::generate()
113 111 FileOut initFile(m_out_dir + "/generated_cpp/" + packName + "/" + packKey + "_init.cpp");
114 112 QTextStream &s = initFile.stream;
115 113
116 if (FileOut::license)
117 writeQtScriptQtBindingsLicense(s);
118
119 114 s << "#include <PythonQt.h>" << endl;
120 115
121 foreach (const AbstractMetaClass *cls, list) {
122 s << "#include \"" << ShellGenerator::wrapperClassName(cls) << ".h\"" << endl;
116 for (int i=0; i<(list.count()+MAX_CLASSES_PER_FILE-1) / MAX_CLASSES_PER_FILE; i++) {
117 s << "#include \"" << packKey << QString::number(i) << ".h\"" << endl;
123 118 }
124 119 s << endl;
125 120
@@ -54,6 +54,10 class SetupGenerator : public Generator
54 54
55 55 void addClass(const AbstractMetaClass *cls);
56 56
57 static void writeInclude(QTextStream &stream, const Include &inc);
58
59 static bool isSpecialStreamingOperator(const AbstractMetaFunction *fun);
60
57 61 private:
58 62 QStringList writePolymorphicHandler(QTextStream &s, const QString &package,
59 63 const AbstractMetaClassList &classes);
@@ -342,7 +342,9 bool ShellGenerator::isBuiltIn(const QString& name) {
342 342 builtIn.insert("QFont");
343 343 builtIn.insert("QPixmap");
344 344 builtIn.insert("QBrush");
345 builtIn.insert("QBitArray");
345 346 builtIn.insert("QPalette");
347 builtIn.insert("QPen");
346 348 builtIn.insert("QIcon");
347 349 builtIn.insert("QImage");
348 350 builtIn.insert("QPolygon");
@@ -372,3 +374,4 bool ShellGenerator::isBuiltIn(const QString& name) {
372 374 }
373 375 return builtIn.contains(name);
374 376 }
377
@@ -46,6 +46,8
46 46 #include "metaqtscript.h"
47 47 #include "prigenerator.h"
48 48
49 #define MAX_CLASSES_PER_FILE 20
50
49 51 class ShellGenerator : public Generator
50 52 {
51 53 Q_OBJECT
@@ -88,7 +90,7 public:
88 90 static bool isBuiltIn(const QString& name);
89 91
90 92 static bool isSpecialStreamingOperator(const AbstractMetaFunction *fun);
91
93
92 94 static void writeInclude(QTextStream &stream, const Include &inc);
93 95
94 96 protected:
@@ -51,15 +51,11 QString ShellHeaderGenerator::fileNameForClass(const AbstractMetaClass *meta_cla
51 51 return QString("PythonQtWrapper_%1.h").arg(meta_class->name());
52 52 }
53 53
54 void writeQtScriptQtBindingsLicense(QTextStream &stream);
55
56 54 void ShellHeaderGenerator::write(QTextStream &s, const AbstractMetaClass *meta_class)
57 55 {
58
59 setupGenerator->addClass(meta_class);
60
61 if (FileOut::license)
62 writeQtScriptQtBindingsLicense(s);
56 if (!ShellGenerator::isBuiltIn(meta_class->name())) {
57 setupGenerator->addClass(meta_class);
58 }
63 59
64 60 QString include_block = "PYTHONQTWRAPPER_" + meta_class->name().toUpper() + "_H";
65 61
@@ -61,12 +61,8 static void writeHelperCode(QTextStream &s, const AbstractMetaClass *)
61 61 {
62 62 }
63 63
64 void writeQtScriptQtBindingsLicense(QTextStream &stream);
65
66 64 void ShellImplGenerator::write(QTextStream &s, const AbstractMetaClass *meta_class)
67 65 {
68 if (FileOut::license)
69 writeQtScriptQtBindingsLicense(s);
70 66
71 67 QString pro_file_name = meta_class->package().replace(".", "_") + "/" + meta_class->package().replace(".", "_") + ".pri";
72 68
General Comments 0
You need to be logged in to leave comments. Login now