2020-01-18 19:34:16 +00:00
|
|
|
#!/usr/bin/env nix-shell
|
2020-04-11 07:51:06 +01:00
|
|
|
#!nix-shell -i bash -p curl jq nix-prefetch
|
2020-01-18 19:34:16 +00:00
|
|
|
set -euo pipefail
|
|
|
|
cd "$(dirname "$0")"
|
|
|
|
owner=rust-analyzer
|
|
|
|
repo=rust-analyzer
|
|
|
|
nixpkgs=../../../../..
|
|
|
|
|
|
|
|
# Update lsp
|
|
|
|
|
2021-04-12 08:06:42 +01:00
|
|
|
ver=$(
|
2020-01-18 19:34:16 +00:00
|
|
|
curl -s "https://api.github.com/repos/$owner/$repo/releases" |
|
|
|
|
jq 'map(select(.prerelease | not)) | .[0].tag_name' --raw-output
|
|
|
|
)
|
2021-04-12 08:06:42 +01:00
|
|
|
old_ver=$(sed -nE 's/.*\bversion = "(.*)".*/\1/p' ./default.nix)
|
2020-04-10 17:52:09 +01:00
|
|
|
if grep -q 'cargoSha256 = ""' ./default.nix; then
|
2021-04-12 08:06:42 +01:00
|
|
|
old_ver='broken'
|
2020-01-18 19:34:16 +00:00
|
|
|
fi
|
2021-04-12 08:06:42 +01:00
|
|
|
if [[ "$ver" == "$old_ver" ]]; then
|
|
|
|
echo "Up to date: $ver"
|
2020-01-18 19:34:16 +00:00
|
|
|
exit
|
|
|
|
fi
|
2021-04-12 08:06:42 +01:00
|
|
|
echo "$old_ver -> $ver"
|
2020-01-18 19:34:16 +00:00
|
|
|
|
2021-04-12 08:06:42 +01:00
|
|
|
sha256=$(nix-prefetch -f "$nixpkgs" rust-analyzer-unwrapped.src --rev "$ver")
|
2020-04-10 17:52:09 +01:00
|
|
|
# Clear cargoSha256 to avoid inconsistency.
|
2021-04-12 08:06:42 +01:00
|
|
|
sed -e "s#version = \".*\"#version = \"$ver\"#" \
|
2021-04-11 18:35:08 +01:00
|
|
|
-e "/fetchFromGitHub/,/}/ s#sha256 = \".*\"#sha256 = \"$sha256\"#" \
|
2021-01-05 15:37:09 +00:00
|
|
|
-e "s#cargoSha256 = \".*\"#cargoSha256 = \"sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=\"#" \
|
2020-01-18 19:34:16 +00:00
|
|
|
--in-place ./default.nix
|
2020-03-17 09:56:26 +00:00
|
|
|
node_src="$(nix-build "$nixpkgs" -A rust-analyzer.src --no-out-link)/editors/code"
|
|
|
|
|
|
|
|
# Check vscode compatibility
|
|
|
|
req_vscode_ver="$(jq '.engines.vscode' "$node_src/package.json" --raw-output)"
|
|
|
|
req_vscode_ver="${req_vscode_ver#^}"
|
2020-11-09 12:33:23 +00:00
|
|
|
cur_vscode_ver="$(nix-instantiate --eval --strict "$nixpkgs" -A vscode.version | tr -d '"')"
|
|
|
|
if [[ "$(nix-instantiate --eval --strict -E "(builtins.compareVersions \"$req_vscode_ver\" \"$cur_vscode_ver\")")" -gt 0 ]]; then
|
2020-03-17 09:56:26 +00:00
|
|
|
echo "vscode $cur_vscode_ver is incompatible with the extension requiring ^$req_vscode_ver"
|
|
|
|
exit 1
|
|
|
|
fi
|
2020-01-18 19:34:16 +00:00
|
|
|
|
2020-04-10 17:52:09 +01:00
|
|
|
echo "Prebuilding for cargoSha256"
|
|
|
|
cargo_sha256=$(nix-prefetch "{ sha256 }: (import $nixpkgs {}).rust-analyzer-unwrapped.cargoDeps.overrideAttrs (_: { outputHash = sha256; })")
|
2020-11-09 12:33:23 +00:00
|
|
|
sed "s#cargoSha256 = \".*\"#cargoSha256 = \"$cargo_sha256\"#" \
|
2020-01-18 19:34:16 +00:00
|
|
|
--in-place ./default.nix
|
|
|
|
|
2020-01-29 19:46:32 +00:00
|
|
|
# Update vscode extension
|
|
|
|
|
2020-04-11 07:51:06 +01:00
|
|
|
build_deps="../../../../misc/vscode-extensions/rust-analyzer/build-deps"
|
|
|
|
# We need devDependencies to build vsix.
|
|
|
|
jq '{ name, version, dependencies: (.dependencies + .devDependencies) }' "$node_src/package.json" \
|
2020-06-23 15:08:48 +01:00
|
|
|
>"$build_deps/package.json.new"
|
2020-04-11 07:51:06 +01:00
|
|
|
|
2021-06-21 19:24:15 +01:00
|
|
|
# FIXME: vsce@1.93.0 breaks the build.
|
|
|
|
sed 's/"vsce": ".*"/"vsce": "=1.88.0"/' --in-place "$build_deps/package.json.new"
|
|
|
|
|
2020-06-23 15:08:48 +01:00
|
|
|
if cmp --quiet "$build_deps"/package.json{.new,}; then
|
|
|
|
echo "package.json not changed, skip updating nodePackages"
|
|
|
|
rm "$build_deps"/package.json.new
|
|
|
|
else
|
|
|
|
echo "package.json changed, updating nodePackages"
|
|
|
|
mv "$build_deps"/package.json{.new,}
|
2020-04-11 07:51:06 +01:00
|
|
|
|
2020-06-23 15:08:48 +01:00
|
|
|
pushd "../../../node-packages"
|
|
|
|
./generate.sh
|
|
|
|
popd
|
|
|
|
fi
|