python-language-server: 2021-05-20 -> 2021-09-08, use buildDotnetModule

This commit is contained in:
Ivar Scholten 2021-11-17 19:25:17 +01:00
parent f54808ee59
commit d820154199
8 changed files with 180 additions and 1434 deletions

View file

@ -1,38 +0,0 @@
#! /usr/bin/env nix-shell
#! nix-shell -p python3 dotnet-sdk_3 -i bash
# Run this script to generate deps.nix
# ./create_deps.sh /path/to/microsoft/python/language/server/source/checkout
set -euo pipefail
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
if [ -d "$1" ]; then
CHECKOUT_PATH="$1"
else
echo "First argument must be a directory, the path to the Microsoft Python Language Server source checkout"
exit 1
fi
# Generate lockfiles in source checkout
cd "$CHECKOUT_PATH/src"
dotnet nuget locals all --clear
dotnet restore -v normal --no-cache PLS.sln --use-lock-file -r linux-x64
# Use the lockfiles to make a file with two columns: name and version number
# for all possible package dependencies
cd "$SCRIPTDIR"
echo "" > all_versions.txt
for lockfile in $(find "$CHECKOUT_PATH" -name packages.lock.json); do
echo "Processing lockfile $lockfile"
python ./process_lockfile.py "$lockfile" >> all_versions.txt
done
# Add extra manually added packages
cat ./manual_deps.txt >> all_versions.txt
cat all_versions.txt | sed '/^$/d' | sort | uniq > tmp
mv tmp all_versions.txt
# Retrieve sha256 hashes for each dependency and format fetchNuGet calls into deps.nix
./format-deps.sh all_versions.txt > deps.nix
rm all_versions.txt

View file

@ -1,105 +1,39 @@
{ lib, stdenv
{ lib
, stdenv
, fetchFromGitHub
, fetchurl
, makeWrapper
, dotnet-sdk_3
, buildDotnetModule
, dotnetCorePackages
, autoPatchelfHook
, openssl
, icu
, patchelf
, Nuget
}:
let deps = import ./deps.nix { inherit fetchurl; };
version = "2021-05-20";
# Build the nuget source needed for the later build all by itself
# since it's a time-consuming step that only depends on ./deps.nix.
# This makes it easier to experiment with the main build.
nugetSource = stdenv.mkDerivation {
pname = "python-language-server-nuget-deps";
inherit version;
dontUnpack = true;
nativeBuildInputs = [ Nuget ];
buildPhase = ''
export HOME=$(mktemp -d)
mkdir -p $out/lib
# disable default-source so nuget does not try to download from online-repo
nuget sources Disable -Name "nuget.org"
# add all dependencies to the source
for package in ${toString deps}; do
nuget add $package -Source $out/lib
done
'';
dontInstall = true;
};
in
stdenv.mkDerivation {
buildDotnetModule rec {
pname = "python-language-server";
inherit version;
version = "2021-09-08";
src = fetchFromGitHub {
owner = "microsoft";
repo = "python-language-server";
rev = "86825796eae15d4d46919bc6e32f1197196ba1b3";
sha256 = "sha256-izDE7Oil9g47Jf3eHPtW5coNixF71t9i0oYSuelakCo=";
rev = "26ea18997f45f7d7bc5a3c5a9efc723a8dbb02fa";
sha256 = "1m8pf9k20wy4fzv27v3bswvc8s01ag6ka2qm9nn6bgq0s0lq78mh";
};
buildInputs = [dotnet-sdk_3 openssl icu];
projectFile = "src/LanguageServer/Impl/Microsoft.Python.LanguageServer.csproj";
nugetDeps = ./deps.nix;
nativeBuildInputs = [
Nuget
makeWrapper
patchelf
];
dotnet-sdk = dotnetCorePackages.sdk_3_1;
dotnet-runtime = dotnetCorePackages.runtime_3_1;
buildPhase = ''
runHook preBuild
mkdir home
export HOME=$(mktemp -d)
export DOTNET_CLI_TELEMETRY_OPTOUT=1
export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
pushd src
nuget sources Disable -Name "nuget.org"
dotnet restore --source ${nugetSource}/lib -r linux-x64
popd
pushd src/LanguageServer/Impl
dotnet publish --no-restore -c Release -r linux-x64
popd
runHook postBuild
'';
installPhase = ''
runHook preInstall
mkdir -p $out
cp -r output/bin/Release/linux-x64/publish $out/lib
mkdir $out/bin
makeWrapper $out/lib/Microsoft.Python.LanguageServer $out/bin/python-language-server
runHook postInstall
'';
nativeBuildInputs = [ autoPatchelfHook ];
buildInputs = [ stdenv.cc.cc.lib ];
runtimeDeps = [ openssl icu ];
postFixup = ''
patchelf --set-rpath ${icu}/lib $out/lib/System.Globalization.Native.so
patchelf --set-rpath ${openssl.out}/lib $out/lib/System.Security.Cryptography.Native.OpenSsl.so
mv $out/bin/Microsoft.Python.LanguageServer $out/bin/python-language-server
'';
# If we don't disable stripping, the executable fails to start with an error about being unable
# to find some of the packaged DLLs.
dontStrip = true;
passthru.updateScript = ./updater.sh;
meta = with lib; {
description = "Microsoft Language Server for Python";

File diff suppressed because it is too large Load diff

View file

@ -1,40 +0,0 @@
#! /usr/bin/env nix-shell
#! nix-shell -p gawk nix -i bash
# Retrieve sha256 hashes for each dependency in and format fetchNuGet calls
echo "" > deps.nix
urlbase="https://www.nuget.org/api/v2/package"
cat << EOL
# This file is autogenerated.
# To regenerate, run "create_deps.sh \$PATH_TO_LANGUAGE_SERVER_CHECKOUT"
{ fetchurl }: let
fetchNuGet = { name, version, sha256 }: fetchurl {
inherit sha256;
url = "$urlbase/\${name}/\${version}";
};
in [
EOL
IFS=''
while read line; do
name=$(echo $line | awk '{print $1}')
version=$(echo $line | awk '{print $2}')
sha256=$(nix-prefetch-url "$urlbase/$name/$version" 2>/dev/null)
if [ -n "$sha256" ]; then
cat << EOL
(fetchNuGet {
name = "$name";
version = "$version";
sha256 = "$sha256";
})
EOL
fi
done < $1
cat << EOL
]
EOL

View file

@ -1,2 +0,0 @@
Microsoft.AspNetCore.App.Runtime.linux-x64 3.1.21
Microsoft.NetCore.App.Runtime.linux-x64 3.1.21

View file

@ -1,37 +0,0 @@
#!/usr/bin/python
import json
import sys
def process_section(name, section):
packages = set()
if "resolved" in section:
packages.add((name, section["resolved"]))
if "dependencies" in section:
for name in section["dependencies"]:
packages.add((name, section["dependencies"][name]))
return packages
def main():
with open(sys.argv[1], 'r') as f:
tree = json.loads(f.read())
packages = set()
topDependencies = tree["dependencies"]
for area in topDependencies:
for name in topDependencies[area]:
packages = packages.union(process_section(name, topDependencies[area][name]))
for (name, version) in packages:
print("%s %s" % (name, version))
if __name__ == "__main__":
main()

View file

@ -0,0 +1,41 @@
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p gnused jq common-updater-scripts nuget-to-nix dotnet-sdk_3 nix-prefetch-git
set -eo pipefail
cd "$(dirname "${BASH_SOURCE[0]}")"
deps_file="$(realpath ./deps.nix)"
nix-prefetch-git https://github.com/microsoft/python-language-server --quiet > repo_info
new_version="$(jq -r ".date" < repo_info | cut -d"T" -f1)"
new_hash="$(jq -r ".sha256" < repo_info)"
new_rev="$(jq -r ".rev" < repo_info)"
rm repo_info
old_rev="$(sed -nE 's/\s*rev = "(.*)".*/\1/p' ./default.nix)"
if [[ $new_rev == $old_rev ]]; then
echo "Already up to date!"
exit 0
fi
pushd ../../../..
update-source-version python-language-server "$new_version" "$new_hash" --rev="$new_rev"
store_src="$(nix-build -A python-language-server.src --no-out-link)"
src="$(mktemp -d /tmp/pylang-server-src.XXX)"
cp -rT "$store_src" "$src"
chmod -R +w "$src"
pushd "$src"
export DOTNET_NOLOGO=1
export DOTNET_CLI_TELEMETRY_OPTOUT=1
mkdir ./nuget_pkgs
dotnet restore src/LanguageServer/Impl/Microsoft.Python.LanguageServer.csproj --packages ./nuget_pkgs
nuget-to-nix ./nuget_pkgs > "$deps_file"
trap ''
rm -r "$src"
'' EXIT

View file

@ -14846,9 +14846,7 @@ with pkgs;
mdl = callPackage ../development/tools/misc/mdl { };
python-language-server = callPackage ../development/dotnet-modules/python-language-server {
inherit (dotnetPackages) Nuget;
};
python-language-server = callPackage ../development/dotnet-modules/python-language-server { };
minify = callPackage ../development/web/minify { };