|
1 | | -fs = import('fs') |
2 | | - |
3 | 1 | maybe_fmt_dep = dependency( |
4 | 2 | 'fmt', |
5 | 3 | version: fmt_spec, |
@@ -84,73 +82,31 @@ install_data( |
84 | 82 | examples = [] |
85 | 83 |
|
86 | 84 | foreach doc : docs |
87 | | - code = '' |
88 | 85 | deps = [msft_proxy4_dep] |
89 | | - |
90 | | - state = 0 |
91 | | - lines = fs.read(doc).splitlines() |
92 | | - foreach line : lines |
93 | | - if state == 0 |
94 | | - if line.contains('## Example') |
95 | | - if code != '' |
96 | | - error( |
97 | | - 'File', |
98 | | - doc, |
99 | | - 'contains more than one "## Example" C++ code block.', |
100 | | - ) |
101 | | - endif |
102 | | - state = 1 |
103 | | - endif |
104 | | - elif state == 1 |
105 | | - if line == '' |
106 | | - state = 2 |
107 | | - else |
108 | | - state = 0 |
109 | | - endif |
110 | | - elif state == 2 |
111 | | - if line == '```cpp' |
112 | | - state = 3 |
113 | | - else |
114 | | - state = 0 |
115 | | - endif |
116 | | - elif state == 3 |
117 | | - if line != '```' |
118 | | - if line.contains('<proxy/proxy_fmt.h>') |
119 | | - deps += maybe_fmt_dep |
120 | | - endif |
121 | | - code += line + '\n' |
122 | | - else |
123 | | - code = code.substring(0, -1) |
124 | | - state = 0 |
125 | | - endif |
126 | | - endif |
127 | | - endforeach |
128 | | - if code != '' |
129 | | - cfg = { |
130 | | - 'MD_PATH': 'docs' / doc, |
131 | | - 'CODE': code, |
132 | | - } |
133 | | - name = doc.replace('/', '_').substring(0, -3) |
134 | | - example_exe = executable( |
135 | | - f'example_@name@', |
136 | | - configure_file( |
137 | | - configuration: cfg, |
138 | | - input: 'example.cpp.in', |
139 | | - output: f'example_@name@.cpp', |
140 | | - ), |
141 | | - extra_files: doc, |
142 | | - implicit_include_directories: false, |
143 | | - dependencies: deps, |
144 | | - build_by_default: false, |
145 | | - ) |
146 | | - examples += example_exe |
147 | | - test( |
148 | | - name, |
149 | | - example_exe, |
150 | | - suite: 'ProxyExamples', |
151 | | - depends: autogen_glob, |
152 | | - ) |
| 86 | + if doc.contains('fmt') |
| 87 | + deps += maybe_fmt_dep |
153 | 88 | endif |
| 89 | + |
| 90 | + name = doc.replace('/', '_').substring(0, -3) |
| 91 | + example_exe = executable( |
| 92 | + f'example_@name@', |
| 93 | + custom_target( |
| 94 | + command: [extract_doctest_exe, '@INPUT@', '@OUTPUT@'], |
| 95 | + input: doc, |
| 96 | + output: f'@name@.cpp', |
| 97 | + ), |
| 98 | + extra_files: doc, |
| 99 | + implicit_include_directories: false, |
| 100 | + dependencies: deps, |
| 101 | + build_by_default: false, |
| 102 | + ) |
| 103 | + examples += example_exe |
| 104 | + test( |
| 105 | + name, |
| 106 | + example_exe, |
| 107 | + suite: 'ProxyExamples', |
| 108 | + depends: autogen_glob, |
| 109 | + ) |
154 | 110 | endforeach |
155 | 111 |
|
156 | 112 | alias_target('examples', examples) |
0 commit comments