]> git.lizzy.rs Git - rust.git/commitdiff
Make graphviz font configurable
authorRich Kadel <richkadel@google.com>
Wed, 16 Sep 2020 15:10:06 +0000 (08:10 -0700)
committerRich Kadel <richkadel@google.com>
Wed, 16 Sep 2020 15:10:06 +0000 (08:10 -0700)
Alternative to PR ##76776.

To change the graphviz output to use an alternative `fontname` value,
add a command line option like: `rustc --graphviz-font=monospace`.

compiler/rustc_graphviz/src/lib.rs
compiler/rustc_mir/src/dataflow/framework/engine.rs
compiler/rustc_mir/src/util/graphviz.rs
compiler/rustc_session/src/options.rs

index 29ec3572016d759185989c8c6efb1e9f7d941eb0..58db81bc1dc619c35d5d6c2ef984f95d928a23b9 100644 (file)
@@ -591,14 +591,14 @@ pub trait GraphWalk<'a> {
     fn target(&'a self, edge: &Self::Edge) -> Self::Node;
 }
 
-#[derive(Copy, Clone, PartialEq, Eq, Debug)]
+#[derive(Clone, PartialEq, Eq, Debug)]
 pub enum RenderOption {
     NoEdgeLabels,
     NoNodeLabels,
     NoEdgeStyles,
     NoNodeStyles,
 
-    Monospace,
+    Fontname(String),
     DarkTheme,
 }
 
@@ -633,11 +633,14 @@ pub fn render_opts<'a, N, E, G, W>(g: &'a G, w: &mut W, options: &[RenderOption]
     // Global graph properties
     let mut graph_attrs = Vec::new();
     let mut content_attrs = Vec::new();
-    if options.contains(&RenderOption::Monospace) {
-        let font = r#"fontname="Courier, monospace""#;
-        graph_attrs.push(font);
-        content_attrs.push(font);
-    };
+    let font;
+    if let Some(fontname) = options.iter().find_map(|option| {
+        if let RenderOption::Fontname(fontname) = option { Some(fontname) } else { None }
+    }) {
+        font = format!(r#"fontname="{}""#, fontname);
+        graph_attrs.push(&font[..]);
+        content_attrs.push(&font[..]);
+    }
     if options.contains(&RenderOption::DarkTheme) {
         graph_attrs.push(r#"bgcolor="black""#);
         content_attrs.push(r#"color="white""#);
index 0b5b437d186aade4297534aaa699ff0327276eee..4084083bd9956a4a493aee952e254243e2812937 100644 (file)
@@ -306,7 +306,8 @@ fn write_graphviz_results<A>(
     let mut buf = Vec::new();
 
     let graphviz = graphviz::Formatter::new(body, def_id, results, style);
-    let mut render_opts = vec![dot::RenderOption::Monospace];
+    let mut render_opts =
+        vec![dot::RenderOption::Fontname(tcx.sess.opts.debugging_opts.graphviz_font.clone())];
     if tcx.sess.opts.debugging_opts.graphviz_dark_mode {
         render_opts.push(dot::RenderOption::DarkTheme);
     }
index e89c9437706384e3a8ff65ca067135485f72a9dc..4511962d68f032dcfccfc933aa943c8f2f3fd383 100644 (file)
@@ -55,9 +55,9 @@ pub fn write_mir_fn_graphviz<'tcx, W>(
     writeln!(w, "{} {}Mir_{} {{", kind, cluster, def_name)?;
 
     // Global graph properties
-    let font = r#"fontname="Courier, monospace""#;
-    let mut graph_attrs = vec![font];
-    let mut content_attrs = vec![font];
+    let font = format!(r#"fontname="{}""#, tcx.sess.opts.debugging_opts.graphviz_font);
+    let mut graph_attrs = vec![&font[..]];
+    let mut content_attrs = vec![&font[..]];
 
     let dark_mode = tcx.sess.opts.debugging_opts.graphviz_dark_mode;
     if dark_mode {
index f31e0431d0da7d65da4f5fa2dd9661db9c0cfe4d..60bd557b880eb956f846d16ac9fc425d5eca9bba 100644 (file)
@@ -909,6 +909,8 @@ fn parse_target_feature(slot: &mut String, v: Option<&str>) -> bool {
         "set the optimization fuel quota for a crate"),
     graphviz_dark_mode: bool = (false, parse_bool, [UNTRACKED],
         "use dark-themed colors in graphviz output (default: no)"),
+    graphviz_font: String = ("Courier, monospace".to_string(), parse_string, [UNTRACKED],
+        "use the given `fontname` in graphviz output (default: `Courier, monospace`)"),
     hir_stats: bool = (false, parse_bool, [UNTRACKED],
         "print some statistics about AST and HIR (default: no)"),
     human_readable_cgu_names: bool = (false, parse_bool, [TRACKED],