Skip to content

Commit 53e6ef6

Browse files
committed
refactor: fix compiler warnings across runtime and utils
- std::reference_wrapper causing the compiler to trigger SFINAE trait checks on RunContext while it was still an incomplete type. So replace it with raw pointer - Fixed some warnings caused by the use of C++20 extensions - Add [[nodiscard]], noexcept, explicit enum types - Extract RuntimeLayer to separate compilation unit Signed-off-by: Yuming He <ComixHe1895@outlook.com>
1 parent e83168e commit 53e6ef6

19 files changed

Lines changed: 321 additions & 240 deletions

File tree

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ NVIDIADriverDetector::getPackageInfoFromRemoteRepo(const std::string &packageNam
8282

8383
LINGLONG_TRACE("Check if NVIDIA driver package exists in repository");
8484

85-
GraphicsDriverInfo driverInfo{ getDriverIdentify(), packageName };
85+
GraphicsDriverInfo driverInfo;
86+
driverInfo.identify = getDriverIdentify();
87+
driverInfo.packageName = packageName;
8688
// Execute ll-cli search command to check driver package existence
8789
auto ret = linglong::utils::Cmd("ll-cli").exec({ "--json", "search", packageName });
8890
if (!ret) {
@@ -192,7 +194,9 @@ NVIDIADriverDetector::getInstalledGraphicsDriverInfo(const std::string &packageN
192194

193195
LINGLONG_TRACE("Get installed NVIDIA graphics driver info");
194196

195-
GraphicsDriverInfo driverInfo{ getDriverIdentify(), packageName };
197+
GraphicsDriverInfo driverInfo;
198+
driverInfo.identify = getDriverIdentify();
199+
driverInfo.packageName = packageName;
196200

197201
auto listResult = linglong::utils::Cmd("ll-cli").exec({ "--json", "list", "--type=extension" });
198202
if (!listResult) {

libs/linglong/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ pfl_add_library(
107107
src/linglong/runtime/container_builder.h
108108
src/linglong/runtime/container.cpp
109109
src/linglong/runtime/container.h
110+
src/linglong/runtime/layer.cpp
111+
src/linglong/runtime/layer.h
110112
src/linglong/runtime/overlayfs_driver.cpp
111113
src/linglong/runtime/overlayfs_driver.h
112114
src/linglong/runtime/run_context.cpp

libs/linglong/src/linglong/cli/cli.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
#include "linglong/common/dir.h"
3030
#include "linglong/common/error.h"
3131
#include "linglong/common/strings.h"
32-
#include "linglong/oci-cfg-generators/container_cfg_builder.h"
3332
#include "linglong/package/layer_file.h"
3433
#include "linglong/package/reference.h"
3534
#include "linglong/repo/config.h"
@@ -42,7 +41,6 @@
4241
#include "linglong/utils/gettext.h"
4342
#include "linglong/utils/namespace.h"
4443
#include "linglong/utils/runtime_config.h"
45-
#include "linglong/utils/xdg/directory.h"
4644
#include "linglong/utils/xdp.h"
4745
#include "ocppi/runtime/ExecOption.hpp"
4846
#include "ocppi/runtime/RunOption.hpp"

libs/linglong/src/linglong/cli/cli.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include "linglong/api/dbus/v1/task.h"
1111
#include "linglong/api/types/v1/CommonOptions.hpp"
1212
#include "linglong/api/types/v1/PackageInfoDisplay.hpp"
13-
#include "linglong/api/types/v1/RepositoryCacheLayersItem.hpp"
1413
#include "linglong/cli/interactive_notifier.h"
1514
#include "linglong/cli/printer.h"
1615
#include "linglong/common/serialize/json.h"

libs/linglong/src/linglong/package_manager/package_task.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515

1616
#include <utility>
1717

18-
const auto TASK_DONE = 100;
19-
2018
namespace linglong::service {
2119

2220
PackageTask::PackageTask(std::function<void(Task &)> job, QObject *parent)

libs/linglong/src/linglong/repo/ostree_repo.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,7 +1352,7 @@ OSTreeRepo::getRefStatistics(const RefMetaData &meta) const noexcept
13521352
}
13531353
g_clear_error(&gErr);
13541354

1355-
RefStatistics stat = { 0 };
1355+
RefStatistics stat{};
13561356

13571357
#if OSTREE_CHECK_VERSION(2020, 1)
13581358
g_autoptr(GPtrArray) sizes = NULL;
@@ -2100,12 +2100,12 @@ utils::error::Result<void> OSTreeRepo::exportDir(const std::string &appID,
21002100
&& common::strings::ends_with(target_path.string(), ".desktop")) {
21012101
auto desktopExists = false;
21022102
// 如果要导出的desktop已存在,则覆盖导出(无论是在default还是overlay中),避免桌面和任务栏的快捷方式失效
2103-
const std::string appDirs[] = { oldAppDir, newAppDir };
2103+
const std::array<std::string, 2> appDirs{ oldAppDir, newAppDir };
21042104
for (const auto &appDir : appDirs) {
21052105
// 如果目标文件存在,删除再导出
2106-
std::filesystem::path linkpath =
2106+
const std::filesystem::path linkpath =
21072107
target_path.string().replace(0, oldAppDir.string().length(), appDir);
2108-
auto status = std::filesystem::symlink_status(linkpath, ec);
2108+
std::ignore = std::filesystem::symlink_status(linkpath, ec);
21092109
if (!ec) {
21102110
desktopExists = true;
21112111
auto target = source_path.lexically_relative(linkpath.parent_path());

libs/linglong/src/linglong/runtime/container.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include <cassert>
2424
#include <fstream>
25+
#include <memory>
2526
#include <utility>
2627

2728
#include <unistd.h>
@@ -143,10 +144,9 @@ auto ContainerContext::create(RunContext &context, CreateOptions options)
143144
}
144145
}
145146

146-
auto containerContext =
147-
std::unique_ptr<ContainerContext>{ new ContainerContext(std::move(containerID),
148-
std::move(*bundleDir),
149-
std::move(options.appCache)) };
147+
auto containerContext = std::make_unique<ContainerContext>(containerID,
148+
std::move(*bundleDir),
149+
std::move(options.appCache));
150150

151151
return containerContext;
152152
}

libs/linglong/src/linglong/runtime/container.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class ContainerContext
5151
[[nodiscard]] auto getBundleDir() const -> const std::filesystem::path &;
5252
[[nodiscard]] auto getContainerCache() const -> const std::optional<std::filesystem::path> &;
5353
void addSecurityContext(std::unique_ptr<SecurityContext> securityContext);
54-
auto setupOverlayFS(RunContext &context, bool readOnly) -> utils::error::Result<void>;
54+
auto setupOverlayFS(RunContext &context, bool persistent) -> utils::error::Result<void>;
5555
auto genLdConf(const std::string &ldConf, bool overlayEnabled) -> utils::error::Result<void>;
5656

5757
private:

libs/linglong/src/linglong/runtime/container_builder.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ auto getXDPDocumentsMountPoint() noexcept -> utils::error::Result<std::filesyste
6262
return LINGLONG_ERR("Documents portal mount point reply is empty");
6363
}
6464

65-
const auto &value = reply.arguments().constFirst();
65+
auto arguments = reply.arguments();
66+
const auto &value = arguments.constFirst();
6667
if (!value.canConvert<QByteArray>()) {
6768
return LINGLONG_ERR(
6869
fmt::format("unexpected Documents portal mount point type: {}", value.typeName()));
@@ -306,7 +307,7 @@ auto ContainerBuilder::prepareContainer(runtime::RunContext &context,
306307
}
307308

308309
PreparedContainer prepared{
309-
.runContext = context,
310+
.runContext = &context,
310311
.context = std::move(*containerContext),
311312
.mode = mode,
312313
};
@@ -323,7 +324,7 @@ auto ContainerBuilder::prepareContainer(runtime::RunContext &context,
323324
auto uid = getuid();
324325
auto gid = getgid();
325326

326-
prepared.cfgBuilder.setAppId(prepared.runContext.get().getTargetID())
327+
prepared.cfgBuilder.setAppId(prepared.runContext->getTargetID())
327328
.setBundlePath(prepared.context->getBundleDir())
328329
.addUIdMapping(uid, uid, 1)
329330
.addGIdMapping(gid, gid, 1)
@@ -353,8 +354,7 @@ auto ContainerBuilder::finalizeContainer(PreparedContainer &prepared) noexcept
353354
bool useOverlayMode = true;
354355
bool needGenLdConf = false;
355356
if (prepared.mode == ContainerMode::Init) {
356-
auto &runContext = prepared.runContext.get();
357-
const auto &appLayer = runContext.getAppLayer();
357+
const auto &appLayer = prepared.runContext->getAppLayer();
358358
if (!appLayer) {
359359
return LINGLONG_ERR("app layer not found");
360360
}
@@ -407,8 +407,7 @@ auto ContainerBuilder::configureBuildContainer(PreparedContainer &prepared,
407407
prepared.cfgBuilder.isolateNetWork();
408408
}
409409

410-
auto &runContext = prepared.runContext.get();
411-
auto res = normalizeContainerRootfs(options.basePath, runContext.getConfig());
410+
auto res = normalizeContainerRootfs(options.basePath, prepared.runContext->getConfig());
412411
if (!res) {
413412
return LINGLONG_ERR(res);
414413
}
@@ -460,7 +459,7 @@ auto ContainerBuilder::configureInitContainer(PreparedContainer &prepared) noexc
460459
{
461460
LINGLONG_TRACE("configure init container");
462461

463-
auto &runContext = prepared.runContext.get();
462+
auto &runContext = *prepared.runContext;
464463

465464
prepared.cfgBuilder.bindXDGRuntime().bindHostRoot().bindHostStatics().forwardDefaultEnv();
466465

@@ -582,7 +581,7 @@ auto ContainerBuilder::configureRunContainer(PreparedContainer &prepared,
582581
capabilities.insert(capabilities.end(), extraCapabilities.begin(), extraCapabilities.end());
583582
prepared.cfgBuilder.setCapabilities(std::move(capabilities));
584583

585-
auto &runContext = prepared.runContext.get();
584+
auto &runContext = *prepared.runContext;
586585
for (const auto &type : options.getSecurityContexts()) {
587586
auto manager = getSecurityContextManager(type);
588587
if (!manager) {

libs/linglong/src/linglong/runtime/container_builder.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class ContainerBuilder
9595
-> utils::error::Result<std::unique_ptr<Container>>;
9696

9797
private:
98-
enum class ContainerMode {
98+
enum class ContainerMode : uint8_t {
9999
Init,
100100
Build,
101101
Run,
@@ -104,7 +104,7 @@ class ContainerBuilder
104104
struct PreparedContainer
105105
{
106106
generator::ContainerCfgBuilder cfgBuilder;
107-
std::reference_wrapper<runtime::RunContext> runContext;
107+
runtime::RunContext *runContext{ nullptr };
108108
std::unique_ptr<ContainerContext> context;
109109
ContainerMode mode{ ContainerMode::Run };
110110
};

0 commit comments

Comments
 (0)