src/Pure/System/platform.scala
author wenzelm
Tue, 26 Jan 2021 22:46:06 +0100
changeset 73439 b8e12e94cfca
parent 72603 e25c0a6cc335
child 73858 37243ad3ecb6
permissions -rw-r--r--
more uniform directory layout for macOS; uniform Isabelle_app executable + lib/scripts/Isabelle_app for Linux and macOS; proper support for Apple "Files and Folders" security via x86_64-darwin executable (which is still able to launch arm64-darwin Java);
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
31825
d47a9dc1f064 moved platform identification to platform.scala;
wenzelm
parents:
diff changeset
     1
/*  Title:      Pure/System/platform.scala
d47a9dc1f064 moved platform identification to platform.scala;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
d47a9dc1f064 moved platform identification to platform.scala;
wenzelm
parents:
diff changeset
     3
69112
5b749aa452c6 misc tuning and modernization;
wenzelm
parents: 64493
diff changeset
     4
System platform identification.
31825
d47a9dc1f064 moved platform identification to platform.scala;
wenzelm
parents:
diff changeset
     5
*/
d47a9dc1f064 moved platform identification to platform.scala;
wenzelm
parents:
diff changeset
     6
d47a9dc1f064 moved platform identification to platform.scala;
wenzelm
parents:
diff changeset
     7
package isabelle
d47a9dc1f064 moved platform identification to platform.scala;
wenzelm
parents:
diff changeset
     8
31828
31584cf201cc sane platform look-and-feel;
wenzelm
parents: 31825
diff changeset
     9
31825
d47a9dc1f064 moved platform identification to platform.scala;
wenzelm
parents:
diff changeset
    10
object Platform
d47a9dc1f064 moved platform identification to platform.scala;
wenzelm
parents:
diff changeset
    11
{
69112
5b749aa452c6 misc tuning and modernization;
wenzelm
parents: 64493
diff changeset
    12
  /* platform family */
31828
31584cf201cc sane platform look-and-feel;
wenzelm
parents: 31825
diff changeset
    13
71592
8313dca6dee9 misc tuning, following hint by IntelliJ;
wenzelm
parents: 69742
diff changeset
    14
  val is_linux: Boolean = System.getProperty("os.name", "") == "Linux"
8313dca6dee9 misc tuning, following hint by IntelliJ;
wenzelm
parents: 69742
diff changeset
    15
  val is_macos: Boolean = System.getProperty("os.name", "") == "Mac OS X"
8313dca6dee9 misc tuning, following hint by IntelliJ;
wenzelm
parents: 69742
diff changeset
    16
  val is_windows: Boolean = System.getProperty("os.name", "").startsWith("Windows")
31825
d47a9dc1f064 moved platform identification to platform.scala;
wenzelm
parents:
diff changeset
    17
69420
c071fcec4323 more explicit Platform.Family;
wenzelm
parents: 69112
diff changeset
    18
  def family: Family.Value =
c071fcec4323 more explicit Platform.Family;
wenzelm
parents: 69112
diff changeset
    19
    if (is_linux) Family.linux
c071fcec4323 more explicit Platform.Family;
wenzelm
parents: 69112
diff changeset
    20
    else if (is_macos) Family.macos
c071fcec4323 more explicit Platform.Family;
wenzelm
parents: 69112
diff changeset
    21
    else if (is_windows) Family.windows
c071fcec4323 more explicit Platform.Family;
wenzelm
parents: 69112
diff changeset
    22
    else error("Failed to determine current platform family")
c071fcec4323 more explicit Platform.Family;
wenzelm
parents: 69112
diff changeset
    23
c071fcec4323 more explicit Platform.Family;
wenzelm
parents: 69112
diff changeset
    24
  object Family extends Enumeration
c071fcec4323 more explicit Platform.Family;
wenzelm
parents: 69112
diff changeset
    25
  {
c071fcec4323 more explicit Platform.Family;
wenzelm
parents: 69112
diff changeset
    26
    val linux, macos, windows = Value
c071fcec4323 more explicit Platform.Family;
wenzelm
parents: 69112
diff changeset
    27
c071fcec4323 more explicit Platform.Family;
wenzelm
parents: 69112
diff changeset
    28
    def unapply(name: String): Option[Value] =
c071fcec4323 more explicit Platform.Family;
wenzelm
parents: 69112
diff changeset
    29
      try { Some(withName(name)) }
c071fcec4323 more explicit Platform.Family;
wenzelm
parents: 69112
diff changeset
    30
      catch { case _: NoSuchElementException => None }
c071fcec4323 more explicit Platform.Family;
wenzelm
parents: 69112
diff changeset
    31
c071fcec4323 more explicit Platform.Family;
wenzelm
parents: 69112
diff changeset
    32
    def parse(name: String): Value =
c071fcec4323 more explicit Platform.Family;
wenzelm
parents: 69112
diff changeset
    33
      unapply(name) getOrElse error("Bad platform family: " + quote(name))
c071fcec4323 more explicit Platform.Family;
wenzelm
parents: 69112
diff changeset
    34
  }
c071fcec4323 more explicit Platform.Family;
wenzelm
parents: 69112
diff changeset
    35
73439
b8e12e94cfca more uniform directory layout for macOS;
wenzelm
parents: 72603
diff changeset
    36
  def standard_platform(platform: Family.Value): String =
b8e12e94cfca more uniform directory layout for macOS;
wenzelm
parents: 72603
diff changeset
    37
    platform match {
b8e12e94cfca more uniform directory layout for macOS;
wenzelm
parents: 72603
diff changeset
    38
      case Platform.Family.linux => "x86_64-linux"
b8e12e94cfca more uniform directory layout for macOS;
wenzelm
parents: 72603
diff changeset
    39
      case Platform.Family.macos => "x86_64-darwin"
b8e12e94cfca more uniform directory layout for macOS;
wenzelm
parents: 72603
diff changeset
    40
      case Platform.Family.windows => "x86_64-cygwin"
b8e12e94cfca more uniform directory layout for macOS;
wenzelm
parents: 72603
diff changeset
    41
    }
b8e12e94cfca more uniform directory layout for macOS;
wenzelm
parents: 72603
diff changeset
    42
31828
31584cf201cc sane platform look-and-feel;
wenzelm
parents: 31825
diff changeset
    43
69112
5b749aa452c6 misc tuning and modernization;
wenzelm
parents: 64493
diff changeset
    44
  /* platform identifiers */
31828
31584cf201cc sane platform look-and-feel;
wenzelm
parents: 31825
diff changeset
    45
69112
5b749aa452c6 misc tuning and modernization;
wenzelm
parents: 64493
diff changeset
    46
  private val X86 = """i.86|x86""".r
5b749aa452c6 misc tuning and modernization;
wenzelm
parents: 64493
diff changeset
    47
  private val X86_64 = """amd64|x86_64""".r
72577
728da67527b9 detect arm64-linux platform;
wenzelm
parents: 72482
diff changeset
    48
  private val Arm64 = """arm64|aarch64""".r
72603
e25c0a6cc335 detect/guess arm32 platform (unsupported);
wenzelm
parents: 72577
diff changeset
    49
  private val Arm32 = """arm""".r
31825
d47a9dc1f064 moved platform identification to platform.scala;
wenzelm
parents:
diff changeset
    50
69742
461f0615faa3 clarified signature;
wenzelm
parents: 69420
diff changeset
    51
  def cpu_arch: String =
461f0615faa3 clarified signature;
wenzelm
parents: 69420
diff changeset
    52
    System.getProperty("os.arch", "") match {
461f0615faa3 clarified signature;
wenzelm
parents: 69420
diff changeset
    53
      case X86() => "x86"
461f0615faa3 clarified signature;
wenzelm
parents: 69420
diff changeset
    54
      case X86_64() => "x86_64"
72577
728da67527b9 detect arm64-linux platform;
wenzelm
parents: 72482
diff changeset
    55
      case Arm64() => "arm64"
72603
e25c0a6cc335 detect/guess arm32 platform (unsupported);
wenzelm
parents: 72577
diff changeset
    56
      case Arm32() => "arm32"
69742
461f0615faa3 clarified signature;
wenzelm
parents: 69420
diff changeset
    57
      case _ => error("Failed to determine CPU architecture")
461f0615faa3 clarified signature;
wenzelm
parents: 69420
diff changeset
    58
    }
461f0615faa3 clarified signature;
wenzelm
parents: 69420
diff changeset
    59
461f0615faa3 clarified signature;
wenzelm
parents: 69420
diff changeset
    60
  def os_name: String =
461f0615faa3 clarified signature;
wenzelm
parents: 69420
diff changeset
    61
    family match {
461f0615faa3 clarified signature;
wenzelm
parents: 69420
diff changeset
    62
      case Family.macos => "darwin"
461f0615faa3 clarified signature;
wenzelm
parents: 69420
diff changeset
    63
      case _ => family.toString
461f0615faa3 clarified signature;
wenzelm
parents: 69420
diff changeset
    64
    }
461f0615faa3 clarified signature;
wenzelm
parents: 69420
diff changeset
    65
461f0615faa3 clarified signature;
wenzelm
parents: 69420
diff changeset
    66
  lazy val jvm_platform: String = cpu_arch + "-" + os_name
31828
31584cf201cc sane platform look-and-feel;
wenzelm
parents: 31825
diff changeset
    67
31584cf201cc sane platform look-and-feel;
wenzelm
parents: 31825
diff changeset
    68
61002
ea38a1922a0b more version information;
wenzelm
parents: 55618
diff changeset
    69
  /* JVM version */
ea38a1922a0b more version information;
wenzelm
parents: 55618
diff changeset
    70
69112
5b749aa452c6 misc tuning and modernization;
wenzelm
parents: 64493
diff changeset
    71
  private val Version = """1\.(\d+)\.0_(\d+)""".r
71592
8313dca6dee9 misc tuning, following hint by IntelliJ;
wenzelm
parents: 69742
diff changeset
    72
  lazy val jvm_version: String =
61002
ea38a1922a0b more version information;
wenzelm
parents: 55618
diff changeset
    73
    System.getProperty("java.version") match {
ea38a1922a0b more version information;
wenzelm
parents: 55618
diff changeset
    74
      case Version(a, b) => a + "u" + b
ea38a1922a0b more version information;
wenzelm
parents: 55618
diff changeset
    75
      case a => a
ea38a1922a0b more version information;
wenzelm
parents: 55618
diff changeset
    76
    }
ea38a1922a0b more version information;
wenzelm
parents: 55618
diff changeset
    77
ea38a1922a0b more version information;
wenzelm
parents: 55618
diff changeset
    78
41381
77990a6cd558 more explicit jvm_name;
wenzelm
parents: 36786
diff changeset
    79
  /* JVM name */
77990a6cd558 more explicit jvm_name;
wenzelm
parents: 36786
diff changeset
    80
53582
8533b4cb8dd7 more robust System.getProperty with default;
wenzelm
parents: 51617
diff changeset
    81
  val jvm_name: String = System.getProperty("java.vm.name", "")
31825
d47a9dc1f064 moved platform identification to platform.scala;
wenzelm
parents:
diff changeset
    82
}