1
Fork 0

Add test for ordering of examples, simplify with single scrape.mk file

This commit is contained in:
Will Crichton 2021-10-08 20:49:05 -07:00
parent 9e4958a3e6
commit b1616f34ef
8 changed files with 49 additions and 40 deletions

View file

@ -1,21 +1,5 @@
-include ../../run-make-fulldeps/tools.mk deps := ex ex2
OUTPUT_DIR := "$(TMPDIR)/rustdoc" -include ./scrape.mk
all: $(TMPDIR)/ex.calls $(TMPDIR)/ex2.calls all: scrape
$(RUSTDOC) src/lib.rs --crate-name foobar --crate-type lib --output $(OUTPUT_DIR) \
-Z unstable-options \
--with-examples $(TMPDIR)/ex.calls \
--with-examples $(TMPDIR)/ex2.calls
$(HTMLDOCCK) $(OUTPUT_DIR) src/lib.rs
$(TMPDIR)/%.calls: $(TMPDIR)/libfoobar.rmeta
$(RUSTDOC) examples/$*.rs --crate-name $* --crate-type bin --output $(OUTPUT_DIR) \
--extern foobar=$(TMPDIR)/libfoobar.rmeta \
-Z unstable-options \
--scrape-examples-output-path $@ \
--scrape-examples-target-crate foobar
$(TMPDIR)/lib%.rmeta: src/lib.rs
$(RUSTC) src/lib.rs --crate-name $* --crate-type lib --emit=metadata

View file

@ -0,0 +1,20 @@
-include ../../run-make-fulldeps/tools.mk
OUTPUT_DIR := "$(TMPDIR)/rustdoc"
$(TMPDIR)/%.calls: $(TMPDIR)/libfoobar.rmeta
$(RUSTDOC) examples/$*.rs --crate-name $* --crate-type bin --output $(OUTPUT_DIR) \
--extern foobar=$(TMPDIR)/libfoobar.rmeta \
-Z unstable-options \
--scrape-examples-output-path $@ \
--scrape-examples-target-crate foobar
$(TMPDIR)/lib%.rmeta: src/lib.rs
$(RUSTC) src/lib.rs --crate-name $* --crate-type lib --emit=metadata
scrape: $(foreach d,$(deps),$(TMPDIR)/$(d).calls)
$(RUSTDOC) src/lib.rs --crate-name foobar --crate-type lib --output $(OUTPUT_DIR) \
-Z unstable-options \
$(foreach d,$(deps),--with-examples $(TMPDIR)/$(d).calls)
$(HTMLDOCCK) $(OUTPUT_DIR) src/lib.rs

View file

@ -1,4 +1,4 @@
// @has foobar/fn.ok.html '//*[@class="prev"]' '' // @has foobar/fn.ok.html '//*[@class="docblock scraped-example-list"]//*[@class="prev"]' ''
// @has foobar/fn.ok.html '//*[@class="more-scraped-examples"]' '' // @has foobar/fn.ok.html '//*[@class="more-scraped-examples"]' ''
pub fn ok() {} pub fn ok() {}

View file

@ -0,0 +1,5 @@
deps := ex1 ex2
-include ../rustdoc-scrape-examples-multiple/scrape.mk
all: scrape

View file

@ -0,0 +1,9 @@
fn main() {
foobar::ok();
// this is a
// BIG
// item
}

View file

@ -0,0 +1,4 @@
fn main() {
foobar::ok();
// small item
}

View file

@ -0,0 +1,4 @@
// @has foobar/fn.ok.html '//*[@class="docblock scraped-example-list"]' 'ex2'
// @has foobar/fn.ok.html '//*[@class="more-scraped-examples"]' 'ex1'
pub fn ok() {}

View file

@ -1,22 +1,5 @@
-include ../../run-make-fulldeps/tools.mk deps := ex
OUTPUT_DIR := "$(TMPDIR)/rustdoc" -include ../rustdoc-scrape-examples-multiple/scrape.mk
all: all: scrape
# 1. compile the library crate and emit an rmeta
$(RUSTC) src/lib.rs --crate-name foobar --crate-type lib --emit=metadata
# 2. scrape examples from the reverse-dependency into an ex.calls file
$(RUSTDOC) examples/ex.rs --crate-name ex --crate-type bin --output $(OUTPUT_DIR) \
--extern foobar=$(TMPDIR)/libfoobar.rmeta \
-Z unstable-options \
--scrape-examples-output-path $(TMPDIR)/ex.calls \
--scrape-examples-target-crate foobar
# 3. pass those examples to rustdoc when documenting the library crate
$(RUSTDOC) src/lib.rs --crate-name foobar --crate-type lib --output $(OUTPUT_DIR) \
-Z unstable-options \
--with-examples $(TMPDIR)/ex.calls
# 4. check that the examples were scraped successfully
$(HTMLDOCCK) $(OUTPUT_DIR) src/lib.rs