|
1 | | -use std::ffi::{OsStr, OsString}; |
| 1 | +use std::ffi::OsString; |
2 | 2 |
|
3 | 3 | use ops; |
4 | | -use core::compiler::Compilation; |
| 4 | +use core::compiler::{Compilation, Doctest}; |
5 | 5 | use util::{self, CargoTestError, ProcessError, Test}; |
6 | 6 | use util::errors::CargoResult; |
7 | 7 | use core::Workspace; |
@@ -154,86 +154,64 @@ fn run_doc_tests( |
154 | 154 | return Ok((Test::Doc, errors)); |
155 | 155 | } |
156 | 156 |
|
157 | | - let libs = compilation.to_doc_test.iter().map(|package| { |
158 | | - ( |
| 157 | + for doctest_info in &compilation.to_doc_test { |
| 158 | + let Doctest { |
159 | 159 | package, |
160 | | - package |
161 | | - .targets() |
162 | | - .iter() |
163 | | - .filter(|t| t.doctested()) |
164 | | - .map(|t| (t.src_path(), t.name(), t.crate_name())), |
165 | | - ) |
166 | | - }); |
167 | | - |
168 | | - for (package, tests) in libs { |
169 | | - for (lib, name, crate_name) in tests { |
170 | | - config.shell().status("Doc-tests", name)?; |
171 | | - let mut p = compilation.rustdoc_process(package)?; |
172 | | - p.arg("--test") |
173 | | - .arg(lib) |
174 | | - .arg("--crate-name") |
175 | | - .arg(&crate_name); |
176 | | - |
177 | | - for &rust_dep in &[&compilation.deps_output] { |
178 | | - let mut arg = OsString::from("dependency="); |
179 | | - arg.push(rust_dep); |
180 | | - p.arg("-L").arg(arg); |
181 | | - } |
| 160 | + target, |
| 161 | + deps, |
| 162 | + } = doctest_info; |
| 163 | + config.shell().status("Doc-tests", target.name())?; |
| 164 | + let mut p = compilation.rustdoc_process(package)?; |
| 165 | + p.arg("--test") |
| 166 | + .arg(target.src_path()) |
| 167 | + .arg("--crate-name") |
| 168 | + .arg(&target.crate_name()); |
| 169 | + |
| 170 | + for &rust_dep in &[&compilation.deps_output] { |
| 171 | + let mut arg = OsString::from("dependency="); |
| 172 | + arg.push(rust_dep); |
| 173 | + p.arg("-L").arg(arg); |
| 174 | + } |
182 | 175 |
|
183 | | - for native_dep in compilation.native_dirs.iter() { |
184 | | - p.arg("-L").arg(native_dep); |
185 | | - } |
| 176 | + for native_dep in compilation.native_dirs.iter() { |
| 177 | + p.arg("-L").arg(native_dep); |
| 178 | + } |
186 | 179 |
|
187 | | - for &host_rust_dep in &[&compilation.host_deps_output] { |
188 | | - let mut arg = OsString::from("dependency="); |
189 | | - arg.push(host_rust_dep); |
190 | | - p.arg("-L").arg(arg); |
191 | | - } |
| 180 | + for &host_rust_dep in &[&compilation.host_deps_output] { |
| 181 | + let mut arg = OsString::from("dependency="); |
| 182 | + arg.push(host_rust_dep); |
| 183 | + p.arg("-L").arg(arg); |
| 184 | + } |
192 | 185 |
|
193 | | - for arg in test_args { |
194 | | - p.arg("--test-args").arg(arg); |
195 | | - } |
| 186 | + for arg in test_args { |
| 187 | + p.arg("--test-args").arg(arg); |
| 188 | + } |
196 | 189 |
|
197 | | - if let Some(cfgs) = compilation.cfgs.get(package.package_id()) { |
198 | | - for cfg in cfgs.iter() { |
199 | | - p.arg("--cfg").arg(cfg); |
200 | | - } |
| 190 | + if let Some(cfgs) = compilation.cfgs.get(package.package_id()) { |
| 191 | + for cfg in cfgs.iter() { |
| 192 | + p.arg("--cfg").arg(cfg); |
201 | 193 | } |
| 194 | + } |
202 | 195 |
|
203 | | - let libs = &compilation.libraries[package.package_id()]; |
204 | | - for &(ref target, ref lib) in libs.iter() { |
205 | | - // Note that we can *only* doctest rlib outputs here. A |
206 | | - // staticlib output cannot be linked by the compiler (it just |
207 | | - // doesn't do that). A dylib output, however, can be linked by |
208 | | - // the compiler, but will always fail. Currently all dylibs are |
209 | | - // built as "static dylibs" where the standard library is |
210 | | - // statically linked into the dylib. The doc tests fail, |
211 | | - // however, for now as they try to link the standard library |
212 | | - // dynamically as well, causing problems. As a result we only |
213 | | - // pass `--extern` for rlib deps and skip out on all other |
214 | | - // artifacts. |
215 | | - if lib.extension() != Some(OsStr::new("rlib")) && !target.for_host() { |
216 | | - continue; |
217 | | - } |
218 | | - let mut arg = OsString::from(target.crate_name()); |
219 | | - arg.push("="); |
220 | | - arg.push(lib); |
221 | | - p.arg("--extern").arg(&arg); |
222 | | - } |
| 196 | + for &(ref target, ref lib) in deps.iter() { |
| 197 | + let mut arg = OsString::from(target.crate_name()); |
| 198 | + arg.push("="); |
| 199 | + arg.push(lib); |
| 200 | + p.arg("--extern").arg(&arg); |
| 201 | + } |
223 | 202 |
|
224 | | - if let Some(flags) = compilation.rustdocflags.get(package.package_id()) { |
225 | | - p.args(flags); |
226 | | - } |
| 203 | + if let Some(flags) = compilation.rustdocflags.get(package.package_id()) { |
| 204 | + p.args(flags); |
| 205 | + } |
227 | 206 |
|
228 | | - config |
229 | | - .shell() |
230 | | - .verbose(|shell| shell.status("Running", p.to_string()))?; |
231 | | - if let Err(e) = p.exec() { |
232 | | - let e = e.downcast::<ProcessError>()?; |
233 | | - errors.push(e); |
234 | | - if !options.no_fail_fast { |
235 | | - return Ok((Test::Doc, errors)); |
236 | | - } |
| 207 | + config |
| 208 | + .shell() |
| 209 | + .verbose(|shell| shell.status("Running", p.to_string()))?; |
| 210 | + if let Err(e) = p.exec() { |
| 211 | + let e = e.downcast::<ProcessError>()?; |
| 212 | + errors.push(e); |
| 213 | + if !options.no_fail_fast { |
| 214 | + return Ok((Test::Doc, errors)); |
237 | 215 | } |
238 | 216 | } |
239 | 217 | } |
|
0 commit comments