From 3329f2ea5574a08241106eb40e9bc4fbcf933b82 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 29 Jun 2018 09:33:56 -0400 Subject: [PATCH] [calamares] Refactor searching for QML dir - Split collecting the search paths into separate function - Don't fall back on the current directory --- src/calamares/CalamaresApplication.cpp | 81 ++++++++++++-------------- 1 file changed, 38 insertions(+), 43 deletions(-) diff --git a/src/calamares/CalamaresApplication.cpp b/src/calamares/CalamaresApplication.cpp index e41516c60..893e76c9b 100644 --- a/src/calamares/CalamaresApplication.cpp +++ b/src/calamares/CalamaresApplication.cpp @@ -133,60 +133,55 @@ CalamaresApplication::mainWindow() } -void -CalamaresApplication::initQmlPath() +static QStringList +qmlDirCandidates( bool assumeBuilddir ) { - QDir importPath; - - QString subpath( "qml" ); + static const char QML[] = "qml"; + QStringList qmlDirs; if ( CalamaresUtils::isAppDataDirOverridden() ) - { - importPath = QDir( CalamaresUtils::appDataDir() - .absoluteFilePath( subpath ) ); - if ( !importPath.exists() || !importPath.isReadable() ) - { - cError() << "FATAL: explicitly configured application data directory" - << CalamaresUtils::appDataDir().absolutePath() - << "does not contain a valid QML modules directory at" - << importPath.absolutePath() - << "\nCowardly refusing to continue startup without the QML directory."; - ::exit( EXIT_FAILURE ); - } - } + qmlDirs << CalamaresUtils::appDataDir().absoluteFilePath( QML ); else { - QStringList qmlDirCandidatesByPriority; - if ( isDebug() ) - { - qmlDirCandidatesByPriority.append( - QDir::current().absoluteFilePath( - QString( "src/%1" ) - .arg( subpath ) ) ); - } - qmlDirCandidatesByPriority.append( CalamaresUtils::appDataDir() - .absoluteFilePath( subpath ) ); + if ( assumeBuilddir ) + qmlDirs << QDir::current().absoluteFilePath( "src/qml" ); // In build-dir + qmlDirs << CalamaresUtils::appDataDir().absoluteFilePath( QML ); + } - foreach ( const QString& path, qmlDirCandidatesByPriority ) - { - QDir dir( path ); - if ( dir.exists() && dir.isReadable() ) - { - importPath = dir; - break; - } - } + return qmlDirs; +} - if ( !importPath.exists() || !importPath.isReadable() ) + +void +CalamaresApplication::initQmlPath() +{ + QDir importPath; // Right now, current-dir + QStringList qmlDirCandidatesByPriority = qmlDirCandidates( isDebug() ); + bool found = false; + + foreach ( const QString& path, qmlDirCandidatesByPriority ) + { + QDir dir( path ); + if ( dir.exists() && dir.isReadable() ) { - cError() << "FATAL: none of the expected QML paths (" - << qmlDirCandidatesByPriority.join( ", " ) - << ") exist." - << "\nCowardly refusing to continue startup without the QML directory."; - ::exit( EXIT_FAILURE ); + importPath = dir; + found = true; + break; } } + if ( !found || !importPath.exists() || !importPath.isReadable() ) + { + cError() << "Cowardly refusing to continue startup without a QML directory." + << Logger::DebugList( qmlDirCandidatesByPriority ); + if ( CalamaresUtils::isAppDataDirOverridden() ) + cError() << "FATAL: explicitly configured application data directory is missing qml/"; + else + cError() << "FATAL: none of the expected QML paths exist."; + ::exit( EXIT_FAILURE ); + } + + cDebug() << "Using Calamares QML directory" << importPath.absolutePath(); CalamaresUtils::setQmlModulesDir( importPath ); }