From ff799eac73dd5334488605c5c5d4b2a5f48f0d19 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Sun, 19 May 2024 08:52:59 -0400 Subject: [PATCH] Update [ghstack-poisoned] --- src/lib.rs | 27 +++++++++++++++++++++++---- src/parsers.rs | 16 ++++++---------- src/types.rs | 1 - 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 66e8b78..fdca0ca 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,7 @@ use anyhow::{anyhow, bail}; use fxhash::FxHashMap; use md5::{Digest, Md5}; +use std::ffi::{OsStr, OsString}; use indicatif::{MultiProgress, ProgressBar, ProgressStyle}; use regex::Regex; @@ -105,7 +106,8 @@ pub fn parse_path(path: &PathBuf, config: ParseConfig) -> anyhow::Result (link, rendered name, output number) // For files, link and rendered name are the same // For links, you can specify a custom name for the link - let mut directory: FxIndexMap, Vec<(String, String, i32)>> = FxIndexMap::default(); + let mut directory: FxIndexMap, Vec<(String, String, i32)>> = + FxIndexMap::default(); let mut metrics_index: CompilationMetricsIndex = FxIndexMap::default(); let stack_index: RefCell = RefCell::new(FxHashMap::default()); @@ -239,11 +241,28 @@ pub fn parse_path(path: &PathBuf, config: ParseConfig) -> anyhow::Result { for parser_result in results { - match parser_result { - ParserOutput::File(filename, out) => { + match parser_result { + ParserOutput::File(raw_filename, out) => { + let filename = if let Some(stem) = raw_filename.file_stem() { + let mut r = OsString::new(); + r.push(stem); + r.push(OsStr::new("_")); + r.push(output_count.to_string()); + if let Some(e) = raw_filename.extension() { + r.push(OsStr::new(".")); + r.push(e); + }; + r.into() + } else { + raw_filename + }; output.push((filename.clone(), out)); let filename_str = format!("{}", filename.to_string_lossy()); - compile_directory.push((filename_str.clone(), filename_str, output_count)); + compile_directory.push(( + filename_str.clone(), + filename_str, + output_count, + )); output_count += 1; } ParserOutput::Link(name, url) => { diff --git a/src/parsers.rs b/src/parsers.rs index d24871e..62ad6e1 100644 --- a/src/parsers.rs +++ b/src/parsers.rs @@ -42,7 +42,6 @@ pub trait StructuredLogParser { fn name(&self) -> &'static str; } - // Takes a filename and a payload and writes that payload into a the file fn simple_file_output( filename: &str, @@ -249,11 +248,7 @@ fn generate_html_output(payload: &str) -> Result { &syntax, &theme_set.themes["InspiredGitHub"], ); - let wrapped_html = format!( - "
{}
", - html.unwrap() - ); - Ok(wrapped_html) + Ok(html) } pub struct OptimizeDdpSplitChildParser; @@ -290,9 +285,7 @@ impl StructuredLogParser for LinkParser { "link_parser" } fn get_metadata<'e>(&self, e: &'e Envelope) -> Option> { - e.link - .as_ref() - .map(|m| Metadata::Link(m)) + e.link.as_ref().map(|m| Metadata::Link(m)) } fn parse<'e>( @@ -304,7 +297,10 @@ impl StructuredLogParser for LinkParser { _payload: &str, ) -> anyhow::Result { if let Metadata::Link(m) = metadata { - Ok(Vec::from([ParserOutput::Link(m.name.clone(), m.url.clone())])) + Ok(Vec::from([ParserOutput::Link( + m.name.clone(), + m.url.clone(), + )])) } else { Err(anyhow::anyhow!("Expected Link Metadata")) } diff --git a/src/types.rs b/src/types.rs index bb5dbbb..7a1087a 100644 --- a/src/types.rs +++ b/src/types.rs @@ -11,7 +11,6 @@ use once_cell::sync::Lazy; use serde::{Deserialize, Serialize}; use std::sync::Mutex; - // Main function returns a list of files to save pub type ParseOutput = Vec<(PathBuf, String)>; pub type CompilationMetricsIndex = FxIndexMap, Vec>;