From a8bb2af30e1b4454ee81518a3b268ee78739ba04 Mon Sep 17 00:00:00 2001 From: Jake Petroules Date: Thu, 10 Nov 2016 23:18:05 -0800 Subject: [PATCH] Qbs: fix Xcode SDK detection (take 2) This adds xcode to the toolchain list, which is required to load the Xcode module. It also uses the compiler path as the mechanism to find the developer path, and then extracts the canonical SDK name using the sysroot if it's a valid one for the previously extracted developer path. amends d121fefaa9631fa482bca534cf3d8d0f15b5ffc3 Change-Id: I73cf1a50acd6b99a9fc3b6003bcc6dc23c2a04ab Reviewed-by: Eike Ziller Reviewed-by: Christian Kandeler --- .../defaultpropertyprovider.cpp | 56 ++++++++++++------- 1 file changed, 36 insertions(+), 20 deletions(-) diff --git a/src/plugins/qbsprojectmanager/defaultpropertyprovider.cpp b/src/plugins/qbsprojectmanager/defaultpropertyprovider.cpp index 6488b81d6f9..93371294fa0 100644 --- a/src/plugins/qbsprojectmanager/defaultpropertyprovider.cpp +++ b/src/plugins/qbsprojectmanager/defaultpropertyprovider.cpp @@ -216,26 +216,6 @@ QVariantMap DefaultPropertyProvider::autoGeneratedProperties(const ProjectExplor data.insert(QLatin1String(QBS_TARGETOS), targetOS); QStringList toolchain = toolchainList(tc); - if (!toolchain.isEmpty()) - data.insert(QLatin1String(QBS_TOOLCHAIN), toolchain); - - if (targetAbi.os() == ProjectExplorer::Abi::MacOS) { - // Reverse engineer Xcode developer path and canonical SDK name from sysroot - QDir sysrootdir(QDir::cleanPath(sysroot)); - const QSettings sdkSettings(sysrootdir.absoluteFilePath(QLatin1String("SDKSettings.plist")), QSettings::NativeFormat); - const QString sdkCanonicalName(sdkSettings.value(QLatin1String("CanonicalName")).toString()); - if (!sdkCanonicalName.isEmpty()) { - const QRegularExpression re(QStringLiteral("^(?.*)/Platforms/(?MacOSX|(?:(?:iPhone|AppleTV|Watch)(?:OS|Simulator)))\\.platform/Developer/SDKs/(?MacOSX|(?:(?:iPhone|AppleTV|Watch)(?:OS|Simulator)))(?:[0-9]+\\.[0-9]+)\\.sdk/?$")); - const QRegularExpressionMatch match = re.match(sysrootdir.absolutePath()); - if (match.hasMatch() && - match.captured(QStringLiteral("platform")) == - match.captured(QStringLiteral("sdkplatform"))) { - data.insert(QLatin1String(XCODE_DEVELOPERPATH), - match.captured(QStringLiteral("developerpath"))); - data.insert(QLatin1String(XCODE_SDK), sdkCanonicalName); - } - } - } Utils::FileName cxx = tc->compilerCommand(); const QFileInfo cxxFileInfo = cxx.toFileInfo(); @@ -262,6 +242,42 @@ QVariantMap DefaultPropertyProvider::autoGeneratedProperties(const ProjectExplor data.insert(QLatin1String(CPP_PLATFORMLINKERFLAGS), gcc->platformLinkerFlags()); } + if (targetAbi.os() == ProjectExplorer::Abi::MacOS) { + // Reverse engineer the Xcode developer path from the compiler path + const QRegularExpression compilerRe( + QStringLiteral("^(?.*)/Toolchains/(?:.+)\\.xctoolchain/usr/bin$")); + const QRegularExpressionMatch compilerReMatch = compilerRe.match(cxxFileInfo.absolutePath()); + if (compilerReMatch.hasMatch()) { + const QString developerPath = compilerReMatch.captured(QStringLiteral("developerpath")); + data.insert(QLatin1String(XCODE_DEVELOPERPATH), developerPath); + toolchain.insert(0, QStringLiteral("xcode")); + + // If the sysroot is part of this developer path, set the canonical SDK name + const QDir sysrootdir(QDir::cleanPath(sysroot)); + const QString sysrootAbs = sysrootdir.absolutePath(); + const QSettings sdkSettings( + sysrootdir.absoluteFilePath(QStringLiteral("SDKSettings.plist")), + QSettings::NativeFormat); + const QString version( + sdkSettings.value(QStringLiteral("Version")).toString()); + QString canonicalName( + sdkSettings.value(QStringLiteral("CanonicalName")).toString()); + canonicalName.chop(version.size()); + if (!canonicalName.isEmpty() && !version.isEmpty() + && sysrootAbs.startsWith(developerPath)) { + if (sysrootAbs.toLower().endsWith(QStringLiteral("/%1.sdk") + .arg(canonicalName + version))) + data.insert(QLatin1String(XCODE_SDK), canonicalName + version); + if (sysrootAbs.toLower().endsWith(QStringLiteral("/%1.sdk") + .arg(canonicalName))) + data.insert(QLatin1String(XCODE_SDK), canonicalName); + } + } + } + + if (!toolchain.isEmpty()) + data.insert(QLatin1String(QBS_TOOLCHAIN), toolchain); + return data; }