From e34ff64196f6817c90530a522d9a3054279df15f Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Mon, 27 Jul 2020 12:56:43 +0200 Subject: [PATCH] qbs build: Add convenience properties for sanitizers Change-Id: I8c0908ed482127712c1cf4052d7b792be5ba79ae Reviewed-by: Christian Stenger --- qbs/imports/QtcProduct.qbs | 39 ++++++++++++++----- qbs/modules/qtc/qtc.qbs | 4 ++ src/tools/valgrindfake/valgrindfake.qbs | 1 + .../valgrind/memcheck/testapps/testapp.qbs | 1 + 4 files changed, 35 insertions(+), 10 deletions(-) diff --git a/qbs/imports/QtcProduct.qbs b/qbs/imports/QtcProduct.qbs index c6d1a26e90f..0509b79d784 100644 --- a/qbs/imports/QtcProduct.qbs +++ b/qbs/imports/QtcProduct.qbs @@ -16,6 +16,7 @@ Product { property string pathToSharedSources: FileInfo.joinPaths(path, FileInfo.relativePath(FileInfo.joinPaths('/', qtc.ide_qbs_imports_path), FileInfo.joinPaths('/', qtc.ide_shared_sources_path))) + property bool sanitizable: true Depends { name: "cpp" } Depends { name: "qtc" } @@ -36,22 +37,40 @@ Product { cpp.cxxFlags: { var flags = []; - if (qbs.toolchain.contains("clang") - && !qbs.hostOS.contains("darwin") - && Utilities.versionCompare(cpp.compilerVersion, "10") >= 0) { - // Triggers a lot in Qt. - flags.push("-Wno-deprecated-copy", "-Wno-constant-logical-operand"); - } - if (qbs.toolchain.contains("gcc") && !qbs.toolchain.contains("clang")) { - flags.push("-Wno-noexcept-type"); - if (Utilities.versionCompare(cpp.compilerVersion, "9") >= 0) - flags.push("-Wno-deprecated-copy", "-Wno-init-list-lifetime"); + if (qbs.toolchain.contains("gcc")) { + if (qbs.toolchain.contains("clang") + && !qbs.hostOS.contains("darwin") + && Utilities.versionCompare(cpp.compilerVersion, "10") >= 0) { + // Triggers a lot in Qt. + flags.push("-Wno-deprecated-copy", "-Wno-constant-logical-operand"); + } + if (!qbs.toolchain.contains("clang")) { + flags.push("-Wno-noexcept-type"); + if (Utilities.versionCompare(cpp.compilerVersion, "9") >= 0) + flags.push("-Wno-deprecated-copy", "-Wno-init-list-lifetime"); + } + if (qtc.enableAddressSanitizer) + flags.push("-fno-omit-frame-pointer"); } else if (qbs.toolchain.contains("msvc")) { flags.push("/w44996"); } return flags; } + Properties { + condition: sanitizable && qbs.toolchain.contains("gcc") + cpp.driverFlags: { + var flags = []; + if (qtc.enableAddressSanitizer) + flags.push("-fsanitize=address"); + if (qtc.enableUbSanitizer) + flags.push("-fsanitize=undefined"); + if (qtc.enableThreadSanitizer) + flags.push("-fsanitize=thread"); + return flags; + } + } + cpp.cxxLanguageVersion: "c++17" cpp.defines: qtc.generalDefines cpp.minimumWindowsVersion: "6.1" diff --git a/qbs/modules/qtc/qtc.qbs b/qbs/modules/qtc/qtc.qbs index 40c2fcdc0cc..e625dfabd93 100644 --- a/qbs/modules/qtc/qtc.qbs +++ b/qbs/modules/qtc/qtc.qbs @@ -65,6 +65,10 @@ Module { property string litehtmlInstallDir: Environment.getEnv("LITEHTML_INSTALL_DIR") + property bool enableAddressSanitizer: false + property bool enableUbSanitizer: false + property bool enableThreadSanitizer: false + property bool make_dev_package: false // Will be replaced when creating modules from products diff --git a/src/tools/valgrindfake/valgrindfake.qbs b/src/tools/valgrindfake/valgrindfake.qbs index 6bd0b45e8e5..e19d2f49938 100644 --- a/src/tools/valgrindfake/valgrindfake.qbs +++ b/src/tools/valgrindfake/valgrindfake.qbs @@ -6,6 +6,7 @@ QtcTool { consoleApplication: true destinationDirectory: qtc.ide_bin_path install: false + sanitizable: false Depends { name: "Qt"; submodules: ["network", "xml"]; } files: [ diff --git a/tests/auto/valgrind/memcheck/testapps/testapp.qbs b/tests/auto/valgrind/memcheck/testapps/testapp.qbs index 375024c5007..29614ee2dc8 100644 --- a/tests/auto/valgrind/memcheck/testapps/testapp.qbs +++ b/tests/auto/valgrind/memcheck/testapps/testapp.qbs @@ -4,6 +4,7 @@ QtcAutotest { type: ["application"] // Not to be executed directly by autotest-runner name: "Memcheck " + testName + " autotest" cpp.warningLevel: "none" + sanitizable: false property string testName targetName: testName // Test runner hardcodes the names of the executables destinationDirectory: project.buildDirectory + '/'