bool Compiler::compile(const QString &url, QDataStream &output) { Q_D(Compiler); bool ret = compile(url); if (ret) { ret = createExportStructures(); if (d->basePathSet) { QString newUrl = d->basePath; int lastSlash = url.lastIndexOf('/'); if (lastSlash == -1) newUrl.append(url); else if (lastSlash < url.length() - 1) newUrl.append(url.mid(lastSlash + 1)); QUrl url; if (newUrl.startsWith(":/")) url.setUrl("qrc:" + newUrl); else url.setUrl("file:" + newUrl); d->compilation->url = url; d->compilation->urlString = url.toString(); } if (ret) ret = exportData(output); } delete takeCompilation(); return ret; }
bool Compiler::compile(const QString &url) { Q_D(Compiler); clearError(); // set env var so one can test in plugins if needed setenv("QMC_COMPILE", "1", 1); // check that engine is using correct factory if (!qgetenv("QV4_FORCE_INTERPRETER").isEmpty()) { QQmlError error; error.setDescription("Compiler is forced to use interpreter"); appendError(error); return false; } Q_ASSERT(d->compilation == NULL); QmlCompilation* c = new QmlCompilation(url, QUrl(url), d->engine); d->compilation = c; c->importCache = new QQmlImports(&QQmlEnginePrivate::get(d->compilation->engine)->typeLoader); c->importDatabase = new QQmlImportDatabase(d->compilation->engine); c->loadUrl = url; int lastSlash = url.lastIndexOf('/'); if (lastSlash == -1) c->url = url; else if (lastSlash + 1 < url.length()) c->url = url.mid(lastSlash + 1); else c->url = ""; if (!loadData()) { delete takeCompilation(); return false; } if (!compileData()) { delete takeCompilation(); return false; } return true; }