Skip to content

Commit

Permalink
Remove as many references to RuntimeEnvironment as possible.
Browse files Browse the repository at this point in the history
  • Loading branch information
eerhardt committed Apr 6, 2020
1 parent 0de0ea7 commit 5304180
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/Cli/Microsoft.DotNet.Cli.Utils/DotnetVersionFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ internal class DotnetVersionFile
/// The runtime identifier (rid) that this CLI was built for.
/// </summary>
/// <remarks>
/// This is different than RuntimeEnvironment.GetRuntimeIdentifier() because the
/// This is different than RuntimeInformation.RuntimeIdentifier because the
/// BuildRid is a RID that is guaranteed to exist and works on the current machine. The
/// RuntimeEnvironment.GetRuntimeIdentifier() may be for a new version of the OS that
/// RuntimeInformation.RuntimeIdentifier may be for a new version of the OS that
/// doesn't have full support yet.
/// </remarks>
public string BuildRid { get; set; }
Expand Down
6 changes: 3 additions & 3 deletions src/Cli/Microsoft.DotNet.Cli.Utils/RuntimeEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ private class DistroInfo
public string VersionId;
}

public static string GetOSName()
private static string GetOSName()
{
switch (GetOSPlatform())
{
Expand All @@ -129,7 +129,7 @@ public static string GetOSName()
}
}

public static string GetOSVersion()
private static string GetOSVersion()
{
switch (GetOSPlatform())
{
Expand Down Expand Up @@ -183,7 +183,7 @@ private static string GetFreeBSDVersion()
return string.Empty;
}

public static Platform GetOSPlatform()
private static Platform GetOSPlatform()
{
return _platform.Value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.IO;
using System.Runtime.InteropServices;
using FluentAssertions;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.CommandFactory;
Expand Down Expand Up @@ -243,7 +244,7 @@ private ProjectPathCommandResolver SetupPlatformProjectPathCommandResolver(

IPlatformCommandSpecFactory platformCommandSpecFactory = new GenericPlatformCommandSpecFactory();

if (RuntimeEnvironment.OperatingSystemPlatform == Platform.Windows
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
&& !forceGeneric)
{
platformCommandSpecFactory = new WindowsExePreferredCommandSpecFactory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@

using System;
using System.IO;
using System.Runtime.InteropServices;
using FluentAssertions;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.CommandFactory;
using Xunit;
using Microsoft.DotNet.Cli.Utils;

namespace Microsoft.DotNet.Tests
{
Expand Down Expand Up @@ -187,7 +188,7 @@ private AppBaseCommandResolver SetupPlatformAppBaseCommandResolver(

IPlatformCommandSpecFactory platformCommandSpecFactory = new GenericPlatformCommandSpecFactory();

if (RuntimeEnvironment.OperatingSystemPlatform == Platform.Windows
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
&& !forceGeneric)
{
platformCommandSpecFactory = new WindowsExePreferredCommandSpecFactory();
Expand Down
2 changes: 1 addition & 1 deletion src/Tests/Microsoft.NET.TestFramework/AssertionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static string[] AppendApphostOnNonMacOS(string ProjectName, string[] expe
{
string apphost = $"{ProjectName}{Constants.ExeSuffix}";
// No UseApphost is false by default on macOS
return !RuntimeInformation.IsOSPlatform (OSPlatform.OSX)
return !RuntimeInformation.IsOSPlatform(OSPlatform.OSX)
? expectedFiles.Append(apphost).ToArray()
: expectedFiles;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

#if NETCOREAPP

using Xunit;

namespace Microsoft.NET.TestFramework
Expand All @@ -16,3 +18,5 @@ public RequiresSpecificFrameworkFactAttribute(string framework)
}
}
}

#endif
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

#if NETCOREAPP

using Microsoft.DotNet.Tools.Test.Utilities;
using System;
using System.Collections.Generic;
Expand All @@ -20,3 +22,5 @@ public RequiresSpecificFrameworkTheoryAttribute(string framework)
}
}
}

#endif
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

#if NETCOREAPP

using Microsoft.DotNet.Cli.Utils;
using System.IO;
using System.Runtime.InteropServices;
using Xunit.Abstractions;

namespace Microsoft.NET.TestFramework.Commands
Expand Down Expand Up @@ -31,10 +34,12 @@ private string BuildRelativeOutputPath(string targetFramework, string configurat
{
if (runtimeIdentifier.Length == 0)
{
runtimeIdentifier = RuntimeEnvironment.GetRuntimeIdentifier();
runtimeIdentifier = RuntimeInformation.RuntimeIdentifier;
}
string arch = runtimeIdentifier.Substring(runtimeIdentifier.LastIndexOf("-") + 1);
return Path.Combine(configuration, arch, targetFramework, PublishSubfolderName);
}
}
}

#endif
8 changes: 6 additions & 2 deletions src/Tests/Microsoft.NET.TestFramework/EnvironmentInfo.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

#if NETCOREAPP

using System;
using System.Runtime.InteropServices;
using NuGet.Frameworks;
Expand All @@ -19,7 +21,7 @@ public static string ExecutableExtension

public static string GetCompatibleRid(string targetFramework = null)
{
string rid = DotNet.Cli.Utils.RuntimeEnvironment.GetRuntimeIdentifier();
string rid = RuntimeInformation.RuntimeIdentifier;

if (targetFramework == null)
{
Expand Down Expand Up @@ -56,7 +58,7 @@ public static string GetCompatibleRid(string targetFramework = null)
public static bool SupportsTargetFramework(string targetFramework)
{
var nugetFramework = NuGetFramework.Parse(targetFramework);
string currentRid = DotNet.Cli.Utils.RuntimeEnvironment.GetRuntimeIdentifier();
string currentRid = RuntimeInformation.RuntimeIdentifier;

string ridOS = currentRid.Split('.')[0];
if (ridOS.Equals("alpine", StringComparison.OrdinalIgnoreCase))
Expand Down Expand Up @@ -162,3 +164,5 @@ public static bool SupportsTargetFramework(string targetFramework)
}
}
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ private static string GetUserProfileRoot(string overrideUserProfileRoot = null)

private static string GetOptimizationRootPath(string version)
{
var rid = DotNet.Cli.Utils.RuntimeEnvironment.GetRuntimeIdentifier();
var rid = RuntimeInformation.RuntimeIdentifier;

return RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
? $@"Microsoft\dotnet\optimizationdata\{version}\{rid}"
Expand Down
2 changes: 1 addition & 1 deletion src/Tests/dotnet.Tests/TelemetryCommonPropertiesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public void TelemetryCommonPropertiesShouldContainEmptyLibcReleaseAndVersion2()
[LinuxOnlyFact]
public void TelemetryCommonPropertiesShouldContainLibcReleaseAndVersion()
{
if (!DotNet.Cli.Utils.RuntimeEnvironment.OperatingSystem.Contains("Alpine", StringComparison.OrdinalIgnoreCase))
if (!RuntimeInformation.RuntimeIdentifier.Contains("alpine", StringComparison.OrdinalIgnoreCase))
{
var unitUnderTest = new TelemetryCommonProperties(getMACAddress: () => null, userLevelCacheWriter: new NothingCache());
unitUnderTest.GetTelemetryCommonProperties()["Libc Release"].Should().NotBeEmpty();
Expand Down

0 comments on commit 5304180

Please sign in to comment.