forked from qt-creator/qt-creator
WebAssembly: Cache emsdk_env and toolchain --dumpversion results
Stores the results of emsdk_env and --dumpversion in the settings database. Also stores the modification time of the ".emscripten" file in the sdk root folder in order to validate the cached entries. Change-Id: Iacb907ee6d8cd9f4c14d33a6ad425ec684c66238 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -3,9 +3,9 @@
|
||||
|
||||
#include "webassemblyemsdk.h"
|
||||
|
||||
#include "webassemblyconstants.h"
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
#include <coreplugin/settingsdatabase.h>
|
||||
|
||||
#include <utils/environment.h>
|
||||
#include <utils/process.h>
|
||||
#include <utils/hostosinfo.h>
|
||||
@@ -16,24 +16,34 @@ using namespace Utils;
|
||||
|
||||
namespace WebAssembly::Internal::WebAssemblyEmSdk {
|
||||
|
||||
using EmSdkEnvCache = QCache<FilePath, QString>;
|
||||
static EmSdkEnvCache *emSdkEnvCache()
|
||||
{
|
||||
static EmSdkEnvCache cache(10);
|
||||
return &cache;
|
||||
}
|
||||
const char emSdkEnvTSFileKey[] = "WebAssembly/emSdkEnvTimeStampFile";
|
||||
const char emSdkEnvTSKey[] = "WebAssembly/emSdkEnvTimeStamp";
|
||||
const char emSdkEnvOutputKey[] = "WebAssembly/emSdkEnvOutput1";
|
||||
|
||||
using EmSdkVersionCache = QCache<FilePath, QVersionNumber>;
|
||||
static EmSdkVersionCache *emSdkVersionCache()
|
||||
const char emSdkVersionTSFileKey[] = "WebAssembly/emSdkVersionTimeStampFile";
|
||||
const char emSdkVersionTSKey[] = "WebAssembly/emSdkVersionTimeStamp";
|
||||
const char emSdkVersionKey[] = "WebAssembly/emSdkVersion1";
|
||||
|
||||
const FilePath timeStampFile(const FilePath &sdkRoot)
|
||||
{
|
||||
static EmSdkVersionCache cache(10);
|
||||
return &cache;
|
||||
return sdkRoot / ".emscripten";
|
||||
}
|
||||
|
||||
static QString emSdkEnvOutput(const FilePath &sdkRoot)
|
||||
{
|
||||
const FilePath tsFile = timeStampFile(sdkRoot); // ts == Timestamp
|
||||
if (!tsFile.exists())
|
||||
return {};
|
||||
const QDateTime ts = tsFile.lastModified();
|
||||
|
||||
Core::SettingsDatabase *db = Core::ICore::settingsDatabase();
|
||||
if (db->value(emSdkEnvTSKey).toDateTime() == ts
|
||||
&& FilePath::fromVariant(db->value(emSdkEnvTSFileKey)) == tsFile
|
||||
&& db->contains(emSdkEnvOutputKey)) {
|
||||
return db->value(emSdkEnvOutputKey).toString();
|
||||
}
|
||||
|
||||
const bool isWindows = sdkRoot.osType() == OsTypeWindows;
|
||||
if (!emSdkEnvCache()->contains(sdkRoot)) {
|
||||
const FilePath scriptFile = sdkRoot.pathAppended(QLatin1String("emsdk_env") +
|
||||
(isWindows ? ".bat" : ".sh"));
|
||||
Process emSdkEnv;
|
||||
@@ -44,10 +54,12 @@ static QString emSdkEnvOutput(const FilePath &sdkRoot)
|
||||
emSdkEnv.setCommand({sdkRoot.withNewPath("bash"), {"-c", ". " + scriptFile.path()}});
|
||||
}
|
||||
emSdkEnv.runBlocking();
|
||||
const QString output = emSdkEnv.allOutput();
|
||||
emSdkEnvCache()->insert(sdkRoot, new QString(output));
|
||||
}
|
||||
return *emSdkEnvCache()->object(sdkRoot);
|
||||
const QString result = emSdkEnv.allOutput();
|
||||
db->setValue(emSdkEnvTSFileKey, tsFile.toVariant());
|
||||
db->setValue(emSdkEnvTSKey, ts);
|
||||
db->setValue(emSdkEnvOutputKey, result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void parseEmSdkEnvOutputAndAddToEnv(const QString &output, Environment &env)
|
||||
@@ -86,9 +98,18 @@ void addToEnvironment(const FilePath &sdkRoot, Environment &env)
|
||||
|
||||
QVersionNumber version(const FilePath &sdkRoot)
|
||||
{
|
||||
if (!sdkRoot.exists())
|
||||
const FilePath tsFile = timeStampFile(sdkRoot); // ts == Timestamp
|
||||
if (!tsFile.exists())
|
||||
return {};
|
||||
if (!emSdkVersionCache()->contains(sdkRoot)) {
|
||||
const QDateTime ts = tsFile.lastModified();
|
||||
|
||||
Core::SettingsDatabase *db = Core::ICore::settingsDatabase();
|
||||
if (db->value(emSdkVersionTSKey).toDateTime() == ts
|
||||
&& FilePath::fromVariant(db->value(emSdkVersionTSFileKey)) == tsFile
|
||||
&& db->contains(emSdkVersionKey)) {
|
||||
return QVersionNumber::fromString(db->value(emSdkVersionKey).toString());
|
||||
}
|
||||
|
||||
Environment env = sdkRoot.deviceEnvironment();
|
||||
addToEnvironment(sdkRoot, env);
|
||||
QLatin1String scriptFile{sdkRoot.osType() == OsType::OsTypeWindows ? "emcc.bat" : "emcc"};
|
||||
@@ -98,17 +119,23 @@ QVersionNumber version(const FilePath &sdkRoot)
|
||||
emcc.setCommand(command);
|
||||
emcc.setEnvironment(env);
|
||||
emcc.runBlocking();
|
||||
const QString version = emcc.cleanedStdOut();
|
||||
emSdkVersionCache()->insert(sdkRoot,
|
||||
new QVersionNumber(QVersionNumber::fromString(version)));
|
||||
}
|
||||
return *emSdkVersionCache()->object(sdkRoot);
|
||||
const QString versionStr = emcc.cleanedStdOut();
|
||||
const QVersionNumber result = QVersionNumber::fromString(versionStr);
|
||||
db->setValue(emSdkVersionTSFileKey, tsFile.toVariant());
|
||||
db->setValue(emSdkVersionTSKey, ts);
|
||||
db->setValue(emSdkVersionKey, result.toString());
|
||||
return result;
|
||||
}
|
||||
|
||||
void clearCaches()
|
||||
{
|
||||
emSdkEnvCache()->clear();
|
||||
emSdkVersionCache()->clear();
|
||||
Core::SettingsDatabase *db = Core::ICore::settingsDatabase();
|
||||
db->remove(emSdkEnvTSFileKey);
|
||||
db->remove(emSdkEnvTSKey);
|
||||
db->remove(emSdkEnvOutputKey);
|
||||
db->remove(emSdkVersionTSFileKey);
|
||||
db->remove(emSdkVersionTSKey);
|
||||
db->remove(emSdkVersionKey);
|
||||
}
|
||||
|
||||
} // namespace WebAssembly::Internal::WebAssemblyEmSdk
|
||||
|
||||
Reference in New Issue
Block a user