aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvan Komissarov <[email protected]>2024-01-04 20:49:45 +0300
committerIvan Komissarov <[email protected]>2024-07-11 15:12:21 +0000
commit93a1a2fa611906e3fe43213da0a6b1e1d8475ad8 (patch)
tree9391d78a637b87e5b39f631c2ff9dba55804e413
parentc415cd11a680bdc86d6509522b728aaa40608785 (diff)
Do not add external deps for static libs
For some reason, Qbs tried to be smart and add external libraries for direct static libs. Unfortunately, this doesn't work in the common case without exporting cpp.libraryPaths. So, remove this functionality since such external deps should be pulled in using Export item. This reverts e16dd899d5d8329aaa83b77393e50e5feba247ca. Releates: QBS-1728 Change-Id: If404cc7ad5c7c538ff3ded2a7b4a733da35d53bf Reviewed-by: Christian Kandeler <[email protected]>
-rw-r--r--doc/reference/modules/cpp-module.qdoc35
-rw-r--r--share/qbs/modules/cpp/CppModule.qbs2
-rw-r--r--share/qbs/modules/cpp/cpp.js3
-rw-r--r--share/qbs/modules/cpp/gcc.js3
-rw-r--r--tests/auto/api/tst_api.cpp3
-rw-r--r--tests/auto/blackbox/testdata/static-lib-deps/a1.cpp (renamed from tests/auto/api/testdata/static-lib-deps/a1.cpp)0
-rw-r--r--tests/auto/blackbox/testdata/static-lib-deps/a2.cpp (renamed from tests/auto/api/testdata/static-lib-deps/a2.cpp)0
-rw-r--r--tests/auto/blackbox/testdata/static-lib-deps/b.cpp (renamed from tests/auto/api/testdata/static-lib-deps/b.cpp)0
-rw-r--r--tests/auto/blackbox/testdata/static-lib-deps/c.cpp (renamed from tests/auto/api/testdata/static-lib-deps/c.cpp)0
-rw-r--r--tests/auto/blackbox/testdata/static-lib-deps/d.cpp (renamed from tests/auto/api/testdata/static-lib-deps/d.cpp)26
-rw-r--r--tests/auto/blackbox/testdata/static-lib-deps/d.mm (renamed from tests/auto/api/testdata/static-lib-deps/d.mm)0
-rw-r--r--tests/auto/blackbox/testdata/static-lib-deps/e.cpp (renamed from tests/auto/api/testdata/static-lib-deps/e.cpp)0
-rw-r--r--tests/auto/blackbox/testdata/static-lib-deps/main.cpp (renamed from tests/auto/api/testdata/static-lib-deps/main.cpp)0
-rw-r--r--tests/auto/blackbox/testdata/static-lib-deps/static-lib-deps.qbs (renamed from tests/auto/api/testdata/static-lib-deps/static-lib-deps.qbs)42
-rw-r--r--tests/auto/blackbox/tst_blackbox.cpp30
-rw-r--r--tests/auto/blackbox/tst_blackbox.h2
16 files changed, 119 insertions, 27 deletions
diff --git a/doc/reference/modules/cpp-module.qdoc b/doc/reference/modules/cpp-module.qdoc
index 2b344aac2..980602964 100644
--- a/doc/reference/modules/cpp-module.qdoc
+++ b/doc/reference/modules/cpp-module.qdoc
@@ -1941,3 +1941,38 @@
\windowsproperty
\defaultvalue \c{true} for MSVC, \c{false} for clang-cl
*/
+
+/*!
+ \qmlproperty string cpp::importPrivateLibraries
+ \since Qbs 2.4
+
+ Whether to automatically import external libraries from dependencies.
+
+ If set to true in the product that depends on the static library, the external dependencies
+ (such as \l{cpp::staticLibraries}{staticLibraries} and
+ \l{cpp::dynamicLibraries}{dynamicLibraries}) of this library are also added to products that
+ depend on this library.
+ \code
+ StaticLibrary {
+ files: "lib.cpp"
+ cpp.staticLibraries: ["l", "y"]
+ }
+ \endcode
+
+ If set to false, the explicit \l{Export} item is required:
+ \code
+ StaticLibrary {
+ files: "lib.cpp"
+ Export {
+ Depends { name: "cpp" }
+ cpp.staticLibraries: ["l", "y"]
+ }
+ }
+ \endcode
+
+ We recommend using the \l{Export} item as it provides more flexibility.
+
+ \note The default value is subject to change.
+
+ \defaultvalue \c{true}
+*/
diff --git a/share/qbs/modules/cpp/CppModule.qbs b/share/qbs/modules/cpp/CppModule.qbs
index bd1eaa242..22e6cc81a 100644
--- a/share/qbs/modules/cpp/CppModule.qbs
+++ b/share/qbs/modules/cpp/CppModule.qbs
@@ -417,6 +417,8 @@ Module {
property bool validateTargetTriple: true // undocumented
+ property bool importPrivateLibraries: true
+
// TODO: The following four rules could use a convenience base item if rule properties
// were available in Artifact items and prepare scripts.
Rule {
diff --git a/share/qbs/modules/cpp/cpp.js b/share/qbs/modules/cpp/cpp.js
index 9f907580a..084f17f69 100644
--- a/share/qbs/modules/cpp/cpp.js
+++ b/share/qbs/modules/cpp/cpp.js
@@ -283,7 +283,8 @@ function collectLibraryDependencies(product) {
seen[dep.name] = true;
dep.dependencies.forEach(traverse);
addArtifactFilePaths(dep, staticLibraryArtifacts);
- addExternalLibs(dep);
+ if (product.cpp.importPrivateLibraries)
+ addExternalLibs(dep);
} else if (dynamicLibraryArtifacts) {
seen[dep.name] = true;
addArtifactFilePaths(dep, dynamicLibraryArtifacts);
diff --git a/share/qbs/modules/cpp/gcc.js b/share/qbs/modules/cpp/gcc.js
index 90f8fc933..8d1deb842 100644
--- a/share/qbs/modules/cpp/gcc.js
+++ b/share/qbs/modules/cpp/gcc.js
@@ -187,7 +187,8 @@ function collectLibraryDependencies(product, isDarwin) {
if (isStaticLibrary) {
if (!isBelowIndirectDynamicLib) {
addArtifactFilePaths(dep, "staticlibrary", addPublicFilePath);
- addExternalLibs(dep);
+ if (product.cpp.importPrivateLibraries)
+ addExternalLibs(dep);
publicDeps[dep.name] = true;
}
} else if (isDynamicLibrary) {
diff --git a/tests/auto/api/tst_api.cpp b/tests/auto/api/tst_api.cpp
index 45463312b..3b8ced680 100644
--- a/tests/auto/api/tst_api.cpp
+++ b/tests/auto/api/tst_api.cpp
@@ -427,9 +427,6 @@ void TestApi::buildProject_data()
QTest::newRow("source files with the same base name but different extensions")
<< QString("same-base-name")
<< relativeExecutableFilePath("basename");
- QTest::newRow("static library dependencies")
- << QString("static-lib-deps")
- << relativeExecutableFilePath("staticLibDeps");
QTest::newRow("simple probes")
<< QString("simple-probe")
<< relativeExecutableFilePath("MyApp");
diff --git a/tests/auto/api/testdata/static-lib-deps/a1.cpp b/tests/auto/blackbox/testdata/static-lib-deps/a1.cpp
index 460eb52e6..460eb52e6 100644
--- a/tests/auto/api/testdata/static-lib-deps/a1.cpp
+++ b/tests/auto/blackbox/testdata/static-lib-deps/a1.cpp
diff --git a/tests/auto/api/testdata/static-lib-deps/a2.cpp b/tests/auto/blackbox/testdata/static-lib-deps/a2.cpp
index 4ab7404f7..4ab7404f7 100644
--- a/tests/auto/api/testdata/static-lib-deps/a2.cpp
+++ b/tests/auto/blackbox/testdata/static-lib-deps/a2.cpp
diff --git a/tests/auto/api/testdata/static-lib-deps/b.cpp b/tests/auto/blackbox/testdata/static-lib-deps/b.cpp
index cec544205..cec544205 100644
--- a/tests/auto/api/testdata/static-lib-deps/b.cpp
+++ b/tests/auto/blackbox/testdata/static-lib-deps/b.cpp
diff --git a/tests/auto/api/testdata/static-lib-deps/c.cpp b/tests/auto/blackbox/testdata/static-lib-deps/c.cpp
index 0ca246c8a..0ca246c8a 100644
--- a/tests/auto/api/testdata/static-lib-deps/c.cpp
+++ b/tests/auto/blackbox/testdata/static-lib-deps/c.cpp
diff --git a/tests/auto/api/testdata/static-lib-deps/d.cpp b/tests/auto/blackbox/testdata/static-lib-deps/d.cpp
index a7ecfd1ee..f0906e2a3 100644
--- a/tests/auto/api/testdata/static-lib-deps/d.cpp
+++ b/tests/auto/blackbox/testdata/static-lib-deps/d.cpp
@@ -26,12 +26,12 @@
**
****************************************************************************/
+#if defined(WITH_ZLIB)
+#include <zlib.h>
+#endif
+
#ifdef WITH_PTHREAD
#include <pthread.h>
-#elif defined(WITH_LEX_YACC)
-extern "C" int yywrap(void);
-extern "C" void yyerror(char const *s);
-extern void printGreeting();
#elif defined(WITH_SETUPAPI)
#include <windows.h>
#include <Setupapi.h>
@@ -44,21 +44,21 @@ int d()
{
b();
c();
+ int result = 0;
+#if defined(WITH_ZLIB)
+ const char source[] = "Hello, world";
+ uLongf buffer_size = compressBound(sizeof(source));
+ result += static_cast<int>(buffer_size);
+#endif
#ifdef WITH_PTHREAD
pthread_t self = pthread_self();
- return static_cast<int>(self);
-#elif defined(WITH_LEX_YACC)
- yywrap();
- yyerror("no error");
- printGreeting();
- return 0;
+ result += static_cast<int>(self);
#elif defined(WITH_SETUPAPI)
CABINET_INFO ci;
ci.SetId = 0;
SetupIterateCabinet(L"invalid-file-path", 0, NULL, NULL);
- return ci.SetId;
-#else
- return 0;
+ result += ci.SetId;
#endif
+ return result;
}
diff --git a/tests/auto/api/testdata/static-lib-deps/d.mm b/tests/auto/blackbox/testdata/static-lib-deps/d.mm
index 5bf48966f..5bf48966f 100644
--- a/tests/auto/api/testdata/static-lib-deps/d.mm
+++ b/tests/auto/blackbox/testdata/static-lib-deps/d.mm
diff --git a/tests/auto/api/testdata/static-lib-deps/e.cpp b/tests/auto/blackbox/testdata/static-lib-deps/e.cpp
index aea27921a..aea27921a 100644
--- a/tests/auto/api/testdata/static-lib-deps/e.cpp
+++ b/tests/auto/blackbox/testdata/static-lib-deps/e.cpp
diff --git a/tests/auto/api/testdata/static-lib-deps/main.cpp b/tests/auto/blackbox/testdata/static-lib-deps/main.cpp
index b42d35a2e..b42d35a2e 100644
--- a/tests/auto/api/testdata/static-lib-deps/main.cpp
+++ b/tests/auto/blackbox/testdata/static-lib-deps/main.cpp
diff --git a/tests/auto/api/testdata/static-lib-deps/static-lib-deps.qbs b/tests/auto/blackbox/testdata/static-lib-deps/static-lib-deps.qbs
index 67800b8eb..8d7b9df78 100644
--- a/tests/auto/api/testdata/static-lib-deps/static-lib-deps.qbs
+++ b/tests/auto/blackbox/testdata/static-lib-deps/static-lib-deps.qbs
@@ -1,4 +1,5 @@
Project {
+ property bool useExport: true
StaticLibrary {
name: "a"
@@ -44,25 +45,45 @@ Project {
]
Group {
- condition: qbs.targetOS.includes("macos")
+ condition: qbs.targetOS.includes("darwin")
files: ["d.mm"]
}
Properties {
condition: qbs.targetOS.includes("windows")
cpp.defines: ["WITH_SETUPAPI"]
- cpp.staticLibraries: ["setupapi"]
+ cpp.staticLibraries: !project.useExport ? ["setupapi"] : []
}
Properties {
- condition: qbs.targetOS.includes("macos")
- cpp.defines: ["WITH_LEX_YACC"]
- cpp.staticLibraries: ["l", "y"]
- cpp.frameworks: ["Foundation"]
+ condition: qbs.targetOS.includes("darwin")
+ cpp.defines: ["WITH_ZLIB"]
+ cpp.staticLibraries: !project.useExport ? ["z"] : []
+ cpp.frameworks: !project.useExport ? ["Foundation"] : []
}
Properties {
- condition: qbs.targetOS.includes("linux")
- cpp.defines: ["WITH_PTHREAD"]
- cpp.staticLibraries: ["pthread"]
+ condition: {
+ console.info(qbs.targetOS);
+ return qbs.targetOS.includes("linux")
+ }
+ cpp.defines: ["WITH_PTHREAD", "WITH_ZLIB"]
+ cpp.staticLibraries: !project.useExport ? ["pthread", "z"] : []
+ }
+ Export {
+ condition : project.useExport
+ Depends { name: "cpp" }
+ Properties {
+ condition: qbs.targetOS.contains("linux")
+ cpp.staticLibraries: ["pthread", "z"]
+ }
+ Properties {
+ condition: qbs.targetOS.contains("darwin")
+ cpp.staticLibraries: ["z"]
+ cpp.frameworks: ["Foundation"]
+ }
+ Properties {
+ condition: qbs.targetOS.contains("windows")
+ cpp.staticLibraries: ["setupapi"]
+ }
}
}
StaticLibrary {
@@ -75,6 +96,9 @@ Project {
files: [
"e.cpp",
]
+ Export {
+ Depends { name: "d" }
+ }
}
CppApplication {
name: "staticLibDeps"
diff --git a/tests/auto/blackbox/tst_blackbox.cpp b/tests/auto/blackbox/tst_blackbox.cpp
index ef5fa8426..5c5959d1a 100644
--- a/tests/auto/blackbox/tst_blackbox.cpp
+++ b/tests/auto/blackbox/tst_blackbox.cpp
@@ -2977,6 +2977,36 @@ void TestBlackbox::setupRunEnvironment()
m_qbsStdout.constData());
}
+void TestBlackbox::staticLibDeps()
+{
+ QFETCH(bool, withExport);
+ QFETCH(bool, importPrivateLibraries);
+ QFETCH(bool, successExpected);
+
+ QDir::setCurrent(testDataDir + "/static-lib-deps");
+ rmDirR(relativeBuildDir());
+
+ QStringList args{
+ QStringLiteral("project.useExport:%1").arg(withExport ? "true" : "false"),
+ QStringLiteral("modules.cpp.importPrivateLibraries:%1")
+ .arg(importPrivateLibraries ? "true" : "false")};
+ QbsRunParameters params(args);
+ params.expectFailure = !successExpected;
+ QCOMPARE(runQbs(params) == 0, successExpected);
+}
+
+void TestBlackbox::staticLibDeps_data()
+{
+ QTest::addColumn<bool>("withExport");
+ QTest::addColumn<bool>("importPrivateLibraries");
+ QTest::addColumn<bool>("successExpected");
+
+ QTest::newRow("no Export, with import") << false << true << true;
+ QTest::newRow("no Export, no import") << false << false << false;
+ QTest::newRow("with Export, with import") << true << true << true;
+ QTest::newRow("with Export, no import") << true << false << true;
+}
+
void TestBlackbox::smartRelinking()
{
QDir::setCurrent(testDataDir + "/smart-relinking");
diff --git a/tests/auto/blackbox/tst_blackbox.h b/tests/auto/blackbox/tst_blackbox.h
index 3f817b481..ef3e2af97 100644
--- a/tests/auto/blackbox/tst_blackbox.h
+++ b/tests/auto/blackbox/tst_blackbox.h
@@ -306,6 +306,8 @@ private slots:
void scanResultInNonDependency();
void setupBuildEnvironment();
void setupRunEnvironment();
+ void staticLibDeps();
+ void staticLibDeps_data();
void smartRelinking();
void smartRelinking_data();
void soVersion();