Skip to content

Commit

Permalink
[mono] Improve mono.proj, auto-detect build configurations (dotnet#31739
Browse files Browse the repository at this point in the history
)

* Auto-detect build configuration in Makefile

* Improve RunCoreClrTests target

* Clone .dotnet to .dotnet-mono

* Implement Console
  • Loading branch information
EgorBo committed Feb 6, 2020
1 parent e8dc3a1 commit 134b198
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 56 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ syntax: glob

# Tool Runtime Dir
.dotnet/
.dotnet-mono/
.packages/
.tools/

Expand Down
68 changes: 34 additions & 34 deletions src/mono/mono.proj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
<DotNetExec Condition="'$(DotNetExec)' == ''">dotnet</DotNetExec>
<LocalDotnetDir>..\..\.dotnet</LocalDotnetDir>
<LocalDotnet>$(LocalDotnetDir)\$(DotNetExec)</LocalDotnet>
<LocalMonoDotnetDir>..\..\.dotnet-mono</LocalMonoDotnetDir>
<LocalMonoDotnet>$(LocalMonoDotnetDir)\$(DotNetExec)</LocalMonoDotnet>
<ScriptExt Condition="'$(OS)' == 'Windows_NT'">.cmd</ScriptExt>
<ScriptExt Condition="'$(OS)' != 'Windows_NT'">.sh</ScriptExt>
<_CoreClrFileName Condition="'$(TargetsWindows)' == 'true'">coreclr.dll</_CoreClrFileName>
Expand Down Expand Up @@ -56,6 +58,12 @@
<Exec Command="msvc\run-msbuild.bat build $(_MonoBuildPlatform) $(Configuration) sgen &quot;$(_MonoBuildParams)&quot; msvc\mono-netcore.sln" IgnoreStandardErrorWarningFormat="true" />
</Target>

<Target Name="BuildCoreLib">
<MSBuild Projects="$(MonoProjectRoot)netcore\System.Private.CoreLib\System.Private.CoreLib.csproj"
Properties="Configuration=$(Configuration)"
Targets="Build" />
</Target>

<!-- General targets -->
<Target Name="Build" DependsOnTargets="BuildMonoRuntimeUnix;BuildMonoRuntimeWindows">
<PropertyGroup>
Expand Down Expand Up @@ -88,25 +96,19 @@

<Target Name="Test" />

<!-- Copy Mono runtime bits to the local .dotnet dir for local experiments (temp solution) -->
<Target Name="PatchLocalDotnet" DependsOnTargets="ValidateLocalDotnet">
<PropertyGroup>
<LocalDotnetRuntimeDir>$([System.IO.Directory]::GetDirectories("$(LocalDotnetDir)\shared\Microsoft.NETCore.App")[0])</LocalDotnetRuntimeDir>
</PropertyGroup>
<!-- Copy Mono runtime bits to the local .dotnet-mono (clone of .dotnet) dir for local experiments (temp solution) -->
<Target Name="PatchLocalMonoDotnet" DependsOnTargets="ValidateLocalDotnet">
<ItemGroup>
<_LocalDotnetFiles Include="$(LocalDotnetDir)\**\*.*" />
<_MonoRuntimeArtifacts Include="$(BinDir)\*.*" />
</ItemGroup>
<Copy SourceFiles="$(_MonoRuntimeArtifacts)"
DestinationFolder="$(LocalDotnetRuntimeDir)"
<Error Condition="@(_MonoRuntimeArtifacts->Count()) &lt; 2" Text="Mono artifacts were not found at $(BinDir)" />
<!-- copy .dotnet to .dotnet-mono if it doesn't exist -->
<Copy SourceFiles="@(_LocalDotnetFiles)"
DestinationFolder="$(LocalMonoDotnetDir)\%(RecursiveDir)"
SkipUnchangedFiles="true" />
</Target>

<!-- Copy Coreclr runtime bits to the local .dotnet dir -->
<Target Name="RestoreLocalDotnet" DependsOnTargets="ValidateLocalDotnet">
<Copy SourceFiles="$(CoreCLRArtifactsPath)\System.Private.CoreLib.dll"
DestinationFiles="$(LocalDotnetRuntimeDir)\System.Private.CoreLib.dll" />
<Copy SourceFiles="$(CoreCLRArtifactsPath)\$(_CoreClrFileName)"
DestinationFiles="$(LocalDotnetRuntimeDir)\$(_CoreClrFileName)" />
<Copy SourceFiles="@(_MonoRuntimeArtifacts)"
DestinationFolder="$([System.IO.Directory]::GetDirectories('$(LocalMonoDotnetDir)\shared\Microsoft.NETCore.App')[0])" />
</Target>

<!-- Copy Mono runtime bits to the coreclr's Core_Root in order to run runtime tests -->
Expand All @@ -115,9 +117,9 @@
<ItemGroup>
<_MonoRuntimeArtifacts Include="$(BinDir)\*.*" />
</ItemGroup>
<Error Condition="@(_MonoRuntimeArtifacts->Count()) &lt; 2" Text="Mono artifacts were not found at $(BinDir)" />
<Copy SourceFiles="@(_MonoRuntimeArtifacts)"
DestinationFolder="$(CoreClrTestCoreRoot)"
SkipUnchangedFiles="true"/>
DestinationFolder="$(CoreClrTestCoreRoot)" />
</Target>

<!-- Copy Coreclr runtime bits back to Core_Root -->
Expand All @@ -129,8 +131,16 @@
</Target>

<!-- Run netcore\sample\HelloWorld sample using Mono Runtime -->
<Target Name="RunSample" DependsOnTargets="PatchLocalDotnet">
<Exec Command="$(LocalDotnet) run -c Release -f $(NetCoreAppCurrent) -p $(MonoProjectRoot)netcore\sample\HelloWorld" />
<Target Name="RunSample" DependsOnTargets="PatchLocalMonoDotnet">
<PropertyGroup>
<EnvVars Condition="'$(OS)' != 'Windows_NT'"><![CDATA[
COMPlus_DebugWriteToStdErr=1 \
MONO_ENV_OPTIONS="" \
]]>
</EnvVars>
</PropertyGroup>
<Exec Condition="'$(OS)' == 'Windows_NT'" Command="$(EnvVars) $(LocalMonoDotnet) run -c $(Configuration) -p $(MonoProjectRoot)netcore/sample/HelloWorld" />
<Exec Condition="'$(OS)' != 'Windows_NT'" Command="$(EnvVars) $(LocalMonoDotnet) run -c $(Configuration) -p $(MonoProjectRoot)netcore\sample\HelloWorld" />
</Target>

<!-- Run CoreCLR runtime test using testhost -->
Expand All @@ -139,25 +149,15 @@
<Exec Command="$(CoreClrTest) -coreroot=&quot;$(CoreClrTestCoreRoot)&quot;"/>
</Target>

<!-- Make sure coreclr tests are built (in $(CoreClrTestConfig) configuration), e.g.
*nix: `cd ../coreclr && ./build.sh -release && ./build-testh.sh -release`
Windows: `cd ../coreclr && build.cmd -release` -->
<!-- Run coreclr tests using runtest.py -->
<Target Name="RunCoreClrTests" DependsOnTargets="ValidateLocalDotnet;PatchCoreClrCoreRoot">
<ItemGroup>
<CoreClrTests Include="$(ArtifactsDir)tests\coreclr\$(OSGroup).$(Platform).$(CoreClrTestConfig)\**\*$(ScriptExt)" />
</ItemGroup>
<Exec Condition="'$(OS)' == 'Windows_NT'" Command="&quot;%(CoreClrTests.Identity)&quot; -coreroot &quot;$(CoreClrTestCoreRoot)&quot;" ContinueOnError="WarnAndContinue" />
<Exec Condition="'$(OS)' != 'Windows_NT'" Command="bash &quot;%(CoreClrTests.Identity)&quot; -coreroot=&quot;$(CoreClrTestCoreRoot)&quot;" ContinueOnError="WarnAndContinue" />
</Target>

<!-- Show summary for coreclr tests -->
<Target Name="CoreClrTestsSummary">
<Exec Command="python $(MonoProjectRoot)..\coreclr\tests\runtest.py --analyze_results_only -test_location $(ArtifactsDir)tests\coreclr\$(OSGroup).$(Platform).$(CoreClrTestConfig) -build_type $(CoreClrTestConfig)" />
<Exec Condition="'$(OS)' == 'Windows_NT'" Command="$(MonoProjectRoot)..\coreclr\tests\runtest.cmd $(CoreClrTestConfig)" ContinueOnError="ErrorAndContinue" />
<Exec Condition="'$(OS)' != 'Windows_NT'" Command="$(MonoProjectRoot)../coreclr/tests/./runtest.sh $(CoreClrTestConfig)" ContinueOnError="ErrorAndContinue" />
</Target>

<Target Name="RunBenchmarks">
<Target Name="RunBenchmarks" DependsOnTargets="PatchLocalMonoDotnet">
<Error Condition="$(BenchmarksRepo) == ''" Text="BenchmarksRepo variable is not set" />
<Exec WorkingDirectory="$(BenchmarksRepo)\src\benchmarks\micro" Command="$(LocalDotnet) run -c Release -f $(NetCoreAppCurrent) --cli $(LocalDotnet)" />
<Exec WorkingDirectory="$(BenchmarksRepo)\src\benchmarks\micro" Command="$(LocalDotnet) run -c Release -f $(NetCoreAppCurrent) --cli $(LocalMonoDotnet)" />
</Target>

<Target Name="ValidateLocalDotnet">
Expand Down
53 changes: 32 additions & 21 deletions src/mono/netcore/Makefile
Original file line number Diff line number Diff line change
@@ -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)
$(DOTNET) msbuild /t:RunBenchmarks /p:BenchmarksRepo=$(BenchmarksRepo)
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@

<!-- Sources -->
<ItemGroup>
<Compile Include="$(BclSourcesRoot)\Mono\Console.Mono.cs" />
<Compile Include="$(BclSourcesRoot)\Mono\MonoListItem.cs" />
<Compile Include="$(BclSourcesRoot)\Mono\MonoDomain.cs" />
<Compile Include="$(BclSourcesRoot)\Mono\MonoDomainSetup.cs" />
Expand Down
19 changes: 19 additions & 0 deletions src/mono/netcore/System.Private.CoreLib/src/Mono/Console.Mono.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
7 changes: 7 additions & 0 deletions src/mono/netcore/init-tools.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion src/mono/netcore/sample/HelloWorld/HelloWorld.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<OutputPath>bin</OutputPath>
<TargetFrameworks>$(NetCoreAppCurrent);netcoreapp3.1</TargetFrameworks>
<TargetFramework>$(NetCoreAppCurrent)</TargetFramework>
<DebugType>full</DebugType>
</PropertyGroup>

Expand Down

0 comments on commit 134b198

Please sign in to comment.