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

Commit bb6dac8

Browse files
authored
Merge pull request #3188 from janvorli/port-add-rhel6-detection
Port to 2.0.0: Add RHEL 6 and CentOS 6 distro detection
2 parents e10d9cf + 69f6efc commit bb6dac8

File tree

5 files changed

+63
-8
lines changed

5 files changed

+63
-8
lines changed

src/corehost/common/pal.unix.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ pal::string_t pal::get_current_os_rid_platform()
274274
{
275275
pal::string_t ridOS;
276276
pal::string_t versionFile(_X("/etc/os-release"));
277+
pal::string_t rhelVersionFile(_X("/etc/redhat-release"));
277278

278279
if (pal::file_exists(versionFile))
279280
{
@@ -353,6 +354,35 @@ pal::string_t pal::get_current_os_rid_platform()
353354
}
354355
}
355356
}
357+
else if (pal::file_exists(rhelVersionFile))
358+
{
359+
// Read the file to check if the current OS is RHEL or CentOS 6.x
360+
std::fstream fsVersionFile;
361+
362+
fsVersionFile.open(rhelVersionFile, std::fstream::in);
363+
364+
// Proceed only if we were able to open the file
365+
if (fsVersionFile.good())
366+
{
367+
pal::string_t line;
368+
// Read the first line
369+
std::getline(fsVersionFile, line);
370+
371+
if (!fsVersionFile.eof())
372+
{
373+
pal::string_t rhel6Prefix(_X("Red Hat Enterprise Linux Server release 6."));
374+
pal::string_t centos6Prefix(_X("CentOS release 6."));
375+
376+
if ((line.find(rhel6Prefix) == 0) || (line.find(centos6Prefix) == 0))
377+
{
378+
ridOS = _X("rhel.6");
379+
}
380+
}
381+
382+
// Close the file now that we are done with it.
383+
fsVersionFile.close();
384+
}
385+
}
356386

357387
return normalize_linux_rid(ridOS);
358388
}

src/managed/CommonManaged.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<PropertyGroup>
77
<RepoRoot>$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)../..'))/</RepoRoot>
8-
<VersionPrefix>2.0.1</VersionPrefix>
8+
<VersionPrefix>2.0.2</VersionPrefix>
99
<AssemblyFileVersion>$(VersionPrefix)</AssemblyFileVersion>
1010
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
1111
<DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences>

src/managed/Microsoft.DotNet.PlatformAbstractions/Native/PlatformApis.cs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ private static string GetDistroVersionId()
8585

8686
private static DistroInfo LoadDistroInfo()
8787
{
88+
DistroInfo result = null;
89+
8890
// Sample os-release file:
8991
// NAME="Ubuntu"
9092
// VERSION = "14.04.3 LTS, Trusty Tahr"
@@ -100,7 +102,7 @@ private static DistroInfo LoadDistroInfo()
100102
if (File.Exists("/etc/os-release"))
101103
{
102104
var lines = File.ReadAllLines("/etc/os-release");
103-
var result = new DistroInfo();
105+
result = new DistroInfo();
104106
foreach (var line in lines)
105107
{
106108
if (line.StartsWith("ID=", StringComparison.Ordinal))
@@ -112,10 +114,30 @@ private static DistroInfo LoadDistroInfo()
112114
result.VersionId = line.Substring(11).Trim('"', '\'');
113115
}
114116
}
117+
}
118+
else if (File.Exists("/etc/redhat-release"))
119+
{
120+
var lines = File.ReadAllLines("/etc/redhat-release");
121+
122+
if (lines.Length >= 1)
123+
{
124+
string line = lines[0];
125+
if (line.StartsWith("Red Hat Enterprise Linux Server release 6.") ||
126+
line.StartsWith("CentOS release 6."))
127+
{
128+
result = new DistroInfo();
129+
result.Id = "rhel";
130+
result.VersionId = "6";
131+
}
132+
}
133+
}
115134

116-
return NormalizeDistroInfo(result);
135+
if (result != null)
136+
{
137+
result = NormalizeDistroInfo(result);
117138
}
118-
return null;
139+
140+
return result;
119141
}
120142

121143
// For some distros, we don't want to use the full version from VERSION_ID. One example is

src/managed/Microsoft.Extensions.DependencyModel/Microsoft.Extensions.DependencyModel.csproj

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<!-- Since Microsoft.DotNet.PlatformAbstractions isn't being serviced, take a dependency on the shipped package. -->
12-
<!--<ProjectReference Include="..\Microsoft.DotNet.PlatformAbstractions\Microsoft.DotNet.PlatformAbstractions.csproj" />-->
13-
<PackageReference Include="Microsoft.DotNet.PlatformAbstractions" Version="2.0.0" />
11+
<ProjectReference Include="..\Microsoft.DotNet.PlatformAbstractions\Microsoft.DotNet.PlatformAbstractions.csproj" />
1412
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
1513
</ItemGroup>
1614

src/pkg/packaging/dir.proj

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,15 @@
170170

171171
<Target Name="GenerateNugetPackages" DependsOnTargets="InitPackage" Condition="'$(UsePrebuiltPortableBinariesForInstallers)' == 'false'">
172172

173-
<ItemGroup Condition="'$(BuildAllPackages)' == 'true'">
173+
<ItemGroup>
174+
<!-- The list of packages we are servicing -->
174175
<PackageProjects Include="$(ProjectDir)src\managed\Microsoft.DotNet.PlatformAbstractions\Microsoft.DotNet.PlatformAbstractions.csproj" />
175176
<PackageProjects Include="$(ProjectDir)src\managed\Microsoft.Extensions.DependencyModel\Microsoft.Extensions.DependencyModel.csproj" />
176177
</ItemGroup>
178+
179+
<ItemGroup Condition="'$(BuildAllPackages)' == 'true'">
180+
<!-- The list of packages we are not servicing -->
181+
</ItemGroup>
177182

178183
<PropertyGroup>
179184
<OutputArg>--output $(PackagesOutDir)</OutputArg>

0 commit comments

Comments
 (0)