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;
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
64493
a2eebcc8bb69 clarified platform selection;
wenzelm
parents: 64370
diff changeset
    14
  val is_linux = System.getProperty("os.name", "") == "Linux"
53582
8533b4cb8dd7 more robust System.getProperty with default;
wenzelm
parents: 51617
diff changeset
    15
  val is_macos = System.getProperty("os.name", "") == "Mac OS X"
8533b4cb8dd7 more robust System.getProperty with default;
wenzelm
parents: 51617
diff changeset
    16
  val is_windows = System.getProperty("os.name", "").startsWith("Windows")
31825
d47a9dc1f064 moved platform identification to platform.scala;
wenzelm
parents:
diff changeset
    17
31828
31584cf201cc sane platform look-and-feel;
wenzelm
parents: 31825
diff changeset
    18
69112
5b749aa452c6 misc tuning and modernization;
wenzelm
parents: 64493
diff changeset
    19
  /* platform identifiers */
31828
31584cf201cc sane platform look-and-feel;
wenzelm
parents: 31825
diff changeset
    20
69112
5b749aa452c6 misc tuning and modernization;
wenzelm
parents: 64493
diff changeset
    21
  private val Linux = """Linux""".r
5b749aa452c6 misc tuning and modernization;
wenzelm
parents: 64493
diff changeset
    22
  private val Darwin = """Mac OS X""".r
5b749aa452c6 misc tuning and modernization;
wenzelm
parents: 64493
diff changeset
    23
  private val Windows = """Windows.*""".r
31825
d47a9dc1f064 moved platform identification to platform.scala;
wenzelm
parents:
diff changeset
    24
69112
5b749aa452c6 misc tuning and modernization;
wenzelm
parents: 64493
diff changeset
    25
  private val X86 = """i.86|x86""".r
5b749aa452c6 misc tuning and modernization;
wenzelm
parents: 64493
diff changeset
    26
  private val X86_64 = """amd64|x86_64""".r
31825
d47a9dc1f064 moved platform identification to platform.scala;
wenzelm
parents:
diff changeset
    27
36205
e86d9a10e982 check JVM platform at most once -- still non-strict to prevent potential failure during initialization of object Platform;
wenzelm
parents: 36195
diff changeset
    28
  lazy val jvm_platform: String =
31825
d47a9dc1f064 moved platform identification to platform.scala;
wenzelm
parents:
diff changeset
    29
  {
36195
9c098598db2a system properties determine the JVM platform, not the Isabelle one;
wenzelm
parents: 35002
diff changeset
    30
    val arch =
53582
8533b4cb8dd7 more robust System.getProperty with default;
wenzelm
parents: 51617
diff changeset
    31
      System.getProperty("os.arch", "") match {
36195
9c098598db2a system properties determine the JVM platform, not the Isabelle one;
wenzelm
parents: 35002
diff changeset
    32
        case X86() => "x86"
9c098598db2a system properties determine the JVM platform, not the Isabelle one;
wenzelm
parents: 35002
diff changeset
    33
        case X86_64() => "x86_64"
9c098598db2a system properties determine the JVM platform, not the Isabelle one;
wenzelm
parents: 35002
diff changeset
    34
        case _ => error("Failed to determine CPU architecture")
9c098598db2a system properties determine the JVM platform, not the Isabelle one;
wenzelm
parents: 35002
diff changeset
    35
      }
9c098598db2a system properties determine the JVM platform, not the Isabelle one;
wenzelm
parents: 35002
diff changeset
    36
    val os =
53582
8533b4cb8dd7 more robust System.getProperty with default;
wenzelm
parents: 51617
diff changeset
    37
      System.getProperty("os.name", "") match {
36195
9c098598db2a system properties determine the JVM platform, not the Isabelle one;
wenzelm
parents: 35002
diff changeset
    38
        case Linux() => "linux"
9c098598db2a system properties determine the JVM platform, not the Isabelle one;
wenzelm
parents: 35002
diff changeset
    39
        case Darwin() => "darwin"
9c098598db2a system properties determine the JVM platform, not the Isabelle one;
wenzelm
parents: 35002
diff changeset
    40
        case Windows() => "windows"
9c098598db2a system properties determine the JVM platform, not the Isabelle one;
wenzelm
parents: 35002
diff changeset
    41
        case _ => error("Failed to determine operating system platform")
9c098598db2a system properties determine the JVM platform, not the Isabelle one;
wenzelm
parents: 35002
diff changeset
    42
      }
9c098598db2a system properties determine the JVM platform, not the Isabelle one;
wenzelm
parents: 35002
diff changeset
    43
    arch + "-" + os
31825
d47a9dc1f064 moved platform identification to platform.scala;
wenzelm
parents:
diff changeset
    44
  }
31828
31584cf201cc sane platform look-and-feel;
wenzelm
parents: 31825
diff changeset
    45
31584cf201cc sane platform look-and-feel;
wenzelm
parents: 31825
diff changeset
    46
61001
ea38a1922a0b more version information;
wenzelm
parents: 55618
diff changeset
    47
  /* JVM version */
ea38a1922a0b more version information;
wenzelm
parents: 55618
diff changeset
    48
69112
5b749aa452c6 misc tuning and modernization;
wenzelm
parents: 64493
diff changeset
    49
  private val Version = """1\.(\d+)\.0_(\d+)""".r
61001
ea38a1922a0b more version information;
wenzelm
parents: 55618
diff changeset
    50
  lazy val jvm_version =
ea38a1922a0b more version information;
wenzelm
parents: 55618
diff changeset
    51
    System.getProperty("java.version") match {
ea38a1922a0b more version information;
wenzelm
parents: 55618
diff changeset
    52
      case Version(a, b) => a + "u" + b
ea38a1922a0b more version information;
wenzelm
parents: 55618
diff changeset
    53
      case a => a
ea38a1922a0b more version information;
wenzelm
parents: 55618
diff changeset
    54
    }
ea38a1922a0b more version information;
wenzelm
parents: 55618
diff changeset
    55
ea38a1922a0b more version information;
wenzelm
parents: 55618
diff changeset
    56
41381
77990a6cd558 more explicit jvm_name;
wenzelm
parents: 36786
diff changeset
    57
  /* JVM name */
77990a6cd558 more explicit jvm_name;
wenzelm
parents: 36786
diff changeset
    58
53582
8533b4cb8dd7 more robust System.getProperty with default;
wenzelm
parents: 51617
diff changeset
    59
  val jvm_name: String = System.getProperty("java.vm.name", "")
31825
d47a9dc1f064 moved platform identification to platform.scala;
wenzelm
parents:
diff changeset
    60
}