forked from qt-creator/qt-creator
QmlProject: Fix issues with cmakefiles.txt generation
If file names contain spaces we simply add quotes around the filename. If file names contain special characters (!, % & etc), then we give a warning and skip the file to not break the build. Task-number: QDS-10745 Change-Id: Iae9497725816769a8922a0ef38f0dc05fb1bb582 Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io> (cherry picked from commit e3461ccc5a3de03a92e665fe31ec0f95f29dab18) Reviewed-by: Qt CI Patch Build Bot <ci_patchbuild_bot@qt.io> Reviewed-by: Knud Dollereder <knud.dollereder@qt.io>
This commit is contained in:
@@ -2,9 +2,8 @@
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include "cmakegeneratordialog.h"
|
||||
#include "cmakegeneratordialogtreemodel.h"
|
||||
#include "generatecmakelistsconstants.h"
|
||||
#include "../qmlprojectmanagertr.h"
|
||||
#include "cmakegeneratordialogtreemodel.h"
|
||||
|
||||
#include <utils/utilsicons.h>
|
||||
#include <utils/detailswidget.h>
|
||||
@@ -21,10 +20,10 @@ using namespace Utils;
|
||||
namespace QmlProjectManager {
|
||||
namespace GenerateCmake {
|
||||
|
||||
CmakeGeneratorDialog::CmakeGeneratorDialog(const FilePath &rootDir, const FilePaths &files)
|
||||
: QDialog(),
|
||||
m_rootDir(rootDir),
|
||||
m_files(files)
|
||||
CmakeGeneratorDialog::CmakeGeneratorDialog(const FilePath &rootDir,
|
||||
const FilePaths &files,
|
||||
const FilePaths invalidFiles)
|
||||
: QDialog(), m_rootDir(rootDir), m_files(files), m_invalidFiles(invalidFiles)
|
||||
{
|
||||
setWindowTitle(Tr::tr("Select Files to Generate"));
|
||||
|
||||
@@ -106,6 +105,8 @@ FilePaths CmakeGeneratorDialog::getFilePaths()
|
||||
|
||||
const QString FILE_CREATE_NOTIFICATION = Tr::tr("File %1 will be created.\n");
|
||||
const QString FILE_OVERWRITE_NOTIFICATION = Tr::tr("File %1 will be overwritten.\n");
|
||||
const QString FILE_INVALID_NOTIFICATION = Tr::tr(
|
||||
"File %1 contains invalid characters and will be skipped.\n");
|
||||
|
||||
void CmakeGeneratorDialog::refreshNotificationText()
|
||||
{
|
||||
@@ -119,6 +120,11 @@ void CmakeGeneratorDialog::refreshNotificationText()
|
||||
|
||||
QList<CheckableFileTreeItem*> nodes = m_model->items();
|
||||
|
||||
for (const auto &file : m_invalidFiles) {
|
||||
cursor.insertImage(iformat);
|
||||
cursor.insertText(QString(FILE_INVALID_NOTIFICATION).arg(file.displayName()));
|
||||
}
|
||||
|
||||
for (CheckableFileTreeItem *node : nodes) {
|
||||
if (!m_files.contains(node->toFilePath()))
|
||||
continue;
|
||||
|
@@ -22,7 +22,9 @@ class CmakeGeneratorDialog : public QDialog
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
CmakeGeneratorDialog(const Utils::FilePath &rootDir, const Utils::FilePaths &files);
|
||||
CmakeGeneratorDialog(const Utils::FilePath &rootDir,
|
||||
const Utils::FilePaths &files,
|
||||
const Utils::FilePaths invalidFiles);
|
||||
Utils::FilePaths getFilePaths();
|
||||
|
||||
public slots:
|
||||
@@ -40,6 +42,7 @@ private:
|
||||
QVariant m_warningIcon;
|
||||
Utils::FilePath m_rootDir;
|
||||
Utils::FilePaths m_files;
|
||||
Utils::FilePaths m_invalidFiles;
|
||||
};
|
||||
|
||||
} //GenerateCmake
|
||||
|
@@ -142,7 +142,7 @@ void onGenerateCmakeLists()
|
||||
for (const GeneratableFile &file: cmakeGen.fileQueue().queuedFiles())
|
||||
allFiles.append(file.filePath);
|
||||
|
||||
CmakeGeneratorDialog dialog(rootDir, allFiles);
|
||||
CmakeGeneratorDialog dialog(rootDir, allFiles, cmakeGen.invalidFileNames());
|
||||
if (dialog.exec()) {
|
||||
FilePaths confirmedFiles = dialog.getFilePaths();
|
||||
cmakeGen.filterFileQueue(confirmedFiles);
|
||||
@@ -334,6 +334,11 @@ bool CmakeFileGenerator::execute()
|
||||
return m_fileQueue.writeQueuedFiles();
|
||||
}
|
||||
|
||||
FilePaths CmakeFileGenerator::invalidFileNames() const
|
||||
{
|
||||
return m_invalidFileNames;
|
||||
}
|
||||
|
||||
const char DO_NOT_EDIT_FILE_COMMENT[] = "### This file is automatically generated by Qt Design Studio.\n### Do not change\n\n";
|
||||
const char ADD_SUBDIR[] = "add_subdirectory(%1)\n";
|
||||
|
||||
@@ -491,8 +496,7 @@ QStringList CmakeFileGenerator::getDirectoryResources(const FilePath &dir)
|
||||
|
||||
FilePaths allFiles = dir.dirEntries(FILES_ONLY);
|
||||
for (FilePath &file : allFiles) {
|
||||
if (!file.fileName().endsWith(".qml", Qt::CaseInsensitive) &&
|
||||
includeFile(file)) {
|
||||
if (!file.fileName().endsWith(".qml", Qt::CaseInsensitive) && includeFile(file)) {
|
||||
moduleFiles.append(file.fileName());
|
||||
}
|
||||
}
|
||||
@@ -519,10 +523,20 @@ QStringList CmakeFileGenerator::getDirectoryTreeQmls(const FilePath &dir)
|
||||
return qmlFileList;
|
||||
}
|
||||
|
||||
static void appendWidthQuotes(QStringList &list, const QString &string)
|
||||
{
|
||||
if (string.contains(' '))
|
||||
list.append("\"" + string + "\"");
|
||||
else
|
||||
list.append(string);
|
||||
}
|
||||
|
||||
QStringList CmakeFileGenerator::getDirectoryTreeResources(const FilePath &dir)
|
||||
{
|
||||
QStringList resourceFileList;
|
||||
|
||||
//for (const auto &string : getDirectoryResources(dir))
|
||||
// appendWidthQuotes(resourceFileList, string);
|
||||
resourceFileList.append(getDirectoryResources(dir));
|
||||
|
||||
FilePaths subDirsList = dir.dirEntries(DIRS_ONLY);
|
||||
@@ -531,9 +545,8 @@ QStringList CmakeFileGenerator::getDirectoryTreeResources(const FilePath &dir)
|
||||
continue;
|
||||
QStringList subDirResources = getDirectoryTreeResources(subDir);
|
||||
for (QString &resource : subDirResources) {
|
||||
resourceFileList.append(subDir.fileName().append('/').append(resource));
|
||||
appendWidthQuotes(resourceFileList, subDir.fileName().append('/').append(resource));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return resourceFileList;
|
||||
@@ -556,6 +569,18 @@ bool CmakeFileGenerator::isDirBlacklisted(const FilePath &dir)
|
||||
return (!dir.fileName().compare(DIRNAME_DESIGNER));
|
||||
}
|
||||
|
||||
bool CmakeFileGenerator::validFileName(const Utils::FilePath &filePath)
|
||||
{
|
||||
QStringList invalidChars = {"!", "\"", "£", "$", "%", "!", "^", "&", "*", "(", ")", "=", "+",
|
||||
"'", ",", ";", ":", "#", "~", "{", "{", "[", "]", "<", ">", "?"};
|
||||
const QString baseName = filePath.baseName();
|
||||
for (const auto &c : invalidChars) {
|
||||
if (baseName.contains(c))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CmakeFileGenerator::includeFile(const FilePath &filePath)
|
||||
{
|
||||
if (m_checkFileIsInProject) {
|
||||
@@ -564,7 +589,12 @@ bool CmakeFileGenerator::includeFile(const FilePath &filePath)
|
||||
return false;
|
||||
}
|
||||
|
||||
return !isFileBlacklisted(filePath.fileName());
|
||||
if (validFileName(filePath))
|
||||
return !isFileBlacklisted(filePath.fileName());
|
||||
else
|
||||
m_invalidFileNames.append(filePath);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CmakeFileGenerator::generateEntryPointFiles(const FilePath &dir)
|
||||
|
@@ -45,6 +45,7 @@ public:
|
||||
const FileQueue fileQueue() const;
|
||||
void filterFileQueue(const Utils::FilePaths &keepFiles);
|
||||
bool execute();
|
||||
Utils::FilePaths invalidFileNames() const;
|
||||
|
||||
private:
|
||||
void generateMainCmake(const Utils::FilePath &rootDir);
|
||||
@@ -63,12 +64,15 @@ private:
|
||||
bool isFileBlacklisted(const QString &fileName);
|
||||
bool isDirBlacklisted(const Utils::FilePath &dir);
|
||||
bool includeFile(const Utils::FilePath &filePath);
|
||||
bool validFileName(const Utils::FilePath &filePath);
|
||||
|
||||
private:
|
||||
FileQueue m_fileQueue;
|
||||
QStringList m_resourceFileLocations;
|
||||
QStringList m_moduleNames;
|
||||
bool m_checkFileIsInProject;
|
||||
|
||||
Utils::FilePaths m_invalidFileNames;
|
||||
};
|
||||
|
||||
} //GenerateCmake
|
||||
|
Reference in New Issue
Block a user