From b8e1b33455645adb0256ff783da58b8960192224 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Mon, 15 Apr 2024 23:22:38 +0200 Subject: [PATCH] Android: Unconvolute onLicenseStdOut() Drop notify arg and dispatch it on the caller side. Return std::optional and pass the cached output in case of assertion. Change-Id: I4e738148ef248bd85a3a9260c07af30bf1586805 Reviewed-by: Reviewed-by: Alessandro Portale --- src/plugins/android/androidsdkmanager.cpp | 27 +++++++++++------------ 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/plugins/android/androidsdkmanager.cpp b/src/plugins/android/androidsdkmanager.cpp index d5e1b1975b2..e51c324839a 100644 --- a/src/plugins/android/androidsdkmanager.cpp +++ b/src/plugins/android/androidsdkmanager.cpp @@ -46,22 +46,16 @@ static const QRegularExpression &assertionRegExp() return theRegExp; } -static bool onLicenseStdOut(const QString &output, bool notify, QString *licenseTextCache, - AndroidSdkManager::OperationOutput &result, SdkCmdPromise &fi) +static std::optional onLicenseStdOut(const QString &output, QString *licenseTextCache) { licenseTextCache->append(output); const QRegularExpressionMatch assertionMatch = assertionRegExp().match(*licenseTextCache); if (assertionMatch.hasMatch()) { - if (notify) { - result.stdOutput = *licenseTextCache; - fi.addResult(result); - } - // Clear the current contents. The found license text is dispatched. Continue collecting the - // next license text. + const QString ret = *licenseTextCache; licenseTextCache->clear(); - return true; + return ret; } - return false; + return {}; } int parseProgress(const QString &out, bool &foundAssertion) @@ -546,9 +540,14 @@ void AndroidSdkManagerPrivate::getPendingLicense(SdkCmdPromise &fi) QString licenseTextCache; while (!licenseCommand.waitForFinished(200ms)) { const QString stdOut = codec->toUnicode(licenseCommand.readAllRawStandardOutput()); - bool assertionFound = false; - if (!stdOut.isEmpty()) - assertionFound = onLicenseStdOut(stdOut, reviewingLicenses, &licenseTextCache, result, fi); + std::optional assertion; + if (!stdOut.isEmpty()) { + assertion = onLicenseStdOut(stdOut, &licenseTextCache); + if (assertion && reviewingLicenses) { + result.stdOutput = *assertion; + fi.addResult(result); + } + } if (reviewingLicenses) { // Check user input @@ -560,7 +559,7 @@ void AndroidSdkManagerPrivate::getPendingLicense(SdkCmdPromise &fi) if (steps != -1) fi.setProgressValue(qRound((inputCounter / (double)steps) * 100)); } - } else if (assertionFound) { + } else if (assertion) { // The first assertion is to start reviewing licenses. Always accept. reviewingLicenses = true; static const QRegularExpression reg(R"((\d+\sof\s)(?\d+))");