Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MDX File sync (code fence)path resolution only downwards in external code quote #5596

Closed
K-Wgit opened this issue Apr 19, 2022 · 3 comments · Fixed by ocaml/opam-repository#21380
Assignees
Labels

Comments

@K-Wgit
Copy link

K-Wgit commented Apr 19, 2022

Issue opened at

dune issue 5596

Expected Behavior

In markdown files, code blocks with file sync feature - file attribute ocaml file=... - do not resolve correctly when non downwards path are used.
This makes it impossible to have a docs directory not below the code.
Trying to do that is either plain error, buggy or not working. Code should work with:

  • relative path not limited to downwards path to access siblings such as ocaml file ../lib/file.ml
  • absolute path from workspace root ocaml file=/lib/file.ml

This is also true for the comment syntax $MDX file=...

$ echo "--- path resolution issues with dune and mdx ---"
--- path resolution issues with dune and mdx ---

Actual Behavior

Sibling

Error: path outside the workspace: ../core/patt.ml from .
-> required by _build/default/lib/docs/.mdx/testmdx1.md.corrected
-> required by alias lib/docs/runtest in lib/docs/dune:1
File "lib/docs/dune", line 1, characters 0-24:
1 | (mdx
2 |  (package extissues1001))

relative path is expanded downward only

normal behaviour the error is expected

Error: No rule found for lib/docs/lib/core/patt.ml
File "README.md", line 1, characters 0-0:

absolute path not from workspace root - error

Internal error, please report upstream including the contents of _build/log.
Description:
  ("Local.relative: received absolute path",
  { t = "."; path = "/lib/core/patt.ml" })
.... see trace ....

Can be reproduced at

https://github.com/K-Wgit/extissues1001

Versions and environment

$ dune --version
3.1.0
$ ocamlc --version
4.14.0
$ ocaml-mdx --version
2.1.0
$ ocaml-mdx deps lib/docs/testmdx1.md
((4:file15:../core/patt.ml))
$ tree -I _build -I _opam ../../
../../
├── README.md
├── dune
├── dune-project
├── extissues1001.opam
└── lib
    ├── core
    │   └── patt.ml
    ├── docs
    │   ├── dune
    │   ├── testmdx1.md
    │   ├── testmdx2.md
    │   └── testmdx3.md
    └── dune

3 directories, 10 files

Some trace

$ dune runtest .

dune runtest
Internal error, please report upstream including the contents of _build/log.
Description:
  ("Local.relative: received absolute path",
  { t = "."; path = "/lib/core/patt.ml" })
Raised at Stdune__code_error.raise in file "otherlibs/stdune/code_error.ml",
  line 11, characters 30-62
Called from Stdune__path.Local_gen.relative in file
  "otherlibs/stdune/path.ml", line 244, characters 6-114
Called from Stdune__path.Local_gen.of_string in file
  "otherlibs/stdune/path.ml" (inlined), line 298, characters 20-53
Called from Dune_rules__mdx.Deps.to_path in file "src/dune_rules/mdx.ml",
  line 73, characters 16-40
Called from Dune_rules__mdx.Deps.dirs_and_files.(fun) in file
  "src/dune_rules/mdx.ml", line 80, characters 24-40
Called from Stdune__list.rev_partition_map.loop in file
  "otherlibs/stdune/list.ml", line 56, characters 13-16
Called from Stdune__list.rev_partition_map.(fun) in file
  "otherlibs/stdune/list.ml" (inlined), line 60, characters 14-29
Called from Stdune__list.partition_map in file "otherlibs/stdune/list.ml",
  line 63, characters 13-35
Called from Dune_rules__mdx.Deps.to_dep_set in file "src/dune_rules/mdx.ml",
  line 84, characters 22-48
Called from Dune_rules__mdx.gen_rules_for_single_file.(fun) in file
  "src/dune_rules/mdx.ml", line 228, characters 38-68
Called from Dune_engine__action_builder0.T.M.bind.(fun) in file
  "src/dune_engine/action_builder0.ml", line 40, characters 28-40
Called from Fiber.Scheduler.exec in file "src/fiber/fiber.ml", line 854,
  characters 10-13
-> required by ("Rule.make", ())
-> required by
   ("execute-rule",
   { id = 49
   ; info =
       From_dune_file
         { pos_fname = "lib/docs/dune"
         ; start = { pos_lnum = 1; pos_bol = 0; pos_cnum = 0 }
         ; stop = { pos_lnum = 2; pos_bol = 5; pos_cnum = 24 }
         }
   })
-> required by ("<unnamed>", ())
-> required by
   ("build-file", In_build_dir "default/lib/docs/.mdx/testmdx3.md.corrected")
-> required by ("<unnamed>", ())
-> required by
   ("build-alias", { dir = "default/lib/docs"; name = "runtest" })
-> required by ("toplevel", ())

I must not crash.  Uncertainty is the mind-killer. Exceptions are the
little-death that brings total obliteration.  I will fully express my cases.
Execution will pass over me and through me.  And when it has gone past, I
will unwind the stack along its path.  Where the cases are handled there will
be nothing.  Only I will remain.
Error: path outside the workspace: ../core/patt.ml from .
-> required by _build/default/lib/docs/.mdx/testmdx1.md.corrected
-> required by alias lib/docs/runtest in lib/docs/dune:1
File "lib/docs/dune", line 1, characters 0-24:
1 | (mdx
2 |  (package extissues1001))
Error: No rule found for lib/docs/lib/core/patt.ml
File "README.md", line 1, characters 0-0:
diff --git a/_build/default/README.md b/_build/default/.mdx/README.md.corrected
index 8f35f3d..ad5349e 100644
--- a/_build/default/README.md
+++ b/_build/default/.mdx/README.md.corrected
@@ -96,7 +96,10 @@ $ ocamlc --version
 $ ocaml-mdx --version
 2.1.0
 $ ocaml-mdx deps lib/docs/testmdx.md
-()
+ocaml-mdx: FILE argument: no 'lib/docs/testmdx.md' file
+Usage: ocaml-mdx deps [OPTION]… FILE
+Try 'ocaml-mdx deps --help' or 'ocaml-mdx --help' for more information.
+[124]
 $ tree --gitignore -I _opam
 .
 ├── META.extissues1001
@@ -107,7 +110,9 @@ $ tree --gitignore -I _opam
 │   ├── docs
 │   │   ├── mdx_gen.bc
 │   │   ├── mdx_gen.ml-gen
-│   │   └── testmdx.md
+│   │   ├── testmdx1.md
+│   │   ├── testmdx2.md
+│   │   └── testmdx3.md
 │   ├── extissues1001.a
 │   ├── extissues1001.cma
 │   ├── extissues1001.cmxa
@@ -118,6 +123,6 @@ $ tree --gitignore -I _opam
 ├── extissues1001.install
 └── extissues1001.opam

-3 directories, 15 files
+3 directories, 17 files
@rgrinberg rgrinberg added the mdx label Apr 20, 2022
@rgrinberg
Copy link
Member

@emillon or @voodoos could you have a look?

@emillon emillon self-assigned this Apr 20, 2022
@emillon
Copy link
Collaborator

emillon commented Apr 20, 2022

I'll have a look. The issue seems to be with the header ocaml file=../core/patt.ml,part=snippet.

emillon added a commit to emillon/dune that referenced this issue May 10, 2022
Signed-off-by: Etienne Millon <[email protected]>
emillon added a commit to emillon/dune that referenced this issue May 10, 2022
This includes repro cases for ocaml#5596.

Signed-off-by: Etienne Millon <[email protected]>
emillon added a commit to emillon/dune that referenced this issue May 10, 2022
This includes repro cases for ocaml#5596.

Signed-off-by: Etienne Millon <[email protected]>
emillon added a commit to emillon/dune that referenced this issue May 10, 2022
This includes repro cases for ocaml#5596.

Signed-off-by: Etienne Millon <[email protected]>
emillon added a commit to emillon/dune that referenced this issue May 10, 2022
This includes repro cases for ocaml#5596.

Signed-off-by: Etienne Millon <[email protected]>
emillon added a commit to emillon/dune that referenced this issue May 13, 2022
This includes repro cases for ocaml#5596.

Signed-off-by: Etienne Millon <[email protected]>
emillon added a commit to emillon/dune that referenced this issue May 13, 2022
This includes repro cases for ocaml#5596.

Signed-off-by: Etienne Millon <[email protected]>
emillon added a commit that referenced this issue May 13, 2022
This includes repro cases for #5596.

Signed-off-by: Etienne Millon <[email protected]>
rgrinberg added a commit to rgrinberg/opam-repository that referenced this issue May 17, 2022
…ne-site, dune-rpc, dune-rpc-lwt, dune-private-libs, dune-glob, dune-configurator, dune-build-info, dune-action-plugin and chrome-trace (3.2.0)

CHANGES:

- Fixed ``dune describe workspace --with-deps`` so that it correctly
  handles Reason files, as well as files any other dialect. (ocaml/dune#5701, @esope)

- Disable alerts when compiling code in vendored directories (ocaml/dune#5683,
  @NathanReb)

- Fixed ``dune describe --with-deps``, that crashed when some
  preprocessing was required in a dune file using ``per_module``.
  (ocaml/dune#5682, fixes ocaml/dune#5680, @esope)

- Add `$ dune describe pp` to print the preprocssed ast of sources. (ocaml/dune#5615,
  fixes ocaml/dune#4470, @cannorin)

- Report dune file evaluation errors concurrently. In the same way we report
  build errors. (ocaml/dune#5655, @rgrinberg)

- Watch mode now default to clearing the terminal on rebuild (ocaml/dune#5636, fixes,
  ocaml/dune#5216, @rgrinberg)

- The output of jobs that finished but were cancelled is now omitted. (ocaml/dune#5631,
  fixes ocaml/dune#5482, @rgrinberg)

- Allows to configure all the default destination directories with `./configure`
  (adds `bin`, `sbin`, `data`, `libexec`). Use `OPAM_SWITCH_PREFIX` instead of
  calling the `opam` binaries in `dune install`. Fix handling of multiple
  `libdir` in `./configure` for handling `/usr/lib/ocaml/` and
  `/usr/local/lib/ocaml`. In `dune install` forbid relative directories in
  `libdir`, `docdir` and others specific directory setting because their handling
  was inconsistent (ocaml/dune#5516, fixes ocaml/dune#3978 and ocaml/dune#5455, @bobot)

- `--terminal-persistence=clear-on-rebuild` will no longer destroy scrollback
  on some terminals (ocaml/dune#5646, @rgrinberg)

- Add a fmt command as a shortcut of `dune build @fmt --auto-promote` (ocaml/dune#5574,
  @tmattio)

- Watch mode now tracks copied external files, external directories for
  dependencies, dune files in OCaml syntax, files used by `include` stanzas,
  dune-project, opam files, libraries builtin with compiler, and foreign
  sources (ocaml/dune#5627, ocaml/dune#5645, ocaml/dune#5652, ocaml/dune#5656, ocaml/dune#5672, ocaml/dune#5691, ocaml/dune#5722, fixes ocaml/dune#5331,
  @rgrinberg)

- Improve metrics for cram tests. Include test names in the event and add a
  category for cram tests (ocaml/dune#5626, @rgrinberg)

- Allow specifying multiple licenses in project file (ocaml/dune#5579, fixes ocaml/dune#5574,
  @liyishuai)

- Match `glob_files` only against files in external directories (ocaml/dune#5614, fixes
  ocaml/dune#5540, @rgrinberg)

- Add pid's to chrome trace output (ocaml/dune#5617, @rgrinberg)

- Fix race when creating local cache directory (ocaml/dune#5613, fixes ocaml/dune#5461, @rgrinberg)

- Add `not` to boolean expressions (ocaml/dune#5610, fix ocaml/dune#5503, @rgrinberg)

- Fix relative dependencies outside the workspace (ocaml/dune#4035, fixes ocaml/dune#5572, @bobot)

- Allow to specify `--prefix` via the environment variable
  `DUNE_INSTALL_PREFIX` (ocaml/dune#5589, @vapourismo)

- Dune-site.plugin: add support for `archive(native|byte, plugin)` used in the
  wild before findlib documented `plugin(native|byte)` in 2015 (ocaml/dune#5518, @bobot)

- Fix a bug where Dune would not correctly interpret `META` files in alternative
  layout (ie when the META file is named `META.$pkg`). The `Llvm` bindings were
  affected by this issue. (ocaml/dune#5619, fixes ocaml/dune#5616, @nojb)

- Support `(binaries)` in `(env)` in dune-workspace files (ocaml/dune#5560, fix ocaml/dune#5555,
  @emillon)

- (mdx) stanza: add support for (locks). (ocaml/dune#5628, fixes ocaml/dune#5489, @emillon)

- (mdx) stanza: support including files in different directories using relative
  paths, and provide better error messages when paths are invalid (ocaml/dune#5703, ocaml/dune#5704,
  fixes ocaml/dune#5596, @emillon)

- Fix ctypes rules for external lib names which aren't valid ocaml names
  (ocaml/dune#5667, fixes ocaml/dune#5511, @Khady)
@emillon
Copy link
Collaborator

emillon commented Jun 1, 2022

This has been fixed by #5703 and #5704.

@emillon emillon closed this as completed Jun 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment