forked from mirrors/nixpkgs
Merge pull request #190403 from IvarWithoutBones/dotnetmodule-fixes
buildDotnetModule: several usability improvements
This commit is contained in:
commit
2650d450a7
|
@ -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:
|
||||
|
||||
* `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 a list of multiple projects as well. Most of the time dotnet can figure this location out by itself, so this should only be set if necessary.
|
||||
* `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`.
|
||||
* `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.
|
||||
|
@ -100,7 +100,7 @@ To package Dotnet applications, you can use `buildDotnetModule`. This has simila
|
|||
* `dotnetPackFlags` can be used to pass flags to `dotnet pack`. Used only if `packNupkg` is set to `true`.
|
||||
* `dotnetFlags` can be used to pass flags to all of the above phases.
|
||||
|
||||
When packaging a new application, you need to fetch it's dependencies. You can set `nugetDeps` to an empty string to make the derivation temporarily evaluate, and then run `nix-build -A package.passthru.fetch-deps` to generate it's dependency fetching script. After running the script, you should have the location of the generated lockfile printed to the console. This can be copied to a stable directory. Note that if either `projectFile` or `nugetDeps` are unset, this script cannot be generated!
|
||||
When packaging a new application, you need to fetch its dependencies. You can run `nix-build -A package.fetch-deps` to generate a script that will build a lockfile for you. After running the script you should have the location of the generated lockfile printed to the console, which can be copied to a stable directory. Then set `nugetDeps = ./deps.nix` and you're ready to build the derivation.
|
||||
|
||||
Here is an example `default.nix`, using some of the previously discussed arguments:
|
||||
```nix
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
{ lib
|
||||
, stdenvNoCC
|
||||
, callPackage
|
||||
, writeShellScript
|
||||
, writeText
|
||||
, srcOnly
|
||||
, linkFarmFromDrvs
|
||||
, symlinkJoin
|
||||
, makeWrapper
|
||||
, dotnetCorePackages
|
||||
, dotnetPackages
|
||||
, mkNugetSource
|
||||
, mkNugetDeps
|
||||
, srcOnly
|
||||
, writeShellScript
|
||||
, writeText
|
||||
, makeWrapper
|
||||
, nuget-to-nix
|
||||
, cacert
|
||||
, symlinkJoin
|
||||
, coreutils
|
||||
}:
|
||||
|
||||
|
@ -20,88 +20,87 @@
|
|||
, pname ? name
|
||||
, enableParallelBuilding ? true
|
||||
, doCheck ? false
|
||||
# Flags to pass to `makeWrapper`. This is done to avoid double wrapping.
|
||||
, makeWrapperArgs ? []
|
||||
# Flags to pass to `makeWrapper`. This is done to avoid double wrapping.
|
||||
, makeWrapperArgs ? [ ]
|
||||
|
||||
# Flags to pass to `dotnet restore`.
|
||||
, dotnetRestoreFlags ? []
|
||||
# Flags to pass to `dotnet build`.
|
||||
, dotnetBuildFlags ? []
|
||||
# Flags to pass to `dotnet test`, if running tests is enabled.
|
||||
, dotnetTestFlags ? []
|
||||
# Flags to pass to `dotnet install`.
|
||||
, dotnetInstallFlags ? []
|
||||
# Flags to pass to `dotnet pack`.
|
||||
, dotnetPackFlags ? []
|
||||
# Flags to pass to dotnet in all phases.
|
||||
, dotnetFlags ? []
|
||||
# Flags to pass to `dotnet restore`.
|
||||
, dotnetRestoreFlags ? [ ]
|
||||
# Flags to pass to `dotnet build`.
|
||||
, dotnetBuildFlags ? [ ]
|
||||
# Flags to pass to `dotnet test`, if running tests is enabled.
|
||||
, dotnetTestFlags ? [ ]
|
||||
# Flags to pass to `dotnet install`.
|
||||
, dotnetInstallFlags ? [ ]
|
||||
# Flags to pass to `dotnet pack`.
|
||||
, dotnetPackFlags ? [ ]
|
||||
# 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.
|
||||
# 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!
|
||||
# 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!
|
||||
, executables ? null
|
||||
# Packs a 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`.
|
||||
# Packs a 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 ? false
|
||||
# The packages project file, which contains instructions on how to compile it. This can be an array of multiple project files as well.
|
||||
# The packages project file, which contains instructions on how to compile it. This can be an array of multiple project files as well.
|
||||
, projectFile ? null
|
||||
# The NuGet dependency file. This locks all NuGet dependency versions, as otherwise they cannot be deterministically fetched.
|
||||
# This can be generated by running the `passthru.fetch-deps` script.
|
||||
# The NuGet dependency file. This locks all NuGet dependency versions, as otherwise they cannot be deterministically fetched.
|
||||
# This can be generated by running the `passthru.fetch-deps` script.
|
||||
, nugetDeps ? null
|
||||
# A list of derivations containing nupkg packages for local project references.
|
||||
# Referenced derivations can be built with `buildDotnetModule` with `packNupkg=true` flag.
|
||||
# Since we are sharing them as nugets they must be added to csproj/fsproj files as `PackageReference` as well.
|
||||
# For example, your project has a local dependency:
|
||||
# <ProjectReference Include="../foo/bar.fsproj" />
|
||||
# To enable discovery through `projectReferences` you would need to add a line:
|
||||
# <ProjectReference Include="../foo/bar.fsproj" />
|
||||
# <PackageReference Include="bar" Version="*" Condition=" '$(ContinuousIntegrationBuild)'=='true' "/>
|
||||
, projectReferences ? []
|
||||
# Libraries that need to be available at runtime should be passed through this.
|
||||
# These get wrapped into `LD_LIBRARY_PATH`.
|
||||
, runtimeDeps ? []
|
||||
# A list of derivations containing nupkg packages for local project references.
|
||||
# Referenced derivations can be built with `buildDotnetModule` with `packNupkg=true` flag.
|
||||
# Since we are sharing them as nugets they must be added to csproj/fsproj files as `PackageReference` as well.
|
||||
# For example, your project has a local dependency:
|
||||
# <ProjectReference Include="../foo/bar.fsproj" />
|
||||
# To enable discovery through `projectReferences` you would need to add a line:
|
||||
# <ProjectReference Include="../foo/bar.fsproj" />
|
||||
# <PackageReference Include="bar" Version="*" Condition=" '$(ContinuousIntegrationBuild)'=='true' "/>
|
||||
, projectReferences ? [ ]
|
||||
# Libraries that need to be available at runtime should be passed through this.
|
||||
# These get wrapped into `LD_LIBRARY_PATH`.
|
||||
, runtimeDeps ? [ ]
|
||||
|
||||
# Tests to disable. This gets passed to `dotnet test --filter "FullyQualifiedName!={}"`, to ensure compatibility with all frameworks.
|
||||
# See https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-test#filter-option-details for more details.
|
||||
, disabledTests ? []
|
||||
# The project file to run unit tests against. This is usually referenced in the regular project file, but sometimes it needs to be manually set.
|
||||
# It gets restored and build, but not installed. You may need to regenerate your nuget lockfile after setting this.
|
||||
# Tests to disable. This gets passed to `dotnet test --filter "FullyQualifiedName!={}"`, to ensure compatibility with all frameworks.
|
||||
# See https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-test#filter-option-details for more details.
|
||||
, disabledTests ? [ ]
|
||||
# The project file to run unit tests against. This is usually referenced in the regular project file, but sometimes it needs to be manually set.
|
||||
# It gets restored and build, but not installed. You may need to regenerate your nuget lockfile after setting this.
|
||||
, testProjectFile ? ""
|
||||
|
||||
# The type of build to perform. This is passed to `dotnet` with the `--configuration` flag. Possible values are `Release`, `Debug`, etc.
|
||||
# The type of build to perform. This is passed to `dotnet` with the `--configuration` flag. Possible values are `Release`, `Debug`, etc.
|
||||
, buildType ? "Release"
|
||||
# If set to true, builds the application as a self-contained - removing the runtime dependency on dotnet
|
||||
# If set to true, builds the application as a self-contained - removing the runtime dependency on dotnet
|
||||
, selfContainedBuild ? false
|
||||
# The dotnet SDK to use.
|
||||
# The dotnet SDK to use.
|
||||
, dotnet-sdk ? dotnetCorePackages.sdk_6_0
|
||||
# The dotnet runtime to use.
|
||||
# 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.
|
||||
# The dotnet SDK to run tests against. This can differentiate from the SDK compiled against.
|
||||
, dotnet-test-sdk ? dotnet-sdk
|
||||
, ... } @ 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.
|
||||
# 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.";
|
||||
, ...
|
||||
} @ args:
|
||||
|
||||
let
|
||||
inherit (callPackage ./hooks {
|
||||
inherit dotnet-sdk dotnet-test-sdk disabledTests nuget-source dotnet-runtime runtimeDeps buildType;
|
||||
}) dotnetConfigureHook dotnetBuildHook dotnetCheckHook dotnetInstallHook dotnetFixupHook;
|
||||
|
||||
localDeps = if (projectReferences != [])
|
||||
localDeps =
|
||||
if (projectReferences != [ ])
|
||||
then linkFarmFromDrvs "${name}-project-references" projectReferences
|
||||
else null;
|
||||
|
||||
_nugetDeps = if lib.isDerivation nugetDeps
|
||||
then nugetDeps
|
||||
else mkNugetDeps { inherit name; nugetDeps = import nugetDeps; };
|
||||
_nugetDeps =
|
||||
if (nugetDeps != null) then
|
||||
if lib.isDerivation nugetDeps
|
||||
then nugetDeps
|
||||
else mkNugetDeps { inherit name; nugetDeps = import nugetDeps; }
|
||||
else 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.";
|
||||
|
||||
# contains the actual package dependencies
|
||||
_dependenciesSource = mkNugetSource {
|
||||
dependenciesSource = mkNugetSource {
|
||||
name = "${name}-dependencies-source";
|
||||
description = "A Nuget source with the dependencies for ${name}";
|
||||
deps = [ _nugetDeps ] ++ lib.optional (localDeps != null) localDeps;
|
||||
|
@ -110,22 +109,23 @@ let
|
|||
# this contains all the nuget packages that are implictly referenced by the dotnet
|
||||
# build system. having them as separate deps allows us to avoid having to regenerate
|
||||
# a packages dependencies when the dotnet-sdk version changes
|
||||
_sdkDeps = mkNugetDeps {
|
||||
sdkDeps = mkNugetDeps {
|
||||
name = "dotnet-sdk-${dotnet-sdk.version}-deps";
|
||||
nugetDeps = dotnet-sdk.passthru.packages;
|
||||
};
|
||||
|
||||
_sdkSource = mkNugetSource {
|
||||
sdkSource = mkNugetSource {
|
||||
name = "dotnet-sdk-${dotnet-sdk.version}-source";
|
||||
deps = [ _sdkDeps ];
|
||||
deps = [ sdkDeps ];
|
||||
};
|
||||
|
||||
nuget-source = symlinkJoin {
|
||||
name = "${name}-nuget-source";
|
||||
paths = [ _dependenciesSource _sdkSource ];
|
||||
paths = [ dependenciesSource sdkSource ];
|
||||
};
|
||||
in stdenvNoCC.mkDerivation (args // {
|
||||
nativeBuildInputs = args.nativeBuildInputs or [] ++ [
|
||||
in
|
||||
stdenvNoCC.mkDerivation (args // {
|
||||
nativeBuildInputs = args.nativeBuildInputs or [ ] ++ [
|
||||
dotnetConfigureHook
|
||||
dotnetBuildHook
|
||||
dotnetCheckHook
|
||||
|
@ -150,74 +150,109 @@ in stdenvNoCC.mkDerivation (args // {
|
|||
passthru = {
|
||||
inherit nuget-source;
|
||||
|
||||
fetch-deps = let
|
||||
# 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; }));
|
||||
fetch-deps =
|
||||
let
|
||||
# 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; }));
|
||||
|
||||
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.
|
||||
# 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.
|
||||
# That causes conflicts. To circumvent it we remove all occurances of the flag.
|
||||
flags =
|
||||
let
|
||||
hasRid = flag: lib.any (v: v) (map (rid: lib.hasInfix rid flag) (lib.attrValues dotnet-sdk.runtimeIdentifierMap));
|
||||
in
|
||||
builtins.filter (flag: !(hasRid flag)) (dotnetFlags ++ dotnetRestoreFlags);
|
||||
|
||||
# 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.
|
||||
# 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.
|
||||
# That causes conflicts. To circumvent it we remove all occurances of the flag.
|
||||
flags =
|
||||
let
|
||||
hasRid = flag: lib.any (v: v) (map (rid: lib.hasInfix rid flag) (lib.attrValues dotnet-sdk.runtimeIdentifierMap));
|
||||
in
|
||||
builtins.filter (flag: !(hasRid flag)) (dotnetFlags ++ dotnetRestoreFlags);
|
||||
runtimeIds = map (system: dotnet-sdk.systemToDotnetRid system) (args.meta.platforms or dotnet-sdk.meta.platforms);
|
||||
in
|
||||
writeShellScript "fetch-${pname}-deps" ''
|
||||
set -euo pipefail
|
||||
|
||||
in writeShellScript "fetch-${pname}-deps" ''
|
||||
set -euo pipefail
|
||||
export PATH="${lib.makeBinPath [ coreutils dotnet-sdk nuget-to-nix ]}"
|
||||
|
||||
export PATH="${lib.makeBinPath [ coreutils dotnet-sdk nuget-to-nix ]}"
|
||||
for arg in "$@"; do
|
||||
case "$arg" in
|
||||
--keep-sources|-k)
|
||||
keepSources=1
|
||||
shift
|
||||
;;
|
||||
--help|-h)
|
||||
echo "usage: $0 <output path> [--keep-sources] [--help]"
|
||||
echo " <output path> The path to write the lockfile to. A temporary file is used if this is not set"
|
||||
echo " --keep-sources Dont remove temporary directories upon exit, useful for debugging"
|
||||
echo " --help Show this help message"
|
||||
exit
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
case "''${1-}" in
|
||||
--help|-h)
|
||||
echo "usage: $0 <output path> [--help]"
|
||||
echo " <output path> The path to write the lockfile to"
|
||||
echo " --help Show this help message"
|
||||
exit
|
||||
;;
|
||||
esac
|
||||
exitTrap() {
|
||||
test -n "''${ranTrap-}" && return
|
||||
ranTrap=1
|
||||
|
||||
deps_file="$(realpath "''${1:-$(mktemp -t "${pname}-deps-XXXXXX.nix")}")"
|
||||
export HOME=$(mktemp -td "${pname}-home-XXXXXX")
|
||||
mkdir -p "$HOME/nuget_pkgs"
|
||||
if test -n "''${keepSources-}"; then
|
||||
echo -e "Path to the source: $src\nPath to the fake home: $HOME"
|
||||
else
|
||||
rm -rf "$src" "$HOME"
|
||||
fi
|
||||
|
||||
store_src="${srcOnly args}"
|
||||
src="$(mktemp -td "${pname}-src-XXXXXX")"
|
||||
cp -rT "$store_src" "$src"
|
||||
chmod -R +w "$src"
|
||||
trap "rm -rf $src $HOME" EXIT
|
||||
# Since mktemp is used this will be empty if the script didnt succesfully complete
|
||||
! test -s "$depsFile" && rm -rf "$depsFile"
|
||||
}
|
||||
|
||||
cd "$src"
|
||||
echo "Restoring project..."
|
||||
trap exitTrap EXIT INT TERM
|
||||
|
||||
export DOTNET_NOLOGO=1
|
||||
export DOTNET_CLI_TELEMETRY_OPTOUT=1
|
||||
dotnetRestore() {
|
||||
local -r project="''${1-}"
|
||||
local -r rid="$2"
|
||||
|
||||
for rid in "${lib.concatStringsSep "\" \"" runtimeIds}"; do
|
||||
for project in "${lib.concatStringsSep "\" \"" ((lib.toList projectFile) ++ lib.optionals (testProjectFile != "") (lib.toList testProjectFile))}"; do
|
||||
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)}
|
||||
done
|
||||
done
|
||||
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)}
|
||||
}
|
||||
|
||||
echo "Succesfully restored project"
|
||||
declare -a projectFiles=( ${toString (lib.toList projectFile)} )
|
||||
declare -a testProjectFiles=( ${toString (lib.toList testProjectFile)} )
|
||||
|
||||
echo "Writing lockfile..."
|
||||
echo -e "# This file was automatically generated by passthru.fetch-deps.\n# Please dont edit it manually, your changes might get overwritten!\n" > "$deps_file"
|
||||
nuget-to-nix "$HOME/nuget_pkgs" "${exclusions}" >> "$deps_file"
|
||||
echo "Succesfully wrote lockfile to: $deps_file"
|
||||
'';
|
||||
} // args.passthru or {};
|
||||
export HOME=$(mktemp -td "${pname}-home-XXXXXX")
|
||||
export DOTNET_NOLOGO=1
|
||||
export DOTNET_CLI_TELEMETRY_OPTOUT=1
|
||||
|
||||
depsFile="$(realpath "''${1:-$(mktemp -t "${pname}-deps-XXXXXX.nix")}")"
|
||||
mkdir -p "$HOME/nuget_pkgs"
|
||||
|
||||
storeSrc="${srcOnly args}"
|
||||
src="$(mktemp -td "${pname}-src-XXXXXX")"
|
||||
cp -rT "$storeSrc" "$src"
|
||||
chmod -R +w "$src"
|
||||
|
||||
cd "$src"
|
||||
echo "Restoring project..."
|
||||
|
||||
for rid in "${lib.concatStringsSep "\" \"" runtimeIds}"; do
|
||||
(( ''${#projectFiles[@]} == 0 )) && dotnetRestore "" "$rid"
|
||||
|
||||
for project in ''${projectFiles[@]-} ''${testProjectFiles[@]-}; do
|
||||
dotnetRestore "$project" "$rid"
|
||||
done
|
||||
done
|
||||
|
||||
echo "Succesfully restored project"
|
||||
|
||||
echo "Writing lockfile..."
|
||||
echo -e "# This file was automatically generated by passthru.fetch-deps.\n# Please dont edit it manually, your changes might get overwritten!\n" > "$depsFile"
|
||||
nuget-to-nix "$HOME/nuget_pkgs" "${exclusions}" >> "$depsFile"
|
||||
echo "Succesfully wrote lockfile to $depsFile"
|
||||
'';
|
||||
} // args.passthru or { };
|
||||
|
||||
meta = {
|
||||
platforms = dotnet-sdk.meta.platforms;
|
||||
} // args.meta or {};
|
||||
} // args.meta or { };
|
||||
})
|
||||
|
|
|
@ -7,11 +7,11 @@ dotnetBuildHook() {
|
|||
runHook preBuild
|
||||
|
||||
if [ "${enableParallelBuilding-}" ]; then
|
||||
maxCpuFlag="$NIX_BUILD_CORES"
|
||||
parallelBuildFlag="true"
|
||||
local -r maxCpuFlag="$NIX_BUILD_CORES"
|
||||
local -r parallelBuildFlag="true"
|
||||
else
|
||||
maxCpuFlag="1"
|
||||
parallelBuildFlag="false"
|
||||
local -r maxCpuFlag="1"
|
||||
local -r parallelBuildFlag="false"
|
||||
fi
|
||||
|
||||
if [ "${selfContainedBuild-}" ]; then
|
||||
|
@ -21,22 +21,28 @@ dotnetBuildHook() {
|
|||
fi
|
||||
|
||||
if [ "${version-}" ]; then
|
||||
versionFlag="-p:Version=${version-}"
|
||||
local -r 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 \
|
||||
-p:UseAppHost=true \
|
||||
--configuration "@buildType@" \
|
||||
--no-restore \
|
||||
${versionFlag-} \
|
||||
${dotnetBuildFlags[@]} \
|
||||
${dotnetFlags[@]}
|
||||
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
|
||||
dotnetBuild "$project"
|
||||
done
|
||||
|
||||
runHook postBuild
|
||||
|
|
|
@ -7,10 +7,16 @@ dotnetCheckHook() {
|
|||
runHook preCheck
|
||||
|
||||
if [ "${disabledTests-}" ]; then
|
||||
disabledTestsFlag="--filter FullyQualifiedName!=@disabledTests@"
|
||||
local -r disabledTestsFlag="--filter FullyQualifiedName!=@disabledTests@"
|
||||
fi
|
||||
|
||||
for project in ${testProjectFile[@]}; do
|
||||
if [ "${enableParallelBuilding-}" ]; then
|
||||
local -r maxCpuFlag="$NIX_BUILD_CORES"
|
||||
else
|
||||
local -r maxCpuFlag="1"
|
||||
fi
|
||||
|
||||
for project in ${testProjectFile[@]-}; do
|
||||
env "LD_LIBRARY_PATH=@libraryPath@" \
|
||||
dotnet test "$project" \
|
||||
-maxcpucount:$maxCpuFlag \
|
||||
|
|
|
@ -10,18 +10,24 @@ dotnetConfigureHook() {
|
|||
runHook preConfigure
|
||||
|
||||
if [ -z "${enableParallelBuilding-}" ]; then
|
||||
parallelFlag="--disable-parallel"
|
||||
local -r parallelFlag="--disable-parallel"
|
||||
fi
|
||||
|
||||
for project in ${projectFile[@]} ${testProjectFile[@]}; do
|
||||
env \
|
||||
dotnet restore "$project" \
|
||||
-p:ContinuousIntegrationBuild=true \
|
||||
-p:Deterministic=true \
|
||||
--source "@nugetSource@/lib" \
|
||||
${parallelFlag-} \
|
||||
${dotnetRestoreFlags[@]} \
|
||||
${dotnetFlags[@]}
|
||||
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
|
||||
dotnetRestore "$project"
|
||||
done
|
||||
|
||||
runHook postConfigure
|
||||
|
|
|
@ -5,38 +5,37 @@ makeWrapperArgs=( ${makeWrapperArgs-} )
|
|||
# the second is the destination for the wrapper.
|
||||
wrapDotnetProgram() {
|
||||
if [ ! "${selfContainedBuild-}" ]; then
|
||||
dotnetRootFlag=("--set" "DOTNET_ROOT" "@dotnetRuntime@")
|
||||
local -r dotnetRootFlag=("--set" "DOTNET_ROOT" "@dotnetRuntime@")
|
||||
fi
|
||||
|
||||
makeWrapper "$1" "$2" \
|
||||
"${dotnetRootFlag[@]}" \
|
||||
--suffix "LD_LIBRARY_PATH" : "@runtimeDeps@" \
|
||||
"${dotnetRootFlag[@]}" \
|
||||
"${gappsWrapperArgs[@]}" \
|
||||
"${makeWrapperArgs[@]}"
|
||||
|
||||
echo "Installed wrapper to: "$2""
|
||||
echo "installed wrapper to "$2""
|
||||
}
|
||||
|
||||
dotnetFixupHook() {
|
||||
echo "Executing dotnetFixupPhase"
|
||||
|
||||
if [ "${executables}" ]; then
|
||||
if [ "${executables-}" ]; then
|
||||
for executable in ${executables[@]}; do
|
||||
execPath="$out/lib/${pname}/$executable"
|
||||
path="$out/lib/$pname/$executable"
|
||||
|
||||
if [[ -f "$execPath" && -x "$execPath" ]]; then
|
||||
wrapDotnetProgram "$execPath" "$out/bin/$(basename "$executable")"
|
||||
if test -x "$path"; then
|
||||
wrapDotnetProgram "$path" "$out/bin/$(basename "$executable")"
|
||||
else
|
||||
echo "Specified binary \"$executable\" is either not an executable, or does not exist!"
|
||||
echo "Specified binary \"$executable\" is either not an executable or does not exist!"
|
||||
echo "Looked in $path"
|
||||
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
|
||||
while IFS= read -d '' executable; do
|
||||
wrapDotnetProgram "$executable" "$out/bin/$(basename "$executable")" \;
|
||||
done < <(find "$out/lib/$pname" ! -name "*.dll" -executable -type f -print0)
|
||||
fi
|
||||
|
||||
echo "Finished dotnetFixupPhase"
|
||||
|
|
|
@ -12,31 +12,47 @@ dotnetInstallHook() {
|
|||
dotnetInstallFlags+=("--no-self-contained")
|
||||
fi
|
||||
|
||||
for project in ${projectFile[@]}; do
|
||||
env \
|
||||
dotnet publish "$project" \
|
||||
-p:ContinuousIntegrationBuild=true \
|
||||
-p:Deterministic=true \
|
||||
-p:UseAppHost=true \
|
||||
--output "$out/lib/${pname}" \
|
||||
--configuration "@buildType@" \
|
||||
--no-build \
|
||||
${dotnetInstallFlags[@]} \
|
||||
${dotnetFlags[@]}
|
||||
done
|
||||
dotnetPublish() {
|
||||
local -r project="${1-}"
|
||||
env dotnet publish ${project-} \
|
||||
-p:ContinuousIntegrationBuild=true \
|
||||
-p:Deterministic=true \
|
||||
-p:UseAppHost=true \
|
||||
--output "$out/lib/${pname}" \
|
||||
--configuration "@buildType@" \
|
||||
--no-build \
|
||||
${dotnetInstallFlags[@]} \
|
||||
${dotnetFlags[@]}
|
||||
}
|
||||
|
||||
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
|
||||
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
|
||||
if (( "${#projectFile[@]}" == 0 )); then
|
||||
dotnetPack
|
||||
else
|
||||
for project in ${projectFile[@]}; do
|
||||
dotnetPack "$project"
|
||||
done
|
||||
fi
|
||||
fi
|
||||
|
||||
runHook postInstall
|
||||
|
|
Loading…
Reference in a new issue