15
15
#include " MultiPageVisitor.hpp"
16
16
#include " SinglePageVisitor.hpp"
17
17
#include " lib/Support/LegibleNames.hpp"
18
+ #include " lib/Support/RawOstream.hpp"
19
+ #include < llvm/Support/FileSystem.h>
20
+ #include < llvm/Support/Path.h>
18
21
#include < mrdocs/Metadata/DomMetadata.hpp>
19
22
#include < mrdocs/Support/Error.hpp>
20
23
#include < mrdocs/Support/Path.hpp>
24
+ #include < fstream>
21
25
#include < optional>
22
26
#include < vector>
23
27
@@ -70,10 +74,35 @@ build(
70
74
if (! ex)
71
75
return ex.error ();
72
76
73
- MultiPageVisitor visitor (*ex, outputPath, corpus);
77
+ std::string path = files::appendPath (outputPath, " reference.tag.xml" );
78
+ if (auto err = files::createDirectory (outputPath))
79
+ {
80
+ return err;
81
+ }
82
+
83
+ std::ofstream os;
84
+ try
85
+ {
86
+ os.open (path,
87
+ std::ios_base::binary |
88
+ std::ios_base::out |
89
+ std::ios_base::trunc // | std::ios_base::noreplace
90
+ );
91
+ }
92
+ catch (std::exception const & ex)
93
+ {
94
+ return formatError (" std::ofstream(\" {}\" ) threw \" {}\" " , path, ex.what ());
95
+ }
96
+
97
+ RawOstream raw_os (os);
98
+ auto tagfileWriter = TagfileWriter (raw_os, corpus);
99
+ tagfileWriter.initialize ();
100
+
101
+ MultiPageVisitor visitor (*ex, outputPath, corpus, tagfileWriter);
74
102
visitor (corpus.globalNamespace ());
75
103
76
104
auto errors = ex->wait ();
105
+ tagfileWriter.finalize ();
77
106
if (! errors.empty ())
78
107
return Error (errors);
79
108
return Error::success ();
@@ -83,8 +112,12 @@ Error
83
112
AdocGenerator::
84
113
buildOne (
85
114
std::ostream& os,
86
- Corpus const & corpus) const
115
+ Corpus const & corpus,
116
+ std::string_view outputPath) const
87
117
{
118
+ namespace path = llvm::sys::path;
119
+ using SmallString = llvm::SmallString<0 >;
120
+
88
121
auto options = loadOptions (corpus);
89
122
if (! options)
90
123
return options.error ();
@@ -106,9 +139,38 @@ buildOne(
106
139
if (! errors.empty ())
107
140
return {errors};
108
141
109
- SinglePageVisitor visitor (*ex, corpus, os);
142
+ SmallString fileName (outputPath);
143
+ path::replace_extension (fileName, " tag.xml" );
144
+ auto parentDir = files::getParentDir (fileName.str ());
145
+ if (auto err = files::createDirectory (parentDir))
146
+ {
147
+ return err;
148
+ }
149
+
150
+ std::ofstream osTagfile;
151
+ try
152
+ {
153
+ osTagfile.open (fileName.str ().str (),
154
+ std::ios_base::binary |
155
+ std::ios_base::out |
156
+ std::ios_base::trunc // | std::ios_base::noreplace
157
+ );
158
+ }
159
+ catch (std::exception const & ex)
160
+ {
161
+ return formatError (" std::ofstream(\" {}\" ) threw \" {}\" " , fileName.str ().str (), ex.what ());
162
+ }
163
+
164
+ RawOstream raw_os (osTagfile);
165
+ auto tagfileWriter = TagfileWriter (raw_os, corpus);
166
+ tagfileWriter.initialize ();
167
+
168
+
169
+ auto const justFileName = path::filename (fileName);
170
+ SinglePageVisitor visitor (*ex, corpus, os, justFileName, tagfileWriter);
110
171
visitor (corpus.globalNamespace ());
111
172
errors = ex->wait ();
173
+ tagfileWriter.finalize ();
112
174
if (! errors.empty ())
113
175
return {errors};
114
176
0 commit comments