mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2025-02-08 19:33:07 +00:00
src: move exit module to new crosvm_cli crate.
Since we have "main" like functions in the devices crate for vhost-user devices, we need to use ExitContext & Exit there. This wasn't possible with the existing location in the crosvm/main crate because crosvm -> devices so we can't have devices -> crosvm. This CL moves exit to a new crate, crosvm_cli, where it can be used by all interested consumers. BUG=b:253348635 TEST=builds Change-Id: Ia06d9dee2cd5826ea20a7fb3a0c2a53c58e2ff1d Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3960854 Commit-Queue: Noah Gold <nkgold@google.com> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
This commit is contained in:
parent
6d0d597b5f
commit
adc5e6fd3f
13 changed files with 68 additions and 20 deletions
11
Cargo.lock
generated
11
Cargo.lock
generated
|
@ -449,6 +449,7 @@ dependencies = [
|
|||
"crash_report",
|
||||
"cros_async",
|
||||
"cros_tracing",
|
||||
"crosvm_cli",
|
||||
"crosvm_plugin",
|
||||
"ctrlc",
|
||||
"data_model",
|
||||
|
@ -518,6 +519,16 @@ dependencies = [
|
|||
"vm_memory",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crosvm_cli"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"cfg-if",
|
||||
"win_util",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crosvm_control"
|
||||
version = "0.1.0"
|
||||
|
|
|
@ -53,6 +53,7 @@ members = [
|
|||
"cros_async",
|
||||
"cros_fdt",
|
||||
"crosvm-fuzz",
|
||||
"crosvm_cli",
|
||||
"crosvm_control",
|
||||
"crosvm_plugin",
|
||||
"devices",
|
||||
|
@ -335,6 +336,7 @@ broker_ipc = { path = "broker_ipc" }
|
|||
cfg-if = "1.0.0"
|
||||
crash_report = { path = "crash_report", optional = true }
|
||||
cros_async = { path = "cros_async" }
|
||||
crosvm_cli = { path = "crosvm_cli" }
|
||||
crosvm_plugin = { path = "crosvm_plugin", optional = true }
|
||||
data_model = "*"
|
||||
devices = { path = "devices" }
|
||||
|
|
15
crosvm_cli/Cargo.toml
Normal file
15
crosvm_cli/Cargo.toml
Normal file
|
@ -0,0 +1,15 @@
|
|||
[package]
|
||||
name = "crosvm_cli"
|
||||
authors = ["The Chromium OS Authors"]
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[features]
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.32"
|
||||
cfg-if = "1.0.0"
|
||||
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
win_util = { path = "../win_util" }
|
||||
winapi = "*"
|
7
crosvm_cli/src/lib.rs
Normal file
7
crosvm_cli/src/lib.rs
Normal file
|
@ -0,0 +1,7 @@
|
|||
// Copyright 2022 The ChromiumOS Authors
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
//! Contains common CLI code (e.g. exit code handling).
|
||||
|
||||
pub mod sys;
|
9
crosvm_cli/src/sys.rs
Normal file
9
crosvm_cli/src/sys.rs
Normal file
|
@ -0,0 +1,9 @@
|
|||
// Copyright 2022 The ChromiumOS Authors
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(windows)] {
|
||||
pub mod windows;
|
||||
}
|
||||
}
|
5
crosvm_cli/src/sys/windows.rs
Normal file
5
crosvm_cli/src/sys/windows.rs
Normal file
|
@ -0,0 +1,5 @@
|
|||
// Copyright 2022 The ChromiumOS Authors
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
pub mod exit;
|
|
@ -6,7 +6,6 @@ pub mod cmdline;
|
|||
pub mod config;
|
||||
|
||||
pub(crate) mod broker;
|
||||
pub(crate) mod exit;
|
||||
#[cfg(feature = "stats")]
|
||||
pub(crate) mod stats;
|
||||
|
||||
|
|
|
@ -56,6 +56,14 @@ use broker_ipc::EmulatorProcessInvariants;
|
|||
use crash_report::product_type;
|
||||
#[cfg(feature = "crash-report")]
|
||||
use crash_report::CrashReportAttributes;
|
||||
use crosvm_cli::bail_exit_code;
|
||||
use crosvm_cli::ensure_exit_code;
|
||||
use crosvm_cli::sys::windows::exit::to_process_type_error;
|
||||
use crosvm_cli::sys::windows::exit::Exit;
|
||||
use crosvm_cli::sys::windows::exit::ExitCode;
|
||||
use crosvm_cli::sys::windows::exit::ExitCodeWrapper;
|
||||
use crosvm_cli::sys::windows::exit::ExitContext;
|
||||
use crosvm_cli::sys::windows::exit::ExitContextAnyhow;
|
||||
#[cfg(feature = "slirp")]
|
||||
use devices::virtio::vhost::user::device::NetBackendConfig;
|
||||
#[cfg(feature = "gpu")]
|
||||
|
@ -75,14 +83,6 @@ use win_util::ProcessType;
|
|||
use winapi::shared::winerror::ERROR_ACCESS_DENIED;
|
||||
use winapi::um::processthreadsapi::TerminateProcess;
|
||||
|
||||
use crate::bail_exit_code;
|
||||
use crate::crosvm::sys::windows::exit::to_process_type_error;
|
||||
use crate::crosvm::sys::windows::exit::Exit;
|
||||
use crate::crosvm::sys::windows::exit::ExitCode;
|
||||
use crate::crosvm::sys::windows::exit::ExitCodeWrapper;
|
||||
use crate::crosvm::sys::windows::exit::ExitContext;
|
||||
use crate::crosvm::sys::windows::exit::ExitContextAnyhow;
|
||||
use crate::ensure_exit_code;
|
||||
use crate::Config;
|
||||
|
||||
const KILL_CHILD_EXIT_CODE: u32 = 1;
|
||||
|
|
|
@ -72,6 +72,9 @@ use base::VmEventType;
|
|||
use base::WaitContext;
|
||||
use broker_ipc::common_child_setup;
|
||||
use broker_ipc::CommonChildStartupArgs;
|
||||
use crosvm_cli::sys::windows::exit::Exit;
|
||||
use crosvm_cli::sys::windows::exit::ExitContext;
|
||||
use crosvm_cli::sys::windows::exit::ExitContextAnyhow;
|
||||
use devices::serial_device::SerialHardware;
|
||||
use devices::serial_device::SerialParameters;
|
||||
use devices::tsc::get_tsc_sync_mitigations;
|
||||
|
@ -206,9 +209,6 @@ use crate::crosvm::config::TouchDeviceOption;
|
|||
use crate::crosvm::sys::config::HypervisorKind;
|
||||
#[cfg(any(feature = "gvm", feature = "whpx"))]
|
||||
use crate::crosvm::sys::config::IrqChipKind;
|
||||
use crate::crosvm::sys::windows::exit::Exit;
|
||||
use crate::crosvm::sys::windows::exit::ExitContext;
|
||||
use crate::crosvm::sys::windows::exit::ExitContextAnyhow;
|
||||
#[cfg(feature = "stats")]
|
||||
use crate::crosvm::sys::windows::stats::StatisticsCollector;
|
||||
use crate::sys::windows::metrics::log_descriptor;
|
||||
|
|
|
@ -18,6 +18,9 @@ use base::FromRawDescriptor;
|
|||
use base::RawDescriptor;
|
||||
use broker_ipc::common_child_setup;
|
||||
use broker_ipc::CommonChildStartupArgs;
|
||||
use crosvm_cli::sys::windows::exit::Exit;
|
||||
use crosvm_cli::sys::windows::exit::ExitContext;
|
||||
use crosvm_cli::sys::windows::exit::ExitContextAnyhow;
|
||||
use metrics::event_details_proto::EmulatorDllDetails;
|
||||
use metrics::event_details_proto::RecordDetails;
|
||||
use metrics::MetricEventType;
|
||||
|
@ -36,9 +39,6 @@ use crate::crosvm::sys::cmdline::DeviceSubcommand;
|
|||
use crate::crosvm::sys::cmdline::RunMainCommand;
|
||||
#[cfg(all(feature = "slirp"))]
|
||||
use crate::crosvm::sys::cmdline::RunSlirpCommand;
|
||||
use crate::crosvm::sys::windows::exit::Exit;
|
||||
use crate::crosvm::sys::windows::exit::ExitContext;
|
||||
use crate::crosvm::sys::windows::exit::ExitContextAnyhow;
|
||||
use crate::metrics::run_metrics;
|
||||
use crate::CommandStatus;
|
||||
use crate::Config;
|
||||
|
|
|
@ -10,7 +10,7 @@ cfg_if::cfg_if! {
|
|||
use base::Tube;
|
||||
use std::thread;
|
||||
use metrics_crate::MetricsController;
|
||||
use crate::crosvm::sys::windows::exit::{Exit, ExitContext, ExitContextAnyhow};
|
||||
use crosvm_cli::sys::windows::exit::{Exit, ExitContext, ExitContextAnyhow};
|
||||
use crate::sys::windows::main::set_bootstrap_arguments;
|
||||
use tube_transporter::{TubeToken, TubeTransporterReader};
|
||||
use base::FromRawDescriptor;
|
||||
|
|
|
@ -41,6 +41,10 @@ use cros_async::Executor;
|
|||
use cros_async::SelectResult;
|
||||
use cros_async::TimerAsync;
|
||||
use cros_tracing::trace_event;
|
||||
use crosvm_cli::bail_exit_code;
|
||||
use crosvm_cli::sys::windows::exit::Exit;
|
||||
use crosvm_cli::sys::windows::exit::ExitContext;
|
||||
use crosvm_cli::sys::windows::exit::ExitContextAnyhow;
|
||||
use devices::tsc::TscSyncMitigations;
|
||||
use devices::Bus;
|
||||
#[cfg(any(target_arch = "arm", target_arch = "aarch64"))]
|
||||
|
@ -81,10 +85,6 @@ use x86_64::cpuid::CpuIdContext;
|
|||
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
|
||||
use x86_64::X8664arch as Arch;
|
||||
|
||||
use crate::bail_exit_code;
|
||||
use crate::crosvm::sys::windows::exit::Exit;
|
||||
use crate::crosvm::sys::windows::exit::ExitContext;
|
||||
use crate::crosvm::sys::windows::exit::ExitContextAnyhow;
|
||||
#[cfg(feature = "stats")]
|
||||
use crate::crosvm::sys::windows::stats::StatisticsCollector;
|
||||
#[cfg(feature = "stats")]
|
||||
|
|
Loading…
Reference in a new issue