4 from io
import StringIO
6 deps_only
= sys
.argv
[1] == '--deps'
13 def open_tracked(name
, mode
='r'):
14 opened_files
.append(name
)
16 return open(name
, mode
)
17 except FileNotFoundError
:
22 output_file
= sys
.argv
[2]
24 os
.remove(output_file
)
25 except FileNotFoundError
:
27 temp_output_file
= output_file
+ '.tmp'
28 file_path
= os
.path
.abspath(__file__
)
29 openpower_path
= os
.path
.split(file_path
)[0]
30 wiki_path
= os
.path
.split(openpower_path
)[0]
31 def body(o
, print=print):
32 def recursive_inline(f
, input_name
, depth
):
33 assert depth
< 10, "probably found an [[!inline]]-loop"
34 for line
in f
.readlines():
35 if input_name
.endswith("comparison_table.tex") and \
36 line
.startswith("\begin{itemize}"):
38 o
.write("\\itemsep -0.3em\n")
40 if not line
.startswith("[[!inline"):
44 # assume first thing is pagename
45 line
= line
.split('"')
47 print(f
"\tdepth={depth}: {fname}")
48 if fname
.endswith(".py"):
49 if fname
.startswith("gf_reference"):
51 wiki_path
+ "/../nmigen-gf/" + fname
) as inc
:
52 recursive_inline(inc
, fname
, depth
+ 1)
54 with
open_tracked(wiki_path
+ "/" + fname
) as inc
:
55 recursive_inline(inc
, fname
, depth
+ 1)
57 if fname
.endswith(".mdwn"):
58 with
open_tracked(wiki_path
+ "/" + fname
) as inc
:
59 recursive_inline(inc
, fname
, depth
+ 1)
60 elif fname
== 'openpower/isatables/fields.text':
62 wiki_path
+ "/../openpower-isa/" + fname
) as inc
:
63 recursive_inline(inc
, fname
, depth
+ 1)
66 wiki_path
+ "/" + fname
+ ".mdwn") as inc
:
67 recursive_inline(inc
, fname
, depth
+ 1)
69 with
open_tracked(sys
.argv
[1], "r") as f
:
70 recursive_inline(f
, sys
.argv
[1], 0)
74 body(o
, print=lambda *_
: None)
75 deps_file
= output_file
+ '.d'
76 with
open(deps_file
, "w") as o
:
77 deps
= " ".join(opened_files
)
78 o
.write(f
"{output_file} {deps_file}: {deps}\n")
80 with
open(temp_output_file
, "w") as o
:
82 os
.rename(temp_output_file
, output_file
)