dotnet-sdk-setup-hook: configure nuget in sourceRoot
Instead of creating a nuget.config in NIX_BUILD_TOP, and depending on inheritance from sourceRoot, we'll make the required changes directly in the latter. This fixes packages where sourceRoot is NIX_BUILD_TOP.
This commit is contained in:
parent
346e862689
commit
e7fb591c92
@ -33,6 +33,11 @@ buildDotnetModule rec {
|
|||||||
|
|
||||||
nugetDeps = ./deps.nix;
|
nugetDeps = ./deps.nix;
|
||||||
|
|
||||||
|
preConfigureNuGet = ''
|
||||||
|
# This should really be in the upstream nuget.config
|
||||||
|
dotnet nuget add source https://api.nuget.org/v3/index.json \
|
||||||
|
-n nuget.org --configfile nuget.config
|
||||||
|
'';
|
||||||
|
|
||||||
# Required for OneClick
|
# Required for OneClick
|
||||||
makeWrapperArgs = [
|
makeWrapperArgs = [
|
||||||
|
@ -28,8 +28,12 @@ _linkPackages() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
createNugetDirs() {
|
configureNuget() {
|
||||||
nugetTemp=$PWD/.nuget-temp
|
runHook preConfigureNuGet
|
||||||
|
|
||||||
|
local nugetTemp x
|
||||||
|
|
||||||
|
nugetTemp="$(mktemp -dt nuget.XXXXXX)"
|
||||||
# trailing slash required here:
|
# trailing slash required here:
|
||||||
# Microsoft.Managed.Core.targets(236,5): error : SourceRoot paths are required to end with a slash or backslash: '/build/.nuget-temp/packages'
|
# Microsoft.Managed.Core.targets(236,5): error : SourceRoot paths are required to end with a slash or backslash: '/build/.nuget-temp/packages'
|
||||||
# also e.g. from avalonia:
|
# also e.g. from avalonia:
|
||||||
@ -39,20 +43,6 @@ createNugetDirs() {
|
|||||||
nugetSource=$nugetTemp/source
|
nugetSource=$nugetTemp/source
|
||||||
mkdir -p "${NUGET_PACKAGES%/}" "${NUGET_FALLBACK_PACKAGES%/}" "$nugetSource"
|
mkdir -p "${NUGET_PACKAGES%/}" "${NUGET_FALLBACK_PACKAGES%/}" "$nugetSource"
|
||||||
|
|
||||||
dotnet new nugetconfig
|
|
||||||
if [[ -z ${keepNugetConfig-} ]]; then
|
|
||||||
dotnet nuget disable source nuget
|
|
||||||
fi
|
|
||||||
|
|
||||||
dotnet nuget add source "$nugetSource" -n _nix
|
|
||||||
nugetConfig=$PWD/nuget.config
|
|
||||||
}
|
|
||||||
|
|
||||||
configureNuget() {
|
|
||||||
runHook preConfigureNuGet
|
|
||||||
|
|
||||||
local x
|
|
||||||
|
|
||||||
for x in "${!_nugetInputs[@]}"; do
|
for x in "${!_nugetInputs[@]}"; do
|
||||||
if [[ -d $x/share/nuget/packages ]]; then
|
if [[ -d $x/share/nuget/packages ]]; then
|
||||||
_linkPackages "$x/share/nuget/packages" "${NUGET_FALLBACK_PACKAGES%/}"
|
_linkPackages "$x/share/nuget/packages" "${NUGET_FALLBACK_PACKAGES%/}"
|
||||||
@ -63,21 +53,6 @@ configureNuget() {
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
find -iname nuget.config -print0 | while IFS= read -rd "" config; do
|
|
||||||
if [[ -n ${keepNugetConfig-} ]]; then
|
|
||||||
# If we're keeping the existing configs, we'll add _nix everywhere,
|
|
||||||
# in case sources are cleared.
|
|
||||||
dotnet nuget add source "$nugetSource" -n _nix --configfile "$config"
|
|
||||||
else
|
|
||||||
# This will allow everything to fall through to our config in the
|
|
||||||
# build root. Deleting them causes some build failures.
|
|
||||||
@xmlstarlet@/bin/xmlstarlet \
|
|
||||||
ed --inplace \
|
|
||||||
-d '//configuration/*' \
|
|
||||||
"$config"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
if [[ -n ${linkNugetPackages-}
|
if [[ -n ${linkNugetPackages-}
|
||||||
|| -f .config/dotnet-tools.json
|
|| -f .config/dotnet-tools.json
|
||||||
|| -f dotnet-tools.json
|
|| -f dotnet-tools.json
|
||||||
@ -100,10 +75,123 @@ configureNuget() {
|
|||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# create a root nuget.config if one doesn't exist
|
||||||
|
local rootConfig
|
||||||
|
rootConfig=$(find . -maxdepth 1 -iname nuget.config -print -quit)
|
||||||
|
if [[ -z $rootConfig ]]; then
|
||||||
|
dotnet new nugetconfig
|
||||||
|
fi
|
||||||
|
|
||||||
|
(
|
||||||
|
shopt -s nullglob
|
||||||
|
|
||||||
|
local -a xmlConfigArgs=() xmlRootConfigArgs=()
|
||||||
|
|
||||||
|
local -ra xmlSourceConfigArgs=(
|
||||||
|
-s /configuration -t elem -n packageSources
|
||||||
|
-d '/configuration/packageSources[position() != 1]'
|
||||||
|
-s /configuration/packageSources -t elem -n __new
|
||||||
|
-i /configuration/packageSources/__new -t attr -n key -v _nix
|
||||||
|
-i /configuration/packageSources/__new -t attr -n value -v "$nugetSource"
|
||||||
|
-r /configuration/packageSources/__new -v add)
|
||||||
|
|
||||||
|
if [[ -z ${keepNugetConfig-} ]]; then
|
||||||
|
xmlConfigArgs+=(-d '//configuration/*')
|
||||||
|
xmlRootConfigArgs+=("${xmlSourceConfigArgs[@]}")
|
||||||
|
else
|
||||||
|
if [[ -n ${mapNuGetDependencies-} ]]; then
|
||||||
|
xmlConfigArgs+=(
|
||||||
|
-s /configuration -t elem -n __tmp
|
||||||
|
# If there's no packageSourceMapping, we need to add * patterns for
|
||||||
|
# all the sources, else they won't be used.
|
||||||
|
-u \$prev -x ../packageSources/add
|
||||||
|
-d '/configuration/__tmp/add/@*[name() != "key"]'
|
||||||
|
-r /configuration/__tmp/add -v packageSource
|
||||||
|
-s /configuration/__tmp/packageSource -t elem -n package
|
||||||
|
-i \$prev -t attr -n pattern -v \*
|
||||||
|
-r /configuration/__tmp -v packageSourceMapping
|
||||||
|
-d '/configuration/packageSourceMapping[position() != 1]'
|
||||||
|
"${xmlSourceConfigArgs[@]}"
|
||||||
|
# add package source mappings from all existing patterns to _nix
|
||||||
|
# this ensures _nix is always considered
|
||||||
|
-s /configuration/packageSourceMapping -t elem -n packageSource
|
||||||
|
-u \$prev -x ../packageSource/package
|
||||||
|
-i \$prev -t attr -n key -v _nix)
|
||||||
|
|
||||||
|
cd "$nugetSource"
|
||||||
|
local id
|
||||||
|
for id in *; do
|
||||||
|
id=${id,,}
|
||||||
|
xmlConfigArgs+=(
|
||||||
|
# unmap any fully-qualified patterns that exist, so they
|
||||||
|
# can't be used, using a horrific method for
|
||||||
|
# case-insensitivity in xpath1
|
||||||
|
-d "/configuration/packageSourceMapping/packageSource/package[translate(@pattern, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') = ${id@Q}]"
|
||||||
|
-s '/configuration/packageSourceMapping/packageSource[@key="_nix"]' -t elem -n package
|
||||||
|
-i \$prev -t attr -n pattern -v "$id")
|
||||||
|
done
|
||||||
|
cd - < /dev/null
|
||||||
|
else
|
||||||
|
xmlConfigArgs+=(
|
||||||
|
"${xmlSourceConfigArgs[@]}"
|
||||||
|
# add package source mappings from all existing patterns to _nix
|
||||||
|
# this ensures _nix is always considered
|
||||||
|
-s /configuration/packageSourceMapping -t elem -n packageSource
|
||||||
|
-u \$prev -x '../packageSource/package'
|
||||||
|
-i \$prev -t attr -n key -v _nix
|
||||||
|
# delete empty _nix mapping
|
||||||
|
-d '/configuration/packageSourceMapping/packageSource[@key="_nix" and not(*)]')
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# try to stop the global config from having any effect
|
||||||
|
if [[ -z ${keepNugetConfig-} || -z ${allowGlobalNuGetConfig-} ]]; then
|
||||||
|
local -ar configSections=(
|
||||||
|
config
|
||||||
|
bindingRedirects
|
||||||
|
packageRestore
|
||||||
|
solution
|
||||||
|
packageSources
|
||||||
|
auditSources
|
||||||
|
apikeys
|
||||||
|
disabledPackageSources
|
||||||
|
activePackageSource
|
||||||
|
fallbackPackageFolders
|
||||||
|
packageSourceMapping
|
||||||
|
packageManagement)
|
||||||
|
|
||||||
|
for section in "${configSections[@]}"; do
|
||||||
|
xmlRootConfigArgs+=(
|
||||||
|
-s /configuration -t elem -n "$section"
|
||||||
|
# hacky way of ensuring we use existing sections when they exist
|
||||||
|
-d "/configuration/$section[position() != 1]"
|
||||||
|
# hacky way of adding to the start of a possibly empty element
|
||||||
|
-s "/configuration/$section" -t elem -n __unused
|
||||||
|
-i "/configuration/$section/*[1]" -t elem -n clear
|
||||||
|
-d "/configuration/$section/__unused"
|
||||||
|
# delete consecutive clears
|
||||||
|
# these actually cause nuget tools to fail in some cases
|
||||||
|
-d "/configuration/$section/clear[position() = 2 and name() = \"clear\"]")
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
find . \( -iname nuget.config \) -print0 | while IFS= read -rd "" config; do
|
||||||
|
local dir isRoot=
|
||||||
|
|
||||||
|
dir=$(dirname "$config")
|
||||||
|
[[ $dir != . ]] || isRoot=1
|
||||||
|
|
||||||
|
@xmlstarlet@/bin/xmlstarlet \
|
||||||
|
ed --inplace \
|
||||||
|
"${xmlConfigArgs[@]}" \
|
||||||
|
${isRoot:+"${xmlRootConfigArgs[@]}"} \
|
||||||
|
"$config"
|
||||||
|
done
|
||||||
|
)
|
||||||
|
|
||||||
runHook postConfigureNuGet
|
runHook postConfigureNuGet
|
||||||
}
|
}
|
||||||
|
|
||||||
if [[ -z ${dontConfigureNuget-} ]]; then
|
if [[ -z ${dontConfigureNuget-} ]]; then
|
||||||
prePhases+=(createNugetDirs)
|
|
||||||
preConfigurePhases+=(configureNuget)
|
preConfigurePhases+=(configureNuget)
|
||||||
fi
|
fi
|
||||||
|
@ -49,10 +49,6 @@ mkPackage rec {
|
|||||||
"${glibcLocales}/lib/locale/locale-archive";
|
"${glibcLocales}/lib/locale/locale-archive";
|
||||||
|
|
||||||
postPatch = ''
|
postPatch = ''
|
||||||
# this is not a valid name for the dotnet build hooks, but it's referenced
|
|
||||||
# by internal scripts, so we need both
|
|
||||||
ln -s NuGet.config nuget.config
|
|
||||||
|
|
||||||
# not patchShebangs, there is /bin/bash in the body of the script as well
|
# not patchShebangs, there is /bin/bash in the body of the script as well
|
||||||
substituteInPlace ./eng/cibuild_bootstrapped_msbuild.sh --replace /bin/bash ${stdenv.shell}
|
substituteInPlace ./eng/cibuild_bootstrapped_msbuild.sh --replace /bin/bash ${stdenv.shell}
|
||||||
|
|
||||||
|
@ -21,6 +21,12 @@ buildDotnetModule rec {
|
|||||||
projectFile = "UI.Console/UI.Console.csproj";
|
projectFile = "UI.Console/UI.Console.csproj";
|
||||||
nugetDeps = ./deps.nix;
|
nugetDeps = ./deps.nix;
|
||||||
|
|
||||||
|
preConfigureNuGet = ''
|
||||||
|
# This should really be in the upstream nuget.config
|
||||||
|
dotnet nuget add source https://api.nuget.org/v3/index.json \
|
||||||
|
-n nuget.org --configfile nuget.config
|
||||||
|
'';
|
||||||
|
|
||||||
runtimeDeps = [
|
runtimeDeps = [
|
||||||
zlib
|
zlib
|
||||||
openssl
|
openssl
|
||||||
|
@ -25,6 +25,12 @@ buildDotnetModule rec {
|
|||||||
projectFile = "Scarab.sln";
|
projectFile = "Scarab.sln";
|
||||||
executables = [ "Scarab" ];
|
executables = [ "Scarab" ];
|
||||||
|
|
||||||
|
preConfigureNuGet = ''
|
||||||
|
# This should really be in the upstream nuget.config
|
||||||
|
dotnet nuget add source https://api.nuget.org/v3/index.json \
|
||||||
|
-n nuget.org --configfile NuGet.Config
|
||||||
|
'';
|
||||||
|
|
||||||
runtimeDeps = [
|
runtimeDeps = [
|
||||||
glibc
|
glibc
|
||||||
zlib
|
zlib
|
||||||
|
Loading…
Reference in New Issue
Block a user