src/Pure/System/platform.scala
changeset 73893 f3a356c64193
parent 73858 37243ad3ecb6
child 73894 a6a9162f3ec1
equal deleted inserted replaced
73892:6945ac084763 73893:f3a356c64193
    14   val is_linux: Boolean = System.getProperty("os.name", "") == "Linux"
    14   val is_linux: Boolean = System.getProperty("os.name", "") == "Linux"
    15   val is_macos: Boolean = System.getProperty("os.name", "") == "Mac OS X"
    15   val is_macos: Boolean = System.getProperty("os.name", "") == "Mac OS X"
    16   val is_windows: Boolean = System.getProperty("os.name", "").startsWith("Windows")
    16   val is_windows: Boolean = System.getProperty("os.name", "").startsWith("Windows")
    17   val is_unix: Boolean = is_linux || is_macos
    17   val is_unix: Boolean = is_linux || is_macos
    18 
    18 
       
    19   def is_arm: Boolean = cpu_arch.startsWith("arm")
       
    20 
    19   def family: Family.Value =
    21   def family: Family.Value =
    20     if (is_linux) Family.linux
    22     if (is_linux && is_arm) Family.linux_arm
       
    23     else if (is_linux) Family.linux
    21     else if (is_macos) Family.macos
    24     else if (is_macos) Family.macos
    22     else if (is_windows) Family.windows
    25     else if (is_windows) Family.windows
    23     else error("Failed to determine current platform family")
    26     else error("Failed to determine current platform family")
    24 
    27 
    25   object Family extends Enumeration
    28   object Family extends Enumeration
    26   {
    29   {
    27     val linux, macos, windows = Value
    30     val linux_arm, linux, macos, windows = Value
       
    31     val list: List[Value] = List(linux_arm, linux, windows, macos)
    28 
    32 
    29     def unapply(name: String): Option[Value] =
    33     def unapply(name: String): Option[Value] =
    30       try { Some(withName(name)) }
    34       try { Some(withName(name)) }
    31       catch { case _: NoSuchElementException => None }
    35       catch { case _: NoSuchElementException => None }
    32 
    36 
    33     def parse(name: String): Value =
    37     def parse(name: String): Value =
    34       unapply(name) getOrElse error("Bad platform family: " + quote(name))
    38       unapply(name) getOrElse error("Bad platform family: " + quote(name))
       
    39 
       
    40     def standard(platform: Value): String =
       
    41       if (platform == linux_arm) "arm64-linux"
       
    42       else if (platform == linux) "x86_64-linux"
       
    43       else if (platform == macos) "x86_64-darwin"
       
    44       else if (platform == windows) "x86_64-cygwin"
       
    45       else error("Unknown platform family " + quote(platform.toString))
    35   }
    46   }
    36 
       
    37   def standard_platform(platform: Family.Value): String =
       
    38     platform match {
       
    39       case Platform.Family.linux => "x86_64-linux"
       
    40       case Platform.Family.macos => "x86_64-darwin"
       
    41       case Platform.Family.windows => "x86_64-cygwin"
       
    42     }
       
    43 
    47 
    44 
    48 
    45   /* platform identifiers */
    49   /* platform identifiers */
    46 
    50 
    47   private val X86 = """i.86|x86""".r
    51   private val X86 = """i.86|x86""".r