author | wenzelm |
Sun, 14 May 2017 15:34:20 +0200 | |
changeset 65822 | 17b8528c2f53 |
parent 64610 | 1b89608974e9 |
child 69277 | 258bef08b31e |
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:
64162
diff
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:
64162
diff
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:
64162
diff
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:
56829
diff
changeset
|
49 |
Output.writeln("Checking " + root + " ...") |
64162 | 50 |
val hg = Mercurial.repository(root) |
51 |
for { |
|
65822
17b8528c2f53
clarified notion of known files (before actual commit);
wenzelm
parents:
64610
diff
changeset
|
52 |
file <- hg.known_files() |
64162 | 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 |
||
65822
17b8528c2f53
clarified notion of known files (before actual commit);
wenzelm
parents:
64610
diff
changeset
|
66 |
Check .thy, .ML, ROOT against known files of Mercurial ROOT_DIRS. |
62452 | 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 |
} |