Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
corngood committed Aug 24, 2024
1 parent 95de0d5 commit fe51471
Show file tree
Hide file tree
Showing 22 changed files with 1,764 additions and 743 deletions.
68 changes: 68 additions & 0 deletions pkgs/build-support/dotnet/add-nuget-deps/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{ writeShellScript
, runtimeShell
, nix
, lib
, substituteAll
, nuget-to-nix
, cacert
, mkNugetDeps
}:

{ depsFile
, overrideFetchAttrs ? x: {}
}: fnOrAttrs: finalAttrs:
let
attrs =
if builtins.isFunction fnOrAttrs
then fnOrAttrs finalAttrs
else fnOrAttrs;

deps = mkNugetDeps {
name = "${finalPackage.name}-nuget-deps";
sourceFile = depsFile;
};

finalPackage = finalAttrs.finalPackage;

in attrs // {
buildInputs = attrs.buildInputs or [] ++ [
deps
];

passthru = attrs.passthru or {} // {
fetch-deps = let
pkg' = finalPackage.overrideAttrs (old: {
buildInputs = lib.remove deps old.buildInputs;
keepNugetConfig = true;
dontBuild = true;
dontInstall = true;
});

pkg'' = pkg'.overrideAttrs overrideFetchAttrs;

drv = builtins.unsafeDiscardOutputDependency pkg''.drvPath;

innerScript = substituteAll {
src = ./fetch-deps.sh;
isExecutable = true;
inherit cacert;
defaultDepsFile =
# Wire in the depsFile such that running the script with no args
# runs it agains the correct deps file by default.
# Note that toString is necessary here as it results in the path at
# eval time (i.e. to the file in your local Nixpkgs checkout) rather
# than the Nix store path of the path after it's been imported.
if lib.isPath depsFile
&& !lib.hasPrefix "${builtins.storeDir}/" (toString depsFile) then
toString depsFile
else
''$(mktemp -t "${finalPackage.name}-deps-XXXXXX.nix")'';
nugetToNix = nuget-to-nix;
};

in writeShellScript "${finalPackage.name}-fetch-deps" ''
NIX_BUILD_SHELL="${runtimeShell}" exec ${nix}/bin/nix-shell \
--pure --run 'source "${innerScript}"' "${drv}"
'';
};
}
19 changes: 19 additions & 0 deletions pkgs/build-support/dotnet/add-nuget-deps/fetch-deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
set -e

tmp=$(mktemp -d)
trap 'chmod -R +w "$tmp" && rm -fr "$tmp"' EXIT

HOME=$tmp/.home
mkdir "$HOME"
cd "$tmp"

export NIX_SSL_CERT_FILE=@cacert@/etc/ssl/certs/ca-bundle.crt

genericBuild

depsFile=$(realpath "${1:-@defaultDepsFile@}")
tmpFile="$tmp"/deps.nix
echo -e "# This file was automatically generated by passthru.fetch-deps.\n# Please dont edit it manually, your changes might get overwritten!\n" > "$tmpFile"
@nugetToNix@/bin/nuget-to-nix "$NUGET_PACKAGES" >> "$tmpFile"
mv "$tmpFile" "$depsFile"
echo "Succesfully wrote lockfile to $depsFile"
2 changes: 1 addition & 1 deletion pkgs/build-support/dotnet/build-dotnet-module/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ let
toString nugetDepsFile
else
''$(mktemp -t "${pname}-deps-XXXXXX.nix")'';
nugetToNix = (nuget-to-nix.override { inherit dotnet-sdk; });
nugetToNix = nuget-to-nix;
};

in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ dotnetInstallHook() {
done
}

local -r pkgs=$PWD/.nuget-pack

dotnetPack() {
local -r projectFile="${1-}"

Expand All @@ -73,7 +71,7 @@ dotnetInstallHook() {
-p:ContinuousIntegrationBuild=true \
-p:Deterministic=true \
-p:OverwriteReadOnlyFiles=true \
--output "$pkgs" \
--output "$out/share/nuget/source" \
--configuration "$dotnetBuildType" \
--no-build \
--runtime "$runtimeId" \
Expand Down Expand Up @@ -104,20 +102,6 @@ dotnetInstallHook() {
fi
fi

local -r unpacked="$pkgs/.unpacked"
for nupkg in "$pkgs"/*.nupkg; do
rm -rf "$unpacked"
unzip -qd "$unpacked" "$nupkg"
chmod -R +rw "$unpacked"
echo {} > "$unpacked"/.nupkg.metadata
local id version
id=$(xq -r '.package.metadata.id|ascii_downcase' "$unpacked"/*.nuspec)
version=$(xq -r '.package.metadata.version|ascii_downcase' "$unpacked"/*.nuspec)
mkdir -p "$out/share/nuget/packages/$id"
mv "$unpacked" "$out/share/nuget/packages/$id/$version"
# TODO: should we fix executable flags here?
done

runHook postInstall

echo "Finished dotnetInstallHook"
Expand Down
13 changes: 10 additions & 3 deletions pkgs/build-support/dotnet/make-nuget-deps/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,27 @@
, unzip
, patchNupkgs
, nugetPackageHook
, callPackage
}:
lib.makeOverridable(
let
overrides = callPackage ./overrides {};
in lib.makeOverridable(
{ name
, nugetDeps ? import sourceFile
, sourceFile ? null
, installable ? false
}:
(symlinkJoin {
name = "${name}-nuget-deps";
name
= "${name}-nuget-deps";
paths = nugetDeps {
fetchNuGet =
{ pname
, version
, sha256 ? ""
, hash ? ""
, url ? "https://www.nuget.org/api/v2/package/${pname}/${version}" }:
overrides.${pname} or lib.id (
stdenvNoCC.mkDerivation rec {
inherit pname version;

Expand Down Expand Up @@ -53,18 +58,20 @@ lib.makeOverridable(
'';

installPhase = ''
runHook preInstall
dir=$out/share/nuget/packages/${lib.toLower pname}/${lib.toLower version}
mkdir -p $dir
cp -r . $dir
echo {} > "$dir"/.nupkg.metadata
runHook postInstall
'';

preFixup = ''
patch-nupkgs $out/share/nuget/packages
'';

createInstallableNugetSource = installable;
};
});
};
}) // {
inherit sourceFile;
Expand Down
21 changes: 21 additions & 0 deletions pkgs/build-support/dotnet/make-nuget-deps/overrides/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
callPackage,
autoPatchelfHook,
fontconfig,
}:
{

"SkiaSharp.NativeAssets.Linux" =
package:
package.overrideAttrs (old: {
nativeBuildInputs = old.nativeBuildInputs or [ ] ++ [ autoPatchelfHook ];

buildInputs = old.buildInputs or [ ] ++ [ fontconfig ];

preInstall =
old.preInstall or ""
+ ''
rm -r runtimes/linux-{arm,arm64,musl-x64}
'';
});
}
5 changes: 2 additions & 3 deletions pkgs/build-support/dotnet/nuget-to-nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
, curl
, gnugrep
, gawk
, dotnet-sdk
, cacert
}:

runCommandLocal "nuget-to-nix" {
script = substituteAll {
src = ./nuget-to-nix.sh;
inherit runtimeShell;
inherit runtimeShell cacert;

binPath = lib.makeBinPath [
nix
Expand All @@ -25,7 +25,6 @@ runCommandLocal "nuget-to-nix" {
curl
gnugrep
gawk
dotnet-sdk
];
};

Expand Down
3 changes: 2 additions & 1 deletion pkgs/build-support/dotnet/nuget-to-nix/nuget-to-nix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
set -euo pipefail
shopt -s nullglob

export PATH="@binPath@"
export SSL_CERT_FILE=@cacert@/etc/ssl/certs/ca-bundle.crt
export PATH="@binPath@:$PATH"
# used for glob ordering of package names
export LC_ALL=C

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
From f4c599a48d153d15ccb1879ff511617c8e310515 Mon Sep 17 00:00:00 2001
From: David McFarland <[email protected]>
Date: Sat, 10 Aug 2024 23:14:12 -0300
Subject: [PATCH 1/2] use files for unicode character database

---
.../BiDiClassTestDataGenerator.cs | 1 -
.../TextFormatting/BiDiTestDataGenerator.cs | 1 -
.../GraphemeBreakClassTrieGenerator.cs | 1 -
.../GraphemeBreakTestDataGenerator.cs | 1 -
.../LineBreakEnumuratorTests.cs | 1 -
.../TextFormatting/UnicodeDataGenerator.cs | 28 +++++++++++++++++--
.../TextFormatting/UnicodeEnumsGenerator.cs | 1 -
7 files changed, 26 insertions(+), 8 deletions(-)

diff --git a/tests/Avalonia.Base.UnitTests/Media/TextFormatting/BiDiClassTestDataGenerator.cs b/tests/Avalonia.Base.UnitTests/Media/TextFormatting/BiDiClassTestDataGenerator.cs
index f6b01d737..bc7278ef8 100644
--- a/tests/Avalonia.Base.UnitTests/Media/TextFormatting/BiDiClassTestDataGenerator.cs
+++ b/tests/Avalonia.Base.UnitTests/Media/TextFormatting/BiDiClassTestDataGenerator.cs
@@ -3,7 +3,6 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
-using System.Net.Http;
using Avalonia.Base.UnitTests.Media.TextFormatting;

namespace Avalonia.Visuals.UnitTests.Media.TextFormatting
diff --git a/tests/Avalonia.Base.UnitTests/Media/TextFormatting/BiDiTestDataGenerator.cs b/tests/Avalonia.Base.UnitTests/Media/TextFormatting/BiDiTestDataGenerator.cs
index 28d37130a..5e26edf49 100644
--- a/tests/Avalonia.Base.UnitTests/Media/TextFormatting/BiDiTestDataGenerator.cs
+++ b/tests/Avalonia.Base.UnitTests/Media/TextFormatting/BiDiTestDataGenerator.cs
@@ -3,7 +3,6 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
-using System.Net.Http;
using Avalonia.Base.UnitTests.Media.TextFormatting;
using Avalonia.Media.TextFormatting.Unicode;

diff --git a/tests/Avalonia.Base.UnitTests/Media/TextFormatting/GraphemeBreakClassTrieGenerator.cs b/tests/Avalonia.Base.UnitTests/Media/TextFormatting/GraphemeBreakClassTrieGenerator.cs
index 1a8d41caa..185b6ea62 100644
--- a/tests/Avalonia.Base.UnitTests/Media/TextFormatting/GraphemeBreakClassTrieGenerator.cs
+++ b/tests/Avalonia.Base.UnitTests/Media/TextFormatting/GraphemeBreakClassTrieGenerator.cs
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
-using System.Net.Http;
using System.Text.RegularExpressions;
using Avalonia.Media.TextFormatting.Unicode;

diff --git a/tests/Avalonia.Base.UnitTests/Media/TextFormatting/GraphemeBreakTestDataGenerator.cs b/tests/Avalonia.Base.UnitTests/Media/TextFormatting/GraphemeBreakTestDataGenerator.cs
index 029f8e236..44c2aaf6a 100644
--- a/tests/Avalonia.Base.UnitTests/Media/TextFormatting/GraphemeBreakTestDataGenerator.cs
+++ b/tests/Avalonia.Base.UnitTests/Media/TextFormatting/GraphemeBreakTestDataGenerator.cs
@@ -3,7 +3,6 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
-using System.Net.Http;
using Avalonia.Base.UnitTests.Media.TextFormatting;

namespace Avalonia.Visuals.UnitTests.Media.TextFormatting
diff --git a/tests/Avalonia.Base.UnitTests/Media/TextFormatting/LineBreakEnumuratorTests.cs b/tests/Avalonia.Base.UnitTests/Media/TextFormatting/LineBreakEnumuratorTests.cs
index 3db9a32b6..b8df1f446 100644
--- a/tests/Avalonia.Base.UnitTests/Media/TextFormatting/LineBreakEnumuratorTests.cs
+++ b/tests/Avalonia.Base.UnitTests/Media/TextFormatting/LineBreakEnumuratorTests.cs
@@ -3,7 +3,6 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
-using System.Net.Http;
using Avalonia.Media.TextFormatting;
using Avalonia.Media.TextFormatting.Unicode;
using Xunit;
diff --git a/tests/Avalonia.Base.UnitTests/Media/TextFormatting/UnicodeDataGenerator.cs b/tests/Avalonia.Base.UnitTests/Media/TextFormatting/UnicodeDataGenerator.cs
index f05a1e574..7e698ae0a 100644
--- a/tests/Avalonia.Base.UnitTests/Media/TextFormatting/UnicodeDataGenerator.cs
+++ b/tests/Avalonia.Base.UnitTests/Media/TextFormatting/UnicodeDataGenerator.cs
@@ -1,16 +1,40 @@
using System;
using System.Collections.Generic;
using System.IO;
-using System.Net.Http;
using System.Text.RegularExpressions;
+using System.Threading.Tasks;
using Avalonia.Media.TextFormatting.Unicode;
using Xunit;

namespace Avalonia.Base.UnitTests.Media.TextFormatting
{
+ class HttpContent : IDisposable {
+ readonly string url;
+ public HttpContent(string url) => this.url = url;
+
+ public void Dispose() {}
+ public Task<Stream> ReadAsStreamAsync() =>
+ Task.FromResult<Stream>(File.OpenRead(url));
+ }
+
+ class HttpResponseMessage : IDisposable {
+ HttpContent content;
+ public HttpResponseMessage(string url) => Content = new(url);
+
+ public void Dispose() {}
+ public bool IsSuccessStatusCode => true;
+ public HttpContent Content { get; init; }
+ }
+
+ class HttpClient : IDisposable {
+ public void Dispose() {}
+ public Task<HttpResponseMessage> GetAsync(string url) =>
+ Task.FromResult<HttpResponseMessage>(new (url));
+ }
+
internal static class UnicodeDataGenerator
{
- public const string Ucd = "https://www.unicode.org/Public/15.0.0/ucd/";
+ public static readonly string Ucd = Environment.GetEnvironmentVariable("UNICODE_CHARACTER_DATABASE");

public static UnicodeTrie GenerateBiDiTrie(out BiDiDataEntries biDiDataEntries, out Dictionary<int, BiDiDataItem> biDiData)
{
diff --git a/tests/Avalonia.Base.UnitTests/Media/TextFormatting/UnicodeEnumsGenerator.cs b/tests/Avalonia.Base.UnitTests/Media/TextFormatting/UnicodeEnumsGenerator.cs
index 110e57cbd..7073ea508 100644
--- a/tests/Avalonia.Base.UnitTests/Media/TextFormatting/UnicodeEnumsGenerator.cs
+++ b/tests/Avalonia.Base.UnitTests/Media/TextFormatting/UnicodeEnumsGenerator.cs
@@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
-using System.Net.Http;

namespace Avalonia.Base.UnitTests.Media.TextFormatting
{
--
2.42.2

Loading

0 comments on commit fe51471

Please sign in to comment.