qmlimportscanner: Extend ignored directories handling
Refactor the checking by extracting a helper function checking on a list extendable by a new command argument. Ignore dot files created by Qt Creator which are not considered hidden on Windows. Pick-to: 6.8 Task-number: PYSIDE-1612 Task-number: PYSIDE-2803 Change-Id: I0d8611bfd346f31b2cfce46ad0033fb46915fa3a Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
This commit is contained in:
parent
558337a0a1
commit
ac55d94395
|
@ -76,6 +76,8 @@ void printUsage(const QString &appNameIn)
|
|||
" " << appName << " -qrcFiles file1.qrc file2.qrc -importPath path/to/qt/qml/directory\n\n"
|
||||
"Example: " << appName << " -rootPath . -importPath "
|
||||
<< QDir::toNativeSeparators(qmlPath).toStdString()
|
||||
<< "\n\nOptions:\n"
|
||||
<< " -exclude <directory>: Exclude directory\n"
|
||||
<< '\n';
|
||||
}
|
||||
|
||||
|
@ -710,7 +712,23 @@ struct pathStartsWith {
|
|||
const QString _path;
|
||||
};
|
||||
|
||||
static QStringList excludedDirectories = {
|
||||
".qtcreator"_L1, ".qtc_clangd"_L1, // Windows does not consider these hidden
|
||||
#ifdef Q_OS_WIN
|
||||
"release"_L1, "debug"_L1
|
||||
#endif
|
||||
};
|
||||
|
||||
static bool isExcluded(const QFileInfo &dir)
|
||||
{
|
||||
if (excludedDirectories.contains(dir.fileName()))
|
||||
return true;
|
||||
|
||||
const QString &path = dir.absoluteFilePath();
|
||||
// Skip obvious build output directories
|
||||
return path.contains("Debug-iphoneos"_L1) || path.contains("Release-iphoneos"_L1)
|
||||
|| path.contains("Debug-iphonesimulator"_L1) || path.contains("Release-iphonesimulator"_L1);
|
||||
}
|
||||
|
||||
// Scan all qml files in directory for import statements
|
||||
QVariantList findQmlImportsInDirectory(const QString &qmlDir,
|
||||
|
@ -726,6 +744,8 @@ QVariantList findQmlImportsInDirectory(const QString &qmlDir,
|
|||
|
||||
while (iterator.hasNext()) {
|
||||
iterator.next();
|
||||
if (isExcluded(iterator.fileInfo()))
|
||||
continue;
|
||||
const QString path = iterator.filePath();
|
||||
const QFileInfoList entries = QDir(path).entryInfoList();
|
||||
|
||||
|
@ -738,16 +758,6 @@ QVariantList findQmlImportsInDirectory(const QString &qmlDir,
|
|||
if (std::find_if(blacklist.cbegin(), blacklist.cend(), pathStartsWith(path)) != blacklist.cend())
|
||||
continue;
|
||||
|
||||
// Skip obvious build output directories
|
||||
if (path.contains(QLatin1String("Debug-iphoneos")) || path.contains(QLatin1String("Release-iphoneos")) ||
|
||||
path.contains(QLatin1String("Debug-iphonesimulator")) || path.contains(QLatin1String("Release-iphonesimulator"))
|
||||
#ifdef Q_OS_WIN
|
||||
|| path.endsWith(QLatin1String("/release")) || path.endsWith(QLatin1String("/debug"))
|
||||
#endif
|
||||
){
|
||||
continue;
|
||||
}
|
||||
|
||||
for (const QFileInfo &x : entries)
|
||||
if (x.isFile()) {
|
||||
const auto entryAbsolutePath = x.absoluteFilePath();
|
||||
|
@ -892,6 +902,7 @@ int main(int argc, char *argv[])
|
|||
|
||||
int i = 1;
|
||||
while (i < args.size()) {
|
||||
bool checkDirExists = true;
|
||||
const QString &arg = args.at(i);
|
||||
++i;
|
||||
QStringList *argReceiver = nullptr;
|
||||
|
@ -913,6 +924,11 @@ int main(int argc, char *argv[])
|
|||
if (i >= args.size())
|
||||
std::cerr << "-importPath requires an argument\n";
|
||||
argReceiver = &qmlImportPaths;
|
||||
} else if (arg == "-exclude"_L1) {
|
||||
if (i >= args.size())
|
||||
std::cerr << "-exclude Path requires an argument\n";
|
||||
checkDirExists = false;
|
||||
argReceiver = &excludedDirectories;
|
||||
} else if (arg == QLatin1String("-cmake-output")) {
|
||||
generateCmakeContent = true;
|
||||
} else if (arg == QLatin1String("-qrcFiles")) {
|
||||
|
@ -936,7 +952,7 @@ int main(int argc, char *argv[])
|
|||
if (arg.startsWith(QLatin1Char('-')) && arg != QLatin1String("-"))
|
||||
break;
|
||||
++i;
|
||||
if (arg != QLatin1String("-") && !QFile::exists(arg)) {
|
||||
if (arg != QLatin1String("-") && checkDirExists && !QFile::exists(arg)) {
|
||||
std::cerr << qPrintable(appName) << ": No such file or directory: \""
|
||||
<< qPrintable(arg) << "\"\n";
|
||||
return 1;
|
||||
|
|
Loading…
Reference in New Issue