set RID as freebsd.11 for FreeBSD. add missing parts to PAL and build script
authorTomas Weinfurt <tweinfurt@yahoo.com>
Wed, 20 Sep 2017 18:54:21 +0000 (11:54 -0700)
committerTomas Weinfurt <tweinfurt@yahoo.com>
Wed, 20 Sep 2017 18:54:21 +0000 (11:54 -0700)
Commit migrated from https://github.com/dotnet/core-setup/commit/9f16aea7056cb0d62839236dffe82d0bd4ec3b48

src/installer/corehost/build.sh
src/installer/corehost/common/pal.unix.cpp
src/installer/managed/Microsoft.DotNet.PlatformAbstractions/RuntimeEnvironment.cs

index d947c4c..2b8cf72 100755 (executable)
@@ -41,14 +41,21 @@ init_rid_plat()
     if [ "$(uname -s)" == "Darwin" ]; then
         __rid_plat=osx.10.12
     fi
+    if [ "$(uname -s)" == "FreeBSD" ]; then
+        major_ver=`uname -U | cut -b1-2`
+        __rid_plat=freebsd.$major_ver
+    fi
 
     if [ $__linkPortable == 1 ]; then
         if [ "$(uname -s)" == "Darwin" ]; then
             __rid_plat="osx"
+        elif [ "$(uname -s)" == "FreeBSD" ]; then
+            __rid_plat="freebsd"
         else
             __rid_plat="linux"
         fi
     fi
+    echo __rid_plat=$__rid_plat
 }
 
 usage()
index 71ecc06..6d44177 100644 (file)
@@ -208,7 +208,7 @@ pal::string_t trim_quotes(pal::string_t stringToCleanup)
 pal::string_t pal::get_current_os_rid_platform()
 {
     pal::string_t ridOS;
-    
+
     char str[256];
 
     // There is no good way to get the visible version of OSX (i.e. something like 10.x.y) as
@@ -244,6 +244,28 @@ pal::string_t pal::get_current_os_rid_platform()
 
     return ridOS;
 }
+#elif defined(__FreeBSD__)
+// On FreeBSD get major verion. Minors should be compatible
+pal::string_t pal::get_current_os_rid_platform()
+{
+    pal::string_t ridOS;
+
+    char str[256];
+
+    size_t size = sizeof(str);
+    int ret = sysctlbyname("kern.osrelease", str, &size, NULL, 0);
+    if (ret == 0)
+    {
+        char *pos = strchr(str,'.');
+        if (pos) {
+            *pos = '\0';
+        }
+        ridOS.append(_X("freebsd."));
+        ridOS.append(str);
+    }
+
+    return ridOS;
+}
 #else
 // For some distros, we don't want to use the full version from VERSION_ID. One example is
 // Red Hat Enterprise Linux, which includes a minor version in their VERSION_ID but minor
@@ -436,17 +458,17 @@ bool pal::get_own_executable_path(pal::string_t* recv)
     if (error_code == ENOMEM)
     {
         size_t len = sysctl(mib, 4, NULL, NULL, NULL, 0);
-        std::unique_ptr<char[]> buffer = new (std::nothrow) char[len];
+        std::unique_ptr<char[]> buffer (new (std::nothrow) char[len]);
 
         if (buffer == NULL)
         {
             return false;
         }
 
-        error_code = sysctl(mib, 4, buffer, &len, NULL, 0);
+        error_code = sysctl(mib, 4, buffer.get(), &len, NULL, 0);
         if (error_code == 0)
         {
-            recv->assign(buffer);
+            recv->assign(buffer.get());
             return true;
         }
     }
index b640809..c9ae561 100644 (file)
@@ -61,7 +61,7 @@ namespace Microsoft.DotNet.PlatformAbstractions
                 case Platform.Darwin:
                     return $".{OperatingSystemVersion}";
                 case Platform.FreeBSD:
-                    return $".{OperatingSystemVersion}";
+                    return $".{OperatingSystemVersion.Split('.')[0]}";
                 default:
                     return string.Empty; // Unknown Platform? Unknown Version!
             }
@@ -104,7 +104,7 @@ namespace Microsoft.DotNet.PlatformAbstractions
                 case Platform.Darwin:
                     return "osx";
                 case Platform.FreeBSD:
-                    return "FreeBSD";
+                    return "freebsd";
                 default:
                     return "unknown";
             }