From baf222f772e3c04e361f16cb33f37979ffae8d76 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Thu, 29 May 2025 20:47:06 +0200 Subject: [PATCH] Revert "feat: add build sha to parser.c header comment" (#4475) This reverts commit dc4e232e6e83b67065fd54b7a85db0d6081ef224. Reason: The sha in the generated output (which most distro builds of tree-sitter, including `cargo install`, strip) produces too many conflicts when verifying via CI that parsers are regenerated on every grammar change. (cherry picked from commit e7f9160867ea1aa639417cd9a491ce4fa162263a) --- cli/build.rs | 2 -- cli/generate/build.rs | 32 -------------------------------- cli/generate/src/render.rs | 7 +------ 3 files changed, 1 insertion(+), 40 deletions(-) delete mode 100644 cli/generate/build.rs diff --git a/cli/build.rs b/cli/build.rs index 04406487..0081395e 100644 --- a/cli/build.rs +++ b/cli/build.rs @@ -60,8 +60,6 @@ fn web_playground_files_present() -> bool { paths.iter().all(|p| Path::new(p).exists()) } -// When updating this function, don't forget to also update generate/build.rs which has a -// near-identical function. fn read_git_sha() -> Option { let crate_path = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()); diff --git a/cli/generate/build.rs b/cli/generate/build.rs deleted file mode 100644 index 6fdbc45b..00000000 --- a/cli/generate/build.rs +++ /dev/null @@ -1,32 +0,0 @@ -use std::{env, path::PathBuf, process::Command}; - -fn main() { - if let Some(git_sha) = read_git_sha() { - println!("cargo:rustc-env=BUILD_SHA={git_sha}"); - } -} - -// This is copied from the build.rs in parent directory. This should be updated if the -// parent build.rs gets fixes. -fn read_git_sha() -> Option { - let crate_path = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()); - - if !crate_path - .parent()? - .parent() - .is_some_and(|p| p.join(".git").exists()) - { - return None; - } - - Command::new("git") - .args(["rev-parse", "HEAD"]) - .current_dir(crate_path) - .output() - .map_or(None, |output| { - if !output.status.success() { - return None; - } - Some(String::from_utf8_lossy(&output.stdout).to_string()) - }) -} diff --git a/cli/generate/src/render.rs b/cli/generate/src/render.rs index 048195b1..1bd52a57 100644 --- a/cli/generate/src/render.rs +++ b/cli/generate/src/render.rs @@ -24,7 +24,6 @@ pub const ABI_VERSION_MIN: usize = 14; pub const ABI_VERSION_MAX: usize = tree_sitter::LANGUAGE_VERSION; const ABI_VERSION_WITH_RESERVED_WORDS: usize = 15; const BUILD_VERSION: &str = env!("CARGO_PKG_VERSION"); -const BUILD_SHA: Option<&'static str> = option_env!("BUILD_SHA"); macro_rules! add { ($this: tt, $($arg: tt)*) => {{ @@ -322,13 +321,9 @@ impl Generator { } fn add_header(&mut self) { - let version = BUILD_SHA.map_or_else( - || BUILD_VERSION.to_string(), - |build_sha| format!("{BUILD_VERSION} ({build_sha})"), - ); add_line!( self, - "/* Automatically @generated by tree-sitter v{version} */", + "/* Automatically @generated by tree-sitter v{BUILD_VERSION} */", ); add_line!(self, ""); }