Skip to content

Commit c11d35d

Browse files
committed
Make BootImage movable and inherit from FlagBase and remove reference dependencies
This will help put it in a flags struct. Bug: b/472361611
1 parent 5d85475 commit c11d35d

File tree

5 files changed

+30
-30
lines changed

5 files changed

+30
-30
lines changed

base/cvd/cuttlefish/host/commands/assemble_cvd/disk_image_flags_vectorization.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ Result<void> DiskImageFlagsVectorization(
9999
for (const auto& num : instance_nums) {
100100
auto instance = config.ForInstance(num);
101101
instance.set_images_dir(system_image_dir.ForIndex(instance_index));
102-
std::string cur_boot_image = boot_image.BootImageForIndex(instance_index);
102+
std::string cur_boot_image = boot_image.ForIndex(instance_index);
103103
instance.set_boot_image(cur_boot_image);
104104
instance.set_new_boot_image(cur_boot_image);
105105

base/cvd/cuttlefish/host/commands/assemble_cvd/flags/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,10 @@ cf_cc_library(
5454
hdrs = ["boot_image.h"],
5555
deps = [
5656
"//cuttlefish/host/commands/assemble_cvd:flags_defaults",
57+
"//cuttlefish/host/commands/assemble_cvd/flags:flag_base",
5758
"//cuttlefish/host/commands/assemble_cvd/flags:system_image_dir",
5859
"//libbase",
60+
"@abseil-cpp//absl/strings",
5961
"@gflags",
6062
],
6163
)

base/cvd/cuttlefish/host/commands/assemble_cvd/flags/boot_image.cc

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
2020
#include <string>
2121
#include <vector>
2222

23-
#include <android-base/strings.h>
24-
#include <gflags/gflags.h>
23+
#include "absl/strings/str_cat.h"
24+
#include "absl/strings/str_split.h"
25+
#include "gflags/gflags.h"
2526

2627
#include "cuttlefish/host/commands/assemble_cvd/flags/system_image_dir.h"
2728
#include "cuttlefish/host/commands/assemble_cvd/flags_defaults.h"
@@ -31,34 +32,33 @@ DEFINE_string(boot_image, CF_DEFAULTS_BOOT_IMAGE,
3132
"boot.img in the directory specified by -system_image_dir.");
3233

3334
namespace cuttlefish {
35+
namespace {
36+
37+
static constexpr std::string_view kName = "boot.img";
38+
39+
std::vector<std::string> Defaults(const SystemImageDirFlag& system_image_dirs) {
40+
std::vector<std::string> defaults;
41+
for (std::string_view system_image_dir : system_image_dirs.AsVector()) {
42+
defaults.emplace_back(absl::StrCat(system_image_dir, "/", kName));
43+
}
44+
return defaults;
45+
}
46+
47+
} // namespace
3448

3549
BootImageFlag BootImageFlag::FromGlobalGflags(
3650
const SystemImageDirFlag& system_image_dir) {
3751
gflags::CommandLineFlagInfo flag_info =
3852
gflags::GetCommandLineFlagInfoOrDie("boot_image");
3953

40-
std::vector<std::string> boot_images =
41-
flag_info.is_default ? std::vector<std::string>{}
42-
: android::base::Split(FLAGS_boot_image, ",");
43-
44-
return BootImageFlag(system_image_dir, boot_images);
45-
}
46-
47-
std::string BootImageFlag::BootImageForIndex(size_t index) const {
48-
if (boot_images_.empty()) {
49-
return system_image_dir_.ForIndex(index) + "/boot.img";
50-
} else if (index < boot_images_.size()) {
51-
return boot_images_[index];
52-
} else {
53-
return boot_images_[0];
54-
}
54+
return flag_info.is_default
55+
? BootImageFlag(Defaults(system_image_dir), true)
56+
: BootImageFlag(absl::StrSplit(FLAGS_boot_image, ","), false);
5557
}
5658

57-
bool BootImageFlag::IsDefault() const { return boot_images_.empty(); }
59+
bool BootImageFlag::IsDefault() const { return is_default_; }
5860

59-
BootImageFlag::BootImageFlag(const SystemImageDirFlag& system_image_dir,
60-
std::vector<std::string> boot_images)
61-
: system_image_dir_(system_image_dir),
62-
boot_images_(std::move(boot_images)) {}
61+
BootImageFlag::BootImageFlag(std::vector<std::string> paths, bool is_default)
62+
: FlagBase(std::move(paths)), is_default_(is_default) {}
6363

6464
} // namespace cuttlefish

base/cvd/cuttlefish/host/commands/assemble_cvd/flags/boot_image.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,22 @@
2020
#include <string>
2121
#include <vector>
2222

23+
#include "cuttlefish/host/commands/assemble_cvd/flags/flag_base.h"
2324
#include "cuttlefish/host/commands/assemble_cvd/flags/system_image_dir.h"
2425

2526
namespace cuttlefish {
2627

2728
/* Android boot image path flag, --boot_image */
28-
class BootImageFlag {
29+
class BootImageFlag : public FlagBase<std::string> {
2930
public:
3031
static BootImageFlag FromGlobalGflags(const SystemImageDirFlag&);
3132

32-
std::string BootImageForIndex(size_t index) const;
33-
3433
bool IsDefault() const;
3534

3635
private:
37-
BootImageFlag(const SystemImageDirFlag&, std::vector<std::string>);
36+
BootImageFlag(std::vector<std::string>, bool is_default);
3837

39-
const SystemImageDirFlag& system_image_dir_;
40-
std::vector<std::string> boot_images_;
38+
bool is_default_;
4139
};
4240

4341
} // namespace cuttlefish

base/cvd/cuttlefish/host/commands/assemble_cvd/guest_config.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ Result<std::vector<GuestConfig>> ReadGuestConfig(
261261
// for the ikconfig header in the image before extracting the config list.
262262
// This code is liable to break if the boot image ever includes the
263263
// ikconfig header outside the kernel.
264-
std::string cur_boot_image = boot_image.BootImageForIndex(instance_index);
264+
std::string cur_boot_image = boot_image.ForIndex(instance_index);
265265

266266
if (!kernel_path.KernelPathForIndex(instance_index).empty()) {
267267
kernel_image_path = kernel_path.KernelPathForIndex(instance_index);

0 commit comments

Comments
 (0)