|
7 | 7 | //! * [`RustcTargetData::info`] to get a [`TargetInfo`] for an in-depth query. |
8 | 8 | //! * [`TargetInfo::rustc_outputs`] to get a list of supported file types. |
9 | 9 |
|
| 10 | +use crate::core::compiler::CompileKind; |
| 11 | +use crate::core::compiler::CompileMode; |
| 12 | +use crate::core::compiler::CompileTarget; |
| 13 | +use crate::core::compiler::CrateType; |
10 | 14 | use crate::core::compiler::apply_env_config; |
11 | | -use crate::core::compiler::{BuildRunner, CompileKind, CompileMode, CompileTarget, CrateType}; |
12 | 15 | use crate::core::{Dependency, Package, Target, TargetKind, Workspace}; |
13 | 16 | use crate::util::context::{GlobalContext, StringList, TargetConfig}; |
14 | 17 | use crate::util::interning::InternedString; |
15 | 18 | use crate::util::{CargoResult, Rustc}; |
| 19 | + |
16 | 20 | use anyhow::Context as _; |
17 | 21 | use cargo_platform::{Cfg, CfgExpr}; |
18 | | -use cargo_util::{ProcessBuilder, paths}; |
19 | | -use serde::{Deserialize, Serialize}; |
| 22 | +use cargo_util::ProcessBuilder; |
| 23 | +use serde::Deserialize; |
| 24 | + |
20 | 25 | use std::cell::RefCell; |
21 | 26 | use std::collections::hash_map::{Entry, HashMap}; |
22 | | -use std::path::{Path, PathBuf}; |
| 27 | +use std::path::PathBuf; |
23 | 28 | use std::rc::Rc; |
24 | 29 | use std::str::{self, FromStr}; |
25 | 30 |
|
@@ -1110,113 +1115,3 @@ impl<'gctx> RustcTargetData<'gctx> { |
1110 | 1115 | &self.requested_kinds |
1111 | 1116 | } |
1112 | 1117 | } |
1113 | | - |
1114 | | -/// Structure used to deal with Rustdoc fingerprinting |
1115 | | -#[derive(Debug, Serialize, Deserialize)] |
1116 | | -pub struct RustDocFingerprint { |
1117 | | - pub rustc_vv: String, |
1118 | | -} |
1119 | | - |
1120 | | -impl RustDocFingerprint { |
1121 | | - /// This function checks whether the latest version of `Rustc` used to compile this |
1122 | | - /// `Workspace`'s docs was the same as the one is currently being used in this `cargo doc` |
1123 | | - /// call. |
1124 | | - /// |
1125 | | - /// In case it's not, it takes care of removing the `doc/` folder as well as overwriting |
1126 | | - /// the rustdoc fingerprint info in order to guarantee that we won't end up with mixed |
1127 | | - /// versions of the `js/html/css` files that `rustdoc` autogenerates which do not have |
1128 | | - /// any versioning. |
1129 | | - pub fn check_rustdoc_fingerprint(build_runner: &BuildRunner<'_, '_>) -> CargoResult<()> { |
1130 | | - if build_runner |
1131 | | - .bcx |
1132 | | - .gctx |
1133 | | - .cli_unstable() |
1134 | | - .skip_rustdoc_fingerprint |
1135 | | - { |
1136 | | - return Ok(()); |
1137 | | - } |
1138 | | - let actual_rustdoc_target_data = RustDocFingerprint { |
1139 | | - rustc_vv: build_runner.bcx.rustc().verbose_version.clone(), |
1140 | | - }; |
1141 | | - |
1142 | | - let fingerprint_path = build_runner |
1143 | | - .files() |
1144 | | - .host_build_root() |
1145 | | - .join(".rustdoc_fingerprint.json"); |
1146 | | - let write_fingerprint = || -> CargoResult<()> { |
1147 | | - paths::write( |
1148 | | - &fingerprint_path, |
1149 | | - serde_json::to_string(&actual_rustdoc_target_data)?, |
1150 | | - ) |
1151 | | - }; |
1152 | | - let Ok(rustdoc_data) = paths::read(&fingerprint_path) else { |
1153 | | - // If the fingerprint does not exist, do not clear out the doc |
1154 | | - // directories. Otherwise this ran into problems where projects |
1155 | | - // like bootstrap were creating the doc directory before running |
1156 | | - // `cargo doc` in a way that deleting it would break it. |
1157 | | - return write_fingerprint(); |
1158 | | - }; |
1159 | | - match serde_json::from_str::<RustDocFingerprint>(&rustdoc_data) { |
1160 | | - Ok(fingerprint) => { |
1161 | | - if fingerprint.rustc_vv == actual_rustdoc_target_data.rustc_vv { |
1162 | | - return Ok(()); |
1163 | | - } else { |
1164 | | - tracing::debug!( |
1165 | | - "doc fingerprint changed:\noriginal:\n{}\nnew:\n{}", |
1166 | | - fingerprint.rustc_vv, |
1167 | | - actual_rustdoc_target_data.rustc_vv |
1168 | | - ); |
1169 | | - } |
1170 | | - } |
1171 | | - Err(e) => { |
1172 | | - tracing::debug!("could not deserialize {:?}: {}", fingerprint_path, e); |
1173 | | - } |
1174 | | - }; |
1175 | | - // Fingerprint does not match, delete the doc directories and write a new fingerprint. |
1176 | | - tracing::debug!( |
1177 | | - "fingerprint {:?} mismatch, clearing doc directories", |
1178 | | - fingerprint_path |
1179 | | - ); |
1180 | | - build_runner |
1181 | | - .bcx |
1182 | | - .all_kinds |
1183 | | - .iter() |
1184 | | - .map(|kind| { |
1185 | | - build_runner |
1186 | | - .files() |
1187 | | - .layout(*kind) |
1188 | | - .artifact_dir() |
1189 | | - .expect("artifact-dir was not locked") |
1190 | | - .doc() |
1191 | | - }) |
1192 | | - .filter(|path| path.exists()) |
1193 | | - .try_for_each(|path| clean_doc(path))?; |
1194 | | - write_fingerprint()?; |
1195 | | - return Ok(()); |
1196 | | - |
1197 | | - fn clean_doc(path: &Path) -> CargoResult<()> { |
1198 | | - let entries = path |
1199 | | - .read_dir() |
1200 | | - .with_context(|| format!("failed to read directory `{}`", path.display()))?; |
1201 | | - for entry in entries { |
1202 | | - let entry = entry?; |
1203 | | - // Don't remove hidden files. Rustdoc does not create them, |
1204 | | - // but the user might have. |
1205 | | - if entry |
1206 | | - .file_name() |
1207 | | - .to_str() |
1208 | | - .map_or(false, |name| name.starts_with('.')) |
1209 | | - { |
1210 | | - continue; |
1211 | | - } |
1212 | | - let path = entry.path(); |
1213 | | - if entry.file_type()?.is_dir() { |
1214 | | - paths::remove_dir_all(path)?; |
1215 | | - } else { |
1216 | | - paths::remove_file(path)?; |
1217 | | - } |
1218 | | - } |
1219 | | - Ok(()) |
1220 | | - } |
1221 | | - } |
1222 | | -} |
0 commit comments