mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-09-29 15:43:00 +00:00
buildDotnetModule: dont require specifing a projectFile
In a lot of cases dotnet can figure this out by itself, so we can just invoke it without the project argument.
This commit is contained in:
parent
a7c598e458
commit
03a1b62cb3
@ -71,7 +71,7 @@ The `dotnetCorePackages.sdk` contains both a runtime and the full sdk of a given
|
|||||||
|
|
||||||
To package Dotnet applications, you can use `buildDotnetModule`. This has similar arguments to `stdenv.mkDerivation`, with the following additions:
|
To package Dotnet applications, you can use `buildDotnetModule`. This has similar arguments to `stdenv.mkDerivation`, with the following additions:
|
||||||
|
|
||||||
* `projectFile` has to be used for specifying the dotnet project file relative to the source root. These usually have `.sln` or `.csproj` file extensions. This can be an array of multiple projects as well.
|
* `projectFile` is used for specifying the dotnet project file relative to the source root. These usually have `.sln` or `.csproj` file extensions. This can be an array of multiple projects as well.
|
||||||
* `nugetDeps` takes either a path to a `deps.nix` file, or a derivation. The `deps.nix` file can be generated using the script attached to `passthru.fetch-deps`. This file can also be generated manually using `nuget-to-nix` tool, which is available in nixpkgs. If the argument is a derivation, it will be used directly and assume it has the same output as `mkNugetDeps`.
|
* `nugetDeps` takes either a path to a `deps.nix` file, or a derivation. The `deps.nix` file can be generated using the script attached to `passthru.fetch-deps`. This file can also be generated manually using `nuget-to-nix` tool, which is available in nixpkgs. If the argument is a derivation, it will be used directly and assume it has the same output as `mkNugetDeps`.
|
||||||
* `packNupkg` is used to pack project as a `nupkg`, and installs it to `$out/share`. If set to `true`, the derivation can be used as a dependency for another dotnet project by adding it to `projectReferences`.
|
* `packNupkg` is used to pack project as a `nupkg`, and installs it to `$out/share`. If set to `true`, the derivation can be used as a dependency for another dotnet project by adding it to `projectReferences`.
|
||||||
* `projectReferences` can be used to resolve `ProjectReference` project items. Referenced projects can be packed with `buildDotnetModule` by setting the `packNupkg = true` attribute and passing a list of derivations to `projectReferences`. Since we are sharing referenced projects as NuGets they must be added to csproj/fsproj files as `PackageReference` as well.
|
* `projectReferences` can be used to resolve `ProjectReference` project items. Referenced projects can be packed with `buildDotnetModule` by setting the `packNupkg = true` attribute and passing a list of derivations to `projectReferences`. Since we are sharing referenced projects as NuGets they must be added to csproj/fsproj files as `PackageReference` as well.
|
||||||
|
@ -82,8 +82,6 @@
|
|||||||
, ...
|
, ...
|
||||||
} @ args:
|
} @ args:
|
||||||
|
|
||||||
assert projectFile == null -> throw "Defining the `projectFile` attribute is required. This is usually an `.csproj`, or `.sln` file.";
|
|
||||||
|
|
||||||
# TODO: Automatically generate a dependency file when a lockfile is present.
|
# TODO: Automatically generate a dependency file when a lockfile is present.
|
||||||
# This file is unfortunately almost never present, as Microsoft recommands not to push this in upstream repositories.
|
# This file is unfortunately almost never present, as Microsoft recommands not to push this in upstream repositories.
|
||||||
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.";
|
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.";
|
||||||
@ -159,8 +157,6 @@ stdenvNoCC.mkDerivation (args // {
|
|||||||
# Because this list is rather long its put in its own store path to maintain readability of the generated script
|
# Because this list is rather long its put in its own store path to maintain readability of the generated script
|
||||||
exclusions = writeText "nuget-package-exclusions" (lib.concatStringsSep "\n" (dotnet-sdk.passthru.packages { fetchNuGet = attrs: attrs.pname; }));
|
exclusions = writeText "nuget-package-exclusions" (lib.concatStringsSep "\n" (dotnet-sdk.passthru.packages { fetchNuGet = attrs: attrs.pname; }));
|
||||||
|
|
||||||
runtimeIds = map (system: dotnet-sdk.systemToDotnetRid system) (args.meta.platforms or dotnet-sdk.meta.platforms);
|
|
||||||
|
|
||||||
# Derivations may set flags such as `--runtime <rid>` based on the host platform to avoid restoring/building nuget dependencies they dont have or dont need.
|
# Derivations may set flags such as `--runtime <rid>` based on the host platform to avoid restoring/building nuget dependencies they dont have or dont need.
|
||||||
# This introduces an issue; In this script we loop over all platforms from `meta` and add the RID flag for it, as to fetch all required dependencies.
|
# This introduces an issue; In this script we loop over all platforms from `meta` and add the RID flag for it, as to fetch all required dependencies.
|
||||||
# The script would inherit the RID flag from the derivation based on the platform building the script, and set the flag for any iteration we do over the RIDs.
|
# The script would inherit the RID flag from the derivation based on the platform building the script, and set the flag for any iteration we do over the RIDs.
|
||||||
@ -171,6 +167,7 @@ stdenvNoCC.mkDerivation (args // {
|
|||||||
in
|
in
|
||||||
builtins.filter (flag: !(hasRid flag)) (dotnetFlags ++ dotnetRestoreFlags);
|
builtins.filter (flag: !(hasRid flag)) (dotnetFlags ++ dotnetRestoreFlags);
|
||||||
|
|
||||||
|
runtimeIds = map (system: dotnet-sdk.systemToDotnetRid system) (args.meta.platforms or dotnet-sdk.meta.platforms);
|
||||||
in
|
in
|
||||||
writeShellScript "fetch-${pname}-deps" ''
|
writeShellScript "fetch-${pname}-deps" ''
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
@ -202,15 +199,27 @@ stdenvNoCC.mkDerivation (args // {
|
|||||||
export DOTNET_NOLOGO=1
|
export DOTNET_NOLOGO=1
|
||||||
export DOTNET_CLI_TELEMETRY_OPTOUT=1
|
export DOTNET_CLI_TELEMETRY_OPTOUT=1
|
||||||
|
|
||||||
|
declare -a projectFiles=( ${toString (lib.toList projectFile)} )
|
||||||
|
declare -a testProjectFiles=( ${toString (lib.toList testProjectFile)} )
|
||||||
|
|
||||||
|
dotnetRestore() {
|
||||||
|
local -r project="''${1-}"
|
||||||
|
local -r rid="''${2-}"
|
||||||
|
|
||||||
|
dotnet restore ''${project-} \
|
||||||
|
-p:ContinuousIntegrationBuild=true \
|
||||||
|
-p:Deterministic=true \
|
||||||
|
--packages "$HOME/nuget_pkgs" \
|
||||||
|
--runtime "$rid" \
|
||||||
|
${lib.optionalString (!enableParallelBuilding) "--disable-parallel"} \
|
||||||
|
${lib.optionalString (flags != []) (toString flags)}
|
||||||
|
}
|
||||||
|
|
||||||
for rid in "${lib.concatStringsSep "\" \"" runtimeIds}"; do
|
for rid in "${lib.concatStringsSep "\" \"" runtimeIds}"; do
|
||||||
for project in "${lib.concatStringsSep "\" \"" ((lib.toList projectFile) ++ lib.optionals (testProjectFile != "") (lib.toList testProjectFile))}"; do
|
(( ''${#projectFiles[@]} == 0 )) && dotnetRestore "" "$rid"
|
||||||
dotnet restore "$project" \
|
|
||||||
-p:ContinuousIntegrationBuild=true \
|
for project in ''${projectFiles[@]-} ''${testProjectFiles[@]-}; do
|
||||||
-p:Deterministic=true \
|
dotnetRestore "$project" "$rid"
|
||||||
--packages "$HOME/nuget_pkgs" \
|
|
||||||
--runtime "$rid" \
|
|
||||||
${lib.optionalString (!enableParallelBuilding) "--disable-parallel"} \
|
|
||||||
${lib.optionalString (flags != []) (toString flags)}
|
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
|
|
||||||
|
@ -24,19 +24,25 @@ dotnetBuildHook() {
|
|||||||
local -r versionFlag="-p:Version=${version-}"
|
local -r versionFlag="-p:Version=${version-}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
dotnetBuild() {
|
||||||
|
local -r project="${1-}"
|
||||||
|
env dotnet build ${project-} \
|
||||||
|
-maxcpucount:$maxCpuFlag \
|
||||||
|
-p:BuildInParallel=$parallelBuildFlag \
|
||||||
|
-p:ContinuousIntegrationBuild=true \
|
||||||
|
-p:Deterministic=true \
|
||||||
|
-p:UseAppHost=true \
|
||||||
|
--configuration "@buildType@" \
|
||||||
|
--no-restore \
|
||||||
|
${versionFlag-} \
|
||||||
|
${dotnetBuildFlags[@]} \
|
||||||
|
${dotnetFlags[@]}
|
||||||
|
}
|
||||||
|
|
||||||
|
(( "${#projectFile[@]}" == 0 )) && dotnetBuild
|
||||||
|
|
||||||
for project in ${projectFile[@]} ${testProjectFile[@]-}; do
|
for project in ${projectFile[@]} ${testProjectFile[@]-}; do
|
||||||
env \
|
dotnetBuild "$project"
|
||||||
dotnet build "$project" \
|
|
||||||
-maxcpucount:$maxCpuFlag \
|
|
||||||
-p:BuildInParallel=$parallelBuildFlag \
|
|
||||||
-p:ContinuousIntegrationBuild=true \
|
|
||||||
-p:Deterministic=true \
|
|
||||||
-p:UseAppHost=true \
|
|
||||||
--configuration "@buildType@" \
|
|
||||||
--no-restore \
|
|
||||||
${versionFlag-} \
|
|
||||||
${dotnetBuildFlags[@]} \
|
|
||||||
${dotnetFlags[@]}
|
|
||||||
done
|
done
|
||||||
|
|
||||||
runHook postBuild
|
runHook postBuild
|
||||||
|
@ -13,15 +13,21 @@ dotnetConfigureHook() {
|
|||||||
local -r parallelFlag="--disable-parallel"
|
local -r parallelFlag="--disable-parallel"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
dotnetRestore() {
|
||||||
|
local -r project="${1-}"
|
||||||
|
env dotnet restore ${project-} \
|
||||||
|
-p:ContinuousIntegrationBuild=true \
|
||||||
|
-p:Deterministic=true \
|
||||||
|
--source "@nugetSource@/lib" \
|
||||||
|
${parallelFlag-} \
|
||||||
|
${dotnetRestoreFlags[@]} \
|
||||||
|
${dotnetFlags[@]}
|
||||||
|
}
|
||||||
|
|
||||||
|
(( "${#projectFile[@]}" == 0 )) && dotnetRestore
|
||||||
|
|
||||||
for project in ${projectFile[@]} ${testProjectFile[@]-}; do
|
for project in ${projectFile[@]} ${testProjectFile[@]-}; do
|
||||||
env \
|
dotnetRestore "$project"
|
||||||
dotnet restore "$project" \
|
|
||||||
-p:ContinuousIntegrationBuild=true \
|
|
||||||
-p:Deterministic=true \
|
|
||||||
--source "@nugetSource@/lib" \
|
|
||||||
${parallelFlag-} \
|
|
||||||
${dotnetRestoreFlags[@]} \
|
|
||||||
${dotnetFlags[@]}
|
|
||||||
done
|
done
|
||||||
|
|
||||||
runHook postConfigure
|
runHook postConfigure
|
||||||
|
@ -12,31 +12,47 @@ dotnetInstallHook() {
|
|||||||
dotnetInstallFlags+=("--no-self-contained")
|
dotnetInstallFlags+=("--no-self-contained")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
for project in ${projectFile[@]}; do
|
dotnetPublish() {
|
||||||
env \
|
local -r project="${1-}"
|
||||||
dotnet publish "$project" \
|
env dotnet publish ${project-} \
|
||||||
-p:ContinuousIntegrationBuild=true \
|
-p:ContinuousIntegrationBuild=true \
|
||||||
-p:Deterministic=true \
|
-p:Deterministic=true \
|
||||||
-p:UseAppHost=true \
|
-p:UseAppHost=true \
|
||||||
--output "$out/lib/${pname}" \
|
--output "$out/lib/${pname}" \
|
||||||
--configuration "@buildType@" \
|
--configuration "@buildType@" \
|
||||||
--no-build \
|
--no-build \
|
||||||
${dotnetInstallFlags[@]} \
|
${dotnetInstallFlags[@]} \
|
||||||
${dotnetFlags[@]}
|
${dotnetFlags[@]}
|
||||||
done
|
}
|
||||||
|
|
||||||
|
dotnetPack() {
|
||||||
|
local -r project="${1-}"
|
||||||
|
env dotnet pack ${project-} \
|
||||||
|
-p:ContinuousIntegrationBuild=true \
|
||||||
|
-p:Deterministic=true \
|
||||||
|
--output "$out/share" \
|
||||||
|
--configuration "@buildType@" \
|
||||||
|
--no-build \
|
||||||
|
${dotnetPackFlags[@]} \
|
||||||
|
${dotnetFlags[@]}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (( "${#projectFile[@]}" == 0 )); then
|
||||||
|
dotnetPublish
|
||||||
|
else
|
||||||
|
for project in ${projectFile[@]}; do
|
||||||
|
dotnetPublish "$project"
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ "${packNupkg-}" ]]; then
|
if [[ "${packNupkg-}" ]]; then
|
||||||
for project in ${projectFile[@]}; do
|
if (( "${#projectFile[@]}" == 0 )); then
|
||||||
env \
|
dotnetPack
|
||||||
dotnet pack "$project" \
|
else
|
||||||
-p:ContinuousIntegrationBuild=true \
|
for project in ${projectFile[@]}; do
|
||||||
-p:Deterministic=true \
|
dotnetPack "$project"
|
||||||
--output "$out/share" \
|
done
|
||||||
--configuration "@buildType@" \
|
fi
|
||||||
--no-build \
|
|
||||||
${dotnetPackFlags[@]} \
|
|
||||||
${dotnetFlags[@]}
|
|
||||||
done
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
runHook postInstall
|
runHook postInstall
|
||||||
|
Loading…
Reference in New Issue
Block a user