Skip to content

Commit 07c6295

Browse files
authored
Rollup merge of #41290 - GuillaumeGomez:put-back-hoedown, r=steveklabnik
Hoedown big comeback! ```bash > cargo +local test Compiling libc v0.2.20 Compiling sysinfo v0.3.4 (file:///Users/imperio/rust/sysinfo) Finished dev [unoptimized + debuginfo] target(s) in 3.2 secs Running target/debug/deps/disk_list-dbd70897f1f7e080 running 1 test test test_disks ... ok test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured Running target/debug/deps/sysinfo-8ad11103abdf5941 running 0 tests test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured Doc-tests sysinfo WARNING: src/sysinfo.rs - (line 45) test will be run in the next rustdoc version. If it's not supposed to, please update your documentation and make it compliant to common mark specifications. WARNING: src/sysinfo.rs - (line 48) test will be run in the next rustdoc version. If it's not supposed to, please update your documentation and make it compliant to common mark specifications. running 1 test test src/sysinfo.rs - (line 14) ... ok test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured ``` r? @rust-lang/docs
2 parents 4ae25a6 + bee0291 commit 07c6295

File tree

9 files changed

+280
-7
lines changed

9 files changed

+280
-7
lines changed

.gitmodules

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
[submodule "src/compiler-rt"]
66
path = src/compiler-rt
77
url = https://github.com/rust-lang/compiler-rt.git
8+
[submodule "src/rt/hoedown"]
9+
path = src/rt/hoedown
10+
url = https://github.com/rust-lang/hoedown.git
11+
branch = rust-2015-09-21-do-not-delete
812
[submodule "src/jemalloc"]
913
path = src/jemalloc
1014
url = https://github.com/rust-lang/jemalloc.git

COPYRIGHT

+22
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,28 @@ their own copyright notices and license terms:
197197
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
198198
OF SUCH DAMAGE.
199199

200+
* Hoedown, the markdown parser, under src/rt/hoedown, is
201+
licensed as follows.
202+
203+
Copyright (c) 2008, Natacha Porté
204+
Copyright (c) 2011, Vicent Martí
205+
Copyright (c) 2013, Devin Torres and the Hoedown authors
206+
207+
Permission to use, copy, modify, and distribute this
208+
software for any purpose with or without fee is hereby
209+
granted, provided that the above copyright notice and
210+
this permission notice appear in all copies.
211+
212+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR
213+
DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
214+
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
215+
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
216+
SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR
217+
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
218+
OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
219+
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
220+
CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
221+
200222
* libbacktrace, under src/libbacktrace:
201223

202224
Copyright (C) 2012-2014 Free Software Foundation, Inc.

src/librustdoc/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
authors = ["The Rust Project Developers"]
33
name = "rustdoc"
44
version = "0.0.0"
5+
build = "build.rs"
56

67
[lib]
78
name = "rustdoc"

src/librustdoc/build.rs

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
extern crate build_helper;
12+
extern crate gcc;
13+
14+
fn main() {
15+
let src_dir = std::path::Path::new("../rt/hoedown/src");
16+
build_helper::rerun_if_changed_anything_in_dir(src_dir);
17+
let mut cfg = gcc::Config::new();
18+
cfg.file("../rt/hoedown/src/autolink.c")
19+
.file("../rt/hoedown/src/buffer.c")
20+
.file("../rt/hoedown/src/document.c")
21+
.file("../rt/hoedown/src/escape.c")
22+
.file("../rt/hoedown/src/html.c")
23+
.file("../rt/hoedown/src/html_blocks.c")
24+
.file("../rt/hoedown/src/html_smartypants.c")
25+
.file("../rt/hoedown/src/stack.c")
26+
.file("../rt/hoedown/src/version.c")
27+
.include(src_dir)
28+
.compile("libhoedown.a");
29+
}
30+

src/librustdoc/html/markdown.rs

+191
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
2626
#![allow(non_camel_case_types)]
2727

28+
use libc;
29+
use std::slice;
30+
2831
use std::ascii::AsciiExt;
2932
use std::cell::RefCell;
3033
use std::collections::{HashMap, VecDeque};
@@ -357,6 +360,194 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for Footnotes<'a, I> {
357360
}
358361
}
359362

363+
const DEF_OUNIT: libc::size_t = 64;
364+
const HOEDOWN_EXT_NO_INTRA_EMPHASIS: libc::c_uint = 1 << 11;
365+
const HOEDOWN_EXT_TABLES: libc::c_uint = 1 << 0;
366+
const HOEDOWN_EXT_FENCED_CODE: libc::c_uint = 1 << 1;
367+
const HOEDOWN_EXT_AUTOLINK: libc::c_uint = 1 << 3;
368+
const HOEDOWN_EXT_STRIKETHROUGH: libc::c_uint = 1 << 4;
369+
const HOEDOWN_EXT_SUPERSCRIPT: libc::c_uint = 1 << 8;
370+
const HOEDOWN_EXT_FOOTNOTES: libc::c_uint = 1 << 2;
371+
372+
const HOEDOWN_EXTENSIONS: libc::c_uint =
373+
HOEDOWN_EXT_NO_INTRA_EMPHASIS | HOEDOWN_EXT_TABLES |
374+
HOEDOWN_EXT_FENCED_CODE | HOEDOWN_EXT_AUTOLINK |
375+
HOEDOWN_EXT_STRIKETHROUGH | HOEDOWN_EXT_SUPERSCRIPT |
376+
HOEDOWN_EXT_FOOTNOTES;
377+
378+
enum hoedown_document {}
379+
380+
type blockcodefn = extern "C" fn(*mut hoedown_buffer, *const hoedown_buffer,
381+
*const hoedown_buffer, *const hoedown_renderer_data,
382+
libc::size_t);
383+
384+
type blockquotefn = extern "C" fn(*mut hoedown_buffer, *const hoedown_buffer,
385+
*const hoedown_renderer_data, libc::size_t);
386+
387+
type headerfn = extern "C" fn(*mut hoedown_buffer, *const hoedown_buffer,
388+
libc::c_int, *const hoedown_renderer_data,
389+
libc::size_t);
390+
391+
type blockhtmlfn = extern "C" fn(*mut hoedown_buffer, *const hoedown_buffer,
392+
*const hoedown_renderer_data, libc::size_t);
393+
394+
type codespanfn = extern "C" fn(*mut hoedown_buffer, *const hoedown_buffer,
395+
*const hoedown_renderer_data, libc::size_t) -> libc::c_int;
396+
397+
type linkfn = extern "C" fn (*mut hoedown_buffer, *const hoedown_buffer,
398+
*const hoedown_buffer, *const hoedown_buffer,
399+
*const hoedown_renderer_data, libc::size_t) -> libc::c_int;
400+
401+
type entityfn = extern "C" fn (*mut hoedown_buffer, *const hoedown_buffer,
402+
*const hoedown_renderer_data, libc::size_t);
403+
404+
type normaltextfn = extern "C" fn(*mut hoedown_buffer, *const hoedown_buffer,
405+
*const hoedown_renderer_data, libc::size_t);
406+
407+
#[repr(C)]
408+
struct hoedown_renderer_data {
409+
opaque: *mut libc::c_void,
410+
}
411+
412+
#[repr(C)]
413+
struct hoedown_renderer {
414+
opaque: *mut libc::c_void,
415+
416+
blockcode: Option<blockcodefn>,
417+
blockquote: Option<blockquotefn>,
418+
header: Option<headerfn>,
419+
420+
other_block_level_callbacks: [libc::size_t; 11],
421+
422+
blockhtml: Option<blockhtmlfn>,
423+
424+
/* span level callbacks - NULL or return 0 prints the span verbatim */
425+
autolink: libc::size_t, // unused
426+
codespan: Option<codespanfn>,
427+
other_span_level_callbacks_1: [libc::size_t; 7],
428+
link: Option<linkfn>,
429+
other_span_level_callbacks_2: [libc::size_t; 6],
430+
431+
/* low level callbacks - NULL copies input directly into the output */
432+
entity: Option<entityfn>,
433+
normal_text: Option<normaltextfn>,
434+
435+
/* header and footer */
436+
other_callbacks: [libc::size_t; 2],
437+
}
438+
439+
#[repr(C)]
440+
struct hoedown_html_renderer_state {
441+
opaque: *mut libc::c_void,
442+
toc_data: html_toc_data,
443+
flags: libc::c_uint,
444+
link_attributes: Option<extern "C" fn(*mut hoedown_buffer,
445+
*const hoedown_buffer,
446+
*const hoedown_renderer_data)>,
447+
}
448+
449+
#[repr(C)]
450+
struct html_toc_data {
451+
header_count: libc::c_int,
452+
current_level: libc::c_int,
453+
level_offset: libc::c_int,
454+
nesting_level: libc::c_int,
455+
}
456+
457+
#[repr(C)]
458+
struct hoedown_buffer {
459+
data: *const u8,
460+
size: libc::size_t,
461+
asize: libc::size_t,
462+
unit: libc::size_t,
463+
}
464+
465+
extern {
466+
fn hoedown_html_renderer_new(render_flags: libc::c_uint,
467+
nesting_level: libc::c_int)
468+
-> *mut hoedown_renderer;
469+
fn hoedown_html_renderer_free(renderer: *mut hoedown_renderer);
470+
471+
fn hoedown_document_new(rndr: *const hoedown_renderer,
472+
extensions: libc::c_uint,
473+
max_nesting: libc::size_t) -> *mut hoedown_document;
474+
fn hoedown_document_render(doc: *mut hoedown_document,
475+
ob: *mut hoedown_buffer,
476+
document: *const u8,
477+
doc_size: libc::size_t);
478+
fn hoedown_document_free(md: *mut hoedown_document);
479+
480+
fn hoedown_buffer_new(unit: libc::size_t) -> *mut hoedown_buffer;
481+
fn hoedown_buffer_free(b: *mut hoedown_buffer);
482+
}
483+
484+
impl hoedown_buffer {
485+
fn as_bytes(&self) -> &[u8] {
486+
unsafe { slice::from_raw_parts(self.data, self.size as usize) }
487+
}
488+
}
489+
490+
pub fn old_find_testable_code(doc: &str, tests: &mut ::test::Collector, position: Span) {
491+
extern fn block(_ob: *mut hoedown_buffer,
492+
text: *const hoedown_buffer,
493+
lang: *const hoedown_buffer,
494+
data: *const hoedown_renderer_data,
495+
line: libc::size_t) {
496+
unsafe {
497+
if text.is_null() { return }
498+
let block_info = if lang.is_null() {
499+
LangString::all_false()
500+
} else {
501+
let lang = (*lang).as_bytes();
502+
let s = str::from_utf8(lang).unwrap();
503+
LangString::parse(s)
504+
};
505+
if !block_info.rust { return }
506+
let opaque = (*data).opaque as *mut hoedown_html_renderer_state;
507+
let tests = &mut *((*opaque).opaque as *mut ::test::Collector);
508+
let line = tests.get_line() + line;
509+
let filename = tests.get_filename();
510+
tests.add_old_test(line, filename);
511+
}
512+
}
513+
514+
extern fn header(_ob: *mut hoedown_buffer,
515+
text: *const hoedown_buffer,
516+
level: libc::c_int, data: *const hoedown_renderer_data,
517+
_: libc::size_t) {
518+
unsafe {
519+
let opaque = (*data).opaque as *mut hoedown_html_renderer_state;
520+
let tests = &mut *((*opaque).opaque as *mut ::test::Collector);
521+
if text.is_null() {
522+
tests.register_header("", level as u32);
523+
} else {
524+
let text = (*text).as_bytes();
525+
let text = str::from_utf8(text).unwrap();
526+
tests.register_header(text, level as u32);
527+
}
528+
}
529+
}
530+
531+
tests.set_position(position);
532+
533+
unsafe {
534+
let ob = hoedown_buffer_new(DEF_OUNIT);
535+
let renderer = hoedown_html_renderer_new(0, 0);
536+
(*renderer).blockcode = Some(block);
537+
(*renderer).header = Some(header);
538+
(*((*renderer).opaque as *mut hoedown_html_renderer_state)).opaque
539+
= tests as *mut _ as *mut libc::c_void;
540+
541+
let document = hoedown_document_new(renderer, HOEDOWN_EXTENSIONS, 16);
542+
hoedown_document_render(document, ob, doc.as_ptr(),
543+
doc.len() as libc::size_t);
544+
hoedown_document_free(document);
545+
546+
hoedown_html_renderer_free(renderer);
547+
hoedown_buffer_free(ob);
548+
}
549+
}
550+
360551
pub fn find_testable_code(doc: &str, tests: &mut ::test::Collector, position: Span) {
361552
tests.set_position(position);
362553

src/librustdoc/markdown.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use externalfiles::{ExternalHtml, LoadStringError, load_string};
2525
use html::render::reset_ids;
2626
use html::escape::Escape;
2727
use html::markdown;
28-
use html::markdown::{Markdown, MarkdownWithToc, find_testable_code};
28+
use html::markdown::{Markdown, MarkdownWithToc, find_testable_code, old_find_testable_code};
2929
use test::{TestOptions, Collector};
3030

3131
/// Separate any lines at the start of the file that begin with `# ` or `%`.
@@ -159,6 +159,7 @@ pub fn test(input: &str, cfgs: Vec<String>, libs: SearchPaths, externs: Externs,
159159
let mut collector = Collector::new(input.to_string(), cfgs, libs, externs,
160160
true, opts, maybe_sysroot, None,
161161
Some(input.to_owned()));
162+
old_find_testable_code(&input_str, &mut collector, DUMMY_SP);
162163
find_testable_code(&input_str, &mut collector, DUMMY_SP);
163164
test_args.insert(0, "rustdoctest".to_string());
164165
testing::test_main(&test_args, collector.tests);

src/librustdoc/test.rs

+28-6
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,8 @@ fn partition_source(s: &str) -> (String, String) {
380380

381381
pub struct Collector {
382382
pub tests: Vec<testing::TestDescAndFn>,
383+
// to be removed when hoedown will be definitely gone
384+
pub old_tests: Vec<String>,
383385
names: Vec<String>,
384386
cfgs: Vec<String>,
385387
libs: SearchPaths,
@@ -401,6 +403,7 @@ impl Collector {
401403
codemap: Option<Rc<CodeMap>>, filename: Option<String>) -> Collector {
402404
Collector {
403405
tests: Vec::new(),
406+
old_tests: Vec::new(),
404407
names: Vec::new(),
405408
cfgs: cfgs,
406409
libs: libs,
@@ -417,19 +420,36 @@ impl Collector {
417420
}
418421
}
419422

420-
pub fn add_test(&mut self, test: String,
421-
should_panic: bool, no_run: bool, should_ignore: bool,
422-
as_test_harness: bool, compile_fail: bool, error_codes: Vec<String>,
423-
line: usize, filename: String) {
424-
let name = if self.use_headers {
423+
fn generate_name(&self, line: usize, filename: &str) -> String {
424+
if self.use_headers {
425425
if let Some(ref header) = self.current_header {
426426
format!("{} - {} (line {})", filename, header, line)
427427
} else {
428428
format!("{} - (line {})", filename, line)
429429
}
430430
} else {
431431
format!("{} - {} (line {})", filename, self.names.join("::"), line)
432-
};
432+
}
433+
}
434+
435+
pub fn add_old_test(&mut self, line: usize, filename: String) {
436+
let name = self.generate_name(line, &filename);
437+
self.old_tests.push(name);
438+
}
439+
440+
pub fn add_test(&mut self, test: String,
441+
should_panic: bool, no_run: bool, should_ignore: bool,
442+
as_test_harness: bool, compile_fail: bool, error_codes: Vec<String>,
443+
line: usize, filename: String) {
444+
let name = self.generate_name(line, &filename);
445+
if self.old_tests.iter().find(|&x| x == &name).is_none() {
446+
let _ = writeln!(&mut io::stderr(),
447+
"WARNING: {} Code block is not currently run as a test, but will in \
448+
future versions of rustdoc. Please ensure this code block is a \
449+
runnable test, or use the `ignore` directive.",
450+
name);
451+
return
452+
}
433453
let cfgs = self.cfgs.clone();
434454
let libs = self.libs.clone();
435455
let externs = self.externs.clone();
@@ -544,6 +564,8 @@ impl<'a, 'hir> HirCollector<'a, 'hir> {
544564
attrs.unindent_doc_comments();
545565
if let Some(doc) = attrs.doc_value() {
546566
self.collector.cnt = 0;
567+
markdown::old_find_testable_code(doc, self.collector,
568+
attrs.span.unwrap_or(DUMMY_SP));
547569
markdown::find_testable_code(doc, self.collector,
548570
attrs.span.unwrap_or(DUMMY_SP));
549571
}

src/rt/hoedown

Submodule hoedown added at da282f1

src/tools/tidy/src/main.rs

+1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ fn filter_dirs(path: &Path) -> bool {
8686
"src/rust-installer",
8787
"src/liblibc",
8888
"src/vendor",
89+
"src/rt/hoedown",
8990
];
9091
skip.iter().any(|p| path.ends_with(p))
9192
}

0 commit comments

Comments
 (0)