Skip to content

Commit

Permalink
Fix relative references to pages
Browse files Browse the repository at this point in the history
  • Loading branch information
Julow committed Jul 3, 2024
1 parent b720828 commit a3f69e4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/odoc/fs.ml
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ module Directory = struct
invalid_arg "Odoc.Fs.Directory.create: not a directory";
path

let contains ~parentdir f = Fpath.is_prefix parentdir f
let contains ~parentdir f = Fpath.is_rooted ~root:parentdir f

let mkdir_p dir =
let mkdir d =
Expand Down
2 changes: 1 addition & 1 deletion src/odoc/resolver.ml
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ end = struct
let make ~current_package ~current_dir = { current_package; current_dir }

let resolve_relative t relpath =
let path = Fpath.normalize (Fs.File.append t.current_dir relpath) in
let path = Fs.File.append t.current_dir relpath in
if Fs.Directory.contains ~parentdir:t.current_package path then Ok path
else Error `Escape_hierarchy
end
Expand Down
32 changes: 11 additions & 21 deletions test/xref2/path_references.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

$ odoc link -P pkg:h/pkg/doc -L libname:h/pkg/lib/libname h/pkg/doc/subdir/page-dup.odoc
$ odoc link -P pkg:h/pkg/doc -L libname:h/pkg/lib/libname h/pkg/doc/subdir/page-bar.odoc
File "h/pkg/doc/subdir/page-Test.odoc":
File does not exist
File "doc/subdir/bar.mld", line 12, characters 49-56:
Warning: Failed to resolve reference unresolvedroot(Test) Couldn't find "Test"
File "doc/subdir/bar.mld", line 12, characters 39-48:
Expand All @@ -17,14 +19,12 @@
Warning: Failed to resolve reference /pkg/libname/Test Path '/pkg/libname/Test' not found
File "doc/subdir/bar.mld", line 12, characters 0-17:
Warning: Failed to resolve reference //libname/Test Path '//libname/Test' not found
File "doc/subdir/bar.mld", line 10, characters 35-43:
Warning: Failed to resolve reference ./dup Path 'dup' not found
File "doc/subdir/bar.mld", line 6, characters 42-50:
Warning: Failed to resolve reference ./bar Path 'bar' not found
File "doc/subdir/bar.mld", line 4, characters 21-27:
Warning: Failed to resolve reference unresolvedroot(foo) Couldn't find "foo"
$ odoc link -P pkg:h/pkg/doc -L libname:h/pkg/lib/libname h/pkg/doc/page-dup.odoc
$ odoc link -P pkg:h/pkg/doc -L libname:h/pkg/lib/libname h/pkg/doc/page-foo.odoc
File "h/pkg/doc/page-Test.odoc":
File does not exist
File "doc/foo.mld", line 12, characters 49-56:
Warning: Failed to resolve reference unresolvedroot(Test) Couldn't find "Test"
File "doc/foo.mld", line 12, characters 39-48:
Expand All @@ -33,18 +33,8 @@
Warning: Failed to resolve reference /pkg/libname/Test Path '/pkg/libname/Test' not found
File "doc/foo.mld", line 12, characters 0-17:
Warning: Failed to resolve reference //libname/Test Path '//libname/Test' not found
File "doc/foo.mld", line 10, characters 35-48:
Warning: Failed to resolve reference ./subdir/dup Path 'subdir/dup' not found
File "doc/foo.mld", line 8, characters 21-29:
Warning: Failed to resolve reference ./dup Path 'dup' not found
File "doc/foo.mld", line 6, characters 56-71:
Warning: Failed to resolve reference ./subdir/bar Path 'subdir/bar' not found
File "doc/foo.mld", line 6, characters 42-55:
Warning: Failed to resolve reference ./subdir/bar Path 'subdir/bar' not found
File "doc/foo.mld", line 6, characters 35-41:
Warning: Failed to resolve reference unresolvedroot(bar) Couldn't find "bar"
File "doc/foo.mld", line 4, characters 28-36:
Warning: Failed to resolve reference ./foo Path 'foo' not found
$ odoc link --current-package pkg -P pkg:h/pkg/doc -L libname:h/pkg/lib/libname h/pkg/lib/libname/test.odoc
File "test.ml", line 12, characters 42-51:
Warning: Failed to resolve reference ./Test Path 'Test' not found
Expand All @@ -69,21 +59,21 @@ Helper that extracts references in a compact way. Headings help to interpret the
{"`Reference":[{"`Resolved":{"`Identifier":{"`LeafPage":[{"Some":{"`Page":[{"Some":{"`Page":["None","pkg"]}},"doc"]}},"foo"]}}},[]]}
{"`Reference":[{"`Resolved":{"`Identifier":{"`LeafPage":[{"Some":{"`Page":[{"Some":{"`Page":["None","pkg"]}},"doc"]}},"foo"]}}},[]]}
{"`Reference":[{"`Resolved":{"`Identifier":{"`LeafPage":[{"Some":{"`Page":[{"Some":{"`Page":["None","pkg"]}},"doc"]}},"foo"]}}},[]]}
{"`Reference":[{"`Page_path":{"`Root":["foo","`TRelativePath"]}},[]]}
{"`Reference":[{"`Resolved":{"`Identifier":{"`LeafPage":[{"Some":{"`Page":[{"Some":{"`Page":["None","pkg"]}},"doc"]}},"foo"]}}},[]]}
["Page","subdir/bar"]
{"`Reference":[{"`Resolved":{"`Identifier":{"`LeafPage":[{"Some":{"`Page":[{"Some":{"`Page":[{"Some":{"`Page":["None","pkg"]}},"doc"]}},"subdir"]}},"bar"]}}},[]]}
{"`Reference":[{"`Resolved":{"`Identifier":{"`LeafPage":[{"Some":{"`Page":[{"Some":{"`Page":[{"Some":{"`Page":["None","pkg"]}},"doc"]}},"subdir"]}},"bar"]}}},[]]}
{"`Reference":[{"`Root":["bar","`TUnknown"]},[]]}
{"`Reference":[{"`Page_path":{"`Slash":[{"`Root":["subdir","`TRelativePath"]},"bar"]}},[]]}
{"`Reference":[{"`Page_path":{"`Slash":[{"`Root":["subdir","`TRelativePath"]},"bar"]}},[]]}
{"`Reference":[{"`Resolved":{"`Identifier":{"`LeafPage":[{"Some":{"`Page":[{"Some":{"`Page":[{"Some":{"`Page":["None","pkg"]}},"doc"]}},"subdir"]}},"bar"]}}},[]]}
{"`Reference":[{"`Resolved":{"`Identifier":{"`LeafPage":[{"Some":{"`Page":[{"Some":{"`Page":[{"Some":{"`Page":["None","pkg"]}},"doc"]}},"subdir"]}},"bar"]}}},[]]}
["Page","dup"]
{"`Reference":[{"`Resolved":{"`Identifier":{"`LeafPage":[{"Some":{"`Page":[{"Some":{"`Page":["None","pkg"]}},"doc"]}},"dup"]}}},[]]}
{"`Reference":[{"`Resolved":{"`Identifier":{"`LeafPage":[{"Some":{"`Page":[{"Some":{"`Page":["None","pkg"]}},"doc"]}},"dup"]}}},[]]}
{"`Reference":[{"`Page_path":{"`Root":["dup","`TRelativePath"]}},[]]}
{"`Reference":[{"`Resolved":{"`Identifier":{"`LeafPage":[{"Some":{"`Page":[{"Some":{"`Page":["None","pkg"]}},"doc"]}},"dup"]}}},[]]}
["Page","subdir/dup"]
{"`Reference":[{"`Resolved":{"`Identifier":{"`LeafPage":[{"Some":{"`Page":[{"Some":{"`Page":[{"Some":{"`Page":["None","pkg"]}},"doc"]}},"subdir"]}},"dup"]}}},[]]}
{"`Reference":[{"`Resolved":{"`Identifier":{"`LeafPage":[{"Some":{"`Page":[{"Some":{"`Page":[{"Some":{"`Page":["None","pkg"]}},"doc"]}},"subdir"]}},"dup"]}}},[]]}
{"`Reference":[{"`Page_path":{"`Slash":[{"`Root":["subdir","`TRelativePath"]},"dup"]}},[]]}
{"`Reference":[{"`Resolved":{"`Identifier":{"`LeafPage":[{"Some":{"`Page":[{"Some":{"`Page":[{"Some":{"`Page":["None","pkg"]}},"doc"]}},"subdir"]}},"dup"]}}},[]]}
["Module","Test"]
{"`Reference":[{"`Page_path":{"`Slash":[{"`Root":["libname","`TCurrentPackage"]},"Test"]}},[]]}
{"`Reference":[{"`Page_path":{"`Slash":[{"`Slash":[{"`Root":["pkg","`TAbsolutePath"]},"libname"]},"Test"]}},[]]}
Expand All @@ -100,14 +90,14 @@ Helper that extracts references in a compact way. Headings help to interpret the
{"`Reference":[{"`Resolved":{"`Identifier":{"`LeafPage":[{"Some":{"`Page":[{"Some":{"`Page":[{"Some":{"`Page":["None","pkg"]}},"doc"]}},"subdir"]}},"bar"]}}},[]]}
{"`Reference":[{"`Resolved":{"`Identifier":{"`LeafPage":[{"Some":{"`Page":[{"Some":{"`Page":[{"Some":{"`Page":["None","pkg"]}},"doc"]}},"subdir"]}},"bar"]}}},[]]}
{"`Reference":[{"`Resolved":{"`Identifier":{"`LeafPage":[{"Some":{"`Page":[{"Some":{"`Page":[{"Some":{"`Page":["None","pkg"]}},"doc"]}},"subdir"]}},"bar"]}}},[]]}
{"`Reference":[{"`Page_path":{"`Root":["bar","`TRelativePath"]}},[]]}
{"`Reference":[{"`Resolved":{"`Identifier":{"`LeafPage":[{"Some":{"`Page":[{"Some":{"`Page":[{"Some":{"`Page":["None","pkg"]}},"doc"]}},"subdir"]}},"bar"]}}},[]]}
["Page","dup"]
{"`Reference":[{"`Resolved":{"`Identifier":{"`LeafPage":[{"Some":{"`Page":[{"Some":{"`Page":["None","pkg"]}},"doc"]}},"dup"]}}},[]]}
{"`Reference":[{"`Resolved":{"`Identifier":{"`LeafPage":[{"Some":{"`Page":[{"Some":{"`Page":["None","pkg"]}},"doc"]}},"dup"]}}},[]]}
["Page","subdir/dup"]
{"`Reference":[{"`Resolved":{"`Identifier":{"`LeafPage":[{"Some":{"`Page":[{"Some":{"`Page":[{"Some":{"`Page":["None","pkg"]}},"doc"]}},"subdir"]}},"dup"]}}},[]]}
{"`Reference":[{"`Resolved":{"`Identifier":{"`LeafPage":[{"Some":{"`Page":[{"Some":{"`Page":[{"Some":{"`Page":["None","pkg"]}},"doc"]}},"subdir"]}},"dup"]}}},[]]}
{"`Reference":[{"`Page_path":{"`Root":["dup","`TRelativePath"]}},[]]}
{"`Reference":[{"`Resolved":{"`Identifier":{"`LeafPage":[{"Some":{"`Page":[{"Some":{"`Page":[{"Some":{"`Page":["None","pkg"]}},"doc"]}},"subdir"]}},"dup"]}}},[]]}
["Module","Test"]
{"`Reference":[{"`Page_path":{"`Slash":[{"`Root":["libname","`TCurrentPackage"]},"Test"]}},[]]}
{"`Reference":[{"`Page_path":{"`Slash":[{"`Slash":[{"`Root":["pkg","`TAbsolutePath"]},"libname"]},"Test"]}},[]]}
Expand Down

0 comments on commit a3f69e4

Please sign in to comment.