Replace custom mono defines with toolchain-provided defines.

This commit is contained in:
Paul Chote
2022-04-24 18:45:33 +01:00
committed by Matthias Mailänder
parent 3e5666ca53
commit a152bf7324
9 changed files with 16 additions and 19 deletions

View File

@@ -17,8 +17,8 @@
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>
<TargetFramework Condition="'$(Mono)' == ''">net6.0</TargetFramework> <TargetFramework Condition="'$(MSBuildRuntimeType)'!='Mono'">net6.0</TargetFramework>
<TargetFramework Condition="'$(Mono)' != ''">netstandard2.1</TargetFramework> <TargetFramework Condition="'$(MSBuildRuntimeType)'=='Mono'">netstandard2.1</TargetFramework>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>

View File

@@ -80,7 +80,7 @@ all:
@echo "Compiling in ${CONFIGURATION} mode..." @echo "Compiling in ${CONFIGURATION} mode..."
ifeq ($(RUNTIME), mono) ifeq ($(RUNTIME), mono)
@command -v $(firstword $(MSBUILD)) >/dev/null || (echo "OpenRA requires the '$(MSBUILD)' tool provided by Mono >= 6.4."; exit 1) @command -v $(firstword $(MSBUILD)) >/dev/null || (echo "OpenRA requires the '$(MSBUILD)' tool provided by Mono >= 6.4."; exit 1)
@$(MSBUILD) -t:Build -restore -p:Configuration=${CONFIGURATION} -p:TargetPlatform=$(TARGETPLATFORM) -p:Mono=true @$(MSBUILD) -t:Build -restore -p:Configuration=${CONFIGURATION} -p:TargetPlatform=$(TARGETPLATFORM)
else else
@$(DOTNET) build -c ${CONFIGURATION} -nologo -p:TargetPlatform=$(TARGETPLATFORM) @$(DOTNET) build -c ${CONFIGURATION} -nologo -p:TargetPlatform=$(TARGETPLATFORM)
endif endif
@@ -100,7 +100,7 @@ check:
@echo "Compiling in Debug mode..." @echo "Compiling in Debug mode..."
ifeq ($(RUNTIME), mono) ifeq ($(RUNTIME), mono)
# Enabling EnforceCodeStyleInBuild and GenerateDocumentationFile as a workaround for some code style rules (in particular IDE0005) being bugged and not reporting warnings/errors otherwise. # Enabling EnforceCodeStyleInBuild and GenerateDocumentationFile as a workaround for some code style rules (in particular IDE0005) being bugged and not reporting warnings/errors otherwise.
@$(MSBUILD) -t:build -restore -p:Configuration=Debug -warnaserror -p:TargetPlatform=$(TARGETPLATFORM) -p:Mono=true -p:EnforceCodeStyleInBuild=true -p:GenerateDocumentationFile=true @$(MSBUILD) -t:build -restore -p:Configuration=Debug -warnaserror -p:TargetPlatform=$(TARGETPLATFORM) -p:EnforceCodeStyleInBuild=true -p:GenerateDocumentationFile=true
else else
# Enabling EnforceCodeStyleInBuild and GenerateDocumentationFile as a workaround for some code style rules (in particular IDE0005) being bugged and not reporting warnings/errors otherwise. # Enabling EnforceCodeStyleInBuild and GenerateDocumentationFile as a workaround for some code style rules (in particular IDE0005) being bugged and not reporting warnings/errors otherwise.
@$(DOTNET) build -c Debug -nologo -warnaserror -p:TargetPlatform=$(TARGETPLATFORM) -p:EnforceCodeStyleInBuild=true -p:GenerateDocumentationFile=true @$(DOTNET) build -c Debug -nologo -warnaserror -p:TargetPlatform=$(TARGETPLATFORM) -p:EnforceCodeStyleInBuild=true -p:GenerateDocumentationFile=true

View File

@@ -351,7 +351,7 @@ namespace OpenRA
{ {
var rendererPath = Path.Combine(Platform.BinDir, "OpenRA.Platforms." + p + ".dll"); var rendererPath = Path.Combine(Platform.BinDir, "OpenRA.Platforms." + p + ".dll");
#if !MONO #if NET5_0_OR_GREATER
var loader = new AssemblyLoader(rendererPath); var loader = new AssemblyLoader(rendererPath);
var platformType = loader.LoadDefaultAssembly().GetTypes().SingleOrDefault(t => typeof(IPlatform).IsAssignableFrom(t)); var platformType = loader.LoadDefaultAssembly().GetTypes().SingleOrDefault(t => typeof(IPlatform).IsAssignableFrom(t));

View File

@@ -26,7 +26,7 @@ namespace OpenRA
var total = response.Content.Headers.ContentLength ?? -1; var total = response.Content.Headers.ContentLength ?? -1;
var canReportProgress = total > 0; var canReportProgress = total > 0;
#if !MONO #if NET5_0_OR_GREATER
using (var contentStream = await response.Content.ReadAsStreamAsync(token)) using (var contentStream = await response.Content.ReadAsStreamAsync(token))
#else #else
using (var contentStream = await response.Content.ReadAsStreamAsync()) using (var contentStream = await response.Content.ReadAsStreamAsync())

View File

@@ -60,7 +60,11 @@ namespace OpenRA
if (!ResolvedAssemblies.TryGetValue(hash, out var assembly)) if (!ResolvedAssemblies.TryGetValue(hash, out var assembly))
{ {
#if MONO #if NET5_0_OR_GREATER
var loader = new AssemblyLoader(resolvedPath);
assembly = loader.LoadDefaultAssembly();
ResolvedAssemblies.Add(hash, assembly);
#else
assembly = Assembly.LoadFile(resolvedPath); assembly = Assembly.LoadFile(resolvedPath);
ResolvedAssemblies.Add(hash, assembly); ResolvedAssemblies.Add(hash, assembly);
@@ -75,10 +79,6 @@ namespace OpenRA
LoadAssembly(assemblyList, depedencyPath); LoadAssembly(assemblyList, depedencyPath);
} }
} }
#else
var loader = new AssemblyLoader(resolvedPath);
assembly = loader.LoadDefaultAssembly();
ResolvedAssemblies.Add(hash, assembly);
#endif #endif
} }

View File

@@ -2,10 +2,7 @@
<PropertyGroup> <PropertyGroup>
<RootNamespace>OpenRA</RootNamespace> <RootNamespace>OpenRA</RootNamespace>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Mono)' != ''"> <ItemGroup Condition="'$(MSBuildRuntimeType)'!='Mono'">
<DefineConstants>MONO</DefineConstants>
</PropertyGroup>
<ItemGroup Condition="'$(Mono)' == ''">
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="6.0.0" /> <PackageReference Include="Microsoft.Extensions.DependencyModel" Version="6.0.0" />
<PackageReference Include="System.Runtime.Loader" Version="4.3.0" /> <PackageReference Include="System.Runtime.Loader" Version="4.3.0" />
</ItemGroup> </ItemGroup>

View File

@@ -11,7 +11,7 @@
// Not used/usable on Mono. Only used for Dotnet Core. // Not used/usable on Mono. Only used for Dotnet Core.
// Based on https://github.com/natemcmaster/DotNetCorePlugins and used under the terms of the Apache 2.0 license // Based on https://github.com/natemcmaster/DotNetCorePlugins and used under the terms of the Apache 2.0 license
#if !MONO #if NET5_0_OR_GREATER
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;

View File

@@ -16,7 +16,7 @@ namespace OpenRA.Support
{ {
public class HttpClientFactory public class HttpClientFactory
{ {
#if !MONO #if NET5_0_OR_GREATER
const int MaxConnectionPerServer = 20; const int MaxConnectionPerServer = 20;
static readonly TimeSpan ConnectionLifeTime = TimeSpan.FromMinutes(1); static readonly TimeSpan ConnectionLifeTime = TimeSpan.FromMinutes(1);
#endif #endif
@@ -30,7 +30,7 @@ namespace OpenRA.Support
static HttpMessageHandler GetHandler() static HttpMessageHandler GetHandler()
{ {
#if !MONO #if NET5_0_OR_GREATER
return new SocketsHttpHandler return new SocketsHttpHandler
{ {
// https://github.com/dotnet/corefx/issues/26895 // https://github.com/dotnet/corefx/issues/26895

View File

@@ -40,7 +40,7 @@ install_assemblies() {
rm -rf "${SRC_PATH}/OpenRA."*/obj rm -rf "${SRC_PATH}/OpenRA."*/obj
rm -rf "${SRC_PATH:?}/bin" rm -rf "${SRC_PATH:?}/bin"
msbuild -verbosity:m -nologo -t:Build -restore -p:Configuration=Release -p:TargetPlatform="${TARGETPLATFORM}" -p:Mono=true msbuild -verbosity:m -nologo -t:Build -restore -p:Configuration=Release -p:TargetPlatform="${TARGETPLATFORM}"
if [ "${TARGETPLATFORM}" = "unix-generic" ]; then if [ "${TARGETPLATFORM}" = "unix-generic" ]; then
./configure-system-libraries.sh ./configure-system-libraries.sh
fi fi