| author | wenzelm | 
| Tue, 14 Mar 2017 16:20:07 +0100 | |
| changeset 65232 | ca571c8c0788 | 
| parent 64610 | 1b89608974e9 | 
| child 65822 | 17b8528c2f53 | 
| permissions | -rw-r--r-- | 
| 64161 | 1 | /* Title: Pure/Admin/check_sources.scala | 
| 56791 | 2 | Author: Makarius | 
| 3 | ||
| 4 | Some sanity checks for Isabelle sources. | |
| 5 | */ | |
| 6 | ||
| 7 | package isabelle | |
| 8 | ||
| 9 | ||
| 62452 | 10 | object Check_Sources | 
| 56791 | 11 | {
 | 
| 12 | def check_file(path: Path) | |
| 13 |   {
 | |
| 14 | val file_name = path.implode | |
| 15 | val file_pos = path.position | |
| 16 | def line_pos(i: Int) = Position.Line_File(i + 1, file_name) | |
| 17 | ||
| 64324 
416f4d031afd
check Windows file names, e.g. relavant for native Mercurial, but also for Isabelle/Scala;
 wenzelm parents: 
64162diff
changeset | 18 |     if (space_explode('/', Word.lowercase(path.expand.split_ext._1.implode)).contains("aux"))
 | 
| 
416f4d031afd
check Windows file names, e.g. relavant for native Mercurial, but also for Isabelle/Scala;
 wenzelm parents: 
64162diff
changeset | 19 |       Output.warning("Illegal file-name on Windows" + Position.here(file_pos))
 | 
| 
416f4d031afd
check Windows file names, e.g. relavant for native Mercurial, but also for Isabelle/Scala;
 wenzelm parents: 
64162diff
changeset | 20 | |
| 56791 | 21 | val content = File.read(path) | 
| 22 | ||
| 23 |     for { (line, i) <- split_lines(content).iterator.zipWithIndex }
 | |
| 24 |     {
 | |
| 25 |       try {
 | |
| 26 | Symbol.decode_strict(line) | |
| 27 | ||
| 64610 | 28 |         for { c <- Codepoint.iterator(line); if c > 128 && !Character.isAlphabetic(c) }
 | 
| 56791 | 29 |         {
 | 
| 64610 | 30 |           Output.warning("Suspicious Unicode character " + quote(Codepoint.string(c)) +
 | 
| 56791 | 31 | Position.here(line_pos(i))) | 
| 32 | } | |
| 33 | } | |
| 62814 | 34 |       catch { case ERROR(msg) => Output.warning(msg + Position.here(line_pos(i))) }
 | 
| 56791 | 35 | |
| 36 |       if (line.contains('\t'))
 | |
| 56792 | 37 |         Output.warning("TAB character" + Position.here(line_pos(i)))
 | 
| 56791 | 38 | } | 
| 39 | ||
| 40 |     if (content.contains('\r'))
 | |
| 56792 | 41 |       Output.warning("CR character" + Position.here(file_pos))
 | 
| 62814 | 42 | |
| 43 | if (Word.bidi_detect(content)) | |
| 64368 | 44 |       Output.warning("Bidirectional Unicode text" + Position.here(file_pos))
 | 
| 56791 | 45 | } | 
| 56829 | 46 | |
| 47 | def check_hg(root: Path) | |
| 48 |   {
 | |
| 56830 
e760242101fc
tuned signature -- channels for diagnostic output for system tools means stderr;
 wenzelm parents: 
56829diff
changeset | 49 |     Output.writeln("Checking " + root + " ...")
 | 
| 64162 | 50 | val hg = Mercurial.repository(root) | 
| 51 |     for {
 | |
| 52 | file <- hg.manifest() | |
| 53 |       if file.endsWith(".thy") || file.endsWith(".ML") || file.endsWith("/ROOT")
 | |
| 54 | } check_file(root + Path.explode(file)) | |
| 56829 | 55 | } | 
| 56 | ||
| 57 | ||
| 62834 | 58 | /* Isabelle tool wrapper */ | 
| 56829 | 59 | |
| 62834 | 60 | val isabelle_tool = | 
| 61 |     Isabelle_Tool("check_sources", "some sanity checks for Isabelle sources", args =>
 | |
| 62 |     {
 | |
| 62454 | 63 |       val getopts = Getopts("""
 | 
| 62452 | 64 | Usage: isabelle check_sources [ROOT_DIRS...] | 
| 65 | ||
| 66 | Check .thy, .ML, ROOT files from manifest of Mercurial ROOT_DIRS. | |
| 67 | """) | |
| 68 | ||
| 69 | val specs = getopts(args) | |
| 70 | if (specs.isEmpty) getopts.usage() | |
| 71 | ||
| 72 | for (root <- specs) check_hg(Path.explode(root)) | |
| 64161 | 73 | }, admin = true) | 
| 56791 | 74 | } |