| 106 | } |
| 107 | |
| 108 | pub fn parse_workspace<T>(directory: T) -> Result<Workspace> |
| 109 | where |
| 110 | T: Into<String>, |
| 111 | { |
| 112 | let dir = directory.into(); |
| 113 | let dir = dir.trim_end_matches('/'); |
| 114 | |
| 115 | let res = Command::new("cargo") |
| 116 | .current_dir(dir) |
| 117 | .arg("metadata") |
| 118 | .arg("--format-version=1") |
| 119 | .stderr(Stdio::inherit()) |
| 120 | .output()?; |
| 121 | |
| 122 | // println!("{:#?}", res); |
| 123 | |
| 124 | if !res.status.success() { |
| 125 | panic!("Fail to parse workspace metadata"); |
| 126 | } |
| 127 | |
| 128 | let workspace_raw = |
| 129 | serde_json::from_slice(&res.stdout).context("Fail to deserialize JSON string")?; |
| 130 | |
| 131 | // println!("{:#?}", workspace_raw); |
| 132 | |
| 133 | Ok(parsing::parse_workspace(workspace_raw)) |
| 134 | } |
| 135 | |
| 136 | fn path_to_str(path: &Path) -> &str { |
| 137 | path.to_str().expect("Failed to convert Path to &str") |