Use the output from fetch_cvd/launch_cvd in assemble_cvd.

Test: Check data passed between launch_cvd and assemble_cvd.
Bug: 135293952
Change-Id: Iaa66db1e10858be6394b38a0cf044f3a8882c4e0
diff --git a/host/commands/assemble_cvd/assemble_cvd.cc b/host/commands/assemble_cvd/assemble_cvd.cc
index 9efc0dd..6eab814 100644
--- a/host/commands/assemble_cvd/assemble_cvd.cc
+++ b/host/commands/assemble_cvd/assemble_cvd.cc
@@ -17,8 +17,32 @@
 
 #include <glog/logging.h>
 
+#include "common/libs/fs/shared_buf.h"
+#include "common/libs/fs/shared_fd.h"
+#include "common/libs/strings/str_split.h"
 #include "host/commands/assemble_cvd/assembler_defs.h"
 #include "host/commands/assemble_cvd/flags.h"
+#include "host/libs/config/fetcher_config.h"
+
+namespace {
+
+std::string kFetcherConfigFile = "fetcher_config.json";
+
+cvd::FetcherConfig FindFetcherConfig(const std::vector<std::string>& files) {
+  cvd::FetcherConfig fetcher_config;
+  for (const auto& file : files) {
+    auto expected_pos = file.size() - kFetcherConfigFile.size();
+    if (file.rfind(kFetcherConfigFile) == expected_pos) {
+      if (fetcher_config.LoadFromFile(file)) {
+        return fetcher_config;
+      }
+      LOG(ERROR) << "Could not load fetcher config file.";
+    }
+  }
+  return fetcher_config;
+}
+
+} // namespace
 
 int main(int argc, char** argv) {
   ::android::base::InitLogging(argv, android::base::StderrLogger);
@@ -36,7 +60,17 @@
     }
   }
 
-  auto config = InitFilesystemAndCreateConfig(&argc, &argv);
+  std::string input_files_str;
+  {
+    auto input_fd = cvd::SharedFD::Dup(0);
+    auto bytes_read = cvd::ReadAll(input_fd, &input_files_str);
+    if (bytes_read < 0) {
+      LOG(FATAL) << "Failed to read input files. Error was \"" << input_fd->StrError() << "\"";
+    }
+  }
+  std::vector<std::string> input_files = cvd::StrSplit(input_files_str, '\n');
+
+  auto config = InitFilesystemAndCreateConfig(&argc, &argv, FindFetcherConfig(input_files));
 
   std::cout << GetConfigFilePath(*config) << "\n";
   std::cout << std::flush;
diff --git a/host/commands/assemble_cvd/flags.cc b/host/commands/assemble_cvd/flags.cc
index 76a31de..786b9a3 100644
--- a/host/commands/assemble_cvd/flags.cc
+++ b/host/commands/assemble_cvd/flags.cc
@@ -14,6 +14,7 @@
 #include "host/commands/assemble_cvd/data_image.h"
 #include "host/commands/assemble_cvd/image_aggregator.h"
 #include "host/commands/assemble_cvd/assembler_defs.h"
+#include "host/libs/config/fetcher_config.h"
 #include "host/libs/vm_manager/crosvm_manager.h"
 #include "host/libs/vm_manager/qemu_manager.h"
 #include "host/libs/vm_manager/vm_manager.h"
@@ -728,7 +729,8 @@
 
 } // namespace
 
-const vsoc::CuttlefishConfig* InitFilesystemAndCreateConfig(int* argc, char*** argv) {
+const vsoc::CuttlefishConfig* InitFilesystemAndCreateConfig(
+    int* argc, char*** argv, cvd::FetcherConfig) {
   if (!ParseCommandLineFlags(argc, argv)) {
     LOG(ERROR) << "Failed to parse command arguments";
     exit(AssemblerExitCodes::kArgumentParsingError);
diff --git a/host/commands/assemble_cvd/flags.h b/host/commands/assemble_cvd/flags.h
index e8c542f..0373388 100644
--- a/host/commands/assemble_cvd/flags.h
+++ b/host/commands/assemble_cvd/flags.h
@@ -1,6 +1,8 @@
 #pragma once
 
 #include "host/libs/config/cuttlefish_config.h"
+#include "host/libs/config/fetcher_config.h"
 
-const vsoc::CuttlefishConfig* InitFilesystemAndCreateConfig(int* argc, char*** argv);
+const vsoc::CuttlefishConfig* InitFilesystemAndCreateConfig(
+    int* argc, char*** argv, cvd::FetcherConfig config);
 std::string GetConfigFilePath(const vsoc::CuttlefishConfig& config);