src/Pure/System/platform.scala
author wenzelm
Wed, 03 Oct 2018 12:27:39 +0200
changeset 69112 5b749aa452c6
parent 64493 a2eebcc8bb69
child 69410 c071fcec4323
permissions -rw-r--r--
misc tuning and modernization;

/*  Title:      Pure/System/platform.scala
    Author:     Makarius

System platform identification.
*/

package isabelle


object Platform
{
  /* platform family */

  val is_linux = System.getProperty("os.name", "") == "Linux"
  val is_macos = System.getProperty("os.name", "") == "Mac OS X"
  val is_windows = System.getProperty("os.name", "").startsWith("Windows")


  /* platform identifiers */

  private val Linux = """Linux""".r
  private val Darwin = """Mac OS X""".r
  private val Windows = """Windows.*""".r

  private val X86 = """i.86|x86""".r
  private val X86_64 = """amd64|x86_64""".r

  lazy val jvm_platform: String =
  {
    val arch =
      System.getProperty("os.arch", "") match {
        case X86() => "x86"
        case X86_64() => "x86_64"
        case _ => error("Failed to determine CPU architecture")
      }
    val os =
      System.getProperty("os.name", "") match {
        case Linux() => "linux"
        case Darwin() => "darwin"
        case Windows() => "windows"
        case _ => error("Failed to determine operating system platform")
      }
    arch + "-" + os
  }


  /* JVM version */

  private val Version = """1\.(\d+)\.0_(\d+)""".r
  lazy val jvm_version =
    System.getProperty("java.version") match {
      case Version(a, b) => a + "u" + b
      case a => a
    }


  /* JVM name */

  val jvm_name: String = System.getProperty("java.vm.name", "")
}