about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJacob Kiesel <jake@bitcrafters.co>2024-09-28 18:09:44 -0600
committerJacob Kiesel <jake@bitcrafters.co>2024-10-01 21:23:21 -0600
commitdba814a9221e815a589a3ba48d2ef5287cd951ab (patch)
tree34adf6db0aae3c5e760de7cb38295fe5e4f90034
parent081661b78d44bd41f8a1fd46b9ed11823cd7811e (diff)
downloadrust-dba814a9221e815a589a3ba48d2ef5287cd951ab.tar.gz
rust-dba814a9221e815a589a3ba48d2ef5287cd951ab.zip
Pile all the checksum info into a comment that goes in the same order as the file list for the makefile
-rw-r--r--compiler/rustc_interface/src/passes.rs33
1 files changed, 20 insertions, 13 deletions
diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs
index b9b65755db5..cd5624e38bd 100644
--- a/compiler/rustc_interface/src/passes.rs
+++ b/compiler/rustc_interface/src/passes.rs
@@ -536,7 +536,7 @@ fn write_out_deps(tcx: TyCtxt<'_>, outputs: &OutputFilenames, out_filenames: &[P
 
         let write_deps_to_file = |file: &mut dyn Write| -> io::Result<()> {
             for path in out_filenames {
-                writeln!(
+                write!(
                     file,
                     "{}: {}\n",
                     path.display(),
@@ -546,6 +546,25 @@ fn write_out_deps(tcx: TyCtxt<'_>, outputs: &OutputFilenames, out_filenames: &[P
                         .intersperse(" ")
                         .collect::<String>()
                 )?;
+
+                // If caller requested this information, add special comments about source file checksums.
+                // These are not necessarily the same checksums as was used in the debug files.
+                if sess.opts.unstable_opts.checksum_hash_algorithm().is_some() {
+                    assert!(
+                        files.iter().all(|(_path, _file_len, hash_algo)| hash_algo.is_some()),
+                        "all files must have a checksum hash computed to output checksum hashes"
+                    );
+                    write!(file, " # ")?;
+                    files
+                        .iter()
+                        .filter_map(|(_path, file_len, hash_algo)| {
+                            hash_algo.map(|hash_algo| (path, file_len, hash_algo))
+                        })
+                        .try_for_each(|(_path, file_len, checksum_hash)| {
+                            write!(file, "checksum:{checksum_hash} file_len:{file_len}, ")
+                        })?;
+                }
+                writeln!(file)?;
             }
 
             // Emit a fake target for each input file to the compilation. This
@@ -575,18 +594,6 @@ fn write_out_deps(tcx: TyCtxt<'_>, outputs: &OutputFilenames, out_filenames: &[P
                 }
             }
 
-            // If caller requested this information, add special comments about source file checksums.
-            // These are not necessarily the same checksums as was used in the debug files.
-            if sess.opts.unstable_opts.checksum_hash_algorithm().is_some() {
-                for (path, file_len, checksum_hash) in
-                    files.iter().filter_map(|(path, file_len, hash_algo)| {
-                        hash_algo.map(|hash_algo| (path, file_len, hash_algo))
-                    })
-                {
-                    writeln!(file, "# checksum:{checksum_hash} file_len:{file_len} {path}")?;
-                }
-            }
-
             Ok(())
         };