forked from qt-creator/qt-creator
Wasm: Some steps towards making it work on docker
To start using the docker bits the emsdk location has to be specified manually in the path selector as docker://<id-of-image>/<path/to/emsdk> Change-Id: I70c6e7a334762953c3931105b7f697c608523159 Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
@@ -1168,11 +1168,8 @@ Abis Abi::abisOfBinary(const Utils::FilePath &path)
|
|||||||
&& getUint8(data, 6) == '>' && getUint8(data, 7) == 0x0a) {
|
&& getUint8(data, 6) == '>' && getUint8(data, 7) == 0x0a) {
|
||||||
// We got an ar file: possibly a static lib for ELF, PE or Mach-O
|
// We got an ar file: possibly a static lib for ELF, PE or Mach-O
|
||||||
|
|
||||||
// FIXME: Implement remote
|
|
||||||
QTC_ASSERT(!path.needsDevice(), return tmp);
|
|
||||||
QFile f(path.toString());
|
QFile f(path.toString());
|
||||||
if (!f.open(QFile::ReadOnly))
|
const bool canRead = f.open(QFile::ReadOnly);
|
||||||
return tmp;
|
|
||||||
|
|
||||||
data = data.mid(8); // Cut of ar file magic
|
data = data.mid(8); // Cut of ar file magic
|
||||||
quint64 offset = 8;
|
quint64 offset = 8;
|
||||||
@@ -1199,6 +1196,11 @@ Abis Abi::abisOfBinary(const Utils::FilePath &path)
|
|||||||
if (!tmp.isEmpty() && tmp.at(0).binaryFormat() != MachOFormat)
|
if (!tmp.isEmpty() && tmp.at(0).binaryFormat() != MachOFormat)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
if (!canRead) {
|
||||||
|
// FIXME: Implement remote
|
||||||
|
QTC_ASSERT(!path.needsDevice(), return {});
|
||||||
|
}
|
||||||
|
|
||||||
offset += (offset % 2); // ar is 2 byte aligned
|
offset += (offset % 2); // ar is 2 byte aligned
|
||||||
f.seek(offset);
|
f.seek(offset);
|
||||||
data = f.read(1024);
|
data = f.read(1024);
|
||||||
|
|||||||
@@ -321,7 +321,9 @@ FilePath IDevice::searchExecutableInPath(const QString &fileName) const
|
|||||||
|
|
||||||
FilePath IDevice::searchExecutable(const QString &fileName, const FilePaths &dirs) const
|
FilePath IDevice::searchExecutable(const QString &fileName, const FilePaths &dirs) const
|
||||||
{
|
{
|
||||||
for (const FilePath &dir : dirs) {
|
for (FilePath dir : dirs) {
|
||||||
|
if (!handlesFile(dir)) // Allow device-local dirs to be used.
|
||||||
|
dir = mapToGlobalPath(dir);
|
||||||
QTC_CHECK(handlesFile(dir));
|
QTC_CHECK(handlesFile(dir));
|
||||||
const FilePath candidate = dir / fileName;
|
const FilePath candidate = dir / fileName;
|
||||||
if (isExecutableFile(candidate))
|
if (isExecutableFile(candidate))
|
||||||
|
|||||||
@@ -43,35 +43,36 @@ using namespace Utils;
|
|||||||
namespace WebAssembly {
|
namespace WebAssembly {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
using EmSdkEnvCache = QCache<QString, QByteArray>;
|
using EmSdkEnvCache = QCache<QString, QString>;
|
||||||
Q_GLOBAL_STATIC_WITH_ARGS(EmSdkEnvCache, emSdkEnvCache, (10))
|
Q_GLOBAL_STATIC_WITH_ARGS(EmSdkEnvCache, emSdkEnvCache, (10))
|
||||||
using EmSdkVersionCache = QCache<QString, QVersionNumber>;
|
using EmSdkVersionCache = QCache<QString, QVersionNumber>;
|
||||||
Q_GLOBAL_STATIC_WITH_ARGS(EmSdkVersionCache, emSdkVersionCache, (10))
|
Q_GLOBAL_STATIC_WITH_ARGS(EmSdkVersionCache, emSdkVersionCache, (10))
|
||||||
|
|
||||||
static QByteArray emSdkEnvOutput(const FilePath &sdkRoot)
|
static QString emSdkEnvOutput(const FilePath &sdkRoot)
|
||||||
{
|
{
|
||||||
const QString cacheKey = sdkRoot.toString();
|
const QString cacheKey = sdkRoot.toString();
|
||||||
|
const bool isWindows = sdkRoot.osType() == OsTypeWindows;
|
||||||
if (!emSdkEnvCache()->contains(cacheKey)) {
|
if (!emSdkEnvCache()->contains(cacheKey)) {
|
||||||
const QString scriptFile = sdkRoot.pathAppended(QLatin1String("emsdk_env") +
|
const QString scriptFile = sdkRoot.pathAppended(QLatin1String("emsdk_env") +
|
||||||
(HostOsInfo::isWindowsHost() ? ".bat" : ".sh")).toString();
|
(isWindows ? ".bat" : ".sh")).path();
|
||||||
QtcProcess emSdkEnv;
|
QtcProcess emSdkEnv;
|
||||||
if (HostOsInfo::isWindowsHost()) {
|
if (isWindows) {
|
||||||
emSdkEnv.setCommand(CommandLine(scriptFile));
|
emSdkEnv.setCommand(CommandLine(scriptFile));
|
||||||
} else {
|
} else {
|
||||||
// File needs to be source'd, not executed.
|
// File needs to be source'd, not executed.
|
||||||
emSdkEnv.setCommand({"bash", {"-c", ". " + scriptFile}});
|
emSdkEnv.setCommand({FilePath::fromString("bash").onDevice(sdkRoot),
|
||||||
|
{"-c", ". " + scriptFile}});
|
||||||
}
|
}
|
||||||
emSdkEnv.start();
|
emSdkEnv.runBlocking();
|
||||||
if (!emSdkEnv.waitForFinished())
|
const QString output = emSdkEnv.allOutput();
|
||||||
return {};
|
emSdkEnvCache()->insert(cacheKey, new QString(output));
|
||||||
emSdkEnvCache()->insert(cacheKey, new QByteArray(emSdkEnv.readAllStandardError()));
|
|
||||||
}
|
}
|
||||||
return *emSdkEnvCache()->object(cacheKey);
|
return *emSdkEnvCache()->object(cacheKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void parseEmSdkEnvOutputAndAddToEnv(const QByteArray &output, Environment &env)
|
static void parseEmSdkEnvOutputAndAddToEnv(const QString &output, Environment &env)
|
||||||
{
|
{
|
||||||
const QStringList lines = QString::fromLocal8Bit(output).split('\n');
|
const QStringList lines = output.split('\n');
|
||||||
|
|
||||||
for (const QString &line : lines) {
|
for (const QString &line : lines) {
|
||||||
const QStringList prependParts = line.trimmed().split(" += ");
|
const QStringList prependParts = line.trimmed().split(" += ");
|
||||||
@@ -104,18 +105,17 @@ QVersionNumber WebAssemblyEmSdk::version(const FilePath &sdkRoot)
|
|||||||
return {};
|
return {};
|
||||||
const QString cacheKey = sdkRoot.toString();
|
const QString cacheKey = sdkRoot.toString();
|
||||||
if (!emSdkVersionCache()->contains(cacheKey)) {
|
if (!emSdkVersionCache()->contains(cacheKey)) {
|
||||||
Environment env = Environment::systemEnvironment();
|
Environment env;
|
||||||
WebAssemblyEmSdk::addToEnvironment(sdkRoot, env);
|
WebAssemblyEmSdk::addToEnvironment(sdkRoot, env);
|
||||||
const QString scriptFile =
|
QLatin1String scriptFile{sdkRoot.osType() == OsType::OsTypeWindows ? "emcc.bat" : "emcc"};
|
||||||
QLatin1String("emcc") + QLatin1String(HostOsInfo::isWindowsHost() ? ".bat" : "");
|
FilePath script =
|
||||||
const CommandLine command(env.searchInPath(scriptFile), {"-dumpversion"});
|
FilePath::fromString(scriptFile).onDevice(sdkRoot).searchOnDevice(env.path());
|
||||||
|
const CommandLine command(script, {"-dumpversion"});
|
||||||
QtcProcess emcc;
|
QtcProcess emcc;
|
||||||
emcc.setCommand(command);
|
emcc.setCommand(command);
|
||||||
emcc.setEnvironment(env);
|
emcc.setEnvironment(env);
|
||||||
emcc.start();
|
emcc.runBlocking();
|
||||||
if (!emcc.waitForFinished())
|
const QString version = emcc.stdOut();
|
||||||
return {};
|
|
||||||
const QString version = QLatin1String(emcc.readAllStandardOutput());
|
|
||||||
emSdkVersionCache()->insert(cacheKey,
|
emSdkVersionCache()->insert(cacheKey,
|
||||||
new QVersionNumber(QVersionNumber::fromString(version)));
|
new QVersionNumber(QVersionNumber::fromString(version)));
|
||||||
}
|
}
|
||||||
@@ -148,7 +148,7 @@ void WebAssemblyEmSdk::clearCaches()
|
|||||||
void WebAssemblyPlugin::testEmSdkEnvParsing()
|
void WebAssemblyPlugin::testEmSdkEnvParsing()
|
||||||
{
|
{
|
||||||
// Output of "emsdk_env"
|
// Output of "emsdk_env"
|
||||||
const QByteArray emSdkEnvOutput = HostOsInfo::isWindowsHost() ?
|
const QString emSdkEnvOutput = QString::fromLatin1(HostOsInfo::isWindowsHost() ?
|
||||||
R"(
|
R"(
|
||||||
Adding directories to PATH:
|
Adding directories to PATH:
|
||||||
PATH += C:\Users\user\dev\emsdk
|
PATH += C:\Users\user\dev\emsdk
|
||||||
@@ -177,7 +177,7 @@ EMSDK = /home/user/dev/emsdk
|
|||||||
EM_CONFIG = /home/user/dev/emsdk/.emscripten
|
EM_CONFIG = /home/user/dev/emsdk/.emscripten
|
||||||
EM_CACHE = /home/user/dev/emsdk/upstream/emscripten/cache
|
EM_CACHE = /home/user/dev/emsdk/upstream/emscripten/cache
|
||||||
EMSDK_NODE = /home/user/dev/emsdk/node/12.18.1_64bit/bin/node
|
EMSDK_NODE = /home/user/dev/emsdk/node/12.18.1_64bit/bin/node
|
||||||
)";
|
)");
|
||||||
Environment env;
|
Environment env;
|
||||||
parseEmSdkEnvOutputAndAddToEnv(emSdkEnvOutput, env);
|
parseEmSdkEnvOutputAndAddToEnv(emSdkEnvOutput, env);
|
||||||
|
|
||||||
|
|||||||
@@ -129,7 +129,7 @@ static QString environmentDisplay(const FilePath &sdkRoot)
|
|||||||
WebAssemblyEmSdk::addToEnvironment(sdkRoot, env);
|
WebAssemblyEmSdk::addToEnvironment(sdkRoot, env);
|
||||||
QString result;
|
QString result;
|
||||||
result.append(WebAssemblyOptionsWidget::tr("<h4>Adding directories to PATH:</h4>"));
|
result.append(WebAssemblyOptionsWidget::tr("<h4>Adding directories to PATH:</h4>"));
|
||||||
result.append(env.value("PATH").replace(HostOsInfo::pathListSeparator(), "<br/>"));
|
result.append(env.value("PATH").replace(OsSpecificAspects::pathListSeparator(sdkRoot.osType()), "<br/>"));
|
||||||
result.append(WebAssemblyOptionsWidget::tr("<h4>Setting environment variables:</h4>"));
|
result.append(WebAssemblyOptionsWidget::tr("<h4>Setting environment variables:</h4>"));
|
||||||
for (const QString &envVar : env.toStringList()) {
|
for (const QString &envVar : env.toStringList()) {
|
||||||
if (!envVar.startsWith("PATH")) // Path was already printed out above
|
if (!envVar.startsWith("PATH")) // Path was already printed out above
|
||||||
|
|||||||
@@ -27,20 +27,20 @@
|
|||||||
#include "webassemblyconstants.h"
|
#include "webassemblyconstants.h"
|
||||||
#include "webassemblyemsdk.h"
|
#include "webassemblyemsdk.h"
|
||||||
|
|
||||||
|
#include <projectexplorer/devicesupport/devicemanager.h>
|
||||||
#include <projectexplorer/kitmanager.h>
|
#include <projectexplorer/kitmanager.h>
|
||||||
#include <projectexplorer/projectexplorerconstants.h>
|
#include <projectexplorer/projectexplorerconstants.h>
|
||||||
#include <projectexplorer/projectmacro.h>
|
#include <projectexplorer/projectmacro.h>
|
||||||
#include <projectexplorer/toolchainmanager.h>
|
#include <projectexplorer/toolchainmanager.h>
|
||||||
|
|
||||||
#include <qtsupport/qtkitinformation.h>
|
#include <qtsupport/qtkitinformation.h>
|
||||||
|
|
||||||
#include <utils/algorithm.h>
|
#include <utils/algorithm.h>
|
||||||
#include <utils/environment.h>
|
#include <utils/environment.h>
|
||||||
#include <utils/fileutils.h>
|
#include <utils/fileutils.h>
|
||||||
#include <utils/hostosinfo.h>
|
#include <utils/hostosinfo.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
#include <QDir>
|
|
||||||
#include <QSettings>
|
|
||||||
|
|
||||||
using namespace ProjectExplorer;
|
using namespace ProjectExplorer;
|
||||||
using namespace QtSupport;
|
using namespace QtSupport;
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
@@ -73,7 +73,7 @@ static void addRegisteredMinGWToEnvironment(Environment &env)
|
|||||||
void WebAssemblyToolChain::addToEnvironment(Environment &env) const
|
void WebAssemblyToolChain::addToEnvironment(Environment &env) const
|
||||||
{
|
{
|
||||||
WebAssemblyEmSdk::addToEnvironment(WebAssemblyEmSdk::registeredEmSdk(), env);
|
WebAssemblyEmSdk::addToEnvironment(WebAssemblyEmSdk::registeredEmSdk(), env);
|
||||||
if (HostOsInfo::isWindowsHost())
|
if (env.osType() == OsTypeWindows)
|
||||||
addRegisteredMinGWToEnvironment(env);
|
addRegisteredMinGWToEnvironment(env);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,9 +88,9 @@ WebAssemblyToolChain::WebAssemblyToolChain() :
|
|||||||
FilePath WebAssemblyToolChain::makeCommand(const Environment &environment) const
|
FilePath WebAssemblyToolChain::makeCommand(const Environment &environment) const
|
||||||
{
|
{
|
||||||
// Diverged duplicate of ClangToolChain::makeCommand and MingwToolChain::makeCommand
|
// Diverged duplicate of ClangToolChain::makeCommand and MingwToolChain::makeCommand
|
||||||
const QStringList makes
|
const QStringList makes = environment.osType() == OsTypeWindows
|
||||||
= HostOsInfo::isWindowsHost() ? QStringList({"mingw32-make.exe", "make.exe"})
|
? QStringList({"mingw32-make.exe", "make.exe"})
|
||||||
: QStringList({"make"});
|
: QStringList({"make"});
|
||||||
|
|
||||||
FilePath tmp;
|
FilePath tmp;
|
||||||
for (const QString &make : makes) {
|
for (const QString &make : makes) {
|
||||||
@@ -162,13 +162,12 @@ QList<ToolChain *> WebAssemblyToolChainFactory::autoDetect(
|
|||||||
const IDevice::Ptr &device)
|
const IDevice::Ptr &device)
|
||||||
{
|
{
|
||||||
Q_UNUSED(alreadyKnown)
|
Q_UNUSED(alreadyKnown)
|
||||||
Q_UNUSED(device)
|
|
||||||
|
|
||||||
const FilePath sdk = WebAssemblyEmSdk::registeredEmSdk();
|
const FilePath sdk = WebAssemblyEmSdk::registeredEmSdk();
|
||||||
if (!WebAssemblyEmSdk::isValid(sdk))
|
if (!WebAssemblyEmSdk::isValid(sdk))
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
Environment env;
|
Environment env = sdk.deviceEnvironment();
|
||||||
WebAssemblyEmSdk::addToEnvironment(sdk, env);
|
WebAssemblyEmSdk::addToEnvironment(sdk, env);
|
||||||
|
|
||||||
QList<ToolChain *> result;
|
QList<ToolChain *> result;
|
||||||
@@ -178,9 +177,11 @@ QList<ToolChain *> WebAssemblyToolChainFactory::autoDetect(
|
|||||||
toolChain->setLanguage(languageId);
|
toolChain->setLanguage(languageId);
|
||||||
toolChain->setDetection(ToolChain::AutoDetection);
|
toolChain->setDetection(ToolChain::AutoDetection);
|
||||||
const bool cLanguage = languageId == ProjectExplorer::Constants::C_LANGUAGE_ID;
|
const bool cLanguage = languageId == ProjectExplorer::Constants::C_LANGUAGE_ID;
|
||||||
const QString scriptFile = QLatin1String(cLanguage ? "emcc" : "em++")
|
const QString script = QLatin1String(cLanguage ? "emcc" : "em++")
|
||||||
+ QLatin1String(HostOsInfo::isWindowsHost() ? ".bat" : "");
|
+ QLatin1String(sdk.osType() == OsTypeWindows ? ".bat" : "");
|
||||||
toolChain->setCompilerCommand(env.searchInPath(scriptFile));
|
const FilePath scriptFile =
|
||||||
|
FilePath::fromString(script).onDevice(sdk).searchOnDevice(env.path());
|
||||||
|
toolChain->setCompilerCommand(scriptFile);
|
||||||
|
|
||||||
const QString displayName = WebAssemblyToolChain::tr("Emscripten Compiler %1 for %2")
|
const QString displayName = WebAssemblyToolChain::tr("Emscripten Compiler %1 for %2")
|
||||||
.arg(toolChain->version(), QLatin1String(cLanguage ? "C" : "C++"));
|
.arg(toolChain->version(), QLatin1String(cLanguage ? "C" : "C++"));
|
||||||
|
|||||||
Reference in New Issue
Block a user