@@ -7,13 +7,25 @@ use std::{
77fn main ( ) {
88 // The workspace root directory is not available without walking up the tree
99 // https://github.com/rust-lang/cargo/issues/3946
10- let workspace_root = Path :: new ( & std:: env:: var ( "CARGO_MANIFEST_DIR" ) . unwrap ( ) )
11- . join ( ".." )
10+ let ruff_workspace_root = Path :: new ( & std:: env:: var ( "CARGO_MANIFEST_DIR" ) . unwrap ( ) )
1211 . join ( ".." )
1312 . join ( ".." ) ;
13+ let ty_workspace_root = ruff_workspace_root. join ( ".." ) ;
14+
15+ version_info ( & ty_workspace_root) ;
16+
17+ // If not in a git repository, do not attempt to retrieve commit information
18+ let git_dir = ty_workspace_root. join ( ".git" ) ;
19+ if git_dir. exists ( ) {
20+ commit_info ( & git_dir, & ty_workspace_root, false ) ;
21+ } else {
22+ // Try if we're inside the ruff repository and, if so, use that commit hash.
23+ let git_dir = ruff_workspace_root. join ( ".git" ) ;
1424
15- version_info ( & workspace_root) ;
16- commit_info ( & workspace_root) ;
25+ if git_dir. exists ( ) {
26+ commit_info ( & git_dir, & ruff_workspace_root, true ) ;
27+ }
28+ }
1729
1830 let target = std:: env:: var ( "TARGET" ) . unwrap ( ) ;
1931 println ! ( "cargo::rustc-env=RUST_HOST_TARGET={target}" ) ;
@@ -45,14 +57,8 @@ fn version_info(workspace_root: &Path) {
4557}
4658
4759/// Retrieve commit information from the Git repository.
48- fn commit_info ( workspace_root : & Path ) {
49- // If not in a git repository, do not attempt to retrieve commit information
50- let git_dir = workspace_root. join ( ".git" ) ;
51- if !git_dir. exists ( ) {
52- return ;
53- }
54-
55- if let Some ( git_head_path) = git_head ( & git_dir) {
60+ fn commit_info ( git_dir : & Path , workspace_root : & Path , is_ruff : bool ) {
61+ if let Some ( git_head_path) = git_head ( git_dir) {
5662 println ! ( "cargo:rerun-if-changed={}" , git_head_path. display( ) ) ;
5763
5864 let git_head_contents = fs:: read_to_string ( git_head_path) ;
@@ -96,7 +102,10 @@ fn commit_info(workspace_root: &Path) {
96102 let mut describe_parts = describe. split ( '-' ) ;
97103 let last_tag = describe_parts. next ( ) . unwrap ( ) ;
98104
99- println ! ( "cargo::rustc-env=TY_LAST_TAG={last_tag}" ) ;
105+ println ! (
106+ "cargo::rustc-env=TY_LAST_TAG={ruff}{last_tag}" ,
107+ ruff = if is_ruff { "ruff/" } else { "" }
108+ ) ;
100109
101110 // If this is the tagged commit, this component will be missing
102111 println ! (
0 commit comments