Get the top level crate that we need to analyze
()
| 63 | |
| 64 | // Get the top level crate that we need to analyze |
| 65 | fn current_crate() -> cargo_metadata::Package { |
| 66 | // We need to get the manifest, and then the metadata, to enumerate targets. |
| 67 | |
| 68 | // Path to the `Cargo.toml` file |
| 69 | let manifest_path = |
| 70 | get_arg_flag_value("--manifest-path").map(|m| Path::new(&m).canonicalize().unwrap()); |
| 71 | |
| 72 | let mut cmd = cargo_metadata::MetadataCommand::new(); |
| 73 | if let Some(ref manifest_path) = manifest_path { |
| 74 | cmd.manifest_path(manifest_path); |
| 75 | } |
| 76 | let mut metadata = if let Ok(metadata) = cmd.exec() { |
| 77 | metadata |
| 78 | } else { |
| 79 | show_error("Could not obtain Cargo metadata; likely an ill-formed manifest".to_string()); |
| 80 | }; |
| 81 | |
| 82 | let current_dir = std::env::current_dir(); |
| 83 | |
| 84 | let package_index = metadata |
| 85 | .packages |
| 86 | .iter() |
| 87 | .position(|package| { |
| 88 | let package_manifest_path = Path::new(&package.manifest_path); |
| 89 | if let Some(ref manifest_path) = manifest_path { |
| 90 | package_manifest_path == manifest_path |
| 91 | } else { |
| 92 | let current_dir = current_dir |
| 93 | .as_ref() |
| 94 | .expect("could not read current directory"); |
| 95 | let package_manifest_directory = package_manifest_path |
| 96 | .parent() |
| 97 | .expect("could not find parent directory of package manifest"); |
| 98 | package_manifest_directory == current_dir |
| 99 | } |
| 100 | }) |
| 101 | .unwrap_or_else(|| { |
| 102 | show_error( |
| 103 | "This seems to be a workspace, which is not supported by cargo-miri".to_string(), |
| 104 | ) |
| 105 | }); |
| 106 | let package = metadata.packages.remove(package_index); |
| 107 | |
| 108 | package |
| 109 | } |
| 110 | |
| 111 | fn bypasser() -> Command { |
| 112 | let mut path = std::env::current_exe().expect("current executable path invalid"); |
no test coverage detected