Hi all,
We just noticed that the setupRunEnviroment scripts are not executed when
starting a product from within QtCreator. The reason seems to be that the
Creator needs to attach to the process and cannot use the
RunEnvironment::runTarget() method for that task. Even getting the final
environment from Qbs is not implemented right now, as can be seen from the
TODO comment in QbsRunConfiguration::addToBaseEnvironment().
Since having the setupRunEnvironment feature is important for us, I decided
to try implementing it. However I noticed that currently there is no way to
get the final environment via the Qbs API. Maybe I overlooked something
here? Anyway, I added these two methods to the RunEnvironment class:
class QBS_EXPORT RunEnvironment
{ ...
const QProcessEnvironment runEnvironment() const;
const QProcessEnvironment buildEnvironment() const;
The implementations call setupXxxEnvironment of the resolvedProduct and
return the created environment. Note that the second method is not strictly
needed, but I thought it would be nice to have it also. If there is a
better way to get the environments, please correct me ;-)
Next, I tried to implement the missing functionality like this.
void QbsRunConfiguration::addToBaseEnvironment(Utils::Environment &env)
const
{
QbsProject *project = static_cast<QbsProject *>(target()->project());
if (project) {
const qbs::ProductData product =
findProduct(project->qbsProjectData(), m_qbsProduct);
if (product.isValid()) {
qbs::RunEnvironment qbsRunEnv =
project->qbsProject().getRunEnvironment(product,
env.toProcessEnvironment(), QbsManager::settings());
QProcessEnvironment procEnv = qbsRunEnv.runEnvironment();
if (!procEnv.isEmpty()) {
env = Utils::Environment();
foreach (const QString &key, procEnv.keys())
env.set(key, procEnv.value(key));
return;
}
}
}
QtSupport::BaseQtVersion *qtVersion =
QtSupport::QtKitInformation::qtVersion(target()->kit());
if (qtVersion)
env.prependOrSetLibrarySearchPath(qtVersion->qmakeProperty("QT_INSTALL_LIBS"));
}
This works fine for us :-) However I'm not sure whether I missed something
important. Also the need for enhancing the Qbs API looks a bit suspect to
me. Maybe there is a much better way to do it? Please could one of the
experts comment on this?
Thanks,
Thomas
_______________________________________________
QBS mailing list
[email protected]
http://lists.qt-project.org/mailman/listinfo/qbs