-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdafnydep
executable file
·46 lines (36 loc) · 1.17 KB
/
dafnydep
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python3
import re
import sys
from os import path
from typing import List
INCLUDE_RE = re.compile(
r"""^\s* # leading whitespace
include \s+
"(?P<path>.*)"
$""",
re.VERBOSE,
)
def get_includes(fname: str) -> List[str]:
"""Parse Dafny file `fname` for include directives."""
includes = []
with open(fname, "r") as f:
for line in f:
m = INCLUDE_RE.search(line)
if m:
includes.append(m.group("path"))
return includes
def relativize(fname: str, include: str) -> str:
"""Resolve `include` to a normalized path, based on the directory of `fname`."""
working_dir = path.dirname(fname)
p = path.join(working_dir, include)
return path.normpath(p)
def dependency_list(fname: str, includes: List[str]) -> str:
"""Return list of dependencies for `fname` from raw include paths
`includes`."""
includes = [relativize(fname, include) + ".ok" for include in includes]
return " ".join(includes)
print("# auto-generated by ./etc/dafnydep")
for fname in sys.argv[1:]:
includes = get_includes(fname)
deps = dependency_list(fname, includes)
print("{}.ok: {}".format(fname, deps))