QmlProject: Resolve import paths relative to target directory

On desktop the target directory is the same as the source directory. On
remote devices, it can be different. We need to resolve when we know
where to deploy.

Change-Id: I3f2bc088476ae73dac5231cb24f277c055f7d044
Task-number: QTCREATORBUG-19888
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
Ulf Hermann
2018-02-22 10:42:13 +01:00
committed by Tim Jenssen
parent 09a7247bfc
commit 30638df441
3 changed files with 19 additions and 20 deletions

View File

@@ -121,22 +121,35 @@ QString QmlProjectRunConfiguration::executable() const
return qmlscene.isEmpty() ? QString("qmlscene") : qmlscene;
}
static QStringList makeAbsolute(const Utils::FileName &path, const QStringList &relativePaths)
{
if (path.isEmpty())
return relativePaths;
const QDir baseDir(path.toString());
return Utils::transform(relativePaths, [&baseDir](const QString &path) {
return QDir::cleanPath(baseDir.absoluteFilePath(path));
});
}
QString QmlProjectRunConfiguration::commandLineArguments() const
{
// arguments in .user file
QString args = m_qmlViewerArgs;
const IDevice::ConstPtr device = DeviceKitInformation::device(target()->kit());
const Target *currentTarget = target();
const IDevice::ConstPtr device = DeviceKitInformation::device(currentTarget->kit());
const Utils::OsType osType = device ? device->osType() : Utils::HostOsInfo::hostOs();
// arguments from .qmlproject file
QmlProject *project = static_cast<QmlProject *>(target()->project());
foreach (const QString &importPath, project->customImportPaths()) {
const QmlProject *project = static_cast<QmlProject *>(currentTarget->project());
foreach (const QString &importPath,
makeAbsolute(project->targetDirectory(currentTarget), project->customImportPaths())) {
Utils::QtcProcess::addArg(&args, QLatin1String("-I"), osType);
Utils::QtcProcess::addArg(&args, importPath, osType);
}
const QString main
= project->targetFile(Utils::FileName::fromString(mainScript()), target()).toString(); ;
const QString main = project->targetFile(Utils::FileName::fromString(mainScript()),
currentTarget).toString();
if (!main.isEmpty())
Utils::QtcProcess::addArg(&args, main, osType);
return args;