summary refs log tree commit diff
path: root/pkgs/build-support
diff options
context:
space:
mode:
authorgithub-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>2022-02-27 12:01:09 +0000
committerGitHub <noreply@github.com>2022-02-27 12:01:09 +0000
commit6fab7a16fa3e2a9328cf2c11bfed50ff3c3f7903 (patch)
tree095234b88078fb8675b7c48585c5440a980a08fe /pkgs/build-support
parentd8e40250665ef073afc1d208f9f911c2fd4ab397 (diff)
parent6896623f630ce8703e2201625eabd9f01dfcc5e0 (diff)
downloadnixpkgs-6fab7a16fa3e2a9328cf2c11bfed50ff3c3f7903.tar
nixpkgs-6fab7a16fa3e2a9328cf2c11bfed50ff3c3f7903.tar.gz
nixpkgs-6fab7a16fa3e2a9328cf2c11bfed50ff3c3f7903.tar.bz2
nixpkgs-6fab7a16fa3e2a9328cf2c11bfed50ff3c3f7903.tar.lz
nixpkgs-6fab7a16fa3e2a9328cf2c11bfed50ff3c3f7903.tar.xz
nixpkgs-6fab7a16fa3e2a9328cf2c11bfed50ff3c3f7903.tar.zst
nixpkgs-6fab7a16fa3e2a9328cf2c11bfed50ff3c3f7903.zip
Merge master into staging-next
Diffstat (limited to 'pkgs/build-support')
-rw-r--r--pkgs/build-support/dotnet/build-dotnet-module/default.nix204
-rw-r--r--pkgs/build-support/dotnet/build-dotnet-module/hooks/default.nix62
-rw-r--r--pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-build-hook.sh41
-rw-r--r--pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-check-hook.sh33
-rw-r--r--pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-configure-hook.sh33
-rw-r--r--pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-fixup-hook.sh42
-rw-r--r--pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-install-hook.sh42
7 files changed, 306 insertions, 151 deletions
diff --git a/pkgs/build-support/dotnet/build-dotnet-module/default.nix b/pkgs/build-support/dotnet/build-dotnet-module/default.nix
index 49a61f4e5d6..d3561282d3f 100644
--- a/pkgs/build-support/dotnet/build-dotnet-module/default.nix
+++ b/pkgs/build-support/dotnet/build-dotnet-module/default.nix
@@ -1,6 +1,7 @@
-{ lib, stdenvNoCC, linkFarmFromDrvs, nuget-to-nix, writeScript, makeWrapper, fetchurl, xml2, dotnetCorePackages, dotnetPackages, cacert }:
+{ lib, stdenvNoCC, linkFarmFromDrvs, callPackage, nuget-to-nix, writeScript, makeWrapper, fetchurl, xml2, dotnetCorePackages, dotnetPackages, cacert }:
 
 { name ? "${args.pname}-${args.version}"
+, pname ? name
 , enableParallelBuilding ? true
 , doCheck ? false
 # Flags to pass to `makeWrapper`. This is done to avoid double wrapping.
@@ -19,6 +20,8 @@
 # Flags to pass to dotnet in all phases.
 , dotnetFlags ? []
 
+# The path to publish the project to. When unset, the directory "$out/lib/$pname" is used.
+, installPath ? null
 # The binaries that should get installed to `$out/bin`, relative to `$out/lib/$pname/`. These get wrapped accordingly.
 # Unfortunately, dotnet has no method for doing this automatically.
 # If unset, all executables in the projects root will get installed. This may cause bloat!
@@ -67,6 +70,10 @@ assert projectFile == null -> throw "Defining the `projectFile` attribute is req
 assert nugetDeps == null -> throw "Defining the `nugetDeps` attribute is required, as to lock the NuGet dependencies. This file can be generated by running the `passthru.fetch-deps` script.";
 
 let
+  inherit (callPackage ./hooks {
+    inherit dotnet-sdk dotnet-test-sdk disabledTests nuget-source dotnet-runtime runtimeDeps buildType;
+  }) dotnetConfigureHook dotnetBuildHook dotnetCheckHook dotnetInstallHook dotnetFixupHook;
+
   _nugetDeps = linkFarmFromDrvs "${name}-nuget-deps" (import nugetDeps {
     fetchNuGet = { pname, version, sha256 }: fetchurl {
       name = "${pname}-${version}.nupkg";
@@ -77,8 +84,8 @@ let
   _localDeps = linkFarmFromDrvs "${name}-local-nuget-deps" projectReferences;
 
   nuget-source = stdenvNoCC.mkDerivation rec {
-    name = "${args.pname}-nuget-source";
-    meta.description = "A Nuget source with the dependencies for ${args.pname}";
+    name = "${pname}-nuget-source";
+    meta.description = "A Nuget source with the dependencies for ${pname}";
 
     nativeBuildInputs = [ dotnetPackages.Nuget xml2 ];
     buildCommand = ''
@@ -103,168 +110,63 @@ let
     )));
   };
 
-  package = stdenvNoCC.mkDerivation (args // {
-    inherit buildType;
-
-    nativeBuildInputs = args.nativeBuildInputs or [] ++ [ dotnet-sdk cacert makeWrapper ];
-
-    # Stripping breaks the executable
-    dontStrip = true;
-
-    # gappsWrapperArgs gets included when wrapping for dotnet, as to avoid double wrapping
-    dontWrapGApps = true;
-
-    DOTNET_NOLOGO = true; # This disables the welcome message.
-    DOTNET_CLI_TELEMETRY_OPTOUT = true;
-
-    passthru = {
-      fetch-deps = writeScript "fetch-${args.pname}-deps" ''
-        set -euo pipefail
-        cd "$(dirname "''${BASH_SOURCE[0]}")"
-
-        export HOME=$(mktemp -d)
-        deps_file="/tmp/${args.pname}-deps.nix"
-
-        store_src="${package.src}"
-        src="$(mktemp -d /tmp/${args.pname}.XXX)"
-        cp -rT "$store_src" "$src"
-        chmod -R +w "$src"
-
-        trap "rm -rf $src $HOME" EXIT
-        pushd "$src"
+in stdenvNoCC.mkDerivation (args // {
+  nativeBuildInputs = args.nativeBuildInputs or [] ++ [
+    dotnetConfigureHook
+    dotnetBuildHook
+    dotnetCheckHook
+    dotnetInstallHook
+    dotnetFixupHook
 
-        export DOTNET_NOLOGO=1
-        export DOTNET_CLI_TELEMETRY_OPTOUT=1
+    dotnet-sdk
+    cacert
+    makeWrapper
+  ];
 
-        mkdir -p "$HOME/nuget_pkgs"
+  # Stripping breaks the executable
+  dontStrip = args.dontStrip or true;
 
-        for project in "${lib.concatStringsSep "\" \"" ((lib.toList projectFile) ++ lib.optionals (testProjectFile != "") (lib.toList testProjectFile))}"; do
-          ${dotnet-sdk}/bin/dotnet restore "$project" \
-            ${lib.optionalString (!enableParallelBuilding) "--disable-parallel"} \
-            -p:ContinuousIntegrationBuild=true \
-            -p:Deterministic=true \
-            --packages "$HOME/nuget_pkgs" \
-            "''${dotnetRestoreFlags[@]}" \
-            "''${dotnetFlags[@]}"
-        done
+  # gappsWrapperArgs gets included when wrapping for dotnet, as to avoid double wrapping
+  dontWrapGApps = args.dontWrapGApps or true;
 
-        echo "Writing lockfile..."
-        ${nuget-to-nix}/bin/nuget-to-nix "$HOME/nuget_pkgs" > "$deps_file"
-        echo "Succesfully wrote lockfile to: $deps_file"
-      '';
-    } // args.passthru or {};
+  DOTNET_NOLOGO = args.DOTNET_NOLOGO or true; # This disables the welcome message.
+  DOTNET_CLI_TELEMETRY_OPTOUT = args.DOTNET_CLI_TELEMETRY_OPTOUT or true;
 
-    configurePhase = args.configurePhase or ''
-      runHook preConfigure
+  passthru = {
+    fetch-deps = writeScript "fetch-${pname}-deps" ''
+      set -euo pipefail
+      cd "$(dirname "''${BASH_SOURCE[0]}")"
 
       export HOME=$(mktemp -d)
+      deps_file="/tmp/${pname}-deps.nix"
 
-      for project in ''${projectFile[@]} ''${testProjectFile[@]}; do
-        dotnet restore "$project" \
-          ${lib.optionalString (!enableParallelBuilding) "--disable-parallel"} \
-          -p:ContinuousIntegrationBuild=true \
-          -p:Deterministic=true \
-          --source "${nuget-source}/lib" \
-          "''${dotnetRestoreFlags[@]}" \
-          "''${dotnetFlags[@]}"
-      done
+      store_src="${args.src}"
+      src="$(mktemp -d /tmp/${pname}.XXX)"
+      cp -rT "$store_src" "$src"
+      chmod -R +w "$src"
 
-      runHook postConfigure
-    '';
+      trap "rm -rf $src $HOME" EXIT
+      pushd "$src"
 
-    buildPhase = args.buildPhase or ''
-      runHook preBuild
+      export DOTNET_NOLOGO=1
+      export DOTNET_CLI_TELEMETRY_OPTOUT=1
 
-      for project in ''${projectFile[@]} ''${testProjectFile[@]}; do
-        dotnet build "$project" \
-          -maxcpucount:${if enableParallelBuilding then "$NIX_BUILD_CORES" else "1"} \
-          -p:BuildInParallel=${if enableParallelBuilding then "true" else "false"} \
-          -p:ContinuousIntegrationBuild=true \
-          -p:Deterministic=true \
-          -p:Version=${args.version} \
-          --configuration "$buildType" \
-          --no-restore \
-          "''${dotnetBuildFlags[@]}"  \
-          "''${dotnetFlags[@]}"
-      done
+      mkdir -p "$HOME/nuget_pkgs"
 
-      runHook postBuild
-    '';
-
-    checkPhase = args.checkPhase or ''
-      runHook preCheck
-
-      for project in ''${testProjectFile[@]}; do
-        ${lib.getBin dotnet-test-sdk}/bin/dotnet test "$project" \
-          -maxcpucount:${if enableParallelBuilding then "$NIX_BUILD_CORES" else "1"} \
+      for project in "${lib.concatStringsSep "\" \"" ((lib.toList projectFile) ++ lib.optionals (testProjectFile != "") (lib.toList testProjectFile))}"; do
+        ${dotnet-sdk}/bin/dotnet restore "$project" \
+          ${lib.optionalString (!enableParallelBuilding) "--disable-parallel"} \
           -p:ContinuousIntegrationBuild=true \
           -p:Deterministic=true \
-          --configuration "$buildType" \
-          --no-build \
-          --logger "console;verbosity=normal" \
-          ${lib.optionalString (disabledTests != []) "--filter \"FullyQualifiedName!=${lib.concatStringsSep "&FullyQualifiedName!=" disabledTests}\""} \
-          "''${dotnetTestFlags[@]}"  \
-          "''${dotnetFlags[@]}"
+          -p:RestoreUseStaticGraphEvaluation=true \
+          --packages "$HOME/nuget_pkgs" \
+          ${lib.optionalString (dotnetRestoreFlags != []) (builtins.toString dotnetRestoreFlags)} \
+          ${lib.optionalString (dotnetFlags != []) (builtins.toString dotnetFlags)}
       done
 
-      runHook postCheck
+      echo "Writing lockfile..."
+      ${nuget-to-nix}/bin/nuget-to-nix "$HOME/nuget_pkgs" > "$deps_file"
+      echo "Succesfully wrote lockfile to: $deps_file"
     '';
-
-    installPhase = args.installPhase or ''
-      runHook preInstall
-
-      for project in ''${projectFile[@]}; do
-        dotnet publish "$project" \
-          -p:ContinuousIntegrationBuild=true \
-          -p:Deterministic=true \
-          --output $out/lib/${args.pname} \
-          --configuration "$buildType" \
-          --no-build \
-          --no-self-contained \
-          "''${dotnetInstallFlags[@]}"  \
-          "''${dotnetFlags[@]}"
-      done
-    '' + lib.optionalString packNupkg ''
-      for project in ''${projectFile[@]}; do
-        dotnet pack "$project" \
-          -p:ContinuousIntegrationBuild=true \
-          -p:Deterministic=true \
-          --output $out/share \
-          --configuration "$buildType" \
-          --no-build \
-          "''${dotnetPackFlags[@]}"  \
-          "''${dotnetFlags[@]}"
-      done
-    '' + ''
-      runHook postInstall
-    '';
-
-    preFixup = ''
-      _wrapDotnetProgram() {
-        makeWrapper "$1" "$out/bin/$(basename "$executable")" \
-          --set DOTNET_ROOT "${dotnet-runtime}" \
-          --suffix LD_LIBRARY_PATH : "${lib.makeLibraryPath runtimeDeps}" \
-          "''${gappsWrapperArgs[@]}" \
-          "''${makeWrapperArgs[@]}"
-      }
-    '' + (if executables != null then ''
-      for executable in ''${executables[@]}; do
-        execPath="$out/lib/${args.pname}/$executable"
-
-        if [[ -f "$execPath" && -x "$execPath" ]]; then
-          _wrapDotnetProgram $execPath
-        else
-          echo "Specified binary \"$executable\" is either not an executable, or does not exist!"
-          exit 1
-        fi
-      done
-    '' else ''
-      for executable in $out/lib/${args.pname}/*; do
-        if [[ -f "$executable" && -x "$executable" && "$executable" != *"dll"* ]]; then
-          _wrapDotnetProgram $executable
-        fi
-      done
-    '');
-  });
-in
-  package
+  } // args.passthru or {};
+})
diff --git a/pkgs/build-support/dotnet/build-dotnet-module/hooks/default.nix b/pkgs/build-support/dotnet/build-dotnet-module/hooks/default.nix
new file mode 100644
index 00000000000..76f7eea5bfe
--- /dev/null
+++ b/pkgs/build-support/dotnet/build-dotnet-module/hooks/default.nix
@@ -0,0 +1,62 @@
+{ lib
+, callPackage
+, makeSetupHook
+, makeWrapper
+, dotnet-sdk
+, dotnet-test-sdk
+, disabledTests
+, nuget-source
+, dotnet-runtime
+, runtimeDeps
+, buildType
+}:
+
+{
+  dotnetConfigureHook = callPackage ({ }:
+    makeSetupHook {
+      name = "dotnet-configure-hook";
+      deps = [ dotnet-sdk nuget-source ];
+      substitutions = {
+        nugetSource = nuget-source;
+      };
+    } ./dotnet-configure-hook.sh) { };
+
+  dotnetBuildHook = callPackage ({ }:
+    makeSetupHook {
+      name = "dotnet-build-hook";
+      deps = [ dotnet-sdk ];
+      substitutions = {
+        inherit buildType;
+      };
+    } ./dotnet-build-hook.sh) { };
+
+  dotnetCheckHook = callPackage ({ }:
+    makeSetupHook {
+      name = "dotnet-check-hook";
+      deps = [ dotnet-test-sdk ];
+      substitutions = {
+        inherit buildType;
+        disabledTests = lib.optionalString (disabledTests != [])
+          (lib.concatStringsSep "&FullyQualifiedName!=" disabledTests);
+      };
+    } ./dotnet-check-hook.sh) { };
+
+  dotnetInstallHook = callPackage ({ }:
+    makeSetupHook {
+      name = "dotnet-install-hook";
+      deps = [ dotnet-sdk ];
+      substitutions = {
+        inherit buildType;
+      };
+    } ./dotnet-install-hook.sh) { };
+
+  dotnetFixupHook = callPackage ({ }:
+    makeSetupHook {
+      name = "dotnet-fixup-hook";
+      deps = [ dotnet-runtime makeWrapper ];
+      substitutions = {
+        dotnetRuntime = dotnet-runtime;
+        runtimeDeps = lib.makeLibraryPath runtimeDeps;
+      };
+    } ./dotnet-fixup-hook.sh) { };
+}
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
new file mode 100644
index 00000000000..a1dc80a77fd
--- /dev/null
+++ b/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-build-hook.sh
@@ -0,0 +1,41 @@
+declare -a projectFile testProjectFile dotnetBuildFlags dotnetFlags
+
+dotnetBuildHook() {
+    echo "Executing dotnetBuildHook"
+
+    runHook preBuild
+
+    if [ "${enableParallelBuilding-}" ]; then
+        maxCpuFlag="$NIX_BUILD_CORES"
+        parallelBuildFlag="true"
+    else
+        maxCpuFlag="1"
+        parallelBuildFlag="false"
+    fi
+
+    if [ "${version-}" ]; then
+        versionFlag="-p:Version=${version-}"
+    fi
+
+    for project in ${projectFile[@]} ${testProjectFile[@]}; do
+        env \
+            dotnet build "$project" \
+                -maxcpucount:$maxCpuFlag \
+                -p:BuildInParallel=$parallelBuildFlag \
+                -p:ContinuousIntegrationBuild=true \
+                -p:Deterministic=true \
+                --configuration "@buildType@" \
+                --no-restore \
+                ${versionFlag-} \
+                "${dotnetBuildFlags[@]}"  \
+                "${dotnetFlags[@]}"
+    done
+
+    runHook postBuild
+
+    echo "Finished dotnetBuildHook"
+}
+
+if [[ -z "${dontDotnetBuild-}" && -z "${buildPhase-}" ]]; then
+    buildPhase=dotnetBuildHook
+fi
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
new file mode 100644
index 00000000000..e3098908fe2
--- /dev/null
+++ b/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-check-hook.sh
@@ -0,0 +1,33 @@
+declare -a testProjectFile dotnetTestFlags dotnetFlags
+
+dotnetCheckHook() {
+    echo "Executing dotnetCheckHook"
+
+    runHook preCheck
+
+    if [ "${disabledTests-}" ]; then
+        disabledTestsFlag="--filter FullyQualifiedName!=@disabledTests@"
+    fi
+
+    for project in ${testProjectFile[@]}; do
+        env \
+            dotnet test "$project" \
+              -maxcpucount:$maxCpuFlag \
+              -p:ContinuousIntegrationBuild=true \
+              -p:Deterministic=true \
+              --configuration "@buildType@" \
+              --no-build \
+              --logger "console;verbosity=normal" \
+              ${disabledTestsFlag-} \
+              "${dotnetTestFlags[@]}"  \
+              "${dotnetFlags[@]}"
+    done
+
+    runHook postCheck
+
+    echo "Finished dotnetCheckHook"
+}
+
+if [[ -z "${dontDotnetCheck-}" && -z "${checkPhase-}" ]]; then
+    checkPhase=dotnetCheckHook
+fi
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
new file mode 100644
index 00000000000..e0522dc95ce
--- /dev/null
+++ b/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-configure-hook.sh
@@ -0,0 +1,33 @@
+declare -a projectFile testProjectFile dotnetRestoreFlags dotnetFlags
+
+dotnetConfigureHook() {
+    echo "Executing dotnetConfigureHook"
+
+    runHook preConfigure
+
+    if [ -z "${enableParallelBuilding-}" ]; then
+        parallelFlag="--disable-parallel"
+    fi
+
+    export HOME=$(mktemp -d)
+
+    for project in ${projectFile[@]} ${testProjectFile[@]}; do
+        env \
+            dotnet restore "$project" \
+                -p:ContinuousIntegrationBuild=true \
+                -p:Deterministic=true \
+                -p:RestoreUseStaticGraphEvaluation=true \
+                --source "@nugetSource@/lib" \
+                ${parallelFlag-} \
+                "${dotnetRestoreFlags[@]}" \
+                "${dotnetFlags[@]}"
+    done
+
+    runHook postConfigure
+
+    echo "Finished dotnetConfigureHook"
+}
+
+if [[ -z "${dontDotnetConfigure-}" && -z "${configurePhase-}" ]]; then
+    configurePhase=dotnetConfigureHook
+fi
diff --git a/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-fixup-hook.sh b/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-fixup-hook.sh
new file mode 100644
index 00000000000..f8bbb7b1805
--- /dev/null
+++ b/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-fixup-hook.sh
@@ -0,0 +1,42 @@
+declare -a makeWrapperArgs gappsWrapperArgs
+
+# First argument is the executable you want to wrap,
+# the second is the destination for the wrapper.
+wrapDotnetProgram() {
+    makeWrapper "$1" "$2" \
+        --set "DOTNET_ROOT" "@dotnetRuntime@" \
+        --suffix "LD_LIBRARY_PATH" : "@runtimeDeps@" \
+        "${gappsWrapperArgs[@]}" \
+        "${makeWrapperArgs[@]}"
+
+    echo "Installed wrapper to: "$2""
+}
+
+dotnetFixupHook() {
+    echo "Executing dotnetFixupPhase"
+
+    if [ "${executables-}" ]; then
+        for executable in ${executables[@]}; do
+            execPath="$out/lib/${pname-}/$executable"
+
+            if [[ -f "$execPath" && -x "$execPath" ]]; then
+                wrapDotnetProgram "$execPath" "$out/bin/$(basename "$executable")"
+            else
+                echo "Specified binary \"$executable\" is either not an executable, or does not exist!"
+                exit 1
+            fi
+        done
+    else
+        for executable in $out/lib/${pname-}/*; do
+            if [[ -f "$executable" && -x "$executable" && "$executable" != *"dll"* ]]; then
+                wrapDotnetProgram "$executable" "$out/bin/$(basename "$executable")"
+            fi
+        done
+    fi
+
+    echo "Finished dotnetFixupPhase"
+}
+
+if [[ -z "${dontDotnetFixup-}" ]]; then
+    preFixupPhases+=" dotnetFixupHook"
+fi
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
new file mode 100644
index 00000000000..ed2c9160cd2
--- /dev/null
+++ b/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-install-hook.sh
@@ -0,0 +1,42 @@
+declare -a projectFile dotnetInstallFlags dotnetFlags
+
+dotnetInstallHook() {
+    echo "Executing dotnetInstallHook"
+
+    runHook preInstall
+
+    for project in ${projectFile[@]}; do
+        env \
+            dotnet publish "$project" \
+                -p:ContinuousIntegrationBuild=true \
+                -p:Deterministic=true \
+                --output "$out/lib/${pname}" \
+                --configuration "@buildType@" \
+                --no-build \
+                --no-self-contained \
+                "${dotnetInstallFlags[@]}"  \
+                "${dotnetFlags[@]}"
+    done
+
+    if [[ "${packNupkg-}" ]]; then
+        for project in ${projectFile[@]}; do
+            env \
+                dotnet pack "$project" \
+                    -p:ContinuousIntegrationBuild=true \
+                    -p:Deterministic=true \
+                    --output "$out/share" \
+                    --configuration "@buildType@" \
+                    --no-build \
+                    "${dotnetPackFlags[@]}"  \
+                    "${dotnetFlags[@]}"
+        done
+    fi
+
+    runHook postInstall
+
+    echo "Finished dotnetInstallHook"
+}
+
+if [[ -z "${dontDotnetInstall-}" && -z "${installPhase-}" ]]; then
+    installPhase=dotnetInstallHook
+fi