Warn if cmx file is missing

Change-Id: I010f91428760b92704522f8a70cc2e31232cf6ef
Reviewed-on: https://fuchsia-review.googlesource.com/c/fargo/+/491738
Reviewed-by: Rob Tsuk <robtsuk@google.com>
diff --git a/src/package.rs b/src/package.rs
index 7840239..f3d4f62 100644
--- a/src/package.rs
+++ b/src/package.rs
@@ -11,7 +11,7 @@
     utils::{strip_binary, target_crate_path},
     RunCargoOptions,
 };
-use failure::{bail, format_err, Error, ResultExt};
+use failure::{bail, ensure, format_err, Error, ResultExt};
 use serde::{Deserialize, Serialize};
 use serde_json::json;
 use std::{
@@ -58,6 +58,8 @@
         println!("validate_cmx_file: cmx_path = {:#?}", cmx_path);
     }
 
+    ensure!(cmx_path.exists(), "No file at {}", cmx_path.to_string_lossy());
+
     let cmc = cmc_path(fuchsia_config)?;
 
     let output = Command::new(cmc)
@@ -74,10 +76,17 @@
 }
 
 fn include_cmx_file(
+    verbose: bool,
     fuchsia_config: &FuchsiaConfig,
     cmx_path: &Path,
     temp_dir: &TempDir,
 ) -> Result<PathBuf, Error> {
+    if verbose {
+        println!("include_cmx_file: cmx_path = {:#?}", cmx_path);
+    }
+
+    ensure!(cmx_path.exists(), "No file at {}", cmx_path.to_string_lossy());
+
     let temp_dir_str = temp_dir.path().to_string_lossy();
     let destination_path = format!(
         "{}/included_{}",
@@ -104,6 +113,9 @@
         .context("Running `cmc` to resolve includes cmx file")?;
 
     if !output.status.success() {
+        if verbose {
+            println!("cmc output: {}", String::from_utf8_lossy(&output.stdout));
+        }
         bail!("cmc returned error: {}", String::from_utf8_lossy(&output.stderr));
     }
 
@@ -115,6 +127,8 @@
     cmx_path: &Path,
     temp_dir: &TempDir,
 ) -> Result<PathBuf, Error> {
+    ensure!(cmx_path.exists(), "No file at {}", cmx_path.to_string_lossy());
+
     let temp_dir_str = temp_dir.path().to_string_lossy();
     let destination_path = format!(
         "{}/{}",
@@ -400,7 +414,8 @@
     }
     create_dir_all(&output_path).context("create_dir_all failed")?;
     let stripped_binary_path = strip_binary(binary_path)?;
-    let included_cmx_file = include_cmx_file(&target_options.config, &cmx_path, &temp_dir)?;
+    let included_cmx_file =
+        include_cmx_file(verbose, &target_options.config, &cmx_path, &temp_dir)?;
     validate_cmx_file(verbose, &target_options.config, &included_cmx_file)?;
     let formatted_path = format_cmx_file(&target_options.config, &included_cmx_file, &temp_dir)?;
     let package_path = temp_dir.path().join("package");