Run the `alpm-pkgbuild srcinfo format` command on a PKGBUILD and compare its output with a given .SRCINFO file. If the generated and read [`SRCINFO`] representations do not match, the respective files `pkgbuild.json` and `srcinfo.json` are output to the current working directory and the function exits with an exit code of `1`. These files contain pretty-printed JSON, which accurately depicts the
(pkgbuild_path: PathBuf, srcinfo_path: PathBuf)
| 148 | /// [`SRCINFO`]: https://alpm.archlinux.page/specifications/SRCINFO.5.html |
| 149 | /// [`alpm-pkgbuild-bridge`]: https://gitlab.archlinux.org/archlinux/alpm/alpm-pkgbuild-bridge |
| 150 | pub fn compare_source_info(pkgbuild_path: PathBuf, srcinfo_path: PathBuf) -> Result<(), Error> { |
| 151 | let pkgbuild_source_info: SourceInfoV1 = SourceInfoV1::from_pkgbuild(&pkgbuild_path)?; |
| 152 | |
| 153 | let source_info = SourceInfo::from_file_with_schema(srcinfo_path, None)?; |
| 154 | let SourceInfo::V1(source_info) = source_info; |
| 155 | |
| 156 | if source_info != pkgbuild_source_info { |
| 157 | let pkgbuild_source_info = |
| 158 | to_string_pretty(&pkgbuild_source_info).map_err(|source| Error::Json { |
| 159 | context: "deserializing a PKGBUILD based SRCINFO as pretty JSON".to_string(), |
| 160 | source, |
| 161 | })?; |
| 162 | let source_info = to_string_pretty(&source_info).map_err(|source| Error::Json { |
| 163 | context: "deserializing a SRCINFO as pretty JSON".to_string(), |
| 164 | source, |
| 165 | })?; |
| 166 | |
| 167 | let pkgbuild_json_path = PathBuf::from("pkgbuild.json"); |
| 168 | write("pkgbuild.json", pkgbuild_source_info).map_err(|source| Error::IoPath { |
| 169 | path: pkgbuild_json_path, |
| 170 | context: "writing pkgbuild.json file".to_string(), |
| 171 | source, |
| 172 | })?; |
| 173 | let srcinfo_json_path = PathBuf::from("srcinfo.json"); |
| 174 | write("srcinfo.json", source_info).map_err(|source| Error::IoPath { |
| 175 | path: srcinfo_json_path, |
| 176 | context: "writing srcinfo.json file".to_string(), |
| 177 | source, |
| 178 | })?; |
| 179 | |
| 180 | eprintln!( |
| 181 | "SRCINFO data generated from PKGBUILD file differs from the .SRCINFO file read from disk.\n\ |
| 182 | Compare the two generated files pkgbuild.json and srcinfo.json for details." |
| 183 | ); |
| 184 | exit(1); |
| 185 | } else { |
| 186 | println!("The generated content matches that read from disk."); |
| 187 | } |
| 188 | |
| 189 | Ok(()) |
| 190 | } |