From 7877140075610ffde57bc215a7e2302798620630 Mon Sep 17 00:00:00 2001 From: Ivan Trubach Date: Tue, 9 Jan 2024 10:29:38 +0300 Subject: [PATCH 1/3] buildDotnetModule: do not run dotnet command using env There should be no reason to use env here: 1. In places where it is used to run dotnet with environment variables, the same can be done with shell syntax. For example, `env "FOO=$bar" baz` is equivalent to `FOO="$bar" baz`. 2. Otherwise, it just unnecessarily forces PATH lookup for dotnet command. In addition to that, some dotnet invocations did not use env. --- .../dotnet/build-dotnet-module/hooks/dotnet-build-hook.sh | 2 +- .../dotnet/build-dotnet-module/hooks/dotnet-check-hook.sh | 2 +- .../dotnet/build-dotnet-module/hooks/dotnet-configure-hook.sh | 4 ++-- .../dotnet/build-dotnet-module/hooks/dotnet-install-hook.sh | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-build-hook.sh b/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-build-hook.sh index 0acfeced9b16..798109291f92 100644 --- a/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-build-hook.sh +++ b/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-build-hook.sh @@ -41,7 +41,7 @@ dotnetBuildHook() { runtimeIdFlags+=("--runtime @runtimeId@") fi - env dotnet build ${project-} \ + dotnet build ${project-} \ -maxcpucount:$maxCpuFlag \ -p:BuildInParallel=$parallelBuildFlag \ -p:ContinuousIntegrationBuild=true \ diff --git a/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-check-hook.sh b/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-check-hook.sh index 507721ef9818..f19bf9f620fe 100644 --- a/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-check-hook.sh +++ b/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-check-hook.sh @@ -22,7 +22,7 @@ dotnetCheckHook() { runtimeIdFlags=("--runtime @runtimeId@") fi - env "LD_LIBRARY_PATH=@libraryPath@" \ + LD_LIBRARY_PATH="@libraryPath@" \ dotnet test "$project" \ -maxcpucount:$maxCpuFlag \ -p:ContinuousIntegrationBuild=true \ diff --git a/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-configure-hook.sh b/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-configure-hook.sh index c046fc3c306b..3eb0d4e1f230 100644 --- a/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-configure-hook.sh +++ b/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-configure-hook.sh @@ -15,7 +15,7 @@ dotnetConfigureHook() { dotnetRestore() { local -r project="${1-}" - env dotnet restore ${project-} \ + dotnet restore ${project-} \ -p:ContinuousIntegrationBuild=true \ -p:Deterministic=true \ --runtime "@runtimeId@" \ @@ -43,7 +43,7 @@ EOF find -name paket.dependencies -exec sed -i 's+source .*+source @nugetSource@/lib+g' {} \; find -name paket.lock -exec sed -i 's+remote:.*+remote: @nugetSource@/lib+g' {} \; - env dotnet tool restore --add-source "@nugetSource@/lib" + dotnet tool restore --add-source "@nugetSource@/lib" (( "${#projectFile[@]}" == 0 )) && dotnetRestore diff --git a/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-install-hook.sh b/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-install-hook.sh index d832eac28809..ed754d8ffcad 100644 --- a/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-install-hook.sh +++ b/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-install-hook.sh @@ -27,7 +27,7 @@ dotnetInstallHook() { runtimeIdFlags+=("--runtime @runtimeId@") fi - env dotnet publish ${project-} \ + dotnet publish ${project-} \ -p:ContinuousIntegrationBuild=true \ -p:Deterministic=true \ --output "${installPath-$out/lib/$pname}" \ @@ -40,7 +40,7 @@ dotnetInstallHook() { dotnetPack() { local -r project="${1-}" - env dotnet pack ${project-} \ + dotnet pack ${project-} \ -p:ContinuousIntegrationBuild=true \ -p:Deterministic=true \ --output "$out/share" \ From 0e64e645c92333257fa9bc78cbe31675c715533b Mon Sep 17 00:00:00 2001 From: Ivan Trubach Date: Tue, 9 Jan 2024 13:13:08 +0300 Subject: [PATCH 2/3] buildDotnetModule: fix cross-compilation and remove dotnet-test-sdk This change fixes cross-compilation for .NET packages (that are not using .sln as project files). See relevant comment in the change list for more details. In addition to that, it removes dotnet-test-sdk that appears to be broken, that is, dotnet --list-sdks does not recognize SDKs from PATH, and when propagated from the check hook it was shadowed by inputs from preceding hooks. Note that dotnet-test-sdk used to work when it was introduced in PR 144062, but PR 155257 probably overlooked this case. However, currently it is not used in Nixpkgs and I think dotnetCorePackages.combinePackages should cover the intended use case for dotnet-test-sdk. --- doc/languages-frameworks/dotnet.section.md | 1 - pkgs/build-support/dotnet/build-dotnet-module/default.nix | 4 +--- .../dotnet/build-dotnet-module/hooks/default.nix | 6 ------ 3 files changed, 1 insertion(+), 10 deletions(-) diff --git a/doc/languages-frameworks/dotnet.section.md b/doc/languages-frameworks/dotnet.section.md index a4e9d6cf9a6c..36c20a9e9c50 100644 --- a/doc/languages-frameworks/dotnet.section.md +++ b/doc/languages-frameworks/dotnet.section.md @@ -117,7 +117,6 @@ For more detail about managing the `deps.nix` file, see [Generating and updating * `useDotnetFromEnv` will change the binary wrapper so that it uses the .NET from the environment. The runtime specified by `dotnet-runtime` is given as a fallback in case no .NET is installed in the user's environment. This is most useful for .NET global tools and LSP servers, which often extend the .NET CLI and their runtime should match the users' .NET runtime. * `dotnet-sdk` is useful in cases where you need to change what dotnet SDK is being used. You can also set this to the result of `dotnetSdkPackages.combinePackages`, if the project uses multiple SDKs to build. * `dotnet-runtime` is useful in cases where you need to change what dotnet runtime is being used. This can be either a regular dotnet runtime, or an aspnetcore. -* `dotnet-test-sdk` is useful in cases where unit tests expect a different dotnet SDK. By default, this is set to the `dotnet-sdk` attribute. * `testProjectFile` is useful in cases where the regular project file does not contain the unit tests. It gets restored and build, but not installed. You may need to regenerate your nuget lockfile after setting this. Note that if set, only tests from this project are executed. * `disabledTests` is used to disable running specific unit tests. This gets passed as: `dotnet test --filter "FullyQualifiedName!={}"`, to ensure compatibility with all unit test frameworks. * `dotnetRestoreFlags` can be used to pass flags to `dotnet restore`. diff --git a/pkgs/build-support/dotnet/build-dotnet-module/default.nix b/pkgs/build-support/dotnet/build-dotnet-module/default.nix index 4548616c7d80..e2ddee48cc00 100644 --- a/pkgs/build-support/dotnet/build-dotnet-module/default.nix +++ b/pkgs/build-support/dotnet/build-dotnet-module/default.nix @@ -84,8 +84,6 @@ , dotnet-sdk ? dotnetCorePackages.sdk_6_0 # The dotnet runtime to use. , dotnet-runtime ? dotnetCorePackages.runtime_6_0 - # The dotnet SDK to run tests against. This can differentiate from the SDK compiled against. -, dotnet-test-sdk ? dotnet-sdk , ... } @ args: @@ -96,7 +94,7 @@ let else dotnet-sdk.meta.platforms; inherit (callPackage ./hooks { - inherit dotnet-sdk dotnet-test-sdk disabledTests nuget-source dotnet-runtime runtimeDeps buildType; + inherit dotnet-sdk disabledTests nuget-source dotnet-runtime runtimeDeps buildType; runtimeId = if runtimeId != null then runtimeId diff --git a/pkgs/build-support/dotnet/build-dotnet-module/hooks/default.nix b/pkgs/build-support/dotnet/build-dotnet-module/hooks/default.nix index 7012ff36a4a5..81becef9b30b 100644 --- a/pkgs/build-support/dotnet/build-dotnet-module/hooks/default.nix +++ b/pkgs/build-support/dotnet/build-dotnet-module/hooks/default.nix @@ -8,7 +8,6 @@ , makeSetupHook , makeWrapper , dotnet-sdk -, dotnet-test-sdk , disabledTests , nuget-source , dotnet-runtime @@ -25,7 +24,6 @@ in dotnetConfigureHook = callPackage ({ }: makeSetupHook { name = "dotnet-configure-hook"; - propagatedBuildInputs = [ dotnet-sdk nuget-source ]; substitutions = { nugetSource = nuget-source; dynamicLinker = "${stdenv.cc}/nix-support/dynamic-linker"; @@ -43,7 +41,6 @@ in dotnetBuildHook = callPackage ({ }: makeSetupHook { name = "dotnet-build-hook"; - propagatedBuildInputs = [ dotnet-sdk ]; substitutions = { inherit buildType runtimeId; }; @@ -52,7 +49,6 @@ in dotnetCheckHook = callPackage ({ }: makeSetupHook { name = "dotnet-check-hook"; - propagatedBuildInputs = [ dotnet-test-sdk ]; substitutions = { inherit buildType runtimeId libraryPath; disabledTests = lib.optionalString (disabledTests != []) @@ -67,7 +63,6 @@ in dotnetInstallHook = callPackage ({ }: makeSetupHook { name = "dotnet-install-hook"; - propagatedBuildInputs = [ dotnet-sdk ]; substitutions = { inherit buildType runtimeId; }; @@ -76,7 +71,6 @@ in dotnetFixupHook = callPackage ({ }: makeSetupHook { name = "dotnet-fixup-hook"; - propagatedBuildInputs = [ dotnet-runtime ]; substitutions = { dotnetRuntime = dotnet-runtime; runtimeDeps = libraryPath; From cfd1bd614134e3705c380c217f6c34bb6621d051 Mon Sep 17 00:00:00 2001 From: Ivan Trubach Date: Wed, 22 May 2024 03:12:30 +0300 Subject: [PATCH 3/3] buildDotnetModule: remove unnecessary callPackage calls This change removes no-op callPackage calls and reformats the file with nixpkgs-fmt. --- .../build-dotnet-module/hooks/default.nix | 49 +++++++++++-------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/pkgs/build-support/dotnet/build-dotnet-module/hooks/default.nix b/pkgs/build-support/dotnet/build-dotnet-module/hooks/default.nix index 81becef9b30b..44091604f5c2 100644 --- a/pkgs/build-support/dotnet/build-dotnet-module/hooks/default.nix +++ b/pkgs/build-support/dotnet/build-dotnet-module/hooks/default.nix @@ -21,8 +21,8 @@ let libraryPath = lib.makeLibraryPath runtimeDeps; in { - dotnetConfigureHook = callPackage ({ }: - makeSetupHook { + dotnetConfigureHook = makeSetupHook + { name = "dotnet-configure-hook"; substitutions = { nugetSource = nuget-source; @@ -36,40 +36,46 @@ in ]; inherit runtimeId; }; - } ./dotnet-configure-hook.sh) { }; + } + ./dotnet-configure-hook.sh; - dotnetBuildHook = callPackage ({ }: - makeSetupHook { + dotnetBuildHook = makeSetupHook + { name = "dotnet-build-hook"; substitutions = { inherit buildType runtimeId; }; - } ./dotnet-build-hook.sh) { }; + } + ./dotnet-build-hook.sh; - dotnetCheckHook = callPackage ({ }: - makeSetupHook { + dotnetCheckHook = makeSetupHook + { name = "dotnet-check-hook"; substitutions = { inherit buildType runtimeId libraryPath; - disabledTests = lib.optionalString (disabledTests != []) - (let - escapedNames = lib.lists.map (n: lib.replaceStrings [","] ["%2C"] n) disabledTests; - filters = lib.lists.map (n: "FullyQualifiedName!=${n}") escapedNames; - in - "${lib.concatStringsSep "&" filters}"); + disabledTests = lib.optionalString (disabledTests != [ ]) + ( + let + escapedNames = lib.lists.map (n: lib.replaceStrings [ "," ] [ "%2C" ] n) disabledTests; + filters = lib.lists.map (n: "FullyQualifiedName!=${n}") escapedNames; + in + "${lib.concatStringsSep "&" filters}" + ); }; - } ./dotnet-check-hook.sh) { }; + } + ./dotnet-check-hook.sh; - dotnetInstallHook = callPackage ({ }: - makeSetupHook { + dotnetInstallHook = makeSetupHook + { name = "dotnet-install-hook"; substitutions = { inherit buildType runtimeId; }; - } ./dotnet-install-hook.sh) { }; + } + ./dotnet-install-hook.sh; - dotnetFixupHook = callPackage ({ }: - makeSetupHook { + dotnetFixupHook = makeSetupHook + { name = "dotnet-fixup-hook"; substitutions = { dotnetRuntime = dotnet-runtime; @@ -79,5 +85,6 @@ in dirname = "${coreutils}/bin/dirname"; realpath = "${coreutils}/bin/realpath"; }; - } ./dotnet-fixup-hook.sh) { }; + } + ./dotnet-fixup-hook.sh; }