Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Smaller improvements of tidy and the unicode generator #100924

Merged
merged 3 commits into from
Aug 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/tools/tidy/src/error_codes_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ pub fn check(paths: &[&Path], bad: &mut bool) {
println!("Checking which error codes lack tests...");

for path in paths {
super::walk(path, &mut |path| super::filter_dirs(path), &mut |entry, contents| {
super::walk(path, &mut super::filter_dirs, &mut |entry, contents| {
let file_name = entry.file_name();
let entry_path = entry.path();

Expand Down
2 changes: 1 addition & 1 deletion src/tools/unicode-table-generator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ fn main() {
let write_location = std::env::args().nth(1).unwrap_or_else(|| {
eprintln!("Must provide path to write unicode tables to");
eprintln!(
"e.g. {} library/core/unicode/unicode_data.rs",
"e.g. {} library/core/src/unicode/unicode_data.rs",
std::env::args().next().unwrap_or_default()
);
std::process::exit(1);
Expand Down
31 changes: 15 additions & 16 deletions src/tools/unicode-table-generator/src/unicode_download.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::UNICODE_DIRECTORY;
use std::path::Path;
use std::process::Command;
use std::process::{Command, Output};

static URL_PREFIX: &str = "https://www.unicode.org/Public/UCD/latest/ucd/";

Expand All @@ -9,6 +9,18 @@ static README: &str = "ReadMe.txt";
static RESOURCES: &[&str] =
&["DerivedCoreProperties.txt", "PropList.txt", "UnicodeData.txt", "SpecialCasing.txt"];

#[track_caller]
fn fetch(url: &str) -> Output {
let output = Command::new("curl").arg(URL_PREFIX.to_owned() + url).output().unwrap();
if !output.status.success() {
panic!(
"Failed to run curl to fetch {url}: stderr: {}",
String::from_utf8_lossy(&output.stderr)
);
}
output
}

pub fn fetch_latest() {
let directory = Path::new(UNICODE_DIRECTORY);
if directory.exists() {
Expand All @@ -20,27 +32,14 @@ pub fn fetch_latest() {
if let Err(e) = std::fs::create_dir_all(directory) {
panic!("Failed to create {UNICODE_DIRECTORY:?}: {e}");
}
let output = Command::new("curl").arg(URL_PREFIX.to_owned() + README).output().unwrap();
if !output.status.success() {
panic!(
"Failed to run curl to fetch readme: stderr: {}",
String::from_utf8_lossy(&output.stderr)
);
}
let output = fetch(README);
let current = std::fs::read_to_string(directory.join(README)).unwrap_or_default();
if current.as_bytes() != &output.stdout[..] {
std::fs::write(directory.join(README), output.stdout).unwrap();
}

for resource in RESOURCES {
let output = Command::new("curl").arg(URL_PREFIX.to_owned() + resource).output().unwrap();
if !output.status.success() {
panic!(
"Failed to run curl to fetch {}: stderr: {}",
resource,
String::from_utf8_lossy(&output.stderr)
);
}
let output = fetch(resource);
std::fs::write(directory.join(resource), output.stdout).unwrap();
}
}