Put cuttlefish_config.json in cuttlefish_assembly

A copy is kept in the instance directory to work with other systems that
expect the file to be present in ~/cuttlefish_runtime, such as tradefed.

The config is no longer instance-specific

Bug: 145247175
Test: Build and run, check ~/cuttlefish_assembly
Change-Id: I838fb18ac24340b05bb1e879615b10e0bc31a737
diff --git a/host/commands/assemble_cvd/flags.cc b/host/commands/assemble_cvd/flags.cc
index aed70e7..ff91c8e 100644
--- a/host/commands/assemble_cvd/flags.cc
+++ b/host/commands/assemble_cvd/flags.cc
@@ -216,6 +216,10 @@
   return cvd::StringFromEnv("HOME", ".") + "/.cuttlefish.sh";
 }
 
+std::string GetLegacyConfigFilePath(const vsoc::CuttlefishConfig& config) {
+  return config.ForDefaultInstance().PerInstancePath("cuttlefish_config.json");
+}
+
 int GetHostPort() {
   constexpr int kFirstHostPort = 6520;
   return vsoc::ForCurrentInstance(kFirstHostPort);
@@ -395,6 +399,11 @@
     LOG(ERROR) << "Unable to save config object";
     return false;
   }
+  auto legacy_config_file = GetLegacyConfigFilePath(tmp_config_obj);
+  if (!tmp_config_obj.SaveToFile(legacy_config_file)) {
+    LOG(ERROR) << "Unable to save legacy config object";
+    return false;
+  }
   setenv(vsoc::kCuttlefishConfigEnvVarName, config_file.c_str(), true);
   if (symlink(config_file.c_str(), config_link.c_str()) != 0) {
     LOG(ERROR) << "Failed to create symlink to config file at " << config_link
@@ -727,6 +736,5 @@
 }
 
 std::string GetConfigFilePath(const vsoc::CuttlefishConfig& config) {
-  return config.ForDefaultInstance()
-      .PerInstancePath("cuttlefish_config.json");
+  return config.AssemblyPath("cuttlefish_config.json");
 }