Add a new command to dump version info.

With command "version", we can dump version information via "crosvm version".
By default it would dump the version specified in Cargo.toml like following:
"crosvm package version 0.1.0".

And if the environment varable "PKG_VERSION=123456" is given during building crosvm,
it would dump followed by a package version, like following:
"crosvm package version 0.1.0-123456".

Sometimes, we need to know which exact version does a crosvm binary come
from for developing and testing. It is useful if the git sha is built-in a
crosvm binary.

BUG=none
TEST=PKG_VERSION=xxxxxx Cargo build && crosvm version
TEST=PKG_VERSION=xxxxx emerge-eve crosvm && crosvm version
TEST=./bin/fmt
TEST=./bin/clippy
TEST=./build_test.py --x86_64-sysroot /build/eve

no errors reported and all behavor is as expected.

v2: Refine version info.

Change-Id: I89686dbe6ab2888d8a6ce5752a37241b4c00160d
Signed-off-by: Yi Sun <yi.sun@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1989256
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
diff --git a/src/main.rs b/src/main.rs
index e52534d..2714ac8 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1542,6 +1542,19 @@
     println!("    create_qcow2  - Create a new qcow2 disk image file.");
     println!("    disk - Manage attached virtual disk devices.");
     println!("    usb - Manage attached virtual USB devices.");
+    println!("    version - Show package version.");
+}
+
+fn pkg_version() -> std::result::Result<(), ()> {
+    const VERSION: Option<&'static str> = option_env!("CARGO_PKG_VERSION");
+    const PKG_VERSION: Option<&'static str> = option_env!("PKG_VERSION");
+
+    print!("crosvm {}", VERSION.unwrap_or("UNKNOWN"));
+    match PKG_VERSION {
+        Some(v) => println!("-{}", v),
+        None => println!(""),
+    }
+    Ok(())
 }
 
 fn crosvm_main() -> std::result::Result<(), ()> {
@@ -1572,6 +1585,7 @@
         Some("create_qcow2") => create_qcow2(args),
         Some("disk") => disk_cmd(args),
         Some("usb") => modify_usb(args),
+        Some("version") => pkg_version(),
         Some(c) => {
             println!("invalid subcommand: {:?}", c);
             print_usage();