Skip to content

Commit 26f18d2

Browse files
committed
Lift GetGuestConfigAndSetDefaults components out
The dependency ordering is easier to express by lifting out the inner function calls, and it slightly splits up the large argument lists. Bug: b/435249755
1 parent 57a27ae commit 26f18d2

File tree

4 files changed

+42
-40
lines changed

4 files changed

+42
-40
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ cf_cc_binary(
3232
"//cuttlefish/host/commands/assemble_cvd:flag_feature",
3333
"//cuttlefish/host/commands/assemble_cvd:flags",
3434
"//cuttlefish/host/commands/assemble_cvd:flags_defaults",
35+
"//cuttlefish/host/commands/assemble_cvd:resolve_instance_files",
3536
"//cuttlefish/host/commands/assemble_cvd:touchpad",
3637
"//cuttlefish/host/commands/assemble_cvd/disk:ap_composite_disk",
3738
"//cuttlefish/host/commands/assemble_cvd/disk:factory_reset_protected",
@@ -42,6 +43,7 @@ cf_cc_binary(
4243
"//cuttlefish/host/commands/assemble_cvd/flags:initramfs_path",
4344
"//cuttlefish/host/commands/assemble_cvd/flags:kernel_path",
4445
"//cuttlefish/host/commands/assemble_cvd/flags:system_image_dir",
46+
"//cuttlefish/host/commands/assemble_cvd/flags:vm_manager",
4547
"//cuttlefish/host/libs/command_util",
4648
"//cuttlefish/host/libs/config:ap_boot_flow",
4749
"//cuttlefish/host/libs/config:config_flag",
@@ -251,7 +253,6 @@ cf_cc_library(
251253
"//cuttlefish/host/commands/assemble_cvd:graphics_flags",
252254
"//cuttlefish/host/commands/assemble_cvd:guest_config",
253255
"//cuttlefish/host/commands/assemble_cvd:network_flags",
254-
"//cuttlefish/host/commands/assemble_cvd:resolve_instance_files",
255256
"//cuttlefish/host/commands/assemble_cvd:touchpad",
256257
"//cuttlefish/host/commands/assemble_cvd/flags:boot_image",
257258
"//cuttlefish/host/commands/assemble_cvd/flags:display_proto",

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

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@
4646
#include "cuttlefish/host/commands/assemble_cvd/flags/initramfs_path.h"
4747
#include "cuttlefish/host/commands/assemble_cvd/flags/kernel_path.h"
4848
#include "cuttlefish/host/commands/assemble_cvd/flags/system_image_dir.h"
49+
#include "cuttlefish/host/commands/assemble_cvd/flags/vm_manager.h"
4950
#include "cuttlefish/host/commands/assemble_cvd/flags_defaults.h"
51+
#include "cuttlefish/host/commands/assemble_cvd/resolve_instance_files.h"
5052
#include "cuttlefish/host/commands/assemble_cvd/touchpad.h"
5153
#include "cuttlefish/host/libs/command_util/snapshot_utils.h"
5254
#include "cuttlefish/host/libs/config/adb/adb.h"
@@ -315,17 +317,18 @@ Result<const CuttlefishConfig*> InitFilesystemAndCreateConfig(
315317
FetcherConfig fetcher_config, const std::vector<GuestConfig>& guest_configs,
316318
fruit::Injector<>& injector, SharedFD log, const BootImageFlag& boot_image,
317319
const InitramfsPathFlag& initramfs_path, const KernelPathFlag& kernel_path,
318-
const SystemImageDirFlag& system_image_dir) {
320+
const SystemImageDirFlag& system_image_dir,
321+
const VmManagerFlag& vm_manager_flag) {
319322
{
320323
// The config object is created here, but only exists in memory until the
321324
// SaveConfig line below. Don't launch cuttlefish subprocesses between these
322325
// two operations, as those will assume they can read the config object from
323326
// disk.
324-
auto config = CF_EXPECT(
325-
InitializeCuttlefishConfiguration(
326-
FLAGS_instance_dir, guest_configs, injector, fetcher_config,
327-
boot_image, initramfs_path, kernel_path, system_image_dir),
328-
"cuttlefish configuration initialization failed");
327+
auto config = CF_EXPECT(InitializeCuttlefishConfiguration(
328+
FLAGS_instance_dir, guest_configs, injector,
329+
fetcher_config, boot_image, initramfs_path,
330+
kernel_path, system_image_dir, vm_manager_flag),
331+
"cuttlefish configuration initialization failed");
329332

330333
const std::string snapshot_path = FLAGS_snapshot_path;
331334
if (!snapshot_path.empty()) {
@@ -646,16 +649,24 @@ Result<int> AssembleCvdMain(int argc, char** argv) {
646649
// gflags either consumes all arguments that start with - or leaves all of
647650
// them in place, and either errors out on unknown flags or accepts any flags.
648651

649-
auto guest_configs =
650-
CF_EXPECT(GetGuestConfigAndSetDefaults(boot_image, initramfs_path,
651-
kernel_path, system_image_dir),
652-
"Failed to parse arguments");
652+
CF_EXPECT(ResolveInstanceFiles(boot_image, initramfs_path, kernel_path,
653+
system_image_dir),
654+
"Failed to resolve instance files");
655+
// Depends on ResolveInstanceFiles to set flag globals
656+
std::vector<GuestConfig> guest_configs =
657+
CF_EXPECT(ReadGuestConfig(boot_image, kernel_path, system_image_dir));
653658

654-
auto config =
655-
CF_EXPECT(InitFilesystemAndCreateConfig(
656-
std::move(fetcher_config), guest_configs, injector, log,
657-
boot_image, initramfs_path, kernel_path, system_image_dir),
658-
"Failed to create config");
659+
VmManagerFlag vm_manager_flag =
660+
CF_EXPECT(VmManagerFlag::FromGlobalGflags(guest_configs));
661+
662+
CF_EXPECT(
663+
SetFlagDefaultsForVmm(guest_configs, system_image_dir, vm_manager_flag));
664+
665+
auto config = CF_EXPECT(
666+
InitFilesystemAndCreateConfig(
667+
std::move(fetcher_config), guest_configs, injector, log, boot_image,
668+
initramfs_path, kernel_path, system_image_dir, vm_manager_flag),
669+
"Failed to create config");
659670

660671
std::cout << GetConfigFilePath(*config) << "\n";
661672
std::cout << std::flush;

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

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
#include "cuttlefish/host/commands/assemble_cvd/graphics_flags.h"
5959
#include "cuttlefish/host/commands/assemble_cvd/guest_config.h"
6060
#include "cuttlefish/host/commands/assemble_cvd/network_flags.h"
61-
#include "cuttlefish/host/commands/assemble_cvd/resolve_instance_files.h"
6261
#include "cuttlefish/host/commands/assemble_cvd/touchpad.h"
6362
#include "cuttlefish/host/libs/config/ap_boot_flow.h"
6463
#include "cuttlefish/host/libs/config/config_constants.h"
@@ -381,7 +380,8 @@ Result<CuttlefishConfig> InitializeCuttlefishConfiguration(
381380
fruit::Injector<>& injector, const FetcherConfig& fetcher_config,
382381
const BootImageFlag& boot_image, const InitramfsPathFlag& initramfs_path,
383382
const KernelPathFlag& kernel_path,
384-
const SystemImageDirFlag& system_image_dir) {
383+
const SystemImageDirFlag& system_image_dir,
384+
const VmManagerFlag& vm_manager_flag) {
385385
CuttlefishConfig tmp_config_obj;
386386
// If a snapshot path is provided, do not read all flags to set up the config.
387387
// Instead, read the config that was saved at time of snapshot and restore
@@ -414,8 +414,6 @@ Result<CuttlefishConfig> InitializeCuttlefishConfiguration(
414414
// TODO(weihsu), b/250988697: moved bootconfig_supported and hctr2_supported
415415
// into each instance, but target_arch is still in todo
416416
// target_arch should be in instance later
417-
VmManagerFlag vm_manager_flag =
418-
CF_EXPECT(VmManagerFlag::FromGlobalGflags(guest_configs));
419417
std::unique_ptr<vm_manager::VmManager> vmm =
420418
GetVmManager(vm_manager_flag.Mode(), guest_configs[0].target_arch);
421419
tmp_config_obj.set_vm_manager(vm_manager_flag.Mode());
@@ -1571,25 +1569,14 @@ void SetDefaultFlagsForOpenwrt(Arch target_arch) {
15711569
}
15721570
}
15731571

1574-
Result<std::vector<GuestConfig>> GetGuestConfigAndSetDefaults(
1575-
const BootImageFlag& boot_image, const InitramfsPathFlag& initramfs_path,
1576-
const KernelPathFlag& kernel_path,
1577-
const SystemImageDirFlag& system_image_dir) {
1572+
Result<void> SetFlagDefaultsForVmm(
1573+
const std::vector<GuestConfig>& guest_configs,
1574+
const SystemImageDirFlag& system_image_dir,
1575+
const VmManagerFlag& vm_manager_flag) {
15781576
auto instance_nums =
15791577
CF_EXPECT(InstanceNumsCalculator().FromGlobalGflags().Calculate());
15801578
int32_t instances_size = instance_nums.size();
15811579

1582-
CF_EXPECT(ResolveInstanceFiles(boot_image, initramfs_path, kernel_path,
1583-
system_image_dir),
1584-
"Failed to resolve instance files");
1585-
1586-
// Depends on ResolveInstanceFiles to set flag globals
1587-
std::vector<GuestConfig> guest_configs =
1588-
CF_EXPECT(ReadGuestConfig(boot_image, kernel_path, system_image_dir));
1589-
1590-
VmManagerFlag vm_manager_flag =
1591-
CF_EXPECT(VmManagerFlag::FromGlobalGflags(guest_configs));
1592-
15931580
// get flag default values and store into map
15941581
auto name_to_default_value = CurrentFlagsToDefaultValue();
15951582

@@ -1642,7 +1629,7 @@ Result<std::vector<GuestConfig>> GetGuestConfigAndSetDefaults(
16421629
// Set the env variable to empty (in case the caller passed a value for it).
16431630
unsetenv(kCuttlefishConfigEnvVarName);
16441631

1645-
return guest_configs;
1632+
return {};
16461633
}
16471634

16481635
std::string GetConfigFilePath(const CuttlefishConfig& config) {

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,24 @@
2424
#include "cuttlefish/host/commands/assemble_cvd/flags/initramfs_path.h"
2525
#include "cuttlefish/host/commands/assemble_cvd/flags/kernel_path.h"
2626
#include "cuttlefish/host/commands/assemble_cvd/flags/system_image_dir.h"
27+
#include "cuttlefish/host/commands/assemble_cvd/flags/vm_manager.h"
2728
#include "cuttlefish/host/commands/assemble_cvd/guest_config.h"
2829
#include "cuttlefish/host/libs/config/cuttlefish_config.h"
2930
#include "cuttlefish/host/libs/config/fetcher_config.h"
3031

3132
namespace cuttlefish {
3233

33-
Result<std::vector<GuestConfig>> GetGuestConfigAndSetDefaults(
34-
const BootImageFlag& boot_image, const InitramfsPathFlag&,
35-
const KernelPathFlag&, const SystemImageDirFlag&);
34+
Result<void> SetFlagDefaultsForVmm(
35+
const std::vector<GuestConfig>& guest_configs,
36+
const SystemImageDirFlag& system_image_dir,
37+
const VmManagerFlag& vm_manager_flag);
3638
// Must be called after ParseCommandLineFlags.
3739
Result<CuttlefishConfig> InitializeCuttlefishConfiguration(
3840
const std::string& root_dir, const std::vector<GuestConfig>& guest_configs,
3941
fruit::Injector<>& injector, const FetcherConfig& fetcher_config,
4042
const BootImageFlag&, const InitramfsPathFlag&,
41-
const KernelPathFlag& kernel_path, const SystemImageDirFlag&);
43+
const KernelPathFlag& kernel_path, const SystemImageDirFlag&,
44+
const VmManagerFlag&);
4245

4346
std::string GetConfigFilePath(const CuttlefishConfig& config);
4447

0 commit comments

Comments
 (0)