efabb12ce55595a8abb78ec595ae1fa732067574
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]
33 def recursive_inline(f
, input_name
, depth
):
34 assert depth
< 10, "probably found an [[!inline]]-loop"
35 skip
= False # found the pattern <!-- hide -->
36 for line
in f
.readlines():
39 if line
.startswith("<!-- show -->"):
42 elif line
.startswith("<!-- hide -->"):
45 # fix separation in comparison table
46 if input_name
.endswith("comparison_table.tex") and \
47 line
.startswith("\begin{itemize}"):
49 o
.write("\\itemsep -0.3em\n")
52 if not line
.startswith("[[!inline"):
56 # assume first thing is pagename
57 line
= line
.split('"')
59 print(f
"\tdepth={depth}: {fname}")
60 if fname
.endswith(".py"):
61 if fname
.startswith("gf_reference"):
63 wiki_path
+ "/../nmigen-gf/" + fname
) as inc
:
64 recursive_inline(inc
, fname
, depth
+ 1)
66 with
open_tracked(wiki_path
+ "/" + fname
) as inc
:
67 recursive_inline(inc
, fname
, depth
+ 1)
69 if fname
.endswith(".mdwn"):
70 with
open_tracked(wiki_path
+ "/" + fname
) as inc
:
71 recursive_inline(inc
, fname
, depth
+ 1)
72 elif fname
== 'openpower/isatables/fields.text':
74 wiki_path
+ "/../openpower-isa/" + fname
) as inc
:
75 recursive_inline(inc
, fname
, depth
+ 1)
77 with
open_tracked(wiki_path
+ "/" + fname
+ ".mdwn") as inc
:
78 recursive_inline(inc
, fname
, depth
+ 1)
81 def body(o
, print=print):
82 with
open_tracked(sys
.argv
[1], "r") as f
:
83 recursive_inline(f
, sys
.argv
[1], 0)
87 body(o
, print=lambda *_
: None)
88 deps_file
= output_file
+ '.d'
89 with
open(deps_file
, "w") as o
:
90 deps
= " ".join(opened_files
)
91 o
.write(f
"{output_file} {deps_file}: {deps}\n")
93 with
open(temp_output_file
, "w") as o
:
95 os
.rename(temp_output_file
, output_file
)