src/Pure/System/mingw.scala
author wenzelm
Sat, 10 Oct 2020 21:04:49 +0200
changeset 72424 10c07d224035
parent 72421 9a8bc089890d
child 72425 d0937d55eb90
permissions -rw-r--r--
tuned signature;

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

Support for MSYS2/MinGW64 on Windows.
*/

package isabelle


object MinGW
{
  def environment: List[(String, String)] =
    List("PATH" -> "/usr/bin:/bin:/mingw64/bin", "CONFIG_SITE" -> "/mingw64/etc/config.site")

  def environment_prefix: String =
    (for ((a, b) <- environment) yield Bash.string(a) + "=" + Bash.string(b))
      .mkString("/usr/bin/env ", " ", " ")

  val none: MinGW = new MinGW(None)
  def root(path: Path) = new MinGW(Some(path))
}

class MinGW private(val root: Option[Path])
{
  override def toString: String =
    root match {
      case None => "MinGW.none"
      case Some(msys_root) => "MinGW.root(" + msys_root.toString + ")"
    }

  def bash_command(command: String): String =
    root match {
      case None => command
      case Some(msys_root) =>
        File.bash_path(msys_root + Path.explode("usr/bin/bash")) +
          " -c " + Bash.string(MinGW.environment_prefix + command)
    }

  def get_root: Path =
    if (!Platform.is_windows) error("Windows platform required")
    else if (root.isEmpty) error("Windows platform needs specification of msys root directory")
    else root.get

  def check
  {
    if (Platform.is_windows) {
      get_root
      val result = Isabelle_System.bash(bash_command("uname -s")).check
      if (!result.out.startsWith("MSYS")) error("Bad msys installation " + get_root)
    }
  }
}