src/Pure/System/mingw.scala
changeset 72421 9a8bc089890d
child 72424 10c07d224035
equal deleted inserted replaced
72420:f6fc180e1cbd 72421:9a8bc089890d
       
     1 /*  Title:      Pure/System/mingw.scala
       
     2     Author:     Makarius
       
     3 
       
     4 Support for MSYS2/MinGW64 on Windows.
       
     5 */
       
     6 
       
     7 package isabelle
       
     8 
       
     9 
       
    10 object MinGW
       
    11 {
       
    12   val none: Context = new Context(None)
       
    13   def context(root: Path) = new Context(Some(root))
       
    14 
       
    15   def environment: List[(String, String)] =
       
    16     List("PATH" -> "/usr/bin:/bin:/mingw64/bin", "CONFIG_SITE" -> "/mingw64/etc/config.site")
       
    17 
       
    18   def environment_prefix: String =
       
    19     (for ((a, b) <- environment) yield Bash.string(a) + "=" + Bash.string(b))
       
    20       .mkString("/usr/bin/env ", " ", " ")
       
    21 
       
    22   class Context private[MinGW](val root: Option[Path])
       
    23   {
       
    24     override def toString: String =
       
    25       root match {
       
    26         case None => "MinGW.none"
       
    27         case Some(msys_root) => "MinGW.context(" + msys_root.toString + ")"
       
    28       }
       
    29 
       
    30     def bash_command(command: String): String =
       
    31       root match {
       
    32         case None => command
       
    33         case Some(msys_root) =>
       
    34           File.bash_path(msys_root + Path.explode("usr/bin/bash")) +
       
    35             " -c " + Bash.string(environment_prefix + command)
       
    36       }
       
    37 
       
    38     def get_root: Path =
       
    39       if (!Platform.is_windows) error("Windows platform required")
       
    40       else if (root.isEmpty) error("Windows platform needs specification of msys root directory")
       
    41       else root.get
       
    42 
       
    43     def check
       
    44     {
       
    45       if (Platform.is_windows) {
       
    46         get_root
       
    47         val result = Isabelle_System.bash(bash_command("uname -s")).check
       
    48         if (!result.out.startsWith("MSYS")) error("Bad msys installation " + get_root)
       
    49       }
       
    50     }
       
    51   }
       
    52 }