Skip to content

Commit 8729128

Browse files
committed
feat(cli): tag each downloaded cli with its proper version
1 parent 1ffe2db commit 8729128

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

src/tree_sitter.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ async fn cli(
4444
}
4545
};
4646
let cli = format!("tree-sitter-{platform}");
47-
let res = PathBuf::new().join(build_dir).join(&cli).canon()?;
47+
let res = PathBuf::new()
48+
.join(build_dir)
49+
.join(format!("{cli}-{tag}"))
50+
.canon()?;
4851

4952
if !res.exists() {
5053
handle.msg(format!("Downloading {tag}",));
@@ -74,7 +77,7 @@ async fn download(gz: &Path, url: &str) -> TsdlResult<()> {
7477

7578
async fn download_and_extract(gz: &Path, url: &str, res: &Path) -> TsdlResult<()> {
7679
download(gz, url).await?;
77-
gunzip(gz).await?;
80+
gunzip(gz, res).await?;
7881
chmod_x(res).await?;
7982
fs::remove_file(gz)
8083
.await
@@ -97,16 +100,16 @@ fn find_tag(refs: &HashMap<String, String>, version: &str) -> Tag {
97100
)
98101
}
99102

100-
async fn gunzip(gz: &Path) -> TsdlResult<()> {
103+
async fn gunzip(gz: &Path, to: &Path) -> TsdlResult<()> {
101104
let file = fs::File::open(gz)
102105
.await
103106
.map_err(|e| TsdlError::context(format!("opening {}", gz.display()), e))?;
104107
let mut decompressor = GzipDecoder::new(tokio::io::BufReader::new(file));
105-
let path = gz.with_extension("");
108+
// let path = gz.with_extension("");
106109

107-
let mut file = tokio::fs::File::create(&path)
110+
let mut file = tokio::fs::File::create(to)
108111
.await
109-
.map_err(|e| TsdlError::context(format!("creating {}", path.display()), e))?;
112+
.map_err(|e| TsdlError::context(format!("creating {}", to.display()), e))?;
110113

111114
io::copy(&mut decompressor, &mut file)
112115
.await

tests/cmd/build.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,9 @@ fn no_args_should_download_tree_sitter_cli() {
2828
"tree-sitter-cli v{TREE_SITTER_VERSION}"
2929
)));
3030
assert!(!sandbox.is_empty());
31-
let tree_sitter_cli = sandbox
32-
.tmp
33-
.child(TSDL_BUILD_DIR)
34-
.child(format!("tree-sitter-{TREE_SITTER_PLATFORM}"));
31+
let tree_sitter_cli = sandbox.tmp.child(TSDL_BUILD_DIR).child(format!(
32+
"tree-sitter-{TREE_SITTER_PLATFORM}-v{TREE_SITTER_VERSION}"
33+
));
3534

3635
tree_sitter_cli
3736
.assert(p::path::exists())
@@ -66,7 +65,7 @@ fn no_args_should_build_tree_sitter_with_specific_version(
6665
sandbox
6766
.tmp
6867
.child(TSDL_BUILD_DIR)
69-
.child(format!("tree-sitter-{TREE_SITTER_PLATFORM}"))
68+
.child(format!("tree-sitter-{TREE_SITTER_PLATFORM}-v{cli_version}"))
7069
.to_path_buf(),
7170
);
7271
tree_sitter_cli.arg("--version");

0 commit comments

Comments
 (0)