Skip to content

Commit

Permalink
fix(doc): Don't generate dead links in the documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Marwes committed Mar 21, 2019
1 parent 3bbf4a9 commit 04131b7
Show file tree
Hide file tree
Showing 8 changed files with 519 additions and 14 deletions.
479 changes: 476 additions & 3 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions doc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,6 @@ serde_json = "1.0.0"

gluon = { version = "0.11.1", path = ".." } # GLUON


[dev-dependencies]
cargo-deadlinks = { path = "../../cargo-deadlinks" }
15 changes: 10 additions & 5 deletions doc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,16 +429,19 @@ pub fn generate_for_path_(thread: &Thread, path: &Path, out_path: &Path) -> Resu
let mut modules = BTreeSet::new();
let mut content = String::new();

let parent = path.parent();

for entry in walkdir::WalkDir::new(path) {
let entry = entry?;
if !entry.file_type().is_file()
|| entry.path().extension().and_then(|ext| ext.to_str()) != Some("glu")
{
continue;
}
debug!("Indexing module: {}", entry.path().display());
let entry_path = entry.path();
debug!("Indexing module: {}", entry_path.display());

let mut input = File::open(&*entry.path()).with_context(|err| {
let mut input = File::open(&*entry_path).with_context(|err| {
format!(
"Unable to open gluon file `{}`: {}",
entry.path().display(),
Expand All @@ -448,9 +451,11 @@ pub fn generate_for_path_(thread: &Thread, path: &Path, out_path: &Path) -> Resu
content.clear();
input.read_to_string(&mut content)?;

let module_path = parent
.and_then(|parent| entry_path.strip_prefix(parent).ok())
.unwrap_or(entry_path);
let name = filename_to_module(
entry
.path()
module_path
.to_str()
.ok_or_else(|| failure::err_msg("Non-UTF-8 filename"))?,
);
Expand All @@ -460,7 +465,7 @@ pub fn generate_for_path_(thread: &Thread, path: &Path, out_path: &Path) -> Resu
.typecheck_str(thread, &name, &content, None)?;
let (meta, _) = metadata(&*thread.get_env(), &expr);

create_dir_all(out_path.join(entry.path().parent().unwrap_or(Path::new(""))))?;
create_dir_all(out_path.join(module_path.parent().unwrap_or(Path::new(""))))?;

let comment = content
.lines()
Expand Down
28 changes: 25 additions & 3 deletions doc/tests/doc.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
extern crate gluon;
extern crate gluon_doc as doc;
extern crate handlebars;
use gluon_doc as doc;

use std::{fs, path::Path};

use {itertools::Itertools, rayon::prelude::*};

use gluon::check::metadata::metadata;
use gluon::{Compiler, RootedThread};
Expand Down Expand Up @@ -63,3 +65,23 @@ let test x = x
},
);
}

#[test]
fn check_links() {
let _ = env_logger::try_init();

let out = Path::new("../target/doc_test");
if out.exists() {
fs::remove_dir_all(out).unwrap_or_else(|err| panic!("{}", err));
}
doc::generate_for_path(&new_vm(), "../std", out).unwrap_or_else(|err| panic!("{}", err));

let out = fs::canonicalize(out).unwrap();
let errors = cargo_deadlinks::unavailable_urls(
&out,
&cargo_deadlinks::CheckContext { check_http: true },
)
.collect::<Vec<_>>();

assert!(errors.is_empty(), "{}", errors.iter().format("\n"));
}
1 change: 1 addition & 0 deletions src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ pub fn load(vm: &Thread) -> Result<ExternModule> {
record! {
type File => GluonFile,
type OpenOptions => OpenOptions,
type IO a => IO<A>,
flat_map => TypedBytecode::<FlatMap>::new("std.io.prim.flat_map", 3, flat_map),
wrap => TypedBytecode::<Wrap>::new("std.io.prim.wrap", 2, wrap),
open_file_with => primitive!(2, std::io::prim::open_file_with),
Expand Down
2 changes: 1 addition & 1 deletion std/io.glu
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//@NO-IMPLICIT-PRELUDE
//! Functions for working with I/O

let io_prim = import! std.io.prim
let io_prim @ { IO } = import! std.io.prim
let { Read } = import! std.io.read
let { Write } = import! std.io.write
let { Disposable } = import! std.disposable
Expand Down
2 changes: 1 addition & 1 deletion vm/src/api/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ where
types::walk_type(&typ, |typ: &ArcType| {
if self_symbol.is_none() {
match **typ {
Type::Ident(ref id) if id.definition_name() == F::name() => {
Type::Ident(ref id) if { id.definition_name() == F::name() } => {
self_symbol = Some(id.clone())
}
_ => (),
Expand Down
3 changes: 2 additions & 1 deletion vm/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,8 @@ impl GlobalVmState {
add_builtin_type::<::std::string::String>(self, BuiltinType::String);
add_builtin_type::<char>(self, BuiltinType::Char)
}
self.register_type::<IO<Generic<A>>>("IO", &["a"]).unwrap();
self.register_type::<IO<Generic<A>>>("std.io.IO", &["a"])
.unwrap();
self.register_type::<Lazy<Generic<A>>>("Lazy", &["a"])
.unwrap();
self.register_type::<Thread>("Thread", &[]).unwrap();
Expand Down

0 comments on commit 04131b7

Please sign in to comment.