diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 03:59:35 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 03:59:35 +0000 |
commit | d1b2d29528b7794b41e66fc2136e395a02f8529b (patch) | |
tree | a4a17504b260206dec3cf55b2dca82929a348ac2 /src/tools/rust-analyzer/xtask | |
parent | Releasing progress-linux version 1.72.1+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-d1b2d29528b7794b41e66fc2136e395a02f8529b.tar.xz rustc-d1b2d29528b7794b41e66fc2136e395a02f8529b.zip |
Merging upstream version 1.73.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/tools/rust-analyzer/xtask')
-rw-r--r-- | src/tools/rust-analyzer/xtask/Cargo.toml | 2 | ||||
-rw-r--r-- | src/tools/rust-analyzer/xtask/src/flags.rs | 29 | ||||
-rw-r--r-- | src/tools/rust-analyzer/xtask/src/install.rs | 10 | ||||
-rw-r--r-- | src/tools/rust-analyzer/xtask/src/metrics.rs | 76 | ||||
-rw-r--r-- | src/tools/rust-analyzer/xtask/src/publish.rs | 11 |
5 files changed, 80 insertions, 48 deletions
diff --git a/src/tools/rust-analyzer/xtask/Cargo.toml b/src/tools/rust-analyzer/xtask/Cargo.toml index b4b294c30..7a34617e2 100644 --- a/src/tools/rust-analyzer/xtask/Cargo.toml +++ b/src/tools/rust-analyzer/xtask/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" publish = false license = "MIT OR Apache-2.0" edition = "2021" -rust-version = "1.65" +rust-version.workspace = true [dependencies] anyhow = "1.0.62" diff --git a/src/tools/rust-analyzer/xtask/src/flags.rs b/src/tools/rust-analyzer/xtask/src/flags.rs index 210047970..7720ad69f 100644 --- a/src/tools/rust-analyzer/xtask/src/flags.rs +++ b/src/tools/rust-analyzer/xtask/src/flags.rs @@ -1,5 +1,7 @@ #![allow(unreachable_pub)] +use std::str::FromStr; + use crate::install::{ClientOpt, Malloc, ServerOpt}; xflags::xflags! { @@ -42,7 +44,7 @@ xflags::xflags! { required changelog: String } cmd metrics { - optional --dry-run + optional measurement_type: MeasurementType } /// Builds a benchmark version of rust-analyzer and puts it into `./target`. cmd bb { @@ -106,8 +108,31 @@ pub struct PublishReleaseNotes { } #[derive(Debug)] +pub enum MeasurementType { + Build, + AnalyzeSelf, + AnalyzeRipgrep, + AnalyzeWebRender, + AnalyzeDiesel, +} + +impl FromStr for MeasurementType { + type Err = String; + fn from_str(s: &str) -> Result<Self, Self::Err> { + match s { + "build" => Ok(Self::Build), + "self" => Ok(Self::AnalyzeSelf), + "ripgrep" => Ok(Self::AnalyzeRipgrep), + "webrender" => Ok(Self::AnalyzeWebRender), + "diesel" => Ok(Self::AnalyzeDiesel), + _ => Err("Invalid option".to_string()), + } + } +} + +#[derive(Debug)] pub struct Metrics { - pub dry_run: bool, + pub measurement_type: Option<MeasurementType>, } #[derive(Debug)] diff --git a/src/tools/rust-analyzer/xtask/src/install.rs b/src/tools/rust-analyzer/xtask/src/install.rs index 83223a551..e8c00c72e 100644 --- a/src/tools/rust-analyzer/xtask/src/install.rs +++ b/src/tools/rust-analyzer/xtask/src/install.rs @@ -2,13 +2,13 @@ use std::{env, path::PathBuf, str}; -use anyhow::{bail, format_err, Context, Result}; +use anyhow::{bail, format_err, Context}; use xshell::{cmd, Shell}; use crate::flags; impl flags::Install { - pub(crate) fn run(self, sh: &Shell) -> Result<()> { + pub(crate) fn run(self, sh: &Shell) -> anyhow::Result<()> { if cfg!(target_os = "macos") { fix_path_for_mac(sh).context("Fix path for mac")?; } @@ -39,7 +39,7 @@ pub(crate) enum Malloc { Jemalloc, } -fn fix_path_for_mac(sh: &Shell) -> Result<()> { +fn fix_path_for_mac(sh: &Shell) -> anyhow::Result<()> { let mut vscode_path: Vec<PathBuf> = { const COMMON_APP_PATH: &str = r"/Applications/Visual Studio Code.app/Contents/Resources/app/bin"; @@ -68,7 +68,7 @@ fn fix_path_for_mac(sh: &Shell) -> Result<()> { Ok(()) } -fn install_client(sh: &Shell, client_opt: ClientOpt) -> Result<()> { +fn install_client(sh: &Shell, client_opt: ClientOpt) -> anyhow::Result<()> { let _dir = sh.push_dir("./editors/code"); // Package extension. @@ -129,7 +129,7 @@ fn install_client(sh: &Shell, client_opt: ClientOpt) -> Result<()> { Ok(()) } -fn install_server(sh: &Shell, opts: ServerOpt) -> Result<()> { +fn install_server(sh: &Shell, opts: ServerOpt) -> anyhow::Result<()> { let features = match opts.malloc { Malloc::System => &[][..], Malloc::Mimalloc => &["--features", "mimalloc"], diff --git a/src/tools/rust-analyzer/xtask/src/metrics.rs b/src/tools/rust-analyzer/xtask/src/metrics.rs index b6f730dbf..685374231 100644 --- a/src/tools/rust-analyzer/xtask/src/metrics.rs +++ b/src/tools/rust-analyzer/xtask/src/metrics.rs @@ -1,6 +1,6 @@ use std::{ collections::BTreeMap, - env, fs, + fs, io::Write as _, path::Path, time::{Instant, SystemTime, UNIX_EPOCH}, @@ -9,16 +9,13 @@ use std::{ use anyhow::{bail, format_err}; use xshell::{cmd, Shell}; -use crate::flags; +use crate::flags::{self, MeasurementType}; type Unit = String; impl flags::Metrics { pub(crate) fn run(self, sh: &Shell) -> anyhow::Result<()> { let mut metrics = Metrics::new(sh)?; - if !self.dry_run { - sh.remove_path("./target/release")?; - } if !Path::new("./target/rustc-perf").exists() { sh.create_dir("./target/rustc-perf")?; cmd!(sh, "git clone https://github.com/rust-lang/rustc-perf.git ./target/rustc-perf") @@ -32,38 +29,47 @@ impl flags::Metrics { let _env = sh.push_env("RA_METRICS", "1"); - { - // https://github.com/rust-lang/rust-analyzer/issues/9997 - let _d = sh.push_dir("target/rustc-perf/collector/benchmarks/webrender"); - cmd!(sh, "cargo update -p url --precise 1.6.1").run()?; - } - metrics.measure_build(sh)?; - metrics.measure_analysis_stats_self(sh)?; - metrics.measure_analysis_stats(sh, "ripgrep")?; - metrics.measure_analysis_stats(sh, "webrender")?; - metrics.measure_analysis_stats(sh, "diesel/diesel")?; - - if !self.dry_run { - let _d = sh.push_dir("target"); - let metrics_token = env::var("METRICS_TOKEN").unwrap(); - cmd!( - sh, - "git clone --depth 1 https://{metrics_token}@github.com/rust-analyzer/metrics.git" - ) - .run()?; - - { - let mut file = - fs::File::options().append(true).open("target/metrics/metrics.json")?; - writeln!(file, "{}", metrics.json())?; + let filename = match self.measurement_type { + Some(ms) => match ms { + MeasurementType::Build => { + metrics.measure_build(sh)?; + "build.json" + } + MeasurementType::AnalyzeSelf => { + metrics.measure_analysis_stats_self(sh)?; + "self.json" + } + MeasurementType::AnalyzeRipgrep => { + metrics.measure_analysis_stats(sh, "ripgrep")?; + "ripgrep.json" + } + MeasurementType::AnalyzeWebRender => { + { + // https://github.com/rust-lang/rust-analyzer/issues/9997 + let _d = sh.push_dir("target/rustc-perf/collector/benchmarks/webrender"); + cmd!(sh, "cargo update -p url --precise 1.6.1").run()?; + } + metrics.measure_analysis_stats(sh, "webrender")?; + "webrender.json" + } + MeasurementType::AnalyzeDiesel => { + metrics.measure_analysis_stats(sh, "diesel/diesel")?; + "diesel.json" + } + }, + None => { + metrics.measure_build(sh)?; + metrics.measure_analysis_stats_self(sh)?; + metrics.measure_analysis_stats(sh, "ripgrep")?; + metrics.measure_analysis_stats(sh, "webrender")?; + metrics.measure_analysis_stats(sh, "diesel/diesel")?; + "all.json" } + }; - let _d = sh.push_dir("metrics"); - cmd!(sh, "git add .").run()?; - cmd!(sh, "git -c user.name=Bot -c user.email=dummy@example.com commit --message 📈") - .run()?; - cmd!(sh, "git push origin master").run()?; - } + let mut file = + fs::File::options().write(true).create(true).open(format!("target/{}", filename))?; + writeln!(file, "{}", metrics.json())?; eprintln!("{metrics:#?}"); Ok(()) } diff --git a/src/tools/rust-analyzer/xtask/src/publish.rs b/src/tools/rust-analyzer/xtask/src/publish.rs index cdb7d8fac..7faae9b20 100644 --- a/src/tools/rust-analyzer/xtask/src/publish.rs +++ b/src/tools/rust-analyzer/xtask/src/publish.rs @@ -1,12 +1,12 @@ mod notes; use crate::flags; -use anyhow::{anyhow, bail, Result}; +use anyhow::bail; use std::env; use xshell::{cmd, Shell}; impl flags::PublishReleaseNotes { - pub(crate) fn run(self, sh: &Shell) -> Result<()> { + pub(crate) fn run(self, sh: &Shell) -> anyhow::Result<()> { let asciidoc = sh.read_file(&self.changelog)?; let mut markdown = notes::convert_asciidoc_to_markdown(std::io::Cursor::new(&asciidoc))?; let file_name = check_file_name(self.changelog)?; @@ -24,11 +24,11 @@ impl flags::PublishReleaseNotes { } } -fn check_file_name<P: AsRef<std::path::Path>>(path: P) -> Result<String> { +fn check_file_name<P: AsRef<std::path::Path>>(path: P) -> anyhow::Result<String> { let file_name = path .as_ref() .file_name() - .ok_or_else(|| anyhow!("file name is not specified as `changelog`"))? + .ok_or_else(|| anyhow::format_err!("file name is not specified as `changelog`"))? .to_string_lossy(); let mut chars = file_name.chars(); @@ -61,7 +61,7 @@ fn create_original_changelog_url(file_name: &str) -> String { format!("https://rust-analyzer.github.io/thisweek/{year}/{month}/{day}/{stem}.html") } -fn update_release(sh: &Shell, tag_name: &str, release_notes: &str) -> Result<()> { +fn update_release(sh: &Shell, tag_name: &str, release_notes: &str) -> anyhow::Result<()> { let token = match env::var("GITHUB_TOKEN") { Ok(token) => token, Err(_) => bail!("Please obtain a personal access token from https://github.com/settings/tokens and set the `GITHUB_TOKEN` environment variable."), @@ -79,6 +79,7 @@ fn update_release(sh: &Shell, tag_name: &str, release_notes: &str) -> Result<()> let release_id = cmd!(sh, "jq .id").stdin(release_json).read()?; let mut patch = String::new(); + // note: the GitHub API doesn't update the target commit if the tag already exists write_json::object(&mut patch) .string("tag_name", tag_name) .string("target_commitish", "master") |