Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
[ghstack-poisoned]
  • Loading branch information
ezyang committed May 19, 2024
1 parent 81ed802 commit ff799ea
Showing 3 changed files with 29 additions and 15 deletions.
27 changes: 23 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -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<ParseOu
// Each entry is a compile id => (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<Option<CompileId>, Vec<(String, String, i32)>> = FxIndexMap::default();
let mut directory: FxIndexMap<Option<CompileId>, Vec<(String, String, i32)>> =
FxIndexMap::default();

let mut metrics_index: CompilationMetricsIndex = FxIndexMap::default();
let stack_index: RefCell<StackIndex> = RefCell::new(FxHashMap::default());
@@ -239,11 +241,28 @@ pub fn parse_path(path: &PathBuf, config: ParseConfig) -> anyhow::Result<ParseOu
match results {
Ok(results) => {
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) => {
16 changes: 6 additions & 10 deletions src/parsers.rs
Original file line number Diff line number Diff line change
@@ -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<String, anyhow::Error> {
&syntax,
&theme_set.themes["InspiredGitHub"],
);
let wrapped_html = format!(
"<div style=\"padding: 10px; border: 1px solid #ffffff; border-radius: 5px; background-color: #ffffff;\">{}</div>",
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<Metadata<'e>> {
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<ParserResults> {
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"))
}
1 change: 0 additions & 1 deletion src/types.rs
Original file line number Diff line number Diff line change
@@ -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<Option<CompileId>, Vec<CompilationMetricsMetadata>>;

0 comments on commit ff799ea

Please sign in to comment.