Skip to content

Commit 81e4d27

Browse files
authored
Merge branch 'OpenAtom-Linyaps:master' into master
2 parents fff019b + fd0b5ca commit 81e4d27

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+6005
-4344
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ repos:
3535
- id: check-xml
3636

3737
- repo: https://github.com/pre-commit/mirrors-clang-format
38-
rev: v21.1.5
38+
rev: v21.1.8
3939
hooks:
4040
- id: clang-format
4141
name: clang-format (C/C++)

api/schema/v1.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1034,7 +1034,8 @@
10341034
"description": "package manager update result",
10351035
"required": [
10361036
"packages",
1037-
"depsOnly"
1037+
"depsOnly",
1038+
"appOnly"
10381039
],
10391040
"properties": {
10401041
"packages": {
@@ -1047,6 +1048,10 @@
10471048
"depsOnly": {
10481049
"type": "boolean",
10491050
"description": "upgrade dependencies only"
1051+
},
1052+
"appOnly": {
1053+
"type": "boolean",
1054+
"description": "upgrade applications only"
10501055
}
10511056
}
10521057
},

api/schema/v1.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,7 @@ $defs:
792792
required:
793793
- packages
794794
- depsOnly
795+
- appOnly
795796
properties:
796797
packages:
797798
type: array
@@ -801,6 +802,9 @@ $defs:
801802
depsOnly:
802803
type: boolean
803804
description: upgrade dependencies only
805+
appOnly:
806+
type: boolean
807+
description: upgrade applications only
804808
PackageManager1ModifyRepoParameters:
805809
type: object
806810
required:

apps/ll-cli/src/main.cpp

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <cstddef>
3333
#include <functional>
3434
#include <memory>
35+
#include <string_view>
3536
#include <thread>
3637

3738
#include <fcntl.h>
@@ -67,36 +68,13 @@ void startProcess(const QString &program, const QStringList &args = {})
6768
std::vector<std::string> transformOldExec(int argc, char **argv) noexcept
6869
{
6970
std::vector<std::string> res;
70-
std::reverse_copy(argv + 1, argv + argc, std::back_inserter(res));
71-
if (std::find(res.rbegin(), res.rend(), "run") == res.rend()) {
72-
return res;
73-
}
74-
75-
auto exec = std::find(res.rbegin(), res.rend(), "--exec");
76-
if (exec == res.rend()) {
77-
return res;
78-
}
7971

80-
if ((exec + 1) == res.rend() || (exec + 2) != res.rend()) {
81-
*exec = "--";
82-
LogD("replace `--exec` with `--`");
83-
return res;
84-
}
85-
86-
wordexp_t words;
87-
auto _ = linglong::utils::finally::finally([&]() {
88-
wordfree(&words);
89-
});
90-
91-
if (auto ret = wordexp((exec + 1)->c_str(), &words, 0); ret != 0) {
92-
LogE("wordexp on {} failed with {} transform old exec arguments failed.", *(exec + 1), ret);
93-
return res;
94-
}
95-
96-
auto it = res.erase(res.rend().base(), exec.base());
97-
res.emplace(it, "--");
98-
for (decltype(words.we_wordc) i = 0; i < words.we_wordc; ++i) {
99-
res.emplace(res.begin(), words.we_wordv[i]);
72+
for (int i = argc - 1; i > 0; --i) {
73+
if (std::string_view(argv[i]) == "--exec") {
74+
res.emplace_back("--");
75+
} else {
76+
res.emplace_back(argv[i]);
77+
}
10078
}
10179

10280
return res;
@@ -355,9 +333,11 @@ void addUpgradeCommand(CLI::App &commandParser,
355333
_("Specify the application ID. If it not be specified, all "
356334
"applications will be upgraded"))
357335
->check(validatorString);
358-
cliUpgrade->add_flag("--deps-only",
359-
upgradeOptions.depsOnly,
360-
_("Only upgrade dependencies of application"));
336+
auto depsOnly = cliUpgrade->add_flag("--deps-only",
337+
upgradeOptions.depsOnly,
338+
_("Only upgrade dependencies of application"));
339+
cliUpgrade->add_flag("--app-only", upgradeOptions.appOnly, _("Only upgrade application"))
340+
->excludes(depsOnly);
361341
}
362342

363343
// Function to add the search subcommand

apps/ll-driver-detect/CMakeLists.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,4 @@ pfl_add_executable(
1616
./src/dbus_notifier.cpp
1717
LINK_LIBRARIES
1818
PRIVATE
19-
CLI11::CLI11
20-
linglong::linglong
21-
linglong::utils)
19+
linglong::linglong)

apps/ll-driver-detect/src/driver_detection_config.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ bool DriverDetectionConfigManager::loadConfig()
4242
}
4343

4444
// Parse configuration
45-
if (jsonConfig.contains("neverRemind") && jsonConfig["neverRemind"].is_boolean()) {
46-
config.neverRemind = jsonConfig["neverRemind"];
45+
auto neverRemindIter = jsonConfig.find("neverRemind");
46+
if (neverRemindIter != jsonConfig.end() && neverRemindIter->is_boolean()) {
47+
config.neverRemind = *neverRemindIter;
4748
}
4849

4950
return true;

apps/ll-driver-detect/src/driver_detection_manager.cpp

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include "driver_detection_manager.h"
66

7+
#include "linglong/utils/cmd.h"
78
#include "linglong/utils/log/log.h"
89
#include "nvidia_driver_detector.h"
910

@@ -14,9 +15,10 @@ DriverDetectionManager::DriverDetectionManager()
1415
registerDetectors();
1516
}
1617

17-
utils::error::Result<DriverDetectionResult> DriverDetectionManager::detectAllDrivers()
18+
utils::error::Result<std::vector<GraphicsDriverInfo>>
19+
DriverDetectionManager::detectAvailableDrivers()
1820
{
19-
DriverDetectionResult result;
21+
std::vector<GraphicsDriverInfo> detectedDrivers;
2022

2123
for (const auto &detector : detectors_) {
2224
auto detectionResult = detector->detect();
@@ -27,13 +29,13 @@ utils::error::Result<DriverDetectionResult> DriverDetectionManager::detectAllDri
2729
continue;
2830
}
2931

30-
result.detectedDrivers.emplace_back(*detectionResult);
32+
detectedDrivers.emplace_back(*detectionResult);
3133
LogD("Detected driver: {} version: {}",
3234
detectionResult->packageName,
33-
detectionResult->version);
35+
detectionResult->packageVersion);
3436
}
3537

36-
return result;
38+
return detectedDrivers;
3739
}
3840

3941
void DriverDetectionManager::registerDetectors()
@@ -46,4 +48,33 @@ void DriverDetectionManager::registerDetectors()
4648
LogD("Registered {} driver detectors", detectors_.size());
4749
}
4850

51+
linglong::utils::error::Result<void>
52+
DriverDetectionManager::installDriverPackage(const std::vector<GraphicsDriverInfo> &drivers)
53+
{
54+
LINGLONG_TRACE("installDriverPackage")
55+
56+
try {
57+
for (const auto &info : drivers) {
58+
LogD("Processing driver: Identify={}, Version={}, Package={}",
59+
info.identify,
60+
info.packageVersion,
61+
info.packageName);
62+
63+
// Execute ll-cli install command to install the package
64+
auto packageRef = info.packageName + "/" + info.packageVersion;
65+
auto ret = linglong::utils::Cmd("ll-cli").exec(
66+
{ "install", packageRef, "--repo", info.repoName });
67+
if (!ret) {
68+
return LINGLONG_ERR("Installation command failed: " + ret.error().message());
69+
}
70+
71+
LogD("Driver package installation command executed successfully: {}", *ret);
72+
}
73+
74+
return LINGLONG_OK;
75+
} catch (const std::exception &e) {
76+
return LINGLONG_ERR("Failed to install driver package: " + std::string(e.what()));
77+
}
78+
}
79+
4980
} // namespace linglong::driver::detect

apps/ll-driver-detect/src/driver_detection_manager.h

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,11 @@
66

77
#include "driver_detector.h"
88

9-
#include <algorithm>
109
#include <memory>
1110
#include <vector>
1211

1312
namespace linglong::driver::detect {
1413

15-
// Result of driver detection for all available drivers
16-
struct DriverDetectionResult
17-
{
18-
std::vector<GraphicsDriverInfo> detectedDrivers;
19-
20-
bool hasAvailableDrivers() const
21-
{
22-
return std::any_of(detectedDrivers.begin(), detectedDrivers.end(), [](const auto &driver) {
23-
return !driver.isInstalled;
24-
});
25-
}
26-
};
27-
2814
// Manager class that coordinates detection of multiple graphics drivers
2915
class DriverDetectionManager
3016
{
@@ -34,12 +20,13 @@ class DriverDetectionManager
3420

3521
// Detect all available graphics drivers on the system
3622
// Returns all detected drivers, or empty vector if none found
37-
utils::error::Result<DriverDetectionResult> detectAllDrivers();
23+
utils::error::Result<std::vector<GraphicsDriverInfo>> detectAvailableDrivers();
24+
linglong::utils::error::Result<void>
25+
installDriverPackage(const std::vector<GraphicsDriverInfo> &drivers);
3826

3927
protected:
4028
// Register all available driver detectors
4129
virtual void registerDetectors();
42-
4330
std::vector<std::unique_ptr<DriverDetector>> detectors_;
4431
};
4532

apps/ll-driver-detect/src/driver_detector.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ namespace linglong::driver::detect {
1313
struct GraphicsDriverInfo
1414
{
1515
std::string identify;
16-
std::string version;
1716
std::string packageName;
18-
bool isInstalled = false;
17+
std::string packageVersion;
18+
std::string repoName{ "stable" };
1919
};
2020

2121
class DriverDetector
@@ -29,6 +29,9 @@ class DriverDetector
2929
// Check if the driver package is installed
3030
virtual utils::error::Result<bool> checkPackageInstalled(const std::string &packageName) = 0;
3131

32+
// Check if the driver package can upgraded
33+
virtual utils::error::Result<bool> checkPackageUpgradable(const std::string &packageName) = 0;
34+
3235
// Get the Identify of driver this detector handles
3336
virtual std::string getDriverIdentify() const = 0;
3437
};

apps/ll-driver-detect/src/main.cpp

Lines changed: 10 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include "driver_detection_manager.h"
1010
#include "driver_detector.h"
1111
#include "linglong/common/global/initialize.h"
12-
#include "linglong/utils/cmd.h"
1312
#include "linglong/utils/error/error.h"
1413
#include "linglong/utils/gettext.h"
1514
#include "tl/expected.hpp"
@@ -86,41 +85,6 @@ linglong::utils::error::Result<DriverDetectionConfigManager> setupConfigManager(
8685
return configManager;
8786
}
8887

89-
linglong::utils::error::Result<void>
90-
installDriverPackage(const std::vector<GraphicsDriverInfo> &drivers)
91-
{
92-
LINGLONG_TRACE("installDriverPackage")
93-
94-
try {
95-
for (const auto &driverInfo : drivers) {
96-
LogD("Processing driver: Identify={}, Version={}, Package={}, Installed={}",
97-
driverInfo.identify,
98-
driverInfo.version,
99-
driverInfo.packageName,
100-
driverInfo.isInstalled);
101-
102-
if (driverInfo.isInstalled) {
103-
LogD("Driver package is already installed: {}", driverInfo.packageName);
104-
continue;
105-
}
106-
107-
// Execute ll-cli install command to install the package
108-
auto ret = linglong::utils::Cmd("ll-cli").exec({ "install", driverInfo.packageName });
109-
if (!ret) {
110-
return LINGLONG_ERR("Installation command failed: " + ret.error().message());
111-
}
112-
113-
LogD("Driver package installation command executed successfully: {}", *ret);
114-
}
115-
116-
return LINGLONG_OK;
117-
} catch (const std::exception &e) {
118-
return LINGLONG_ERR("Failed to install driver package: " + std::string(e.what()));
119-
}
120-
121-
return LINGLONG_OK;
122-
}
123-
12488
} // namespace
12589

12690
int main(int argc, char *argv[])
@@ -191,7 +155,7 @@ int main(int argc, char *argv[])
191155
DriverDetectionManager detectionManager;
192156

193157
// Run driver detection and handling for all available drivers
194-
auto result = detectionManager.detectAllDrivers();
158+
auto result = detectionManager.detectAvailableDrivers();
195159

196160
if (!result) {
197161
LogF("Driver detection failed: {}", result.error().message());
@@ -201,8 +165,8 @@ int main(int argc, char *argv[])
201165

202166
const auto &detectionResult = *result;
203167

204-
if (!detectionResult.hasAvailableDrivers()) {
205-
std::cout << "No available graphics drivers detected or already installed" << std::endl;
168+
if (detectionResult.size() == 0) {
169+
LogD("No graphics drivers detected that require installation or upgrade");
206170
return 0;
207171
}
208172

@@ -211,22 +175,21 @@ int main(int argc, char *argv[])
211175
"will be performed."
212176
<< std::endl;
213177
std::cout << "Detected drivers:" << std::endl;
214-
for (const auto &driverInfo : detectionResult.detectedDrivers) {
178+
for (const auto &info : detectionResult) {
215179
std::cout << "----------------------------------------" << std::endl;
216-
std::cout << " Identify: " << driverInfo.identify << std::endl;
217-
std::cout << " Version: " << driverInfo.version << std::endl;
218-
std::cout << " Package: " << driverInfo.packageName << std::endl;
219-
std::cout << " Installed: " << (driverInfo.isInstalled ? "Yes" : "No") << std::endl;
180+
std::cout << " Identify: " << info.identify << std::endl;
181+
std::cout << " Version: " << info.packageVersion << std::endl;
182+
std::cout << " Package: " << info.packageName << std::endl;
220183
std::cout << "----------------------------------------" << std::endl;
221184
}
222185
return 0;
223186
}
224187

225-
LogD("Detected {} graphics driver(s)", detectionResult.detectedDrivers.size());
188+
LogD("Detected {} graphics driver(s)", detectionResult.size());
226189

227190
if (options.installOnly) {
228191
std::cout << "Install-only: installing detected drivers without notifications" << std::endl;
229-
auto installResult = installDriverPackage(detectionResult.detectedDrivers);
192+
auto installResult = detectionManager.installDriverPackage(detectionResult);
230193
if (!installResult) {
231194
LogW("Failed to install driver package {}: {}",
232195
options.packageName,
@@ -270,7 +233,7 @@ int main(int argc, char *argv[])
270233
if (response.action == kActionInstallNow && response.success) {
271234
LogD("User chose to install graphics driver");
272235

273-
auto installResult = installDriverPackage(detectionResult.detectedDrivers);
236+
auto installResult = detectionManager.installDriverPackage(detectionResult);
274237
if (!installResult) {
275238
LogW("Failed to install driver package: {}", installResult.error().message());
276239
return 1;

0 commit comments

Comments
 (0)