Core::GeneratedFiles dryRunCustomWizardGeneratorScript(const QString &targetPath, const QStringList &script, const QList<GeneratorScriptArgument> &arguments, const QMap<QString, QString> &fieldMap, QString *errorMessage) { // Run in temporary directory as the target path may not exist yet. QString stdOut; if (!runGenerationScriptHelper(QDir::tempPath(), script, arguments, true, fieldMap, &stdOut, errorMessage)) return Core::GeneratedFiles(); Core::GeneratedFiles files; // Parse the output consisting of lines with ',' separated tokens. // (file name + attributes matching those of the <file> element) foreach (const QString &line, stdOut.split(QLatin1Char('\n'))) { const QString trimmed = line.trimmed(); if (!trimmed.isEmpty()) { Core::GeneratedFile file; Core::GeneratedFile::Attributes attributes = Core::GeneratedFile::CustomGeneratorAttribute; const QStringList tokens = line.split(QLatin1Char(',')); const int count = tokens.count(); for (int i = 0; i < count; i++) { const QString &token = tokens.at(i); if (i) { if (token == QLatin1String(customWizardFileOpenEditorAttributeC)) attributes |= Core::GeneratedFile::OpenEditorAttribute; else if (token == QLatin1String(customWizardFileOpenProjectAttributeC)) attributes |= Core::GeneratedFile::OpenProjectAttribute; } else { // Token 0 is file name. Wizard wants native names. // Expand to full path if relative const QFileInfo fileInfo(token); const QString fullPath = fileInfo.isAbsolute() ? token : (targetPath + QLatin1Char('/') + token); file.setPath(fullPath); } } file.setAttributes(attributes); files.push_back(file); } } if (CustomWizard::verbose()) { QDebug nospace = qDebug().nospace(); nospace << script << " generated:\n"; foreach (const Core::GeneratedFile &f, files) nospace << ' ' << f.path() << f.attributes() << '\n'; } return files; }
Core::GeneratedFiles LibraryWizard::generateFiles(const QWizard *w, QString *errorMessage) const { Q_UNUSED(errorMessage) const LibraryWizardDialog *dialog = qobject_cast<const LibraryWizardDialog *>(w); const QtProjectParameters projectParams = dialog->parameters(); const QString projectPath = projectParams.projectPath(); const LibraryParameters params = dialog->libraryParameters(); const QString sharedLibExportMacro = QtProjectParameters::exportMacro(projectParams.fileName); Core::GeneratedFiles rc; // Class header + source const QString sourceFileName = buildFileName(projectPath, params.sourceFileName, sourceSuffix()); Core::GeneratedFile source(sourceFileName); source.setAttributes(Core::GeneratedFile::OpenEditorAttribute); const QString headerFileFullName = buildFileName(projectPath, params.headerFileName, headerSuffix()); const QString headerFileName = Utils::FileName::fromString(headerFileFullName).fileName(); QString pluginJsonFileFullName; QString pluginJsonFileName; if (projectParams.type == QtProjectParameters::Qt4Plugin) { pluginJsonFileFullName = buildFileName(projectPath, projectParams.fileName, QLatin1String("json")); pluginJsonFileName = Utils::FileName::fromString(pluginJsonFileFullName).fileName(); } Core::GeneratedFile header(headerFileFullName); // Create files: global header for shared libs QString globalHeaderFileName; if (projectParams.type == QtProjectParameters::SharedLibrary) { const QString globalHeaderName = buildFileName(projectPath, projectParams.fileName.toLower() + QLatin1String(sharedHeaderPostfixC), headerSuffix()); Core::GeneratedFile globalHeader(globalHeaderName); globalHeaderFileName = Utils::FileName::fromString(globalHeader.path()).fileName(); globalHeader.setContents(CppTools::AbstractEditorSupport::licenseTemplate(globalHeaderFileName) + LibraryParameters::generateSharedHeader(globalHeaderFileName, projectParams.fileName, sharedLibExportMacro)); rc.push_back(globalHeader); } // Generate code QString headerContents, sourceContents; params.generateCode(projectParams.type, projectParams.fileName, headerFileName, globalHeaderFileName, sharedLibExportMacro, pluginJsonFileName, /* indentation*/ 4, &headerContents, &sourceContents); source.setContents(CppTools::AbstractEditorSupport::licenseTemplate(sourceFileName, params.className) + sourceContents); header.setContents(CppTools::AbstractEditorSupport::licenseTemplate(headerFileFullName, params.className) + headerContents); rc.push_back(source); rc.push_back(header); // Create files: profile const QString profileName = buildFileName(projectPath, projectParams.fileName, profileSuffix()); Core::GeneratedFile profile(profileName); profile.setAttributes(Core::GeneratedFile::OpenProjectAttribute); QString profileContents; { QTextStream proStr(&profileContents); QtProjectParameters::writeProFileHeader(proStr); projectParams.writeProFile(proStr); proStr << "\nSOURCES += " << Utils::FileName::fromString(source.path()).fileName() << "\n\nHEADERS += " << headerFileName; if (!globalHeaderFileName.isEmpty()) proStr << "\\\n " << globalHeaderFileName << '\n'; if (!pluginJsonFileName.isEmpty()) proStr << "\nDISTFILES += " << pluginJsonFileName << '\n'; writeLinuxProFile(proStr); } profile.setContents(profileContents); rc.push_back(profile); if (!pluginJsonFileName.isEmpty()) { Core::GeneratedFile jsonFile(pluginJsonFileFullName); jsonFile.setContents(QLatin1String("{\n \"Keys\" : [ ]\n}\n")); rc.push_back(jsonFile); } return rc; }