From 256c3a7a534106cfc441c88b97c4514793bccda3 Mon Sep 17 00:00:00 2001 From: Raphael Robatsch Date: Fri, 26 May 2023 10:40:36 +0000 Subject: [PATCH 1/2] tests.dotnet: init with test for projectReferences Add a test for buildDotnetModule's `projectReferences = [ ... ];` feature, which is currently unused and therefore untested in nixpkgs. --- pkgs/test/default.nix | 2 + pkgs/test/dotnet/default.nix | 5 +++ .../application/Application.cs | 1 + .../application/Application.csproj | 10 +++++ .../dotnet/project-references/default.nix | 38 +++++++++++++++++++ .../project-references/library/Library.cs | 8 ++++ .../project-references/library/Library.csproj | 5 +++ .../dotnet/project-references/nuget-deps.nix | 5 +++ 8 files changed, 74 insertions(+) create mode 100644 pkgs/test/dotnet/default.nix create mode 100644 pkgs/test/dotnet/project-references/application/Application.cs create mode 100644 pkgs/test/dotnet/project-references/application/Application.csproj create mode 100644 pkgs/test/dotnet/project-references/default.nix create mode 100644 pkgs/test/dotnet/project-references/library/Library.cs create mode 100644 pkgs/test/dotnet/project-references/library/Library.csproj create mode 100644 pkgs/test/dotnet/project-references/nuget-deps.nix diff --git a/pkgs/test/default.nix b/pkgs/test/default.nix index 9f684dcea72..b6793d25b6e 100644 --- a/pkgs/test/default.nix +++ b/pkgs/test/default.nix @@ -86,6 +86,8 @@ with pkgs; coq = callPackage ./coq {}; + dotnet = recurseIntoAttrs (callPackages ./dotnet { }); + makeHardcodeGsettingsPatch = callPackage ./make-hardcode-gsettings-patch { }; makeWrapper = callPackage ./make-wrapper { }; diff --git a/pkgs/test/dotnet/default.nix b/pkgs/test/dotnet/default.nix new file mode 100644 index 00000000000..7592b09d76e --- /dev/null +++ b/pkgs/test/dotnet/default.nix @@ -0,0 +1,5 @@ +{ callPackage }: + +{ + project-references = callPackage ./project-references { }; +} diff --git a/pkgs/test/dotnet/project-references/application/Application.cs b/pkgs/test/dotnet/project-references/application/Application.cs new file mode 100644 index 00000000000..ae2c956a4df --- /dev/null +++ b/pkgs/test/dotnet/project-references/application/Application.cs @@ -0,0 +1 @@ +ProjectReferencesTest.Library.Hello(); diff --git a/pkgs/test/dotnet/project-references/application/Application.csproj b/pkgs/test/dotnet/project-references/application/Application.csproj new file mode 100644 index 00000000000..6507637a553 --- /dev/null +++ b/pkgs/test/dotnet/project-references/application/Application.csproj @@ -0,0 +1,10 @@ + + + exe + + + + + + + diff --git a/pkgs/test/dotnet/project-references/default.nix b/pkgs/test/dotnet/project-references/default.nix new file mode 100644 index 00000000000..f40b9196c20 --- /dev/null +++ b/pkgs/test/dotnet/project-references/default.nix @@ -0,0 +1,38 @@ +# Tests the `projectReferences = [ ... ];` feature of buildDotnetModule. +# The `library` derivation exposes a .nupkg, which is then consumed by the `application` derivation. +# https://nixos.org/manual/nixpkgs/unstable/index.html#packaging-a-dotnet-application + +{ lib +, dotnet-sdk +, buildDotnetModule +, runCommand +}: + +let + nugetDeps = ./nuget-deps.nix; + + # Specify the TargetFramework via an environment variable so that we don't + # have to update the .csproj files when updating dotnet-sdk + TargetFramework = "net${lib.versions.majorMinor (lib.getVersion dotnet-sdk)}"; + + library = buildDotnetModule { + name = "project-references-test-library"; + src = ./library; + inherit nugetDeps TargetFramework; + + packNupkg = true; + }; + + application = buildDotnetModule { + name = "project-references-test-application"; + src = ./application; + inherit nugetDeps TargetFramework; + + projectReferences = [ library ]; + }; +in + +runCommand "project-references-test" { } '' + ${application}/bin/Application + touch $out +'' diff --git a/pkgs/test/dotnet/project-references/library/Library.cs b/pkgs/test/dotnet/project-references/library/Library.cs new file mode 100644 index 00000000000..a4af4a0fea2 --- /dev/null +++ b/pkgs/test/dotnet/project-references/library/Library.cs @@ -0,0 +1,8 @@ +namespace ProjectReferencesTest; +public static class Library +{ + public static void Hello() + { + System.Console.WriteLine("Hello, World!"); + } +} diff --git a/pkgs/test/dotnet/project-references/library/Library.csproj b/pkgs/test/dotnet/project-references/library/Library.csproj new file mode 100644 index 00000000000..b9a71276d24 --- /dev/null +++ b/pkgs/test/dotnet/project-references/library/Library.csproj @@ -0,0 +1,5 @@ + + + ProjectReferencesTest.Library + + diff --git a/pkgs/test/dotnet/project-references/nuget-deps.nix b/pkgs/test/dotnet/project-references/nuget-deps.nix new file mode 100644 index 00000000000..f3a17967e25 --- /dev/null +++ b/pkgs/test/dotnet/project-references/nuget-deps.nix @@ -0,0 +1,5 @@ +# This file was automatically generated by passthru.fetch-deps. +# Please dont edit it manually, your changes might get overwritten! + +{ fetchNuGet }: [ +] From 0d2981488007617e666959b55e43fb1b2c2409f8 Mon Sep 17 00:00:00 2001 From: Raphael Robatsch Date: Thu, 25 May 2023 11:49:10 +0200 Subject: [PATCH 2/2] mkNugetSource: Also copy .nupkg files from subdirectories Previously only .nupkg files directly in the deps directory were copied. This is a regression because it breaks `projectReferences = [ ... ];` in buildDotnetModule. --- .../build-support/dotnet/make-nuget-source/default.nix | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/pkgs/build-support/dotnet/make-nuget-source/default.nix b/pkgs/build-support/dotnet/make-nuget-source/default.nix index 6bda65f18d5..a23a143ab24 100644 --- a/pkgs/build-support/dotnet/make-nuget-source/default.nix +++ b/pkgs/build-support/dotnet/make-nuget-source/default.nix @@ -15,12 +15,10 @@ let buildCommand = '' mkdir -p $out/{lib,share} - ( - shopt -s nullglob - for nupkg in ${lib.concatMapStringsSep " " (dep: "\"${dep}\"/*.nupkg") deps}; do - cp --no-clobber "$nupkg" $out/lib - done - ) + # use -L to follow symbolic links. When `projectReferences` is used in + # buildDotnetModule, one of the deps will be a symlink farm. + find -L ${lib.concatStringsSep " " deps} -type f -name '*.nupkg' -exec \ + cp --no-clobber '{}' $out/lib ';' # Generates a list of all licenses' spdx ids, if available. # Note that this currently ignores any license provided in plain text (e.g. "LICENSE.txt")