Get sha1 commit from tree-sitter-cpp crate for mozcpp
Instead of hard-coding the sha1 of the commit associated to the tree-sitter-cpp grammar used to generate the mozcpp grammar, retrieve automatically it from the tree-sitter-cpp crate version present in Cargo.toml
This commit is contained in:
Родитель
1fea1184ef
Коммит
acabe8914a
|
@ -4,22 +4,47 @@
|
|||
#
|
||||
# Usage: ./generate-grammars/generate-mozcpp.sh
|
||||
|
||||
# Set tree-sitter-cpp version
|
||||
TS_CPP_VERSION="05cf2030e5415e9e931f620f0924107f73976796"
|
||||
# Name of the tree-sitter-cpp crate
|
||||
TS_CPP_CRATE="tree-sitter-cpp"
|
||||
|
||||
# Filename of the JSON file containing the sha1 of the commit associated to
|
||||
# the current tree-sitter-cpp crate version
|
||||
JSON_CRATE_FILENAME=".cargo_vcs_info.json"
|
||||
|
||||
# Get the current tree-sitter-cpp crate version from the tree-sitter-mozcpp grammar
|
||||
TS_CPP_VERSION=`grep tree-sitter-mozcpp Cargo.toml | cut -f2 -d "," | cut -f2 -d "=" | tr -d ' ' | tr -d } | tr -d \"`
|
||||
|
||||
# Name assigned to the compressed binary crate downloaded from crates.io
|
||||
CRATE_OUTPUT="$TS_CPP_CRATE-download.gz"
|
||||
|
||||
# Link of the current tree-sitter-cpp crate on crates.io
|
||||
CRATES_IO_LINK="https://crates.io/api/v1/crates/$TS_CPP_CRATE/$TS_CPP_VERSION/download"
|
||||
|
||||
# Download the crate from crates.io and uncompress it
|
||||
wget -O $CRATE_OUTPUT $CRATES_IO_LINK && tar -xf $CRATE_OUTPUT
|
||||
|
||||
# Uncompressed directory name
|
||||
CRATE_DIR="$TS_CPP_CRATE-$TS_CPP_VERSION"
|
||||
|
||||
# Get the sha1 of the commit associated to the current tree-sitter-cpp crate version
|
||||
TS_CPP_SHA1=`grep "sha1" $CRATE_DIR/$JSON_CRATE_FILENAME | cut -f2 -d ":" | tr -d ' ' | tr -d \"`
|
||||
|
||||
# Remove compressed binary file and the relative uncompressed directory
|
||||
rm -rf $CRATE_OUTPUT $CRATE_DIR
|
||||
|
||||
# Enter the mozcpp directory
|
||||
pushd tree-sitter-mozcpp
|
||||
|
||||
# Create tree-sitter-cpp directory
|
||||
mkdir -p tree-sitter-cpp
|
||||
mkdir -p $TS_CPP_CRATE
|
||||
|
||||
# Enter tree-sitter-cpp directory
|
||||
pushd tree-sitter-cpp
|
||||
pushd $TS_CPP_CRATE
|
||||
|
||||
# Shallow clone tree-sitter-cpp to a specific revision
|
||||
git init
|
||||
git remote add origin https://github.com/tree-sitter/tree-sitter-cpp.git
|
||||
git fetch --depth 1 origin $TS_CPP_VERSION
|
||||
git fetch --depth 1 origin $TS_CPP_SHA1
|
||||
git checkout FETCH_HEAD
|
||||
|
||||
# Install tree-sitter-cpp dependencies
|
||||
|
@ -29,7 +54,7 @@ npm install -y
|
|||
popd
|
||||
|
||||
# Copy tree-sitter-cpp `scanner.cc` functions into the `src` directory
|
||||
cp --verbose tree-sitter-cpp/src/scanner.cc ./src/scanner.cc
|
||||
cp --verbose $TS_CPP_CRATE/src/scanner.cc ./src/scanner.cc
|
||||
|
||||
# Exit tree-sitter-mozcpp directory
|
||||
popd
|
||||
|
@ -38,4 +63,4 @@ popd
|
|||
./generate-grammars/generate-grammar.sh tree-sitter-mozcpp
|
||||
|
||||
# Delete tree-sitter-mozcpp/tree-sitter-cpp directory
|
||||
rm -rf ./tree-sitter-mozcpp/tree-sitter-cpp
|
||||
rm -rf ./tree-sitter-mozcpp/$TS_CPP_CRATE
|
||||
|
|
Загрузка…
Ссылка в новой задаче