Skip to content

Commit

Permalink
build: fixes version for published packages
Browse files Browse the repository at this point in the history
  • Loading branch information
Dav1dde committed Nov 26, 2023
1 parent 50ccac8 commit e240b6c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 7 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down Expand Up @@ -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}"
}}
Expand Down
13 changes: 13 additions & 0 deletions publish.sh
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit e240b6c

Please sign in to comment.