Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit d53cbfb

Browse files
committed
Merge pull request #3043 from gkhanna79/FixNugetPkg
Generate Microsoft.NETCore.Runtime.CoreCLR nuget packages
2 parents cf66383 + f025f9c commit d53cbfb

23 files changed

+714
-169
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ publish/
144144
# NuGet Packages
145145
*.nupkg
146146
**/packages/*
147+
project.lock.json
147148

148149
# Windows Azure Build Output
149150
csx/

build.cmd

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,31 @@ if errorlevel 1 (
449449
exit /b 1
450450
)
451451

452+
:GenerateNuget
453+
if /i "%__BuildArch%" =="arm64" goto :SkipNuget
454+
455+
set "__BuildLog=%__LogsDir%\Nuget_%__BuildOS%__%__BuildArch%__%__BuildType%.log"
456+
set "__BuildWrn=%__LogsDir%\Nuget_%__BuildOS%__%__BuildArch%__%__BuildType%.wrn"
457+
set "__BuildErr=%__LogsDir%\Nuget_%__BuildOS%__%__BuildArch%__%__BuildType%.err"
458+
set __msbuildLogArgs=^
459+
/fileloggerparameters:Verbosity=normal;LogFile="%__BuildLog%" ^
460+
/fileloggerparameters1:WarningsOnly;LogFile="%__BuildWrn%" ^
461+
/fileloggerparameters2:ErrorsOnly;LogFile="%__BuildErr%" ^
462+
/consoleloggerparameters:Summary ^
463+
/verbosity:minimal
464+
465+
set __msbuildArgs="%__ProjectFilesDir%\src\.nuget\Microsoft.NETCore.Runtime.CoreClr\Microsoft.NETCore.Runtime.CoreCLR.builds" /p:Platform=%__BuildArch%
466+
%_msbuildexe% %__msbuildArgs% %__msbuildLogArgs%
467+
if errorlevel 1 (
468+
echo %__MsgPrefix%Error: Nuget package generation failed build failed. Refer to the build log files for details:
469+
echo %__BuildLog%
470+
echo %__BuildWrn%
471+
echo %__BuildErr%
472+
exit /b 1
473+
)
474+
475+
:SkipNuget
476+
452477
:SkipCrossGenBuild
453478

454479
REM endlocal to rid us of environment changes from vsdevenv.bat

build.proj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,9 @@
1515
<Target Name="Clean">
1616
<Delete Files="$(BinDir)mscorlib.*" />
1717
</Target>
18+
19+
<Target Name="RestoreNETCorePlatforms" AfterTargets="Build">
20+
<Exec Command="$(DnuRestoreCommand) $(SourceDir).nuget/init/project.json --source https://www.myget.org/F/dotnet-core/" />
21+
</Target>
22+
1823
</Project>

build.sh

Lines changed: 108 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,24 @@ usage()
2323
exit 1
2424
}
2525

26+
initDistroName()
27+
{
28+
if [ "$__BuildOS" == "Linux" ]; then
29+
# Detect Distro
30+
if [ "$(cat /etc/*-release | grep -cim1 ubuntu)" -eq 1 ]; then
31+
export __DistroName=ubuntu
32+
elif [ "$(cat /etc/*-release | grep -cim1 centos)" -eq 1 ]; then
33+
export __DistroName=rhel
34+
elif [ "$(cat /etc/*-release | grep -cim1 rhel)" -eq 1 ]; then
35+
export __DistroName=rhel
36+
elif [ "$(cat /etc/*-release | grep -cim1 debian)" -eq 1 ]; then
37+
export __DistroName=debian
38+
else
39+
export __DistroName=""
40+
fi
41+
fi
42+
}
43+
2644
setup_dirs()
2745
{
2846
echo Setting up directories for build
@@ -162,50 +180,49 @@ build_coreclr()
162180
fi
163181
}
164182

165-
build_mscorlib()
183+
restoreBuildTools()
166184
{
167-
hash mono 2> /dev/null || { echo >&2 "Skipping mscorlib.dll build since Mono is not installed."; return; }
168-
169-
if [ $__SkipMSCorLib == 1 ]; then
170-
echo "Skipping mscorlib.dll build."
171-
return
185+
echo "Restoring BuildTools..."
186+
$__ProjectRoot/init-tools.sh
187+
if [ $? -ne 0 ]; then
188+
echo "Failed to restore BuildTools."
189+
exit 1
172190
fi
191+
}
173192

174-
# Temporary hack to make dnu restore more reliable. This is specifically for dnu beta 5 since this issue should already be addressed in later versions of dnu.
175-
export MONO_THREADS_PER_CPU=2000
193+
isMSBuildOnNETCoreSupported()
194+
{
195+
__isMSBuildOnNETCoreSupported=0
176196

177-
echo "Commencing build of mscorlib components for $__BuildOS.$__BuildArch.$__BuildType"
197+
if [ "$__BuildOS" == "Linux" ]; then
198+
if [ "$__DistroName" == "ubuntu" ]; then
199+
__isMSBuildOnNETCoreSupported=1
200+
fi
201+
elif [ "$__BuildOS" == "OSX" ]; then
202+
__isMSBuildOnNETCoreSupported=1
203+
fi
204+
}
178205

179-
# Pull NuGet.exe down if we don't have it already
180-
if [ ! -e "$__NuGetPath" ]; then
181-
hash curl 2>/dev/null || hash wget 2>/dev/null || { echo >&2 echo "cURL or wget is required to build mscorlib." ; exit 1; }
206+
build_mscorlib()
207+
{
182208

183-
echo "Restoring NuGet.exe..."
209+
if [ $__isMSBuildOnNETCoreSupported == 0 ]; then
210+
echo "Mscorlib.dll build unsupported."
211+
return
212+
fi
184213

185-
# curl has HTTPS CA trust-issues less often than wget, so lets try that first.
186-
which curl > /dev/null 2> /dev/null
187-
if [ $? -ne 0 ]; then
188-
mkdir -p $__PackagesDir
189-
wget -q -O $__NuGetPath https://api.nuget.org/downloads/nuget.exe
190-
else
191-
curl -sSL --create-dirs -o $__NuGetPath https://api.nuget.org/downloads/nuget.exe
192-
fi
214+
# CI_TODO: Until we switch CI to stop building mscorlib for platforms supported by isMSBuildOnNETCoreSupported function,
215+
# we should ignore skipping building mscorlib.
216+
# if [ $__SkipMSCorLib == 1 ]; then
217+
# echo "Skipping building mscorlib."
218+
# return
219+
# fi
193220

194-
if [ $? -ne 0 ]; then
195-
echo "Failed to restore NuGet.exe."
196-
exit 1
197-
fi
198-
fi
221+
# Restore buildTools
199222

200-
# Grab the MSBuild package if we don't have it already
201-
if [ ! -e "$__MSBuildPath" ]; then
202-
echo "Restoring MSBuild..."
203-
$__ProjectRoot/init-tools.sh
204-
if [ $? -ne 0 ]; then
205-
echo "Failed to restore MSBuild."
206-
exit 1
207-
fi
208-
fi
223+
restoreBuildTools
224+
225+
echo "Commencing build of mscorlib components for $__BuildOS.$__BuildArch.$__BuildType"
209226

210227
# Invoke MSBuild
211228
$__ProjectRoot/Tools/corerun "$__MSBuildPath" /nologo "$__ProjectRoot/build.proj" /verbosity:minimal "/fileloggerparameters:Verbosity=normal;LogFile=$__LogsDir/MSCorLib_$__BuildOS__$__BuildArch__$__BuildType.log" /t:Build /p:__BuildOS=$__BuildOS /p:__BuildArch=$__BuildArch /p:__BuildType=$__BuildType /p:__IntermediatesDir=$__IntermediatesDir /p:UseRoslynCompiler=true /p:BuildNugetPackage=false /p:UseSharedCompilation=false
@@ -225,6 +242,38 @@ build_mscorlib()
225242
fi
226243
}
227244

245+
generate_NugetPackages()
246+
{
247+
# We can only generate nuget package if we also support building mscorlib as part of this build.
248+
if [ $__isMSBuildOnNETCoreSupported == 0 ]; then
249+
echo "Microsoft.NETCore.Runtime.CoreCLR nuget package generation unsupported."
250+
return
251+
fi
252+
253+
# Since we can build mscorlib for this OS, did we build the native components as well?
254+
if [ $__SkipCoreCLR == 1 ]; then
255+
echo "Unable to generate Microsoft.NETCore.Runtime.CoreCLR nuget package since native components were not built."
256+
return
257+
fi
258+
259+
# CI_TODO: Until we switch CI to stop building mscorlib for platforms supported by isMSBuildOnNETCoreSupported function,
260+
# we should ignore skipping building mscorlib.
261+
# if [ $__SkipMSCorLib == 1 ]; then
262+
# echo "Unable to generate Microsoft.NETCore.Runtime.CoreCLR nuget package since mscorlib was not built."
263+
# return
264+
# fi
265+
266+
echo "Generating nuget packages for "$__BuildOS
267+
268+
# Invoke MSBuild
269+
$__ProjectRoot/Tools/corerun "$__MSBuildPath" /nologo "$__ProjectRoot/src/.nuget/Microsoft.NETCore.Runtime.CoreCLR/Microsoft.NETCore.Runtime.CoreCLR.builds" /verbosity:minimal "/fileloggerparameters:Verbosity=normal;LogFile=$__LogsDir/Nuget_$__BuildOS__$__BuildArch__$__BuildType.log" /t:Build /p:__BuildOS=$__BuildOS /p:__BuildArch=$__BuildArch /p:__BuildType=$__BuildType /p:__IntermediatesDir=$__IntermediatesDir /p:UseRoslynCompiler=true /p:BuildNugetPackage=false /p:UseSharedCompilation=false
270+
271+
if [ $? -ne 0 ]; then
272+
echo "Failed to generate Nuget packages."
273+
exit 1
274+
fi
275+
}
276+
228277
echo "Commencing CoreCLR Repo build"
229278

230279
# Argument types supported by this script:
@@ -240,7 +289,7 @@ __ProjectRoot="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
240289
# Use uname to determine what the CPU is.
241290
CPUName=$(uname -p)
242291
# Some Linux platforms report unknown for platform, but the arch for machine.
243-
if [ $CPUName = "unknown" ]; then
292+
if [ $CPUName == "unknown" ]; then
244293
CPUName=$(uname -m)
245294
fi
246295

@@ -327,6 +376,7 @@ __ClangMajorVersion=3
327376
__ClangMinorVersion=5
328377
__MSBuildPath=$__ProjectRoot/Tools/MSBuild.exe
329378
__NuGetPath="$__PackagesDir/NuGet.exe"
379+
__DistroName=""
330380

331381
for i in "$@"
332382
do
@@ -443,13 +493,30 @@ if [[ $__ConfigureOnly == 1 && $__SkipConfigure == 1 ]]; then
443493
exit 1
444494
fi
445495

496+
# init the distro name
497+
initDistroName
498+
446499
# Set the remaining variables based upon the determined build configuration
447500
__BinDir="$__RootBinDir/Product/$__BuildOS.$__BuildArch.$__BuildType"
448501
__PackagesBinDir="$__BinDir/.nuget"
449502
__ToolsDir="$__RootBinDir/tools"
450503
__TestWorkingDir="$__RootBinDir/tests/$__BuildOS.$__BuildArch.$__BuildType"
451504
export __IntermediatesDir="$__RootBinDir/obj/$__BuildOS.$__BuildArch.$__BuildType"
452505
__TestIntermediatesDir="$__RootBinDir/tests/obj/$__BuildOS.$__BuildArch.$__BuildType"
506+
__isMSBuildOnNETCoreSupported=0
507+
508+
# Init if MSBuild for .NET Core is supported for this platform
509+
isMSBuildOnNETCoreSupported
510+
511+
# CI_SPECIFIC - On CI machines, $HOME may not be set. In such a case, create a subfolder and set the variable to set.
512+
# This is needed by CLI to function.
513+
if [ -z "$HOME" ]; then
514+
if [ ! -d "$__ProjectDir/temp_home" ]; then
515+
mkdir temp_home
516+
fi
517+
export HOME=$__ProjectDir/temp_home
518+
echo "HOME not defined; setting it to $HOME"
519+
fi
453520

454521
# Specify path to be set for CMAKE_INSTALL_PREFIX.
455522
# This is where all built CoreClr libraries will copied to.
@@ -489,6 +556,11 @@ build_coreclr
489556

490557
build_mscorlib
491558

559+
# Generate nuget packages
560+
561+
generate_NugetPackages
562+
563+
492564
# Build complete
493565

494566
echo "Repo successfully built."

dir.props

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
fails to write packages to it if the path contains the forward slash.
6060
-->
6161
<PackagesBinDir>$(__PackagesBinDir)</PackagesBinDir>
62-
<PackagesBinDir Condition="'$(__PackagesBinDir)'==''">$(BinDir).nuget</PackagesBinDir>
62+
<PackagesBinDir Condition="'$(__PackagesBinDir)'==''">$(BinDir).nuget\</PackagesBinDir>
6363

6464
<ToolsDir Condition="'$(ToolsDir)'==''">$(ProjectDir)Tools/</ToolsDir>
6565
<DotnetCliPath Condition="'$(DotnetCliPath)'==''">$(ToolsDir)dotnetcli/bin/</DotnetCliPath>
@@ -103,17 +103,11 @@
103103

104104
<!-- Setup Nuget properties -->
105105
<ItemGroup>
106-
<NuSpecSrcs Include="$(SourceDir)\.nuget\Microsoft.DotNet.CoreCLR.nuspec" />
107106
<NuSpecSrcs Include="$(SourceDir)\.nuget\toolchain.win7-x64.Microsoft.DotNet.RyuJit.nuspec" />
108-
<NuSpecSrcs Condition="'$(Configuration)'=='Release'" Include="$(SourceDir)\.nuget\Microsoft.DotNet.CoreCLR.Development.nuspec" />
109-
<NuSpecSrcs Condition="'$(Configuration)'=='Debug'" Include="$(SourceDir)\.nuget\Microsoft.DotNet.CoreCLR.Debug.Development.nuspec" />
110107
</ItemGroup>
111108
<ItemGroup>
112109
<!-- Backslash appended, see note in dir.props about the PackagesBinDir property -->
113-
<NuSpecs Include="$(PackagesBinDir)\Microsoft.DotNet.CoreCLR.nuspec" />
114110
<NuSpecs Include="$(PackagesBinDir)\toolchain.win7-x64.Microsoft.DotNet.RyuJit.nuspec" />
115-
<NuSpecs Condition="'$(Configuration)'=='Release'" Include="$(PackagesBinDir)\Microsoft.DotNet.CoreCLR.Development.nuspec" />
116-
<NuSpecs Condition="'$(Configuration)'=='Debug'" Include="$(PackagesBinDir)\Microsoft.DotNet.CoreCLR.Debug.Development.nuspec" />
117111
</ItemGroup>
118112

119113
<!--
@@ -132,5 +126,31 @@
132126
<TargetsWindows Condition="'$(BuildOS)' == 'Windows_NT'">true</TargetsWindows>
133127

134128
<TargetsUnix Condition="'$(TargetsFreeBSD)' == 'true' or '$(TargetsLinux)' == 'true' or '$(TargetsOSX)' == 'true'">true</TargetsUnix>
129+
130+
<!-- We are only tracking Linux Distributions for Nuget RID mapping -->
131+
<DistroName Condition="'$(TargetsLinux)' == 'true'">$(__DistroName)</DistroName>
132+
135133
</PropertyGroup>
134+
135+
<!-- Packaging properties -->
136+
<PropertyGroup>
137+
<PreReleaseLabel>rc3</PreReleaseLabel>
138+
<PackageDescriptionFile>$(SourceDir).nuget/descriptions.json</PackageDescriptionFile>
139+
<PackageLicenseFile>$(SourceDir).nuget/dotnet_library_license.txt</PackageLicenseFile>
140+
<PackageThirdPartyNoticesFile>$(SourceDir).nuget/ThirdPartyNotices.txt</PackageThirdPartyNoticesFile>
141+
142+
<!-- This should be kept in sync with package details in src/.nuget/init/project.json -->
143+
<RuntimeIdGraphDefinitionFile>$(PackagesDir)/Microsoft.NETCore.Platforms/1.0.1-rc2-23712/runtime.json</RuntimeIdGraphDefinitionFile>
144+
145+
<!-- On Windows, MSbuild still runs against Desktop FX while it runs on .NET Core on non-Windows. this requires
146+
pulling in different packaging dependencies.
147+
-->
148+
<PackagingTaskDir Condition="'$(TargetsWindows)' == 'true'">$(ToolsDir)net45/</PackagingTaskDir>
149+
<BuildNumberMajor Condition="'$(BuildNumberMajor)' == ''">00001</BuildNumberMajor>
150+
<!-- defined in buildtools packaging.targets, but we need this before targets are imported -->
151+
<PackagePlatform Condition="'$(PackagePlatform)' == ''">$(BuildArch)</PackagePlatform>
152+
<PackagePlatform Condition="'$(PackagePlatform)' == 'amd64'">x64</PackagePlatform>
153+
<PackageOutputPath>$(PackagesBinDir)/pkg/</PackageOutputPath>
154+
</PropertyGroup>
155+
136156
</Project>

init-tools.sh

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,35 @@
11
#!/usr/bin/env bash
22

3+
initDistroName()
4+
{
5+
if [ "$1" == "Linux" ]; then
6+
# Detect Distro
7+
if [ "$(cat /etc/*-release | grep -cim1 ubuntu)" -eq 1 ]; then
8+
export __DistroName=ubuntu
9+
elif [ "$(cat /etc/*-release | grep -cim1 centos)" -eq 1 ]; then
10+
export __DistroName=centos
11+
elif [ "$(cat /etc/*-release | grep -cim1 rhel)" -eq 1 ]; then
12+
export __DistroName=rhel
13+
elif [ "$(cat /etc/*-release | grep -cim1 debian)" -eq 1 ]; then
14+
export __DistroName=debian
15+
else
16+
export __DistroName=""
17+
fi
18+
fi
19+
}
20+
321
__scriptpath=$(cd "$(dirname "$0")"; pwd -P)
22+
23+
# CI_SPECIFIC - On CI machines, $HOME may not be set. In such a case, create a subfolder and set the variable to set.
24+
# This is needed by CLI to function.
25+
if [ -z "$HOME" ]; then
26+
if [ ! -d "$__scriptpath/temp_home" ]; then
27+
mkdir temp_home
28+
fi
29+
export HOME=$__scriptpath/temp_home
30+
echo "HOME not defined; setting it to $HOME"
31+
fi
32+
433
__PACKAGES_DIR=$__scriptpath/packages
534
__TOOLRUNTIME_DIR=$__scriptpath/Tools
635
__DOTNET_PATH=$__TOOLRUNTIME_DIR/dotnetcli
@@ -12,6 +41,7 @@ __BUILD_TOOLS_PATH=$__PACKAGES_DIR/Microsoft.DotNet.BuildTools/$__BUILD_TOOLS_PA
1241
__PROJECT_JSON_PATH=$__TOOLRUNTIME_DIR/$__BUILD_TOOLS_PACKAGE_VERSION
1342
__PROJECT_JSON_FILE=$__PROJECT_JSON_PATH/project.json
1443
__PROJECT_JSON_CONTENTS="{ \"dependencies\": { \"Microsoft.DotNet.BuildTools\": \"$__BUILD_TOOLS_PACKAGE_VERSION\" }, \"frameworks\": { \"dnxcore50\": { } } }"
44+
__DistroName=""
1545

1646
OSName=$(uname -s)
1747
case $OSName in
@@ -32,6 +62,16 @@ case $OSName in
3262
;;
3363
esac
3464

65+
# Initialize Linux Distribution name and .NET CLI package name.
66+
67+
initDistroName $OS
68+
if [ "$__DistroName" == "centos" ]; then
69+
__DOTNET_PKG=dotnet-centos-x64
70+
fi
71+
72+
__CLIDownloadURL=https://dotnetcli.blob.core.windows.net/dotnet/dev/Binaries/${__DOTNET_TOOLS_VERSION}/${__DOTNET_PKG}.${__DOTNET_TOOLS_VERSION}.tar.gz
73+
echo ".NET CLI will be downloaded from $__CLIDownloadURL"
74+
3575
if [ ! -e $__PROJECT_JSON_FILE ]; then
3676
if [ -e $__TOOLRUNTIME_DIR ]; then rm -rf -- $__TOOLRUNTIME_DIR; fi
3777

@@ -40,9 +80,9 @@ if [ ! -e $__PROJECT_JSON_FILE ]; then
4080
which curl > /dev/null 2> /dev/null
4181
if [ $? -ne 0 ]; then
4282
mkdir -p "$__DOTNET_PATH"
43-
wget -q -O $__DOTNET_PATH/dotnet.tar https://dotnetcli.blob.core.windows.net/dotnet/dev/Binaries/${__DOTNET_TOOLS_VERSION}/${__DOTNET_PKG}.${__DOTNET_TOOLS_VERSION}.tar.gz
83+
wget -q -O $__DOTNET_PATH/dotnet.tar $__CLIDownloadURL
4484
else
45-
curl -sSL --create-dirs -o $__DOTNET_PATH/dotnet.tar https://dotnetcli.blob.core.windows.net/dotnet/dev/Binaries/${__DOTNET_TOOLS_VERSION}/${__DOTNET_PKG}.${__DOTNET_TOOLS_VERSION}.tar.gz
85+
curl -sSL --create-dirs -o $__DOTNET_PATH/dotnet.tar $__CLIDownloadURL
4686
fi
4787
cd $__DOTNET_PATH
4888
tar -xf $__DOTNET_PATH/dotnet.tar
File renamed without changes.

0 commit comments

Comments
 (0)