diff --git a/Cargo.toml b/Cargo.toml index c842ec9..c6cc7fd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,6 +11,7 @@ build = "build.rs" include = [ "**/*.rs", "Cargo.toml", + "sitters/tree-sitter-*/pepegsitter-version", "sitters/tree-sitter-*/*.js", "sitters/tree-sitter-*/queries/*.scm", "sitters/tree-sitter-*/**/*.c", diff --git a/build.rs b/build.rs index cd68b0b..14b2e24 100644 --- a/build.rs +++ b/build.rs @@ -55,6 +55,11 @@ impl Sitter { fn version(&self) -> &str { self.version.get_or_init(|| { + let version_file = self.path.join("pepegsitter-version"); + if let Ok(version) = std::fs::read_to_string(version_file) { + return version.trim().to_owned(); + } + let output = Command::new("git") .arg("rev-parse") .arg(format!("HEAD:{}", self.path.display())) @@ -177,6 +182,8 @@ fn write_pepegsit(sitter @ Sitter { lang, .. }: &Sitter) -> std::io::Result<()> }} /// Get the commit hash or version of this grammar. + /// + /// Current version: `{version}`. pub const fn version() -> &'static str {{ "{version}" }} diff --git a/publish.sh b/publish.sh new file mode 100755 index 0000000..36bc702 --- /dev/null +++ b/publish.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +# `cargo publish` ignores directories containing a Cargo.toml +git submodule foreach "rm -f Cargo.toml" + +# Record the version, so the build script has access to it +git submodule foreach "git rev-parse HEAD > pepegsitter-version" + +# Run the publish, user needs to pass --allow-dirty, just to make sure ... +cargo publish $@ + +# Reset the changes just made. +git submodule foreach "git reset --hard HEAD && git clean -f"