From 134b198b966f014fdb4a10b18c6bf19c5ebb8a6d Mon Sep 17 00:00:00 2001 From: Egor Bogatov Date: Thu, 6 Feb 2020 18:34:16 +0300 Subject: [PATCH] [mono] Improve mono.proj, auto-detect build configurations (#31739) * Auto-detect build configuration in Makefile * Improve RunCoreClrTests target * Clone .dotnet to .dotnet-mono * Implement Console --- .gitignore | 1 + src/mono/mono.proj | 68 +++++++++++----------- src/mono/netcore/Makefile | 53 ++++++++++------- .../System.Private.CoreLib.csproj | 1 + .../src/Mono/Console.Mono.cs | 19 ++++++ src/mono/netcore/init-tools.sh | 7 +++ .../netcore/sample/HelloWorld/HelloWorld.csproj | 2 +- 7 files changed, 95 insertions(+), 56 deletions(-) create mode 100644 src/mono/netcore/System.Private.CoreLib/src/Mono/Console.Mono.cs create mode 100644 src/mono/netcore/init-tools.sh diff --git a/.gitignore b/.gitignore index fa697b5..e111924 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ syntax: glob # Tool Runtime Dir .dotnet/ +.dotnet-mono/ .packages/ .tools/ diff --git a/src/mono/mono.proj b/src/mono/mono.proj index 5d54552..32b1c10 100644 --- a/src/mono/mono.proj +++ b/src/mono/mono.proj @@ -9,6 +9,8 @@ dotnet ..\..\.dotnet $(LocalDotnetDir)\$(DotNetExec) + ..\..\.dotnet-mono + $(LocalMonoDotnetDir)\$(DotNetExec) .cmd .sh <_CoreClrFileName Condition="'$(TargetsWindows)' == 'true'">coreclr.dll @@ -56,6 +58,12 @@ + + + + @@ -88,25 +96,19 @@ - - - - $([System.IO.Directory]::GetDirectories("$(LocalDotnetDir)\shared\Microsoft.NETCore.App")[0]) - + + + <_LocalDotnetFiles Include="$(LocalDotnetDir)\**\*.*" /> <_MonoRuntimeArtifacts Include="$(BinDir)\*.*" /> - + + - - - - - - + @@ -115,9 +117,9 @@ <_MonoRuntimeArtifacts Include="$(BinDir)\*.*" /> + + DestinationFolder="$(CoreClrTestCoreRoot)" /> @@ -129,8 +131,16 @@ - - + + + + + + + @@ -139,25 +149,15 @@ - + - - - - - - - - - - + + - + - + diff --git a/src/mono/netcore/Makefile b/src/mono/netcore/Makefile index 57aa399..de287eb 100644 --- a/src/mono/netcore/Makefile +++ b/src/mono/netcore/Makefile @@ -1,38 +1,49 @@ -DOTNET=../../../.dotnet/dotnet +DOTNET := $(shell bash init-tools.sh | tail -1) +# DOTNET_MONO is a copy of DOTNET (local .dotnet) with Mono Runtime bits (see patch-mono-dotnet rule) +DOTNET_MONO = ../../../.dotnet-mono/dotnet -# run sample using local .dotnet (will be patched with Mono Runtime) -run-sample: - $(DOTNET) msbuild /t:RunSample ../mono.proj +CORECLR_TESTS_CONFIG=Release +MONO_RUNTIME_CONFIG=Release + +# auto detect configurations for mono runtime and coreclr tests +ifeq ($(words $(wildcard ../../../artifacts/bin/mono/*.*.*)), 1) + MONO_RUNTIME_CONFIG := $(word 3,$(subst ., ,$(notdir $(wildcard ../../../artifacts/bin/mono/*.*.*)))) +endif + +ifeq ($(words $(wildcard ../../../artifacts/tests/coreclr/*.*.*)), 1) + CORECLR_TESTS_CONFIG := $(word 3,$(subst ., ,$(notdir $(wildcard ../../../artifacts/tests/coreclr/*.*.*)))) +endif + +MONO_PROJ=/p:CoreClrTestConfig=$(CORECLR_TESTS_CONFIG) /p:Configuration=$(MONO_RUNTIME_CONFIG) ../mono.proj + +# run sample using local .dotnet-mono +run-sample: patch-mono-dotnet + COMPlus_DebugWriteToStdErr=1 $(DOTNET_MONO) run -c Debug -p sample/HelloWorld -# run sample using dotnet from PATH run-sample-coreclr: - dotnet run -c Release -p sample/HelloWorld -f netcoreapp3.1 + $(DOTNET) run -c Debug -p sample/HelloWorld -runtime: - $(DOTNET) msbuild /t:Build ../mono.proj +bcl corelib: + $(DOTNET) msbuild /t:BuildCoreLib $(MONO_PROJ) -# temp: makes $(DOTNET) to use mono runtime (to run real-world apps using '$(DOTNET) run') -patch-local-dotnet: - $(DOTNET) msbuild /t:PatchLocalDotnet ../mono.proj +runtime: + $(DOTNET) msbuild /t:Build $(MONO_PROJ) -restore-local-dotnet: - $(DOTNET) msbuild /t:RestoreLocalDotnet ../mono.proj +# call it if you want to use $(DOTNET_MONO) in this Makefile +patch-mono-dotnet: + $(DOTNET) msbuild /t:PatchLocalMonoDotnet $(MONO_PROJ) # run specific coreclr test, e.g.: -# make run-tests-coreclr CoreClrTest="bash ../../artifacts/tests/coreclr/OSX.x64.Checked/JIT/opt/InstructionCombining/DivToMul/DivToMul.sh" +# make run-tests-coreclr CoreClrTest="bash ../../artifacts/tests/coreclr/OSX.x64.Release/JIT/opt/InstructionCombining/DivToMul/DivToMul.sh" run-tests-coreclr: - $(DOTNET) msbuild /t:RunCoreClrTest /p:CoreClrTest="$(CoreClrTest)" ../mono.proj + $(DOTNET) msbuild /t:RunCoreClrTest /p:CoreClrTest="$(CoreClrTest)" $(MONO_PROJ) # run all coreclr tests run-tests-coreclr-all: - $(DOTNET) msbuild /t:RunCoreClrTests ../mono.proj - -# show summary for coreclr tests -tests-coreclr-summary: - $(DOTNET) msbuild /t:CoreClrTestsSummary ../mono.proj + $(DOTNET) msbuild /t:RunCoreClrTests $(MONO_PROJ) # run 'dotnet/performance' benchmarks # e.g. 'make run-benchmarks BenchmarksRepo=/prj/performance' # you can append BDN parameters at the end, e.g. ` -- --filter Burgers --keepFiles` run-benchmarks: patch-local-dotnet - $(DOTNET) msbuild /t:RunBenchmarks /p:BenchmarksRepo=$(BenchmarksRepo) \ No newline at end of file + $(DOTNET) msbuild /t:RunBenchmarks /p:BenchmarksRepo=$(BenchmarksRepo) diff --git a/src/mono/netcore/System.Private.CoreLib/System.Private.CoreLib.csproj b/src/mono/netcore/System.Private.CoreLib/System.Private.CoreLib.csproj index 388eea8..45e60e8 100644 --- a/src/mono/netcore/System.Private.CoreLib/System.Private.CoreLib.csproj +++ b/src/mono/netcore/System.Private.CoreLib/System.Private.CoreLib.csproj @@ -143,6 +143,7 @@ + diff --git a/src/mono/netcore/System.Private.CoreLib/src/Mono/Console.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/Mono/Console.Mono.cs new file mode 100644 index 0000000..396dfec --- /dev/null +++ b/src/mono/netcore/System.Private.CoreLib/src/Mono/Console.Mono.cs @@ -0,0 +1,19 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Diagnostics; + +namespace Internal +{ + // Some CoreCLR tests use it for internal printf-style debugging in System.Private.CoreLib + public static class Console + { + public static void Write(string? s) => DebugProvider.WriteCore(s); + + public static void WriteLine(string? s) => Write(s + Environment.NewLineConst); + + public static void WriteLine() => Write(Environment.NewLineConst); + } +} \ No newline at end of file diff --git a/src/mono/netcore/init-tools.sh b/src/mono/netcore/init-tools.sh new file mode 100644 index 0000000..ae2ed15 --- /dev/null +++ b/src/mono/netcore/init-tools.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +# always ignore system dotnet +export use_installed_dotnet_cli=false +. "../../../eng/common/tools.sh" +InitializeDotNetCli true +which dotnet \ No newline at end of file diff --git a/src/mono/netcore/sample/HelloWorld/HelloWorld.csproj b/src/mono/netcore/sample/HelloWorld/HelloWorld.csproj index af90cfd..521875c 100644 --- a/src/mono/netcore/sample/HelloWorld/HelloWorld.csproj +++ b/src/mono/netcore/sample/HelloWorld/HelloWorld.csproj @@ -3,7 +3,7 @@ Exe bin - $(NetCoreAppCurrent);netcoreapp3.1 + $(NetCoreAppCurrent) full -- 2.7.4