aboutsummaryrefslogtreecommitdiffstats
path: root/sources
diff options
context:
space:
mode:
authorAlexandru Croitor <alexandru.croitor@qt.io>2018-07-05 17:50:34 +0200
committerAlexandru Croitor <alexandru.croitor@qt.io>2018-07-09 09:18:36 +0000
commit5662706937bd6a1449538539e3a503c6cbc45399 (patch)
treec2d72bd88f0637deb0272c12c1e0f3c7f2c61eef /sources
parentfd0c92305419be804e9b095adf8babb536631e29 (diff)
Fix macOS build when building inside Homebrew environment
A brew build environment sets up a clang shim (fake clang ruby script that sets up additional compiler flags), which passes all brew formula dependency include paths as system include paths (via -isystem). This also includes the Qt dependency. Because our clang parser currently ignores system headers (see Builder::visitLocation in clangbuilder.cpp) and because Qt include statements inside header files would resolve to the system header location, this would result in no Qt classes being recognized by the API extractor, and thus fail the build. Fix this by checking for an environment variable that brew sets inside its build environment, to filter out the unnecessary -isystem flags. This way the Qt include path would be passed as a non-system include path from CMake, and thus correctly complete the build. Task-number: PYSIDE-731 Change-Id: I9b543eddc85270f1e8a90d9f30194b2a862e80d7 Reviewed-by: Christian Tismer <tismer@stackless.com> Reviewed-by: Alberto Sottile <alby128@gmail.com>
Diffstat (limited to 'sources')
-rw-r--r--sources/shiboken2/ApiExtractor/clangparser/compilersupport.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/sources/shiboken2/ApiExtractor/clangparser/compilersupport.cpp b/sources/shiboken2/ApiExtractor/clangparser/compilersupport.cpp
index 820909713..0d98999b1 100644
--- a/sources/shiboken2/ApiExtractor/clangparser/compilersupport.cpp
+++ b/sources/shiboken2/ApiExtractor/clangparser/compilersupport.cpp
@@ -95,6 +95,36 @@ static bool runProcess(const QString &program, const QStringList &arguments,
static QByteArray frameworkPath() { return QByteArrayLiteral(" (framework directory)"); }
+#if defined(Q_OS_MACOS)
+static void filterHomebrewHeaderPaths(HeaderPaths &headerPaths)
+{
+ QByteArray homebrewPrefix = qgetenv("HOMEBREW_OPT");
+
+ // If HOMEBREW_OPT is found we assume that the build is happening
+ // inside a brew environment, which means we need to filter out
+ // the -isystem flags added by the brew clang shim. This is needed
+ // because brew passes the Qt include paths as system include paths
+ // and because our parser ignores system headers, Qt classes won't
+ // be found and thus compilation errors will occur.
+ if (homebrewPrefix.isEmpty())
+ return;
+
+ qCInfo(lcShiboken) << "Found HOMEBREW_OPT with value:" << homebrewPrefix
+ << "Assuming homebrew build environment.";
+
+ HeaderPaths::iterator it = headerPaths.begin();
+ while (it != headerPaths.end()) {
+ if (it->path.startsWith(homebrewPrefix)) {
+ qCInfo(lcShiboken) << "Filtering out homebrew include path: "
+ << it->path;
+ it = headerPaths.erase(it);
+ } else {
+ ++it;
+ }
+ }
+}
+#endif
+
// Determine g++'s internal include paths from the output of
// g++ -E -x c++ - -v </dev/null
// Output looks like:
@@ -130,6 +160,10 @@ static HeaderPaths gppInternalIncludePaths(const QString &compiler)
isIncludeDir = true;
}
}
+
+#if defined(Q_OS_MACOS)
+ filterHomebrewHeaderPaths(result);
+#endif
return result;
}
#endif // Q_CC_MSVC