Skip to content

Commit 37caf6d

Browse files
committed
Use vectorized flag serial_number correctly
Separate by commas first, then use the correct one for the instance Bug: 444302522 Merged-In: If4c841a85d9544653b567fe756c3d146836547fa
1 parent 862713e commit 37caf6d

File tree

1 file changed

+19
-3
lines changed
  • base/cvd/cuttlefish/host/commands/assemble_cvd

1 file changed

+19
-3
lines changed

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

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -485,8 +485,10 @@ Result<CuttlefishConfig> InitializeCuttlefishConfiguration(
485485
CF_EXPECT(GET_FLAG_STR_VALUE(userdata_format));
486486
std::vector<bool> guest_enforce_security_vec = CF_EXPECT(GET_FLAG_BOOL_VALUE(
487487
guest_enforce_security));
488-
std::vector<bool> use_random_serial_vec = CF_EXPECT(GET_FLAG_BOOL_VALUE(
489-
use_random_serial));
488+
std::vector<std::string> serial_number_vec =
489+
CF_EXPECT(GET_FLAG_STR_VALUE(serial_number));
490+
std::vector<bool> use_random_serial_vec =
491+
CF_EXPECT(GET_FLAG_BOOL_VALUE(use_random_serial));
490492
std::vector<bool> use_allocd_vec = CF_EXPECT(GET_FLAG_BOOL_VALUE(use_allocd));
491493
std::vector<bool> use_cvdalloc_vec = CF_EXPECT(GET_FLAG_BOOL_VALUE(use_cvdalloc));
492494
std::vector<bool> use_sdcard_vec = CF_EXPECT(GET_FLAG_BOOL_VALUE(use_sdcard));
@@ -742,6 +744,20 @@ Result<CuttlefishConfig> InitializeCuttlefishConfiguration(
742744
auto num_to_webrtc_device_id_flag_map =
743745
CF_EXPECT(CreateNumToWebrtcDeviceIdMap(tmp_config_obj, instance_nums,
744746
FLAGS_webrtc_device_id));
747+
size_t provided_serials_cnt =
748+
android::base::Split(FLAGS_serial_number, ",").size();
749+
CF_EXPECTF(
750+
provided_serials_cnt == 1 || provided_serials_cnt == instances_size,
751+
"Must have a single serial number prefix or one serial number per "
752+
"instance, have {} but expectected {}",
753+
provided_serials_cnt, instances_size);
754+
if (provided_serials_cnt == 1 && instances_size > 1) {
755+
// Make sure the serial numbers are different when running multiple
756+
// instances and using the default value for the flag
757+
for (size_t i = 0; i < instance_nums.size(); ++i) {
758+
serial_number_vec[i] += std::to_string(instance_nums[i]);
759+
}
760+
}
745761
for (const auto& num : instance_nums) {
746762
auto instance = tmp_config_obj.ForInstance(num);
747763
auto const_instance =
@@ -865,7 +881,7 @@ Result<CuttlefishConfig> InitializeCuttlefishConfiguration(
865881
instance.set_serial_number(
866882
RandomSerialNumber("CFCVD" + std::to_string(num)));
867883
} else {
868-
instance.set_serial_number(FLAGS_serial_number + std::to_string(num));
884+
instance.set_serial_number(serial_number_vec[instance_index]);
869885
}
870886

871887
instance.set_grpc_socket_path(const_instance.PerInstanceGrpcSocketPath(""));

0 commit comments

Comments
 (0)