Skip to content

Commit 8ab2621

Browse files
committed
Migrate use_cvdalloc to a dedicated flag type.
Eventually, we will interpose default value handling for ramping up enablement of this feature. For now, there should be no functional changes intended.
1 parent 8ea98b6 commit 8ab2621

File tree

6 files changed

+106
-5
lines changed

6 files changed

+106
-5
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ cf_cc_library(
282282
"//cuttlefish/host/commands/assemble_cvd/flags:mcu_config_path",
283283
"//cuttlefish/host/commands/assemble_cvd/flags:super_image",
284284
"//cuttlefish/host/commands/assemble_cvd/flags:system_image_dir",
285+
"//cuttlefish/host/commands/assemble_cvd/flags:use_cvdalloc",
285286
"//cuttlefish/host/commands/assemble_cvd/flags:vendor_boot_image",
286287
"//cuttlefish/host/commands/assemble_cvd/flags:vm_manager",
287288
"//cuttlefish/host/commands/cvdalloc:interface",

base/cvd/cuttlefish/host/commands/assemble_cvd/assemble_cvd_flags.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,6 @@ DEFINE_vec(
115115
"Frame socket path to use when launching a VM "
116116
"For example, \"--frames_socket_path=${XDG_RUNTIME_DIR}/wayland-0\"");
117117

118-
DEFINE_vec(use_cvdalloc, CF_DEFAULTS_USE_CVDALLOC? "true": "false",
119-
"Acquire static resources with cvdalloc.");
120-
121118
DEFINE_vec(
122119
enable_minimal_mode, CF_DEFAULTS_ENABLE_MINIMAL_MODE ? "true" : "false",
123120
"Only enable the minimum features to boot a cuttlefish device and "

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
#include "cuttlefish/host/commands/assemble_cvd/flags/kernel_path.h"
6161
#include "cuttlefish/host/commands/assemble_cvd/flags/mcu_config_path.h"
6262
#include "cuttlefish/host/commands/assemble_cvd/flags/system_image_dir.h"
63+
#include "cuttlefish/host/commands/assemble_cvd/flags/use_cvdalloc.h"
6364
#include "cuttlefish/host/commands/assemble_cvd/flags/vendor_boot_image.h"
6465
#include "cuttlefish/host/commands/assemble_cvd/flags/vm_manager.h"
6566
#include "cuttlefish/host/commands/assemble_cvd/graphics_flags.h"
@@ -491,7 +492,8 @@ Result<CuttlefishConfig> InitializeCuttlefishConfiguration(
491492
CF_EXPECT(GET_FLAG_STR_VALUE(serial_number));
492493
std::vector<bool> use_random_serial_vec =
493494
CF_EXPECT(GET_FLAG_BOOL_VALUE(use_random_serial));
494-
std::vector<bool> use_cvdalloc_vec = CF_EXPECT(GET_FLAG_BOOL_VALUE(use_cvdalloc));
495+
UseCvdallocFlag use_cvdalloc_values =
496+
CF_EXPECT(UseCvdallocFlag::FromGlobalGflags());
495497
std::vector<bool> use_sdcard_vec = CF_EXPECT(GET_FLAG_BOOL_VALUE(use_sdcard));
496498
std::vector<bool> pause_in_bootloader_vec = CF_EXPECT(GET_FLAG_BOOL_VALUE(
497499
pause_in_bootloader));
@@ -764,7 +766,7 @@ Result<CuttlefishConfig> InitializeCuttlefishConfiguration(
764766
auto const_instance =
765767
const_cast<const CuttlefishConfig&>(tmp_config_obj).ForInstance(num);
766768

767-
instance.set_use_cvdalloc(use_cvdalloc_vec[instance_index]);
769+
instance.set_use_cvdalloc(use_cvdalloc_values.ForIndex(instance_index));
768770

769771
IfaceConfig iface_config =
770772
CF_EXPECT(DefaultNetworkInterfaces(const_instance));

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,18 @@ cf_cc_library(
211211
],
212212
)
213213

214+
cf_cc_library(
215+
name = "use_cvdalloc",
216+
srcs = ["use_cvdalloc.cc"],
217+
hdrs = ["use_cvdalloc.h"],
218+
deps = [
219+
"//cuttlefish/common/libs/utils:result",
220+
"//cuttlefish/host/commands/assemble_cvd:flags_defaults",
221+
"//cuttlefish/host/commands/assemble_cvd/flags:from_gflags",
222+
"@gflags",
223+
],
224+
)
225+
214226
cf_cc_library(
215227
name = "vendor_boot_image",
216228
srcs = ["vendor_boot_image.cc"],
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright (C) 2025 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
#include "cuttlefish/host/commands/assemble_cvd/flags/use_cvdalloc.h"
17+
18+
#include <stddef.h>
19+
20+
#include <utility>
21+
#include <vector>
22+
23+
#include <gflags/gflags.h>
24+
25+
#include "cuttlefish/common/libs/utils/result.h"
26+
#include "cuttlefish/host/commands/assemble_cvd/flags/from_gflags.h"
27+
28+
DEFINE_string(use_cvdalloc, "unset", "Acquire static resources with cvdalloc.");
29+
30+
namespace cuttlefish {
31+
32+
Result<UseCvdallocFlag> UseCvdallocFlag::FromGlobalGflags() {
33+
const auto flag_info = gflags::GetCommandLineFlagInfoOrDie("use_cvdalloc");
34+
std::vector<bool> flag_values =
35+
CF_EXPECT(BoolFromGlobalGflags(flag_info, "use_cvdalloc", false));
36+
return UseCvdallocFlag(std::move(flag_values));
37+
}
38+
39+
bool UseCvdallocFlag::ForIndex(const std::size_t index) const {
40+
if (index < values_.size()) {
41+
return values_[index];
42+
} else {
43+
return values_[0];
44+
}
45+
}
46+
47+
UseCvdallocFlag::UseCvdallocFlag(std::vector<bool> values)
48+
: values_(std::move(values)) {}
49+
50+
} // namespace cuttlefish
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright (C) 2025 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
#pragma once
17+
18+
#include <stddef.h>
19+
20+
#include <vector>
21+
22+
#include "cuttlefish/common/libs/utils/result.h"
23+
24+
namespace cuttlefish {
25+
26+
/* `--use_cvdalloc` flag */
27+
class UseCvdallocFlag {
28+
public:
29+
static Result<UseCvdallocFlag> FromGlobalGflags();
30+
31+
bool ForIndex(const std::size_t index) const;
32+
33+
private:
34+
UseCvdallocFlag(std::vector<bool> values);
35+
36+
std::vector<bool> values_;
37+
};
38+
39+
} // namespace cuttlefish

0 commit comments

Comments
 (0)