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

More improvements to upgrade process #1495

Merged
merged 4 commits into from
Jan 19, 2025
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
3 changes: 3 additions & 0 deletions .github/workflows/upgrade_examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ jobs:
# https://github.com/peter-evans/create-pull-request/blob/main/docs/concepts-guidelines.md#push-using-ssh-deploy-keys
ssh-key: ${{ secrets.SSH_KEY }}

- name: Install dylint-link
run: cargo install --path ./dylint-link --force

- name: Upgrade examples
run: |
scripts/upgrade_examples.sh
Expand Down
64 changes: 38 additions & 26 deletions dylint/src/package_options/auto_correct/highlight.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::tokenization::{tokenize_fragment, tokenize_lines};
use crate::opts;
use crate::{error::warn, opts};
use anyhow::Result;
use cargo_metadata::diagnostic::{Diagnostic, DiagnosticSpan};
use cargo_metadata::diagnostic::{Diagnostic, DiagnosticLevel, DiagnosticSpan};
use dylint_internal::{cargo, rustup::SanitizeEnvironment, CommandExt};
use serde::Deserialize;
use std::{path::Path, time::Instant};
Expand Down Expand Up @@ -111,44 +111,56 @@ impl Highlight {
/// Invokes `cargo build` at `path` and returns the generated diagnostic messages as [`Highlight`]s.
pub fn collect_highlights(opts: &opts::Dylint, path: &Path) -> Result<Vec<Highlight>> {
let start = Instant::now();

let output = cargo::check("upgraded library package")
.quiet(opts.quiet)
.build()
.sanitize_environment()
.current_dir(path)
.arg("--message-format=json")
.logged_output(false)?;
let elapsed = start.elapsed();
eprintln!(
"Checked upgraded library package in {} seconds",
elapsed.as_secs()
);

if output.status.success() {
return Ok(Vec::new());
}

let mut highlights = Vec::new();
let stdout = String::from_utf8(output.stdout)?;
for result in serde_json::Deserializer::from_str(&stdout).into_iter::<Message>() {
let message = result?;
if message.reason != "compiler-message" {
continue;
}
let Some(diagnostic) = message.diagnostic else {
continue;
};
for span in diagnostic.spans {
if span.text.is_empty() {

if !output.status.success() {
let stdout = String::from_utf8(output.stdout)?;
for result in serde_json::Deserializer::from_str(&stdout).into_iter::<Message>() {
let message = result?;
if message.reason != "compiler-message" {
continue;
}
let highlight = Highlight::try_new(&diagnostic.message, span)?;
assert!(!highlight.tokens.is_empty());
highlights.push(highlight);
let Some(diagnostic) = message.diagnostic else {
continue;
};
if diagnostic.level == DiagnosticLevel::Error && diagnostic.spans.is_empty() {
warn(
opts,
&format!(
"Found diagnostic error with no spans: {}",
&diagnostic.message
),
);
continue;
}
for span in diagnostic.spans {
if span.text.is_empty() {
continue;
}
let highlight = Highlight::try_new(&diagnostic.message, span)?;
assert!(!highlight.tokens.is_empty());
highlights.push(highlight);
}
}

highlights.sort();
}

highlights.sort();
let elapsed = start.elapsed();
eprintln!(
"Found {} highlights in {} seconds",
highlights.len(),
elapsed.as_secs()
);

Ok(highlights)
}
4 changes: 2 additions & 2 deletions scripts/upgrade_examples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ for EXAMPLE in examples/general examples/supplementary examples/restriction $EXP
PREV_REV="$(sed -n 's/^clippy_utils\>.*\(\<\(rev\|tag\) = "[^"]*"\).*$/\1/;T;p' "$EXAMPLE"/Cargo.toml)"
PREV_CHANNEL="$(sed -n 's/^channel = "[^"]*"$/&/;T;p' "$EXAMPLE"/rust-toolchain)"

$CARGO_DYLINT upgrade "$EXAMPLE" --auto-correct || true
RUST_LOG=debug $CARGO_DYLINT upgrade "$EXAMPLE" --auto-correct

REV="$(sed -n 's/^clippy_utils\>.*\(\<\(rev\|tag\) = "[^"]*"\).*$/\1/;T;p' "$EXAMPLE"/Cargo.toml)"
sed -i "s/^\(clippy_config\>.*\)\<\(rev\|tag\) = \"[^\"]*\"\(.*\)$/\1$REV\3/" "$EXAMPLE"/Cargo.toml
Expand All @@ -53,7 +53,7 @@ for EXAMPLE in examples/general examples/supplementary examples/restriction $EXP
mv "$EXAMPLE"/Cargo.toml~ "$EXAMPLE"/Cargo.toml
fi

$CARGO_DYLINT upgrade "$EXAMPLE" --auto-correct
RUST_LOG=debug $CARGO_DYLINT upgrade "$EXAMPLE" --auto-correct

if [[ "$EXAMPLE" = 'internal/template' ]]; then
mv "$EXAMPLE"/Cargo.toml "$EXAMPLE"/Cargo.toml~
Expand Down
Loading