()
| 67 | } |
| 68 | |
| 69 | fn run() -> Result<(), Error> { |
| 70 | let manifest_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")); |
| 71 | let workspace_dir = PathBuf::from(env!("CARGO_WORKSPACE_DIR")); |
| 72 | |
| 73 | #[cfg(feature = "desktop")] |
| 74 | let output_path = workspace_dir.join("desktop/third-party-licenses.txt.xz"); |
| 75 | #[cfg(not(feature = "desktop"))] |
| 76 | let output_path = workspace_dir.join("frontend/third-party-licenses.txt"); |
| 77 | |
| 78 | #[cfg(feature = "desktop")] |
| 79 | let current_hash_path = manifest_dir.join("desktop.hash"); |
| 80 | #[cfg(not(feature = "desktop"))] |
| 81 | let current_hash_path = manifest_dir.join("web.hash"); |
| 82 | |
| 83 | let cargo_source = CargoLicenseSource::new(); |
| 84 | let npm_source = NpmLicenseSource::new(workspace_dir.join("frontend")); |
| 85 | #[cfg(feature = "desktop")] |
| 86 | let cef_source = CefLicenseSource::new(); |
| 87 | |
| 88 | let mut run = Run { |
| 89 | cargo: &cargo_source, |
| 90 | npm: &npm_source, |
| 91 | #[cfg(feature = "desktop")] |
| 92 | cef: &cef_source, |
| 93 | output: &fs::read(&output_path).unwrap_or_default(), |
| 94 | }; |
| 95 | |
| 96 | let mut hasher = DefaultHasher::new(); |
| 97 | run.hash(&mut hasher); |
| 98 | let current_hash = format!("{:016x}", hasher.finish()); |
| 99 | |
| 100 | if current_hash == fs::read_to_string(¤t_hash_path).unwrap_or_default() { |
| 101 | return Ok(()); |
| 102 | } |
| 103 | eprintln!("Changes in licenses detected, generating new license file..."); |
| 104 | |
| 105 | let licenses = merge_filter_dedup_and_sort(vec![ |
| 106 | cargo_source.licenses()?, |
| 107 | npm_source.licenses()?, |
| 108 | #[cfg(feature = "desktop")] |
| 109 | cef_source.licenses()?, |
| 110 | ]); |
| 111 | let formatted = format_credits(&licenses); |
| 112 | |
| 113 | #[cfg(feature = "desktop")] |
| 114 | let output = compress(&formatted)?; |
| 115 | #[cfg(not(feature = "desktop"))] |
| 116 | let output = formatted.as_bytes().to_vec(); |
| 117 | if let Some(parent) = output_path.parent() { |
| 118 | fs::create_dir_all(parent).map_err(|e| Error::Io(e, format!("Failed to create directory {}", parent.display())))?; |
| 119 | } |
| 120 | fs::write(&output_path, &output).map_err(|e| Error::Io(e, format!("Failed to write {}", output_path.display())))?; |
| 121 | run.output = &output; |
| 122 | |
| 123 | let hash = { |
| 124 | let mut hasher = DefaultHasher::new(); |
| 125 | run.hash(&mut hasher); |
| 126 | format!("{:016x}", hasher.finish()) |
no test coverage detected