Merge pull request #178004 from mdarocha/omnisharp-dotnet-module

omnisharp-roslyn: use buildDotnetModules
This commit is contained in:
Ivv 2022-06-21 15:55:51 +02:00 committed by GitHub
commit 3d82b8d13b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 402 additions and 3048 deletions

View file

@ -1,4 +1,4 @@
{ lib, stdenvNoCC, linkFarmFromDrvs, callPackage, nuget-to-nix, writeScript, makeWrapper, fetchurl, xml2, dotnetCorePackages, dotnetPackages, mkNugetSource, mkNugetDeps, cacert }:
{ lib, stdenvNoCC, linkFarmFromDrvs, callPackage, nuget-to-nix, writeScript, makeWrapper, fetchurl, xml2, dotnetCorePackages, dotnetPackages, mkNugetSource, mkNugetDeps, cacert, srcOnly }:
{ name ? "${args.pname}-${args.version}"
, pname ? name
@ -115,7 +115,7 @@ in stdenvNoCC.mkDerivation (args // {
export HOME=$(mktemp -d)
deps_file="/tmp/${pname}-deps.nix"
store_src="${args.src}"
store_src="${srcOnly args}"
src="$(mktemp -d /tmp/${pname}.XXX)"
cp -rT "$store_src" "$src"
chmod -R +w "$src"

View file

@ -1,9 +1,10 @@
{ linkFarmFromDrvs, fetchurl }:
{ name, nugetDeps }:
linkFarmFromDrvs "${name}-nuget-deps" (nugetDeps {
fetchNuGet = { pname, version, sha256 }: fetchurl {
linkFarmFromDrvs "${name}-nuget-deps" (nugetDeps {
fetchNuGet = { pname, version, sha256
, url ? "https://www.nuget.org/api/v2/package/${pname}/${version}" }:
fetchurl {
name = "${pname}-${version}.nupkg";
url = "https://www.nuget.org/api/v2/package/${pname}/${version}";
inherit sha256;
inherit url sha256;
};
})
})

View file

@ -6,6 +6,8 @@
, coreutils
, findutils
, gnused
, jq
, curl
}:
runCommandLocal "nuget-to-nix" {
@ -18,6 +20,8 @@ runCommandLocal "nuget-to-nix" {
coreutils
findutils
gnused
jq
curl
];
};

View file

@ -13,6 +13,8 @@ pkgs=$1
tmpfile=$(mktemp /tmp/nuget-to-nix.XXXXXX)
trap "rm -f ${tmpfile}" EXIT
declare -A nuget_sources_cache
echo "{ fetchNuGet }: ["
while read pkg_spec; do
@ -21,7 +23,14 @@ while read pkg_spec; do
sed -nE 's/.*<id>([^<]*).*/\1/p; s/.*<version>([^<+]*).*/\1/p' "$pkg_spec")
pkg_sha256="$(nix-hash --type sha256 --flat --base32 "$(dirname "$pkg_spec")"/*.nupkg)"
echo " (fetchNuGet { pname = \"$pkg_name\"; version = \"$pkg_version\"; sha256 = \"$pkg_sha256\"; })" >> ${tmpfile}
pkg_src="$(jq --raw-output '.source' "$(dirname "$pkg_spec")/.nupkg.metadata")"
if [[ $pkg_src != https://api.nuget.org/* ]]; then
pkg_source_url="${nuget_sources_cache[$pkg_src]:=$(curl --fail "$pkg_src" | jq --raw-output '.resources[] | select(."@type" == "PackageBaseAddress/3.0.0")."@id"')}"
pkg_url="$pkg_source_url${pkg_name,,}/${pkg_version,,}/${pkg_name,,}.${pkg_version,,}.nupkg"
echo " (fetchNuGet { pname = \"$pkg_name\"; version = \"$pkg_version\"; sha256 = \"$pkg_sha256\"; url = \"$pkg_url\"; })" >> ${tmpfile}
else
echo " (fetchNuGet { pname = \"$pkg_name\"; version = \"$pkg_version\"; sha256 = \"$pkg_sha256\"; })" >> ${tmpfile}
fi
done < <(find $1 -name '*.nuspec')
LC_ALL=C sort --ignore-case ${tmpfile}

View file

@ -7,25 +7,13 @@
#
# > srcOnly pkgs.hello
#
{ name
, src
, stdenv ? orig.stdenv
, patches ? []
, # deprecated, use the nativeBuildInputs
buildInputs ? []
, # used to pass extra unpackers
nativeBuildInputs ? []
, # needed when passing an existing derivation
...
}:
stdenv.mkDerivation {
inherit
buildInputs
name
nativeBuildInputs
patches
src
;
attrs:
let
args = if builtins.hasAttr "drvAttrs" attrs then attrs.drvAttrs else attrs;
name = if builtins.hasAttr "name" args then args.name else "${args.pname}-${args.version}";
in
stdenv.mkDerivation (args // {
name = "${name}-source";
installPhase = "cp -r . $out";
phases = ["unpackPhase" "patchPhase" "installPhase"];
}
})

View file

@ -1,74 +0,0 @@
#!/usr/bin/env nix-shell
#!nix-shell -I nixpkgs=../../../.. -i bash -p dotnet-sdk_6 jq xmlstarlet curl
set -euo pipefail
cat << EOL
{ fetchurl }: [
EOL
# enter a temporary directory containing the source code, copied from the derivation
srcdir="$(mktemp -d)"
cp -r "$(nix-build -A omnisharp-roslyn.src ../../../..)"/. "$srcdir"
rm -f "$srcdir"/global.json
pushd $srcdir >&2
tmpdir="$(mktemp -d -p "$(pwd)")" # must be under source root
mapfile -t repos < <(
xmlstarlet sel -t -v 'configuration/packageSources/add/@value' -n NuGet.Config |
while IFS= read index
do
curl --compressed -fsL "$index" | \
jq -r '.resources[] | select(."@type" == "PackageBaseAddress/3.0.0")."@id"'
done
)
dotnet msbuild -t:restore -p:Configuration=Release -p:RestorePackagesPath="$tmpdir" \
-p:RestoreNoCache=true -p:RestoreForce=true \
"$srcdir/src/OmniSharp.Stdio.Driver/OmniSharp.Stdio.Driver.csproj" >&2
cd "$tmpdir"
for package in *
do
cd "$package"
for version in *
do
found=false
for repo in "${repos[@]}"
do
url="$repo$package/$version/$package.$version.nupkg"
if curl -fsL "$url" -o /dev/null
then
found=true
break
fi
done
if ! $found
then
echo "couldn't find $package $version" >&2
exit 1
fi
sha256=$(nix-prefetch-url "$url" 2>/dev/null)
cat << EOL
{
pname = "$package";
version = "$version";
src = fetchurl {
url = "$url";
sha256 = "$sha256";
};
}
EOL
done
cd ..
done
cd ..
cat << EOL
]
EOL
popd >&2

View file

@ -1,68 +1,9 @@
{ lib, stdenv
, fetchFromGitHub
, fetchurl
, dotnetCorePackages
, makeWrapper
, unzip
, writeText
}:
{ lib, fetchFromGitHub, buildDotnetModule, dotnetCorePackages }:
let
dotnet-sdk = dotnetCorePackages.sdk_6_0;
deps = map (package: stdenv.mkDerivation (with package; {
inherit pname version src;
buildInputs = [ unzip ];
unpackPhase = ''
unzip $src
chmod -R u+r .
function traverseRename () {
for e in *
do
t="$(echo "$e" | sed -e "s/%20/\ /g" -e "s/%2B/+/g")"
[ "$t" != "$e" ] && mv -vn "$e" "$t"
if [ -d "$t" ]
then
cd "$t"
traverseRename
cd ..
fi
done
}
traverseRename
'';
installPhase = ''
runHook preInstall
package=$out/lib/dotnet/${pname}/${version}
mkdir -p $package
cp -r . $package
echo "{}" > $package/.nupkg.metadata
runHook postInstall
'';
dontFixup = true;
}))
(import ./deps.nix { inherit fetchurl; });
nuget-config = writeText "NuGet.Config" ''
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
</packageSources>
<fallbackPackageFolders>
${lib.concatStringsSep "\n" (map (package: "<add key=\"${package}\" value=\"${package}/lib/dotnet\"/>") deps)}
</fallbackPackageFolders>
</configuration>
'';
in stdenv.mkDerivation rec {
sdkVersion = dotnetCorePackages.sdk_6_0.version;
in
buildDotnetModule rec {
pname = "omnisharp-roslyn";
version = "1.38.2";
@ -73,36 +14,21 @@ in stdenv.mkDerivation rec {
sha256 = "7XJIdotfffu8xo+S6xlc1zcK3oY9QIg1CJhCNJh5co0=";
};
nativeBuildInputs = [ makeWrapper dotnet-sdk ];
projectFile = "src/OmniSharp.Stdio.Driver/OmniSharp.Stdio.Driver.csproj";
nugetDeps = ./deps.nix;
dotnetInstallFlags = [ "--framework net6.0" ];
postPatch = ''
# Relax the version requirement
substituteInPlace global.json \
--replace '6.0.100' '${dotnet-sdk.version}'
--replace '6.0.100' '${sdkVersion}'
'';
buildPhase = ''
runHook preBuild
HOME=$(pwd)/fake-home dotnet msbuild -r \
-p:Configuration=Release \
-p:RestoreConfigFile=${nuget-config} \
src/OmniSharp.Stdio.Driver/OmniSharp.Stdio.Driver.csproj
runHook postBuild
'';
installPhase = ''
mkdir -p $out/bin
cp -r bin/Release/OmniSharp.Stdio.Driver/net6.0 $out/src
postFixup = ''
# Delete files to mimick hacks in https://github.com/OmniSharp/omnisharp-roslyn/blob/bdc14ca/build.cake#L594
rm $out/src/NuGet.*.dll
rm $out/src/System.Configuration.ConfigurationManager.dll
makeWrapper $out/src/OmniSharp $out/bin/omnisharp \
--prefix DOTNET_ROOT : ${dotnet-sdk} \
--suffix PATH : ${dotnet-sdk}/bin
rm $out/lib/omnisharp-roslyn/NuGet.*.dll
rm $out/lib/omnisharp-roslyn/System.Configuration.ConfigurationManager.dll
'';
meta = with lib; {
@ -114,8 +40,7 @@ in stdenv.mkDerivation rec {
binaryNativeCode # dependencies
];
license = licenses.mit;
maintainers = with maintainers; [ tesq0 ericdallo corngood ];
mainProgram = "omnisharp";
maintainers = with maintainers; [ tesq0 ericdallo corngood mdarocha ];
mainProgram = "OmniSharp";
};
}

File diff suppressed because it is too large Load diff