Mercurial > projects > qtd
annotate generator/main.cpp @ 384:d2f48c4cb3e3
Same behavior of shared libs on linux and windows. Minor build script fixes.
author | Max Samukha <maxter@spambox.com> |
---|---|
date | Fri, 16 Jul 2010 20:04:29 +0300 |
parents | 6cd923119ab1 |
children |
rev | line source |
---|---|
1 | 1 /**************************************************************************** |
2 ** | |
3 ** Copyright (C) 1992-2008 Nokia. All rights reserved. | |
4 ** | |
5 ** This file is part of Qt Jambi. | |
6 ** | |
7 ** * Commercial Usage | |
8 * Licensees holding valid Qt Commercial licenses may use this file in | |
9 * accordance with the Qt Commercial License Agreement provided with the | |
10 * Software or, alternatively, in accordance with the terms contained in | |
11 * a written agreement between you and Nokia. | |
12 * | |
13 * | |
14 * GNU General Public License Usage | |
15 * Alternatively, this file may be used under the terms of the GNU | |
16 * General Public License versions 2.0 or 3.0 as published by the Free | |
17 * Software Foundation and appearing in the file LICENSE.GPL included in | |
18 * the packaging of this file. Please review the following information | |
19 * to ensure GNU General Public Licensing requirements will be met: | |
20 * http://www.fsf.org/licensing/licenses/info/GPLv2.html and | |
21 * http://www.gnu.org/copyleft/gpl.html. In addition, as a special | |
22 * exception, Nokia gives you certain additional rights. These rights | |
23 * are described in the Nokia Qt GPL Exception version 1.2, included in | |
24 * the file GPL_EXCEPTION.txt in this package. | |
25 * | |
26 * Qt for Windows(R) Licensees | |
27 * As a special exception, Nokia, as the sole copyright holder for Qt | |
28 * Designer, grants users of the Qt/Eclipse Integration plug-in the | |
29 * right for the Qt/Eclipse Integration to link to functionality | |
30 * provided by Qt Designer and its related libraries. | |
31 * | |
32 * | |
33 * If you are unsure which license is appropriate for your use, please | |
34 * contact the sales department at qt-sales@nokia.com. | |
35 | |
36 ** | |
37 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | |
38 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | |
39 ** | |
40 ****************************************************************************/ | |
41 | |
42 #include "main.h" | |
43 #include "asttoxml.h" | |
44 #include "reporthandler.h" | |
45 #include "typesystem.h" | |
46 #include "generatorset.h" | |
47 #include "fileout.h" | |
48 #include "binder.h" | |
384
d2f48c4cb3e3
Same behavior of shared libs on linux and windows. Minor build script fixes.
Max Samukha <maxter@spambox.com>
parents:
265
diff
changeset
|
49 #include "global.h" |
1 | 50 |
51 #include "abstractmetalang.h" | |
52 | |
53 #include <QDir> | |
54 | |
55 void ReportHandler_message_handler(const std::string &str) | |
56 { | |
57 ReportHandler::warning(QString::fromStdString(str)); | |
58 } | |
59 | |
60 | |
61 void displayHelp(GeneratorSet *generatorSet); | |
62 | |
63 #include <QDebug> | |
64 int main(int argc, char *argv[]) | |
65 { | |
66 GeneratorSet *gs = GeneratorSet::getInstance(); | |
67 | |
68 QString default_file = "qtjambi_masterinclude.h"; | |
69 QString default_system = "build_all.txt"; | |
70 | |
71 QString fileName; | |
72 QString typesystemFileName; | |
73 QString pp_file = ".preprocessed.tmp"; | |
74 QStringList rebuild_classes; | |
4 | 75 QString source_dir; |
1 | 76 |
77 QMap<QString, QString> args; | |
78 | |
79 int argNum = 0; | |
80 for (int i=1; i<argc; ++i) { | |
81 QString arg(argv[i]); | |
82 arg = arg.trimmed(); | |
83 if( arg.startsWith("--") ) { | |
84 int split = arg.indexOf("="); | |
85 if( split > 0 ) | |
86 args[arg.mid(2).left(split-2)] = arg.mid(split + 1).trimmed(); | |
87 else | |
88 args[arg.mid(2)] = QString(); | |
89 } else if( arg.startsWith("-")) { | |
90 args[arg.mid(1)] = QString(); | |
91 } else { | |
92 argNum++; | |
93 args[QString("arg-%1").arg(argNum)] = arg; | |
94 } | |
95 } | |
96 | |
97 if (args.contains("no-suppress-warnings")) { | |
98 TypeDatabase *db = TypeDatabase::instance(); | |
99 db->setSuppressWarnings(false); | |
100 } | |
101 | |
102 if (args.contains("include-eclipse-warnings")) { | |
103 TypeDatabase *db = TypeDatabase::instance(); | |
104 db->setIncludeEclipseWarnings(true); | |
105 } | |
106 | |
107 if (args.contains("debug-level")) { | |
108 QString level = args.value("debug-level"); | |
109 if (level == "sparse") | |
110 ReportHandler::setDebugLevel(ReportHandler::SparseDebug); | |
111 else if (level == "medium") | |
112 ReportHandler::setDebugLevel(ReportHandler::MediumDebug); | |
113 else if (level == "full") | |
114 ReportHandler::setDebugLevel(ReportHandler::FullDebug); | |
115 } | |
116 | |
117 if (args.contains("dummy")) { | |
118 FileOut::dummy = true; | |
119 } | |
120 | |
121 if (args.contains("diff")) { | |
122 FileOut::diff = true; | |
123 } | |
124 | |
125 if (args.contains("rebuild-only")) { | |
126 QStringList classes = args.value("rebuild-only").split(",", QString::SkipEmptyParts); | |
127 TypeDatabase::instance()->setRebuildClasses(classes); | |
128 } | |
129 | |
384
d2f48c4cb3e3
Same behavior of shared libs on linux and windows. Minor build script fixes.
Max Samukha <maxter@spambox.com>
parents:
265
diff
changeset
|
130 QString dTarget = args.value("d-target"); |
d2f48c4cb3e3
Same behavior of shared libs on linux and windows. Minor build script fixes.
Max Samukha <maxter@spambox.com>
parents:
265
diff
changeset
|
131 if (!dTarget.isEmpty()) |
1 | 132 { |
384
d2f48c4cb3e3
Same behavior of shared libs on linux and windows. Minor build script fixes.
Max Samukha <maxter@spambox.com>
parents:
265
diff
changeset
|
133 dTarget = args.value("d-target"); |
1 | 134 if (dTarget == "d1-tango") |
384
d2f48c4cb3e3
Same behavior of shared libs on linux and windows. Minor build script fixes.
Max Samukha <maxter@spambox.com>
parents:
265
diff
changeset
|
135 global.dVersion = 1; |
1 | 136 /* |
137 else if (dtarget == "d2-tango") | |
138 qFatal("Tango D2 target is not supported"); | |
139 */ | |
140 else if (dTarget == "d2-phobos") | |
141 { | |
384
d2f48c4cb3e3
Same behavior of shared libs on linux and windows. Minor build script fixes.
Max Samukha <maxter@spambox.com>
parents:
265
diff
changeset
|
142 global.dVersion = 2; |
d2f48c4cb3e3
Same behavior of shared libs on linux and windows. Minor build script fixes.
Max Samukha <maxter@spambox.com>
parents:
265
diff
changeset
|
143 global.dPhobos = true; |
1 | 144 } |
145 else | |
146 { | |
147 fprintf(stderr, "D target '%s' is not recognized", qPrintable(dTarget)); | |
148 return 1; | |
149 } | |
150 } | |
151 | |
4 | 152 source_dir = args.value("source-directory"); |
1 | 153 fileName = args.value("arg-1"); |
265 | 154 if (!source_dir.isEmpty() && !QFileInfo(fileName).exists()) |
4 | 155 { |
156 fileName = source_dir + "/" + fileName; | |
265 | 157 if(!QFileInfo(fileName).exists()) |
158 { | |
159 fprintf(stderr, "Master include '%s' is not found", fileName.toAscii().data()); | |
160 return 1; | |
161 } | |
4 | 162 } |
1 | 163 |
164 typesystemFileName = args.value("arg-2"); | |
165 if (args.contains("arg-3")) | |
166 displayHelp(gs); | |
167 | |
168 if (fileName.isEmpty()) | |
169 fileName = default_file; | |
170 | |
171 if (typesystemFileName.isEmpty()) | |
172 typesystemFileName = default_system; | |
173 | |
174 if (fileName.isEmpty() || typesystemFileName.isEmpty() ) | |
175 displayHelp(gs); | |
176 | |
177 if (!gs->readParameters(args)) | |
178 displayHelp(gs); | |
179 | |
384
d2f48c4cb3e3
Same behavior of shared libs on linux and windows. Minor build script fixes.
Max Samukha <maxter@spambox.com>
parents:
265
diff
changeset
|
180 global.cppShared = args.contains("cpp-shared"); |
d2f48c4cb3e3
Same behavior of shared libs on linux and windows. Minor build script fixes.
Max Samukha <maxter@spambox.com>
parents:
265
diff
changeset
|
181 |
d2f48c4cb3e3
Same behavior of shared libs on linux and windows. Minor build script fixes.
Max Samukha <maxter@spambox.com>
parents:
265
diff
changeset
|
182 global.setTargetPlatform(args.value("target-platform")); |
1 | 183 |
184 printf("Running the QtD Generator. Please wait while source files are being generated...\n"); | |
185 | |
4 | 186 if (!TypeDatabase::instance()->parseFile(typesystemFileName, source_dir)) |
1 | 187 qFatal("Cannot parse file: '%s'", qPrintable(typesystemFileName)); |
188 | |
4 | 189 if (!Preprocess::preprocess(fileName, pp_file, args.value("include-paths"), source_dir, args.value("qt-include-directory"))) { |
1 | 190 fprintf(stderr, "Preprocessor failed on file: '%s'\n", qPrintable(fileName)); |
191 return 1; | |
192 } | |
193 | |
194 if (args.contains("ast-to-xml")) { | |
195 astToXML(pp_file); | |
196 return 0; | |
197 } | |
198 | |
199 ArgumentReplace::init(); // replacer for arguments which are D keywords such as "version" | |
200 | |
201 Binder::installMessageHandler(ReportHandler_message_handler); | |
202 gs->buildModel(pp_file); | |
203 if (args.contains("dump-object-tree")) { | |
204 gs->dumpObjectTree(); | |
205 return 0; | |
206 } | |
207 printf("%s\n", qPrintable(gs->generate())); | |
208 | |
209 printf("Done, %d warnings (%d known issues)\n", ReportHandler::warningCount(), | |
210 ReportHandler::suppressedCount()); | |
211 } | |
212 | |
213 | |
214 void displayHelp(GeneratorSet* generatorSet) { | |
215 #if defined(Q_OS_WIN32) | |
216 char path_splitter = ';'; | |
217 #else | |
218 char path_splitter = ':'; | |
219 #endif | |
220 printf("Usage:\n generator [options] header-file typesystem-file\n\n"); | |
221 printf("Available options:\n\n"); | |
222 printf("General:\n"); | |
223 printf( | |
224 " --cpp-shared \n" | |
4 | 225 " --qt-include-directory \n" |
226 " --qt-directory \n" | |
227 " --source-directory \n" | |
1 | 228 " --debug-level=[sparse|medium|full] \n" |
4 | 229 " --d-target=[d1-tango|d2-phobos] \n" |
1 | 230 " --dump-object-tree \n" |
231 " --help, -h or -? \n" | |
232 " --no-suppress-warnings \n" | |
233 " --include-eclipse-warnings \n" | |
234 " --output-directory=[dir] \n" | |
235 " --include-paths=<path>[%c<path>%c...] \n" | |
236 " --print-stdout \n" | |
237 , | |
238 path_splitter, path_splitter); | |
239 | |
240 printf("%s", qPrintable( generatorSet->usage())); | |
241 exit(0); | |
242 } |