Move the kernel argument generation to another file.

While this doesn't include the kernel arguments produced by the VMM
interface code, it does get a lot into one place.

Moving this to another file helps shorten run_cvd.cc which is carrying a
lot of other responsibilities, and establishes the API surface between
the VMM executor and the kernel command line inputs through the
kernel_args.h header file.

Test: Build and run locally
Bug: 145247175
Change-Id: I533ff9c1d306a4f223cea58e0dc26f08e87aafa5
diff --git a/host/commands/run_cvd/Android.bp b/host/commands/run_cvd/Android.bp
index a7893fe..c338f08 100644
--- a/host/commands/run_cvd/Android.bp
+++ b/host/commands/run_cvd/Android.bp
@@ -16,9 +16,10 @@
 cc_binary_host {
     name: "run_cvd",
     srcs: [
+        "kernel_args.cc",
         "launch.cc",
-        "process_monitor.cc",
         "main.cc",
+        "process_monitor.cc",
     ],
     header_libs: [
         "cuttlefish_glog",
diff --git a/host/commands/run_cvd/kernel_args.cc b/host/commands/run_cvd/kernel_args.cc
new file mode 100644
index 0000000..4d0b35f
--- /dev/null
+++ b/host/commands/run_cvd/kernel_args.cc
@@ -0,0 +1,108 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "host/commands/run_cvd/kernel_args.h"
+
+#include <string>
+#include <vector>
+
+#include "host/commands/run_cvd/launch.h"
+#include "host/commands/run_cvd/runner_defs.h"
+#include "host/libs/config/cuttlefish_config.h"
+#include "host/libs/vm_manager/vm_manager.h"
+
+template<typename T>
+static void AppendVector(std::vector<T>* destination, const std::vector<T>& source) {
+  destination->insert(destination->end(), source.begin(), source.end());
+}
+
+template<typename S, typename T>
+static std::string concat(const S& s, const T& t) {
+  std::ostringstream os;
+  os << s << t;
+  return os.str();
+}
+
+std::vector<std::string> KernelCommandLineFromConfig(const vsoc::CuttlefishConfig& config) {
+  std::vector<std::string> kernel_cmdline;
+
+  AppendVector(&kernel_cmdline, config.boot_image_kernel_cmdline());
+  AppendVector(&kernel_cmdline,
+               vm_manager::VmManager::ConfigureGpuMode(config.vm_manager(), config.gpu_mode()));
+  AppendVector(&kernel_cmdline, vm_manager::VmManager::ConfigureBootDevices(config.vm_manager()));
+
+  kernel_cmdline.push_back(concat("androidboot.serialno=", config.serial_number()));
+  kernel_cmdline.push_back(concat("androidboot.lcd_density=", config.dpi()));
+  if (config.logcat_mode() == cvd::kLogcatVsockMode) {
+    kernel_cmdline.push_back(concat("androidboot.vsock_logcat_port=", config.logcat_vsock_port()));
+  }
+  kernel_cmdline.push_back(concat(
+      "androidboot.cuttlefish_config_server_port=", config.config_server_port()));
+  kernel_cmdline.push_back(concat(
+      "androidboot.setupwizard_mode=", config.setupwizard_mode()));
+  if (!config.use_bootloader()) {
+    std::string slot_suffix;
+    if (config.boot_slot().empty()) {
+      slot_suffix = "_a";
+    } else {
+      slot_suffix = "_" + config.boot_slot();
+    }
+    kernel_cmdline.push_back(concat("androidboot.slot_suffix=", slot_suffix));
+  }
+  kernel_cmdline.push_back(concat("loop.max_part=", config.loop_max_part()));
+  if (config.guest_enforce_security()) {
+    kernel_cmdline.push_back("enforcing=1");
+  } else {
+    kernel_cmdline.push_back("enforcing=0");
+    kernel_cmdline.push_back("androidboot.selinux=permissive");
+  }
+  if (config.guest_audit_security()) {
+    kernel_cmdline.push_back("audit=1");
+  } else {
+    kernel_cmdline.push_back("audit=0");
+  }
+
+  AppendVector(&kernel_cmdline, config.extra_kernel_cmdline());
+
+  return kernel_cmdline;
+}
+
+std::vector<std::string> KernelCommandLineFromVnc(const VncServerPorts& vnc_ports) {
+  std::vector<std::string> kernel_args;
+  if (vnc_ports.frames_server_vsock_port) {
+    kernel_args.push_back(concat("androidboot.vsock_frames_port=",
+                                 *vnc_ports.frames_server_vsock_port));
+  }
+  if (vnc_ports.touch_server_vsock_port) {
+    kernel_args.push_back(concat("androidboot.vsock_touch_port=",
+                                 *vnc_ports.touch_server_vsock_port));
+  }
+  if (vnc_ports.keyboard_server_vsock_port) {
+    kernel_args.push_back(concat("androidboot.vsock_keyboard_port=",
+                                 *vnc_ports.keyboard_server_vsock_port));
+  }
+  return kernel_args;
+}
+
+std::vector<std::string> KernelCommandLineFromTombstone(const TombstoneReceiverPorts& tombstone) {
+  if (!tombstone.server_vsock_port) {
+    return { "androidboot.tombstone_transmit=0" };
+  }
+  return {
+    "androidboot.tombstone_transmit=1",
+    concat("androidboot.vsock_tombstone_port=", *tombstone.server_vsock_port),
+  };
+}
diff --git a/host/commands/run_cvd/kernel_args.h b/host/commands/run_cvd/kernel_args.h
new file mode 100644
index 0000000..9356023
--- /dev/null
+++ b/host/commands/run_cvd/kernel_args.h
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <string>
+#include <vector>
+
+#include "host/commands/run_cvd/launch.h"
+#include "host/libs/config/cuttlefish_config.h"
+
+std::vector<std::string> KernelCommandLineFromConfig(const vsoc::CuttlefishConfig& config);
+std::vector<std::string> KernelCommandLineFromVnc(const VncServerPorts& vnc_config);
+std::vector<std::string> KernelCommandLineFromTombstone(const TombstoneReceiverPorts& tombstone);
diff --git a/host/commands/run_cvd/main.cc b/host/commands/run_cvd/main.cc
index 9188833..7bc2c55 100644
--- a/host/commands/run_cvd/main.cc
+++ b/host/commands/run_cvd/main.cc
@@ -46,6 +46,7 @@
 #include "common/libs/utils/files.h"
 #include "common/libs/utils/subprocess.h"
 #include "common/libs/utils/size_utils.h"
+#include "host/commands/run_cvd/kernel_args.h"
 #include "host/commands/run_cvd/launch.h"
 #include "host/commands/run_cvd/runner_defs.h"
 #include "host/commands/run_cvd/process_monitor.h"
@@ -277,87 +278,6 @@
   return config.PerInstancePath("cuttlefish_config.json");
 }
 
-template<typename T>
-void AppendVector(std::vector<T>* destination, const std::vector<T>& source) {
-  destination->insert(destination->end(), source.begin(), source.end());
-}
-
-template<typename S, typename T>
-static std::string concat(const S& s, const T& t) {
-  std::ostringstream os;
-  os << s << t;
-  return os.str();
-}
-
-std::vector<std::string> KernelCommandLineFromConfig(const vsoc::CuttlefishConfig& config) {
-  std::vector<std::string> kernel_cmdline;
-
-  AppendVector(&kernel_cmdline, config.boot_image_kernel_cmdline());
-  AppendVector(&kernel_cmdline,
-               vm_manager::VmManager::ConfigureGpuMode(config.vm_manager(), config.gpu_mode()));
-  AppendVector(&kernel_cmdline, vm_manager::VmManager::ConfigureBootDevices(config.vm_manager()));
-
-  kernel_cmdline.push_back(concat("androidboot.serialno=", config.serial_number()));
-  kernel_cmdline.push_back(concat("androidboot.lcd_density=", config.dpi()));
-  if (config.logcat_mode() == cvd::kLogcatVsockMode) {
-    kernel_cmdline.push_back(concat("androidboot.vsock_logcat_port=", config.logcat_vsock_port()));
-  }
-  kernel_cmdline.push_back(concat(
-      "androidboot.cuttlefish_config_server_port=", config.config_server_port()));
-  kernel_cmdline.push_back(concat(
-      "androidboot.setupwizard_mode=", config.setupwizard_mode()));
-  if (!config.use_bootloader()) {
-    std::string slot_suffix;
-    if (config.boot_slot().empty()) {
-      slot_suffix = "_a";
-    } else {
-      slot_suffix = "_" + config.boot_slot();
-    }
-    kernel_cmdline.push_back(concat("androidboot.slot_suffix=", slot_suffix));
-  }
-  kernel_cmdline.push_back(concat("loop.max_part=", config.loop_max_part()));
-  if (config.guest_enforce_security()) {
-    kernel_cmdline.push_back("enforcing=1");
-  } else {
-    kernel_cmdline.push_back("enforcing=0");
-    kernel_cmdline.push_back("androidboot.selinux=permissive");
-  }
-  if (config.guest_audit_security()) {
-    kernel_cmdline.push_back("audit=1");
-  } else {
-    kernel_cmdline.push_back("audit=0");
-  }
-
-  AppendVector(&kernel_cmdline, config.extra_kernel_cmdline());
-
-  return kernel_cmdline;
-}
-std::vector<std::string> KernelCommandLineFromVnc(const VncServerPorts& vnc_ports) {
-  std::vector<std::string> kernel_args;
-  if (vnc_ports.frames_server_vsock_port) {
-    kernel_args.push_back(concat("androidboot.vsock_frames_port=",
-                                 *vnc_ports.frames_server_vsock_port));
-  }
-  if (vnc_ports.touch_server_vsock_port) {
-    kernel_args.push_back(concat("androidboot.vsock_touch_port=",
-                                 *vnc_ports.touch_server_vsock_port));
-  }
-  if (vnc_ports.keyboard_server_vsock_port) {
-    kernel_args.push_back(concat("androidboot.vsock_keyboard_port=",
-                                 *vnc_ports.keyboard_server_vsock_port));
-  }
-  return kernel_args;
-}
-std::vector<std::string> KernelCommandLineFromTombstone(const TombstoneReceiverPorts& tombstone) {
-  if (!tombstone.server_vsock_port) {
-    return { "androidboot.tombstone_transmit=0" };
-  }
-  return {
-    "androidboot.tombstone_transmit=1",
-    concat("androidboot.vsock_tombstone_port=", *tombstone.server_vsock_port),
-  };
-}
-
 }  // namespace
 
 int main(int argc, char** argv) {