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

Add ruff version with long version display #8034

Merged
merged 13 commits into from
Oct 20, 2023
150 changes: 4 additions & 146 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions crates/ruff_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ thiserror = { workspace = true }
tracing = { workspace = true, features = ["log"] }
walkdir = { version = "2.3.2" }
wild = { version = "2" }
shadow-rs = { version = "0.24.1" }

[build-dependencies]
shadow-rs = { version = "0.24.1" }

[dev-dependencies]
assert_cmd = { version = "2.0.8" }
Expand Down
44 changes: 42 additions & 2 deletions crates/ruff_cli/build.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,43 @@
fn main() -> shadow_rs::SdResult<()> {
shadow_rs::new()
use std::process::Command;

fn main() {
commit_info();
#[allow(clippy::disallowed_methods)]
let target = std::env::var("TARGET").unwrap();
println!("cargo:rustc-env=RUST_HOST_TARGET={target}");
}

fn commit_info() {
let output = match Command::new("git")
zanieb marked this conversation as resolved.
Show resolved Hide resolved
.arg("log")
.arg("-1")
.arg("--date=short")
.arg("--abbrev=9")
.arg("--format=%H %h %cd %(describe)")
.output()
{
Ok(output) if output.status.success() => output,
foo => foo.unwrap(),
};
let stdout = String::from_utf8(output.stdout).unwrap();
let mut parts = stdout.split_whitespace();
let mut next = || parts.next().unwrap();
println!("cargo:rustc-env=RUFF_COMMIT_HASH={}", next());
println!("cargo:rustc-env=RUFF_COMMIT_SHORT_HASH={}", next());
println!("cargo:rustc-env=RUFF_COMMIT_DATE={}", next());

// Describe can fail for some commits
// https://git-scm.com/docs/pretty-formats#Documentation/pretty-formats.txt-emdescribeoptionsem
if let Some(describe) = parts.next() {
let mut describe_parts = describe.split('-');
println!(
"cargo:rustc-env=RUFF_LAST_TAG={}",
describe_parts.next().unwrap()
);
// If this is the tagged commit, this component will be missing
println!(
"cargo:rustc-env=RUFF_LAST_TAG_DISTANCE={}",
describe_parts.next().unwrap_or("0")
);
}
}
2 changes: 1 addition & 1 deletion crates/ruff_cli/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub struct Args {
pub enum Command {
/// Run Ruff on the given files or directories (default).
Check(CheckCommand),
/// Display full Ruff version information
/// Display Ruff's version
Version {
#[arg(long, value_enum, default_value = "text")]
output_format: HelpFormat,
Expand Down
Loading