Skip to content

Commit

Permalink
Merge pull request #234235 from raphaelr/mknugetsource-support-subdirs
Browse files Browse the repository at this point in the history
buildDotnetModule: fix `projectReferences = [ ... ]`
  • Loading branch information
SuperSandro2000 authored Jun 14, 2023
2 parents f45bee3 + 0d29814 commit 6b942b5
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 6 deletions.
10 changes: 4 additions & 6 deletions pkgs/build-support/dotnet/make-nuget-source/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 2 additions & 0 deletions pkgs/test/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ with pkgs;

coq = callPackage ./coq {};

dotnet = recurseIntoAttrs (callPackages ./dotnet { });

makeHardcodeGsettingsPatch = callPackage ./make-hardcode-gsettings-patch { };

makeWrapper = callPackage ./make-wrapper { };
Expand Down
5 changes: 5 additions & 0 deletions pkgs/test/dotnet/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{ callPackage }:

{
project-references = callPackage ./project-references { };
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ProjectReferencesTest.Library.Hello();
10 changes: 10 additions & 0 deletions pkgs/test/dotnet/project-references/application/Application.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>exe</OutputType>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="../library/Library.csproj" />
<PackageReference Include="ProjectReferencesTest.Library" Version="*" Condition=" '$(ContinuousIntegrationBuild)'=='true' " />
</ItemGroup>
</Project>
38 changes: 38 additions & 0 deletions pkgs/test/dotnet/project-references/default.nix
Original file line number Diff line number Diff line change
@@ -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
''
8 changes: 8 additions & 0 deletions pkgs/test/dotnet/project-references/library/Library.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace ProjectReferencesTest;
public static class Library
{
public static void Hello()
{
System.Console.WriteLine("Hello, World!");
}
}
5 changes: 5 additions & 0 deletions pkgs/test/dotnet/project-references/library/Library.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<PackageId>ProjectReferencesTest.Library</PackageId>
</PropertyGroup>
</Project>
5 changes: 5 additions & 0 deletions pkgs/test/dotnet/project-references/nuget-deps.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# This file was automatically generated by passthru.fetch-deps.
# Please dont edit it manually, your changes might get overwritten!

{ fetchNuGet }: [
]

0 comments on commit 6b942b5

Please sign in to comment.