From 2df86fee6ab2086535d08f2a6b188a5e500d563f Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Thu, 6 Jul 2023 17:05:46 +0200 Subject: [PATCH] Vcpkg: Parse dependencies from vcpkg.json manifest Also, extend the tests accordingly. Task-number: QTCREATORBUG-29333 Change-Id: I24104b6b0bdbbd47c36cc4d43f4647169fa619d8 Reviewed-by: Cristian Adam --- src/plugins/vcpkg/vcpkg_test.cpp | 7 +++++++ src/plugins/vcpkg/vcpkgsearch.cpp | 9 +++++++++ src/plugins/vcpkg/vcpkgsearch.h | 1 + 3 files changed, 17 insertions(+) diff --git a/src/plugins/vcpkg/vcpkg_test.cpp b/src/plugins/vcpkg/vcpkg_test.cpp index 65079b96a4e..c48e6ec3881 100644 --- a/src/plugins/vcpkg/vcpkg_test.cpp +++ b/src/plugins/vcpkg/vcpkg_test.cpp @@ -21,6 +21,7 @@ void VcpkgSearchTest::testVcpkgJsonParser_data() QTest::addColumn("name"); QTest::addColumn("version"); QTest::addColumn("license"); + QTest::addColumn("dependencies"); QTest::addColumn("shortDescription"); QTest::addColumn("description"); QTest::addColumn("homepage"); @@ -33,6 +34,7 @@ void VcpkgSearchTest::testVcpkgJsonParser_data() "description": "The CImg Library is a small, open-source, and modern C++ toolkit for image processing", "homepage": "https://github.com/dtschump/CImg", "dependencies": [ + "fmt", { "name": "vcpkg-cmake", "host": true @@ -42,6 +44,7 @@ void VcpkgSearchTest::testVcpkgJsonParser_data() << "cimg" << "2.9.9" << "" + << QStringList({"fmt", "vcpkg-cmake"}) << "The CImg Library is a small, open-source, and modern C++ toolkit for image processing" << QStringList() << QUrl::fromUserInput("https://github.com/dtschump/CImg") @@ -62,6 +65,7 @@ void VcpkgSearchTest::testVcpkgJsonParser_data() << "catch-classic" << "1.12.2" << "" + << QStringList() << "A modern, header-only test framework for unit tests" << QStringList({"This is specifically the legacy 1.x branch provided for compatibility", "with older compilers."}) @@ -77,6 +81,7 @@ void VcpkgSearchTest::testVcpkgJsonParser_data() << "" << "1.0" << "WTFPL" + << QStringList() << "foo" << QStringList() << QUrl() @@ -89,6 +94,7 @@ void VcpkgSearchTest::testVcpkgJsonParser() QFETCH(QString, name); QFETCH(QString, version); QFETCH(QString, license); + QFETCH(QStringList, dependencies); QFETCH(QString, shortDescription); QFETCH(QStringList, description); QFETCH(QUrl, homepage); @@ -101,6 +107,7 @@ void VcpkgSearchTest::testVcpkgJsonParser() QCOMPARE(mf.name, name); QCOMPARE(mf.version, version); QCOMPARE(mf.license, license); + QCOMPARE(mf.dependencies, dependencies); QCOMPARE(mf.shortDescription, shortDescription); QCOMPARE(mf.description, description); QCOMPARE(mf.homepage, homepage); diff --git a/src/plugins/vcpkg/vcpkgsearch.cpp b/src/plugins/vcpkg/vcpkgsearch.cpp index 1ed757dd975..175e889a888 100644 --- a/src/plugins/vcpkg/vcpkgsearch.cpp +++ b/src/plugins/vcpkg/vcpkgsearch.cpp @@ -169,6 +169,15 @@ VcpkgManifest parseVcpkgManifest(const QByteArray &vcpkgManifestJsonData, bool * } if (const QJsonValue license = jsonObject.value("license"); !license.isUndefined()) result.license = license.toString(); + if (const QJsonValue deps = jsonObject.value("dependencies"); !deps.isUndefined()) { + const QJsonArray dependencies = deps.toArray(); + for (const QJsonValue &dependency : dependencies) { + if (dependency.isString()) + result.dependencies.append(dependency.toString()); + else if (const QJsonValue name = dependency.toObject().value("name"); name.isString()) + result.dependencies.append(name.toString()); + } + } if (const QJsonValue description = jsonObject.value("description"); !description.isUndefined()) { if (description.isArray()) { const QJsonArray descriptionLines = description.toArray(); diff --git a/src/plugins/vcpkg/vcpkgsearch.h b/src/plugins/vcpkg/vcpkgsearch.h index bb2d568a00c..2f9242257e6 100644 --- a/src/plugins/vcpkg/vcpkgsearch.h +++ b/src/plugins/vcpkg/vcpkgsearch.h @@ -15,6 +15,7 @@ struct VcpkgManifest QString name; QString version; QString license; + QStringList dependencies; QString shortDescription; QStringList description; QUrl homepage;