src/Pure/System/build.scala
author wenzelm
Tue Jul 17 22:34:29 2012 +0200 (2012-07-17)
changeset 48280 7d86239986c2
parent 48276 4bd480886813
child 48334 8dff9933e72a
permissions -rw-r--r--
basic support for session ROOT files, with examples for FOL and ZF;
wenzelm@48276
     1
/*  Title:      Pure/System/build.scala
wenzelm@48276
     2
    Author:     Makarius
wenzelm@48276
     3
wenzelm@48276
     4
Build and manage Isabelle sessions.
wenzelm@48276
     5
*/
wenzelm@48276
     6
wenzelm@48276
     7
package isabelle
wenzelm@48276
     8
wenzelm@48276
     9
wenzelm@48276
    10
object Build
wenzelm@48276
    11
{
wenzelm@48276
    12
  /* command line entry point */
wenzelm@48276
    13
wenzelm@48276
    14
  private object Bool
wenzelm@48276
    15
  {
wenzelm@48276
    16
    def unapply(s: String): Option[Boolean] =
wenzelm@48276
    17
      s match {
wenzelm@48276
    18
        case "true" => Some(true)
wenzelm@48276
    19
        case "false" => Some(false)
wenzelm@48276
    20
        case _ => None
wenzelm@48276
    21
      }
wenzelm@48276
    22
  }
wenzelm@48276
    23
wenzelm@48276
    24
  def main(args: Array[String])
wenzelm@48276
    25
  {
wenzelm@48276
    26
    def bad_args()
wenzelm@48276
    27
    {
wenzelm@48276
    28
      java.lang.System.err.println("Bad arguments: " + args.toString)
wenzelm@48276
    29
      sys.exit(2)
wenzelm@48276
    30
    }
wenzelm@48276
    31
wenzelm@48276
    32
    args.toList match {
wenzelm@48276
    33
      case Bool(all_sessions) :: Bool(build_images) :: Bool(list_only) :: rest =>
wenzelm@48276
    34
        rest.indexWhere(_ == "\n") match {
wenzelm@48276
    35
          case -1 => bad_args()
wenzelm@48276
    36
          case i =>
wenzelm@48276
    37
            val (options, rest1) = rest.splitAt(i)
wenzelm@48276
    38
            val sessions = rest1.tail
wenzelm@48276
    39
            val rc = build(all_sessions, build_images, list_only, options, sessions)
wenzelm@48276
    40
            sys.exit(rc)
wenzelm@48276
    41
        }
wenzelm@48276
    42
      case _ => bad_args()
wenzelm@48276
    43
    }
wenzelm@48276
    44
  }
wenzelm@48276
    45
wenzelm@48276
    46
wenzelm@48276
    47
  /* build */
wenzelm@48276
    48
wenzelm@48276
    49
  def build(all_sessions: Boolean, build_images: Boolean, list_only: Boolean,
wenzelm@48276
    50
    options: List[String], sessions: List[String]): Int =
wenzelm@48276
    51
  {
wenzelm@48276
    52
    val rc = 1
wenzelm@48276
    53
wenzelm@48276
    54
    println("options = " + options.toString)
wenzelm@48276
    55
    println("sessions = " + sessions.toString)
wenzelm@48276
    56
wenzelm@48276
    57
    rc
wenzelm@48276
    58
  }
wenzelm@48280
    59
wenzelm@48280
    60
wenzelm@48280
    61
  /* session information */
wenzelm@48280
    62
wenzelm@48280
    63
  case class Session_Info(
wenzelm@48280
    64
    val dir: Path,
wenzelm@48280
    65
    val text: String)
wenzelm@48280
    66
wenzelm@48280
    67
  val ROOT_NAME = "ROOT"
wenzelm@48280
    68
wenzelm@48280
    69
  def find_sessions(): List[Session_Info] =
wenzelm@48280
    70
  {
wenzelm@48280
    71
    for {
wenzelm@48280
    72
      dir <- Isabelle_System.components()
wenzelm@48280
    73
      root = Isabelle_System.platform_file(dir + Path.basic(ROOT_NAME))
wenzelm@48280
    74
      if root.isFile
wenzelm@48280
    75
    }
wenzelm@48280
    76
    yield Session_Info(dir, Standard_System.read_file(root))
wenzelm@48280
    77
  }
wenzelm@48276
    78
}
wenzelm@48276
    79