mirror of
https://github.com/Noratrieb/target-tier-docs-experiment.git
synced 2026-01-14 16:35:09 +01:00
things
This commit is contained in:
parent
a00ca6ae97
commit
a7cd3d46f9
5 changed files with 100 additions and 76 deletions
1
hello
Normal file
1
hello
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
1
|
||||||
70
src/main.rs
70
src/main.rs
|
|
@ -38,9 +38,12 @@ fn main() -> Result<()> {
|
||||||
let input_dir = args
|
let input_dir = args
|
||||||
.get(1)
|
.get(1)
|
||||||
.ok_or_eyre("first argument must be path to target_infos directory containing target source md files (src/doc/rustc/target_infos/)")?;
|
.ok_or_eyre("first argument must be path to target_infos directory containing target source md files (src/doc/rustc/target_infos/)")?;
|
||||||
let output_src = args
|
let output_src = args.get(2).ok_or_eyre(
|
||||||
.get(2)
|
"second argument must be path to `src` output directory (build/$target/md-doc/rustc/src)",
|
||||||
.ok_or_eyre("second argument must be path to `src` output directory (src/doc/rustc/src)")?;
|
)?;
|
||||||
|
|
||||||
|
println!("Loading target info docs from {input_dir}");
|
||||||
|
println!("Writing output to {output_src}");
|
||||||
|
|
||||||
let rustc =
|
let rustc =
|
||||||
PathBuf::from(std::env::var("RUSTC").expect("must pass RUSTC env var pointing to rustc"));
|
PathBuf::from(std::env::var("RUSTC").expect("must pass RUSTC env var pointing to rustc"));
|
||||||
|
|
@ -53,24 +56,15 @@ fn main() -> Result<()> {
|
||||||
.wrap_err("failed loading target_info")?
|
.wrap_err("failed loading target_info")?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|info| {
|
.map(|info| {
|
||||||
let footnotes_used = info
|
let footnotes_used =
|
||||||
.footnotes
|
info.footnotes.iter().map(|(target, _)| (target.clone(), false)).collect();
|
||||||
.iter()
|
TargetPatternEntry { info, used: false, footnotes_used }
|
||||||
.map(|(target, _)| (target.clone(), false))
|
|
||||||
.collect();
|
|
||||||
TargetPatternEntry {
|
|
||||||
info,
|
|
||||||
used: false,
|
|
||||||
footnotes_used,
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
eprintln!("Collecting rustc information");
|
eprintln!("Collecting rustc information");
|
||||||
let rustc_infos = targets
|
let rustc_infos =
|
||||||
.iter()
|
targets.iter().map(|target| rustc_target_info(&rustc, target)).collect::<Vec<_>>();
|
||||||
.map(|target| rustc_target_info(&rustc, target))
|
|
||||||
.collect::<Vec<_>>();
|
|
||||||
|
|
||||||
let targets = targets
|
let targets = targets
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
|
@ -79,9 +73,7 @@ fn main() -> Result<()> {
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
eprintln!("Rendering targets check_only={check_only}");
|
eprintln!("Rendering targets check_only={check_only}");
|
||||||
let targets_dir = Path::new(output_src)
|
let targets_dir = Path::new(output_src).join("platform-support").join("targets");
|
||||||
.join("platform-support")
|
|
||||||
.join("targets");
|
|
||||||
if !check_only {
|
if !check_only {
|
||||||
std::fs::create_dir_all(&targets_dir).wrap_err("creating platform-support/targets dir")?;
|
std::fs::create_dir_all(&targets_dir).wrap_err("creating platform-support/targets dir")?;
|
||||||
}
|
}
|
||||||
|
|
@ -96,10 +88,7 @@ fn main() -> Result<()> {
|
||||||
|
|
||||||
for target_pattern in info_patterns {
|
for target_pattern in info_patterns {
|
||||||
if !target_pattern.used {
|
if !target_pattern.used {
|
||||||
bail!(
|
bail!("target pattern `{}` was never used", target_pattern.info.pattern);
|
||||||
"target pattern `{}` was never used",
|
|
||||||
target_pattern.info.pattern
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for footnote_target in target_pattern.info.footnotes.keys() {
|
for footnote_target in target_pattern.info.footnotes.keys() {
|
||||||
|
|
@ -127,7 +116,6 @@ struct TargetPatternEntry {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn target_doc_info(info_patterns: &mut [TargetPatternEntry], target: &str) -> TargetDocs {
|
fn target_doc_info(info_patterns: &mut [TargetPatternEntry], target: &str) -> TargetDocs {
|
||||||
let mut tier = None;
|
|
||||||
let mut maintainers = Vec::new();
|
let mut maintainers = Vec::new();
|
||||||
let mut sections = Vec::new();
|
let mut sections = Vec::new();
|
||||||
|
|
||||||
|
|
@ -140,14 +128,6 @@ fn target_doc_info(info_patterns: &mut [TargetPatternEntry], target: &str) -> Ta
|
||||||
|
|
||||||
maintainers.extend_from_slice(&target_pattern.maintainers);
|
maintainers.extend_from_slice(&target_pattern.maintainers);
|
||||||
|
|
||||||
if let Some(pattern_value) = &target_pattern.tier {
|
|
||||||
if tier.is_some() {
|
|
||||||
panic!(
|
|
||||||
"target {target} inherits a tier from multiple patterns, create a more specific pattern and add it there"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
tier = Some(pattern_value.clone());
|
|
||||||
}
|
|
||||||
|
|
||||||
for (section_name, content) in &target_pattern.sections {
|
for (section_name, content) in &target_pattern.sections {
|
||||||
if sections.iter().any(|(name, _)| name == section_name) {
|
if sections.iter().any(|(name, _)| name == section_name) {
|
||||||
|
|
@ -159,9 +139,7 @@ fn target_doc_info(info_patterns: &mut [TargetPatternEntry], target: &str) -> Ta
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(target_footnotes) = target_pattern.footnotes.get(target) {
|
if let Some(target_footnotes) = target_pattern.footnotes.get(target) {
|
||||||
target_pattern_entry
|
target_pattern_entry.footnotes_used.insert(target.to_owned(), true);
|
||||||
.footnotes_used
|
|
||||||
.insert(target.to_owned(), true);
|
|
||||||
|
|
||||||
if !footnotes.is_empty() {
|
if !footnotes.is_empty() {
|
||||||
panic!("target {target} is assigned metadata from more than one pattern");
|
panic!("target {target} is assigned metadata from more than one pattern");
|
||||||
|
|
@ -171,12 +149,7 @@ fn target_doc_info(info_patterns: &mut [TargetPatternEntry], target: &str) -> Ta
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TargetDocs {
|
TargetDocs { name: target.to_owned(), maintainers, sections, footnotes }
|
||||||
name: target.to_owned(),
|
|
||||||
maintainers,
|
|
||||||
sections,
|
|
||||||
footnotes,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Information about a target obtained from rustc.
|
/// Information about a target obtained from rustc.
|
||||||
|
|
@ -218,21 +191,12 @@ fn rustc_target_info(rustc: &Path, target: &str) -> RustcTargetInfo {
|
||||||
|
|
||||||
let json_spec = rustc_stdout(
|
let json_spec = rustc_stdout(
|
||||||
rustc,
|
rustc,
|
||||||
&[
|
&["-Zunstable-options", "--print", "target-spec-json", "--target", target],
|
||||||
"-Zunstable-options",
|
|
||||||
"--print",
|
|
||||||
"target-spec-json",
|
|
||||||
"--target",
|
|
||||||
target,
|
|
||||||
],
|
|
||||||
);
|
);
|
||||||
let spec = serde_json::from_str::<TargetJson>(&json_spec)
|
let spec = serde_json::from_str::<TargetJson>(&json_spec)
|
||||||
.expect("parsing --print target-spec-json for metadata");
|
.expect("parsing --print target-spec-json for metadata");
|
||||||
|
|
||||||
RustcTargetInfo {
|
RustcTargetInfo { target_cfgs, metadata: spec.metadata }
|
||||||
target_cfgs,
|
|
||||||
metadata: spec.metadata,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn rustc_stdout(rustc: &Path, args: &[&str]) -> String {
|
fn rustc_stdout(rustc: &Path, args: &[&str]) -> String {
|
||||||
|
|
|
||||||
13
src/parse.rs
13
src/parse.rs
|
|
@ -4,20 +4,9 @@ use eyre::{bail, OptionExt, Result, WrapErr};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use std::{collections::HashMap, fs::DirEntry, path::Path};
|
use std::{collections::HashMap, fs::DirEntry, path::Path};
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Clone, Deserialize)]
|
|
||||||
pub enum Tier {
|
|
||||||
#[serde(rename = "1")]
|
|
||||||
One,
|
|
||||||
#[serde(rename = "2")]
|
|
||||||
Two,
|
|
||||||
#[serde(rename = "3")]
|
|
||||||
Three,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct ParsedTargetInfoFile {
|
pub struct ParsedTargetInfoFile {
|
||||||
pub pattern: String,
|
pub pattern: String,
|
||||||
pub tier: Option<Tier>,
|
|
||||||
pub maintainers: Vec<String>,
|
pub maintainers: Vec<String>,
|
||||||
pub sections: Vec<(String, String)>,
|
pub sections: Vec<(String, String)>,
|
||||||
pub footnotes: HashMap<String, Vec<String>>,
|
pub footnotes: HashMap<String, Vec<String>>,
|
||||||
|
|
@ -27,7 +16,6 @@ pub struct ParsedTargetInfoFile {
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
#[serde(deny_unknown_fields)]
|
#[serde(deny_unknown_fields)]
|
||||||
struct Frontmatter {
|
struct Frontmatter {
|
||||||
tier: Option<Tier>,
|
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
maintainers: Vec<String>,
|
maintainers: Vec<String>,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
|
|
@ -138,7 +126,6 @@ fn parse_file(name: &str, content: &str) -> Result<ParsedTargetInfoFile> {
|
||||||
Ok(ParsedTargetInfoFile {
|
Ok(ParsedTargetInfoFile {
|
||||||
pattern: name.to_owned(),
|
pattern: name.to_owned(),
|
||||||
maintainers: frontmatter.maintainers,
|
maintainers: frontmatter.maintainers,
|
||||||
tier: frontmatter.tier,
|
|
||||||
sections,
|
sections,
|
||||||
footnotes: frontmatter.footnotes,
|
footnotes: frontmatter.footnotes,
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -5,15 +5,25 @@ use crate::{RustcTargetInfo, TargetDocs};
|
||||||
|
|
||||||
/// Renders a single target markdown file from the information obtained.
|
/// Renders a single target markdown file from the information obtained.
|
||||||
pub fn render_target_md(target: &TargetDocs, rustc_info: &RustcTargetInfo) -> String {
|
pub fn render_target_md(target: &TargetDocs, rustc_info: &RustcTargetInfo) -> String {
|
||||||
|
let render_header_option_bool = |bool| {
|
||||||
|
match bool {
|
||||||
|
Some(true) => "Yes",
|
||||||
|
Some(false) => "No",
|
||||||
|
None => "?",
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let mut doc = format!(
|
let mut doc = format!(
|
||||||
"# {}\n\n**Tier: {}**\n\n",
|
"# {}\n\n**Tier: {}**\n\n**std: {}**\n\n**host tools: {}**\n\n",
|
||||||
target.name,
|
target.name,
|
||||||
match rustc_info.metadata.tier {
|
match rustc_info.metadata.tier {
|
||||||
Some(1) => "1",
|
Some(1) => "1",
|
||||||
Some(2) => "2",
|
Some(2) => "2",
|
||||||
Some(3) => "3",
|
Some(3) => "3",
|
||||||
_ => "UNKNOWN",
|
_ => "UNKNOWN",
|
||||||
}
|
},
|
||||||
|
render_header_option_bool(rustc_info.metadata.std),
|
||||||
|
render_header_option_bool(rustc_info.metadata.host_tools),
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut section = |name: &str, content: &str| {
|
let mut section = |name: &str, content: &str| {
|
||||||
|
|
@ -52,10 +62,7 @@ pub fn render_target_md(target: &TargetDocs, rustc_info: &RustcTargetInfo) -> St
|
||||||
section("Maintainers", &maintainers_content);
|
section("Maintainers", &maintainers_content);
|
||||||
|
|
||||||
for section_name in crate::SECTIONS {
|
for section_name in crate::SECTIONS {
|
||||||
let value = target
|
let value = target.sections.iter().find(|(name, _)| name == section_name);
|
||||||
.sections
|
|
||||||
.iter()
|
|
||||||
.find(|(name, _)| name == section_name);
|
|
||||||
|
|
||||||
let section_content = match value {
|
let section_content = match value {
|
||||||
Some((_, value)) => value.clone(),
|
Some((_, value)) => value.clone(),
|
||||||
|
|
@ -93,9 +100,7 @@ fn replace_section(prev_content: &str, section_name: &str, replacement: &str) ->
|
||||||
.split_once(&magic_summary_end)
|
.split_once(&magic_summary_end)
|
||||||
.ok_or_eyre("<!-- TARGET SECTION START --> not found")?;
|
.ok_or_eyre("<!-- TARGET SECTION START --> not found")?;
|
||||||
|
|
||||||
let new = format!(
|
let new = format!("{pre_target}{replacement}{post_target}");
|
||||||
"{pre_target}{magic_summary_start}\n{replacement}\n{magic_summary_end}{post_target}"
|
|
||||||
);
|
|
||||||
Ok(new)
|
Ok(new)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -110,7 +115,7 @@ pub fn render_static(
|
||||||
|
|
||||||
let target_list = targets
|
let target_list = targets
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(target, _)| format!("- [{0}](targets/{0}.md)", target.name))
|
.map(|(target, _)| format!("- [{0}](platform-support/targets/{0}.md)", target.name))
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.join("\n");
|
.join("\n");
|
||||||
|
|
||||||
|
|
@ -132,6 +137,16 @@ pub fn render_static(
|
||||||
.wrap_err("writing platform-support.md")?;
|
.wrap_err("writing platform-support.md")?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let summary = src_output.join("SUMMARY.md");
|
||||||
|
let summary_old = fs::read_to_string(&summary).wrap_err("reading SUMMARY.md")?;
|
||||||
|
// indent the list
|
||||||
|
let summary_new =
|
||||||
|
replace_section(&summary_old, "TARGET_LIST", &target_list.replace("- ", " - "))
|
||||||
|
.wrap_err("replacig SUMMARY.md")?;
|
||||||
|
if !check_only {
|
||||||
|
fs::write(summary, summary_new).wrap_err("writing SUMAMRY.md")?;
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
57
trace
Normal file
57
trace
Normal file
|
|
@ -0,0 +1,57 @@
|
||||||
|
Attaching 3 probes...
|
||||||
|
@fdpath[1871, 27]: /proc/sys/net/ipv6/conf/enp39s0/mtu
|
||||||
|
@fdpath[2483, 6]: /etc/passwd
|
||||||
|
@fdpath[3226, 103]: /proc/135816/cmdline
|
||||||
|
@fdpath[3842, 82]: /proc/4192/status
|
||||||
|
@fdpath[4020, 53]: /dev/video0
|
||||||
|
@fdpath[4020, 56]: /proc/253926/stat
|
||||||
|
@fdpath[4020, -2]: /dev/video63
|
||||||
|
@fdpath[5494, 36]: /proc/253923/cmdline
|
||||||
|
@fdpath[10038, 41]: /proc/154305/cmdline
|
||||||
|
@fdpath[252060, 7]: /dev/null
|
||||||
|
@fdpath[253926, 13]: /sys/kernel/debug/tracing/events/syscalls/sys_enter_write/id
|
||||||
|
@fdpath[253926, 15]: /dev/null
|
||||||
|
@fdpath[253937, 3]: /etc/localtime
|
||||||
|
@fdpath[253937, -2]: /.envrc
|
||||||
|
@fdpath[253943, 3]: .git/packed-refs
|
||||||
|
@fdpath[253943, -2]: /nix/store/jgrsps4vp9243gbakax7y3mz9pkdfnfk-pcre2-10.43/lib/lib
|
||||||
|
@fdpath[253944, 3]: .git/refs/heads/master
|
||||||
|
@fdpath[253944, -2]: /nix/store/jgrsps4vp9243gbakax7y3mz9pkdfnfk-pcre2-10.43/lib/lib
|
||||||
|
@fdpath[253945, 3]: .git/config
|
||||||
|
@fdpath[253945, 4]: /nix/store/ksk3rnb0ljx8gngzk19jlmbjyvac4hw6-glibc-2.38-44/lib/g
|
||||||
|
@fdpath[253945, -2]: /nix/store/ksk3rnb0ljx8gngzk19jlmbjyvac4hw6-glibc-2.38-44/lib/g
|
||||||
|
@fdpath[253946, 3]: /etc/localtime
|
||||||
|
@fdpath[253946, -2]: /.envrc
|
||||||
|
@fdpath[253952, 3]: .git/packed-refs
|
||||||
|
@fdpath[253952, -2]: /nix/store/jgrsps4vp9243gbakax7y3mz9pkdfnfk-pcre2-10.43/lib/lib
|
||||||
|
@fdpath[253953, 3]: .git/refs/heads/master
|
||||||
|
@fdpath[253953, -2]: /nix/store/jgrsps4vp9243gbakax7y3mz9pkdfnfk-pcre2-10.43/lib/lib
|
||||||
|
@fdpath[253954, 3]: .git/config
|
||||||
|
@fdpath[253954, 4]: /nix/store/ksk3rnb0ljx8gngzk19jlmbjyvac4hw6-glibc-2.38-44/lib/g
|
||||||
|
@fdpath[253954, -2]: /nix/store/ksk3rnb0ljx8gngzk19jlmbjyvac4hw6-glibc-2.38-44/lib/g
|
||||||
|
@openatpaths[1871]: /proc/sys/net/ipv6/conf/enp39s0/mtu
|
||||||
|
@openatpaths[2485]: /etc/passwd
|
||||||
|
@openatpaths[2486]: /etc/passwd
|
||||||
|
@openatpaths[2487]: /etc/passwd
|
||||||
|
@openatpaths[2488]: /etc/passwd
|
||||||
|
@openatpaths[2489]: /etc/passwd
|
||||||
|
@openatpaths[2490]: /etc/passwd
|
||||||
|
@openatpaths[2491]: /etc/passwd
|
||||||
|
@openatpaths[2492]: /etc/passwd
|
||||||
|
@openatpaths[3226]: /proc/135816/cmdline
|
||||||
|
@openatpaths[3842]: /proc/4192/status
|
||||||
|
@openatpaths[4137]: /dev/video0
|
||||||
|
@openatpaths[4149]: /proc/253926/stat
|
||||||
|
@openatpaths[5494]: /proc/253923/cmdline
|
||||||
|
@openatpaths[10038]: /proc/154305/cmdline
|
||||||
|
@openatpaths[252060]: /dev/null
|
||||||
|
@openatpaths[253926]: /sys/kernel/debug/tracing/events/syscalls/sys_enter_write/id
|
||||||
|
@openatpaths[253937]: /.envrc
|
||||||
|
@openatpaths[253943]: .git/packed-refs
|
||||||
|
@openatpaths[253944]: .git/refs/heads/master
|
||||||
|
@openatpaths[253945]: .git/config
|
||||||
|
@openatpaths[253946]: /.envrc
|
||||||
|
@openatpaths[253952]: .git/packed-refs
|
||||||
|
@openatpaths[253953]: .git/refs/heads/master
|
||||||
|
@openatpaths[253954]: .git/config
|
||||||
|
@writer[fish, 252060]: /home/nils/projects/target-tier-docs-experiment/hello
|
||||||
Loading…
Add table
Add a link
Reference in a new issue