summary refs log tree commit diff
diff options
context:
space:
mode:
authorWeijia Wang <9713184+wegank@users.noreply.github.com>2023-11-16 23:41:25 +0100
committerGitHub <noreply@github.com>2023-11-16 23:41:25 +0100
commitb1044bdc9d0c66c7182116cce971f108dd7c8d02 (patch)
treecc425755931c9e987d86508b29d86ad0d875d180
parent731d094bf348b5e6fc15b0b2b6a67adea25d9a05 (diff)
parentd016404ccd291838794c6e6c1e9ac6779cc5fa9f (diff)
downloadnixpkgs-b1044bdc9d0c66c7182116cce971f108dd7c8d02.tar
nixpkgs-b1044bdc9d0c66c7182116cce971f108dd7c8d02.tar.gz
nixpkgs-b1044bdc9d0c66c7182116cce971f108dd7c8d02.tar.bz2
nixpkgs-b1044bdc9d0c66c7182116cce971f108dd7c8d02.tar.lz
nixpkgs-b1044bdc9d0c66c7182116cce971f108dd7c8d02.tar.xz
nixpkgs-b1044bdc9d0c66c7182116cce971f108dd7c8d02.tar.zst
nixpkgs-b1044bdc9d0c66c7182116cce971f108dd7c8d02.zip
Merge pull request #258184 from mdarocha/dotnet-fixes
buildDotnetModule small improvements
-rw-r--r--doc/languages-frameworks/dotnet.section.md4
-rw-r--r--pkgs/build-support/dotnet/build-dotnet-module/default.nix18
-rw-r--r--pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-build-hook.sh9
3 files changed, 27 insertions, 4 deletions
diff --git a/doc/languages-frameworks/dotnet.section.md b/doc/languages-frameworks/dotnet.section.md
index 9ba0fef2a27..978ec07cb96 100644
--- a/doc/languages-frameworks/dotnet.section.md
+++ b/doc/languages-frameworks/dotnet.section.md
@@ -138,7 +138,9 @@ in buildDotnetModule rec {
   src = ./.;
 
   projectFile = "src/project.sln";
-  nugetDeps = ./deps.nix; # File generated with `nix-build -A package.passthru.fetch-deps`.
+  # File generated with `nix-build -A package.passthru.fetch-deps`.
+  # To run fetch-deps when this file does not yet exist, set nugetDeps to null
+  nugetDeps = ./deps.nix;
 
   projectReferences = [ referencedProject ]; # `referencedProject` must contain `nupkg` in the folder structure.
 
diff --git a/pkgs/build-support/dotnet/build-dotnet-module/default.nix b/pkgs/build-support/dotnet/build-dotnet-module/default.nix
index 686d89f8c11..f8ed3a38890 100644
--- a/pkgs/build-support/dotnet/build-dotnet-module/default.nix
+++ b/pkgs/build-support/dotnet/build-dotnet-module/default.nix
@@ -158,6 +158,22 @@ stdenvNoCC.mkDerivation (args // {
     dotnet-sdk
   ];
 
+  # Parse the version attr into a format acceptable for the Version msbuild property
+  # The actual version attr is saved in InformationalVersion, which accepts an arbitrary string
+  versionForDotnet = if !(lib.hasAttr "version" args) || args.version == null
+  then null else let
+    components = lib.pipe args.version [
+      lib.splitVersion
+      (lib.filter (x: (lib.strings.match "[0-9]+" x) != null))
+      (lib.filter (x: (lib.toInt x) < 65535)) # one version component in dotnet has to fit in 16 bits
+    ];
+  in if (lib.length components) == 0
+  then null
+  else lib.concatStringsSep "." ((lib.take 4 components)
+    ++ (if (lib.length components) < 4
+       then lib.replicate (4 - (lib.length components)) "0"
+       else [ ]));
+
   makeWrapperArgs = args.makeWrapperArgs or [ ] ++ [
     "--prefix LD_LIBRARY_PATH : ${dotnet-sdk.icu}/lib"
   ];
@@ -172,7 +188,7 @@ stdenvNoCC.mkDerivation (args // {
 
   passthru = {
     inherit nuget-source;
-  } // lib.optionalAttrs (nugetDepsFile != null) {
+  } // lib.optionalAttrs (!lib.isDerivation nugetDeps) {
     fetch-deps =
       let
         flags = dotnetFlags ++ dotnetRestoreFlags;
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 e9567b64cf2..0acfeced9b1 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
@@ -24,8 +24,13 @@ dotnetBuildHook() {
         dotnetBuildFlags+=("-p:UseAppHost=true")
     fi
 
+    local versionFlags=()
     if [ "${version-}" ]; then
-        local -r versionFlag="-p:Version=${version-}"
+        versionFlags+=("-p:InformationalVersion=${version-}")
+    fi
+
+    if [ "${versionForDotnet-}" ]; then
+        versionFlags+=("-p:Version=${versionForDotnet-}")
     fi
 
     dotnetBuild() {
@@ -43,7 +48,7 @@ dotnetBuildHook() {
             -p:Deterministic=true \
             --configuration "@buildType@" \
             --no-restore \
-            ${versionFlag-} \
+            ${versionFlags[@]} \
             ${runtimeIdFlags[@]} \
             ${dotnetBuildFlags[@]}  \
             ${dotnetFlags[@]}