This commit is contained in:
swrup 2025-11-11 02:07:51 +01:00
parent aa2ff7b2f0
commit 2f3113f55d
11742 changed files with 1223940 additions and 0 deletions

View file

@ -0,0 +1,144 @@
Testing the "dune show aliases" command. This command shows the aliases in the
current directory. It acts similarly to ls. It will not show aliases that appear
in subdirectories although this could be changed in the future.
In an empty dune project, the following aliases are available.
$ dune show aliases
all
default
fmt
ocaml-index
pkg-install
User defined aliases can be added to a dune file. These should be picked up by
the command.
$ cat > dune << EOF
> (alias
> (name foo))
> EOF
$ dune show aliases
all
default
fmt
foo
ocaml-index
pkg-install
Aliases in subdirectories should not be picked up.
$ mkdir subdir
$ cat > subdir/dune << EOF
> (alias
> (name bar))
> EOF
$ dune show aliases
all
default
fmt
foo
ocaml-index
pkg-install
But checking the subdirectory it should be available.
$ dune show aliases subdir
all
bar
default
fmt
Adding an OCaml library will introduce OCaml specific aliases:
$ cat > dune << EOF
> (library
> (name foo))
> EOF
$ dune show aliases
all
check
default
doc-private
fmt
ocaml-index
pkg-install
Adding a cram test will introduce an alias with the name of the test and also
introduce the runtest alias:
bbb
$ rm dune
$ cat > mytest.t
$ dune show aliases
all
default
fmt
mytest
ocaml-index
pkg-install
runtest
We can also show aliases in multiple directories at once:
$ dune show aliases . subdir
.:
all
default
fmt
mytest
ocaml-index
pkg-install
runtest
subdir:
all
bar
default
fmt
Including those in the _build/ directory:
$ dune build
$ dune show aliases . _build/default
.:
all
default
fmt
mytest
ocaml-index
pkg-install
runtest
_build/default:
all
default
fmt
mytest
ocaml-index
pkg-install
runtest
These are context sensitive:
$ cat > dune-workspace << EOF
> (lang dune 3.9)
> (context
> (default
> (name other_context)))
> EOF
$ dune show aliases --context other_context _build/default
Error: Directory _build/default is not in context "other_context".
$ dune show aliases --context other_context _build/other_context
all
default
fmt
mytest
ocaml-index
pkg-install
runtest

View file

@ -0,0 +1,19 @@
Showcase behavior of the `dune describe contexts` subcommand
$ cat >dune-project <<EOF
> (lang dune 3.14)
> EOF
$ cat > dune-workspace << EOF
> (lang dune 3.14)
>
> (context default)
>
> (context
> (default
> (name alt)))
> EOF
$ dune describe contexts
alt
default

View file

@ -0,0 +1,4 @@
(include_subdirs unqualified)
(library
(name foo))

View file

@ -0,0 +1,4 @@
(executable
(name pp))
(ocamllex pp)

View file

@ -0,0 +1,10 @@
rule main = parse
| eof { () }
| "_STRING_" { Printf.printf "%S" "Hello, world!"; main lexbuf }
| _ as c { print_char c; main lexbuf }
{
let () =
set_binary_mode_out stdout true;
main (Lexing.from_channel (open_in_bin Sys.argv.(1)))
}

View file

@ -0,0 +1,29 @@
We can show the preprocessed output of a source code
$ dune describe pp src/main.ml
;;Util.log "Hello, world!"
Re-running the command keeps showing output
$ dune describe pp src/main.ml
;;Util.log "Hello, world!"
We can also show the original source if it is not preprocessed
$ dune describe pp src/util.ml
let log str = print_endline str
We also make sure that the dump file is not present
$ dune_cmd exists profile.dump
false
This also works for reason code
$ dune describe pp src/main_re.re
# 1 "src/main_re.pp.re.ml"
# 1 "src/main_re.pp.re"
Util.log ("Hello, world!")
$ dune describe pp lib/subdir/bazy.ml

View file

@ -0,0 +1,3 @@
(executables
(names main main_re)
(preprocess (action (run pp/pp.exe %{input-file}))))

View file

@ -0,0 +1 @@
let log str = print_endline str

View file

@ -0,0 +1,4 @@
(library
(name ppx_suffix)
(kind ppx_rewriter)
(libraries ppxlib))

View file

@ -0,0 +1,13 @@
open Ppxlib
let expand ~ctxt s =
let loc = Expansion_context.Extension.extension_point_loc ctxt in
Ast_builder.Default.estring ~loc (s ^ "_suffixed")
let my_extension =
Extension.V3.declare "add_suffix" Extension.Context.expression
Ast_pattern.(single_expr_payload (estring __))
expand
let rule = Ppxlib.Context_free.Rule.extension my_extension
let () = Driver.register_transformation ~rules:[ rule ] "add_suffix"

View file

@ -0,0 +1,8 @@
It should fail with a message that `describe pp` doesn't support `staged_pps`.
$ dune describe pp src/main.ml
File "src/dune", line 4, characters 2-25:
4 | (staged_pps ppx_suffix)))
^^^^^^^^^^^^^^^^^^^^^^^
Error: staged_pps are not supported.
[1]

View file

@ -0,0 +1,4 @@
(library
(name main)
(preprocess
(staged_pps ppx_suffix)))

View file

@ -0,0 +1 @@
let () = print_string [%add_suffix "hello"]

View file

@ -0,0 +1,3 @@
(cram
(applies_to describe-pp)
(deps %{bin:refmt}))

View file

@ -0,0 +1,437 @@
Tests for the `dune describe` command
====================================
The following tests verify that `dune describe workspace` returns
consistent dependencies for executables and libraries, in the
particular case of dependencies towards PPX-rewriters.
They witness an issue reported in #6486, that is fixed in #6727
Setup
-----
$ cat >dune-project <<EOF
> (lang dune 3.4)
> EOF
$ mkdir static_lib
$ cd static_lib
$ cat >dune <<EOF
> (library
> (name static_lib))
> EOF
$ touch static_lib.ml
$ cd ..
$ mkdir dummy_ppx
$ cd dummy_ppx
$ cat >dune <<EOF
> (library
> (name dummy_ppx)
> (kind ppx_rewriter)
> (libraries ppxlib static_lib))
> EOF
$ cat >dummy_ppx.ml <<EOF
> (* dummy PPX rewriter, for use in tests *)
> (* artificial static dependency on library static_lib *)
> module M = Static_lib
> let () =
> Ppxlib.Driver.register_transformation
> "dummy2"
> ~impl:(fun s -> s)
> EOF
$ cd ..
$ mkdir lib
$ cd lib
$ cat >dune <<EOF
> (library
> (name lib)
> (preprocess (pps dummy_ppx)))
> EOF
$ touch lib.ml
$ cd ..
$ mkdir exe
$ cd exe
$ cat >dune <<EOF
> (executable
> (name exe)
> (preprocess (pps dummy_ppx)))
> EOF
$ touch exe.ml
$ cd ..
Describe various things
-----------------------
Warning: when testing the ``dune describe workspace`` command, do not
forget to pass the ``--sanitize-for-tests`` flags, so that the tests
are reproducible, and are kept consistent between different machines.
``dune describe workspace`` may indeed print absolute paths, that are
not stable across different setups.
$ dune describe workspace --lang 0.1 --sanitize-for-tests exe
((root /WORKSPACE_ROOT)
(build_context _build/default)
(executables
((names (exe))
(requires ())
(modules
(((name Exe)
(impl (_build/default/exe/exe.ml))
(intf ())
(cmt (_build/default/exe/.exe.eobjs/byte/dune__exe__Exe.cmt))
(cmti ()))))
(include_dirs (_build/default/exe/.exe.eobjs/byte)))))
$ dune describe workspace --lang 0.1 --sanitize-for-tests lib
((root /WORKSPACE_ROOT)
(build_context _build/default)
(library
((name lib)
(uid 48f89f472eed42cfe8a7ae83e2c8c1ce)
(local true)
(requires ())
(source_dir _build/default/lib)
(modules
(((name Lib)
(impl (_build/default/lib/lib.ml))
(intf ())
(cmt (_build/default/lib/.lib.objs/byte/lib.cmt))
(cmti ()))))
(include_dirs (_build/default/lib/.lib.objs/byte)))))
$ dune describe workspace --lang 0.1 --sanitize-for-tests --with-pps exe
((root /WORKSPACE_ROOT)
(build_context _build/default)
(executables
((names (exe))
(requires
(25fa301af563256248c5dadd60078c6e
b3f1696f67e77afbbf90bbd4ff4db3f7
3238f110cc121b8de5fb94811b5395f0
aa150dea272f13137145f9b1336e6f89
dc50e9309dbe56e9ba5a145dd0c7d272
c1f4a4a8fcca6a7045ebee5b639dc729
5df1715b4499126654748a00e0142c5e
9087f2ff68e06ebafea537cd921b2b75
3e0806da37ceb5ee0d783c15826db0e1
b6a38388b521e9d788bf8c241c8b7131
e7b78a2ef3334358a41a86855c8739c2
1513262a352b79a04ff483cd84ebd966
2c25d00eb24f552a85fba122b2d45dd1
12c434f04237f2f66660cf4ef9d28bac
d4bbc5a64c5463ce6eb84f54a61aa8b8))
(modules
(((name Exe)
(impl (_build/default/exe/exe.ml))
(intf ())
(cmt (_build/default/exe/.exe.eobjs/byte/dune__exe__Exe.cmt))
(cmti ()))))
(include_dirs (_build/default/exe/.exe.eobjs/byte))))
(library
((name compiler-libs)
(uid 25fa301af563256248c5dadd60078c6e)
(local false)
(requires ())
(source_dir /FINDLIB/compiler-libs)
(modules ())
(include_dirs (/FINDLIB/compiler-libs))))
(library
((name compiler-libs.common)
(uid b3f1696f67e77afbbf90bbd4ff4db3f7)
(local false)
(requires (25fa301af563256248c5dadd60078c6e))
(source_dir /FINDLIB/compiler-libs)
(modules ())
(include_dirs (/FINDLIB/compiler-libs))))
(library
((name dummy_ppx)
(uid d4bbc5a64c5463ce6eb84f54a61aa8b8)
(local true)
(requires
(c1f4a4a8fcca6a7045ebee5b639dc729
2c25d00eb24f552a85fba122b2d45dd1
12c434f04237f2f66660cf4ef9d28bac))
(source_dir _build/default/dummy_ppx)
(modules
(((name Dummy_ppx)
(impl (_build/default/dummy_ppx/dummy_ppx.ml))
(intf ())
(cmt (_build/default/dummy_ppx/.dummy_ppx.objs/byte/dummy_ppx.cmt))
(cmti ()))))
(include_dirs (_build/default/dummy_ppx/.dummy_ppx.objs/byte))))
(library
((name ocaml-compiler-libs.common)
(uid 3238f110cc121b8de5fb94811b5395f0)
(local false)
(requires (b3f1696f67e77afbbf90bbd4ff4db3f7))
(source_dir /FINDLIB/ocaml-compiler-libs/common)
(modules ())
(include_dirs (/FINDLIB/ocaml-compiler-libs/common))))
(library
((name ocaml-compiler-libs.shadow)
(uid 5df1715b4499126654748a00e0142c5e)
(local false)
(requires ())
(source_dir /FINDLIB/ocaml-compiler-libs/shadow)
(modules ())
(include_dirs (/FINDLIB/ocaml-compiler-libs/shadow))))
(library
((name ppx_derivers)
(uid 3e0806da37ceb5ee0d783c15826db0e1)
(local false)
(requires ())
(source_dir /FINDLIB/ppx_derivers)
(modules ())
(include_dirs (/FINDLIB/ppx_derivers))))
(library
((name ppxlib)
(uid 2c25d00eb24f552a85fba122b2d45dd1)
(local false)
(requires
(c1f4a4a8fcca6a7045ebee5b639dc729
5df1715b4499126654748a00e0142c5e
aa150dea272f13137145f9b1336e6f89
9087f2ff68e06ebafea537cd921b2b75
3e0806da37ceb5ee0d783c15826db0e1
b6a38388b521e9d788bf8c241c8b7131
1513262a352b79a04ff483cd84ebd966
dc50e9309dbe56e9ba5a145dd0c7d272
e7b78a2ef3334358a41a86855c8739c2
b3f1696f67e77afbbf90bbd4ff4db3f7))
(source_dir /FINDLIB/ppxlib)
(modules ())
(include_dirs (/FINDLIB/ppxlib))))
(library
((name ppxlib.ast)
(uid c1f4a4a8fcca6a7045ebee5b639dc729)
(local false)
(requires
(aa150dea272f13137145f9b1336e6f89 dc50e9309dbe56e9ba5a145dd0c7d272))
(source_dir /FINDLIB/ppxlib/ast)
(modules ())
(include_dirs (/FINDLIB/ppxlib/ast))))
(library
((name ppxlib.astlib)
(uid aa150dea272f13137145f9b1336e6f89)
(local false)
(requires
(3238f110cc121b8de5fb94811b5395f0 b3f1696f67e77afbbf90bbd4ff4db3f7))
(source_dir /FINDLIB/ppxlib/astlib)
(modules ())
(include_dirs (/FINDLIB/ppxlib/astlib))))
(library
((name ppxlib.print_diff)
(uid 9087f2ff68e06ebafea537cd921b2b75)
(local false)
(requires ())
(source_dir /FINDLIB/ppxlib/print_diff)
(modules ())
(include_dirs (/FINDLIB/ppxlib/print_diff))))
(library
((name ppxlib.stdppx)
(uid 1513262a352b79a04ff483cd84ebd966)
(local false)
(requires
(e7b78a2ef3334358a41a86855c8739c2 dc50e9309dbe56e9ba5a145dd0c7d272))
(source_dir /FINDLIB/ppxlib/stdppx)
(modules ())
(include_dirs (/FINDLIB/ppxlib/stdppx))))
(library
((name ppxlib.traverse_builtins)
(uid b6a38388b521e9d788bf8c241c8b7131)
(local false)
(requires ())
(source_dir /FINDLIB/ppxlib/traverse_builtins)
(modules ())
(include_dirs (/FINDLIB/ppxlib/traverse_builtins))))
(library
((name sexplib0)
(uid e7b78a2ef3334358a41a86855c8739c2)
(local false)
(requires ())
(source_dir /FINDLIB/sexplib0)
(modules ())
(include_dirs (/FINDLIB/sexplib0))))
(library
((name static_lib)
(uid 12c434f04237f2f66660cf4ef9d28bac)
(local true)
(requires ())
(source_dir _build/default/static_lib)
(modules
(((name Static_lib)
(impl (_build/default/static_lib/static_lib.ml))
(intf ())
(cmt (_build/default/static_lib/.static_lib.objs/byte/static_lib.cmt))
(cmti ()))))
(include_dirs (_build/default/static_lib/.static_lib.objs/byte))))
(library
((name stdlib-shims)
(uid dc50e9309dbe56e9ba5a145dd0c7d272)
(local false)
(requires ())
(source_dir /FINDLIB/stdlib-shims)
(modules ())
(include_dirs (/FINDLIB/stdlib-shims)))))
$ dune describe workspace --lang 0.1 --sanitize-for-tests --with-pps lib
((root /WORKSPACE_ROOT)
(build_context _build/default)
(library
((name compiler-libs)
(uid 25fa301af563256248c5dadd60078c6e)
(local false)
(requires ())
(source_dir /FINDLIB/compiler-libs)
(modules ())
(include_dirs (/FINDLIB/compiler-libs))))
(library
((name compiler-libs.common)
(uid b3f1696f67e77afbbf90bbd4ff4db3f7)
(local false)
(requires (25fa301af563256248c5dadd60078c6e))
(source_dir /FINDLIB/compiler-libs)
(modules ())
(include_dirs (/FINDLIB/compiler-libs))))
(library
((name dummy_ppx)
(uid d4bbc5a64c5463ce6eb84f54a61aa8b8)
(local true)
(requires
(c1f4a4a8fcca6a7045ebee5b639dc729
2c25d00eb24f552a85fba122b2d45dd1
12c434f04237f2f66660cf4ef9d28bac))
(source_dir _build/default/dummy_ppx)
(modules
(((name Dummy_ppx)
(impl (_build/default/dummy_ppx/dummy_ppx.ml))
(intf ())
(cmt (_build/default/dummy_ppx/.dummy_ppx.objs/byte/dummy_ppx.cmt))
(cmti ()))))
(include_dirs (_build/default/dummy_ppx/.dummy_ppx.objs/byte))))
(library
((name lib)
(uid 48f89f472eed42cfe8a7ae83e2c8c1ce)
(local true)
(requires ())
(source_dir _build/default/lib)
(modules
(((name Lib)
(impl (_build/default/lib/lib.ml))
(intf ())
(cmt (_build/default/lib/.lib.objs/byte/lib.cmt))
(cmti ()))))
(include_dirs (_build/default/lib/.lib.objs/byte))))
(library
((name ocaml-compiler-libs.common)
(uid 3238f110cc121b8de5fb94811b5395f0)
(local false)
(requires (b3f1696f67e77afbbf90bbd4ff4db3f7))
(source_dir /FINDLIB/ocaml-compiler-libs/common)
(modules ())
(include_dirs (/FINDLIB/ocaml-compiler-libs/common))))
(library
((name ocaml-compiler-libs.shadow)
(uid 5df1715b4499126654748a00e0142c5e)
(local false)
(requires ())
(source_dir /FINDLIB/ocaml-compiler-libs/shadow)
(modules ())
(include_dirs (/FINDLIB/ocaml-compiler-libs/shadow))))
(library
((name ppx_derivers)
(uid 3e0806da37ceb5ee0d783c15826db0e1)
(local false)
(requires ())
(source_dir /FINDLIB/ppx_derivers)
(modules ())
(include_dirs (/FINDLIB/ppx_derivers))))
(library
((name ppxlib)
(uid 2c25d00eb24f552a85fba122b2d45dd1)
(local false)
(requires
(c1f4a4a8fcca6a7045ebee5b639dc729
5df1715b4499126654748a00e0142c5e
aa150dea272f13137145f9b1336e6f89
9087f2ff68e06ebafea537cd921b2b75
3e0806da37ceb5ee0d783c15826db0e1
b6a38388b521e9d788bf8c241c8b7131
1513262a352b79a04ff483cd84ebd966
dc50e9309dbe56e9ba5a145dd0c7d272
e7b78a2ef3334358a41a86855c8739c2
b3f1696f67e77afbbf90bbd4ff4db3f7))
(source_dir /FINDLIB/ppxlib)
(modules ())
(include_dirs (/FINDLIB/ppxlib))))
(library
((name ppxlib.ast)
(uid c1f4a4a8fcca6a7045ebee5b639dc729)
(local false)
(requires
(aa150dea272f13137145f9b1336e6f89 dc50e9309dbe56e9ba5a145dd0c7d272))
(source_dir /FINDLIB/ppxlib/ast)
(modules ())
(include_dirs (/FINDLIB/ppxlib/ast))))
(library
((name ppxlib.astlib)
(uid aa150dea272f13137145f9b1336e6f89)
(local false)
(requires
(3238f110cc121b8de5fb94811b5395f0 b3f1696f67e77afbbf90bbd4ff4db3f7))
(source_dir /FINDLIB/ppxlib/astlib)
(modules ())
(include_dirs (/FINDLIB/ppxlib/astlib))))
(library
((name ppxlib.print_diff)
(uid 9087f2ff68e06ebafea537cd921b2b75)
(local false)
(requires ())
(source_dir /FINDLIB/ppxlib/print_diff)
(modules ())
(include_dirs (/FINDLIB/ppxlib/print_diff))))
(library
((name ppxlib.stdppx)
(uid 1513262a352b79a04ff483cd84ebd966)
(local false)
(requires
(e7b78a2ef3334358a41a86855c8739c2 dc50e9309dbe56e9ba5a145dd0c7d272))
(source_dir /FINDLIB/ppxlib/stdppx)
(modules ())
(include_dirs (/FINDLIB/ppxlib/stdppx))))
(library
((name ppxlib.traverse_builtins)
(uid b6a38388b521e9d788bf8c241c8b7131)
(local false)
(requires ())
(source_dir /FINDLIB/ppxlib/traverse_builtins)
(modules ())
(include_dirs (/FINDLIB/ppxlib/traverse_builtins))))
(library
((name sexplib0)
(uid e7b78a2ef3334358a41a86855c8739c2)
(local false)
(requires ())
(source_dir /FINDLIB/sexplib0)
(modules ())
(include_dirs (/FINDLIB/sexplib0))))
(library
((name static_lib)
(uid 12c434f04237f2f66660cf4ef9d28bac)
(local true)
(requires ())
(source_dir _build/default/static_lib)
(modules
(((name Static_lib)
(impl (_build/default/static_lib/static_lib.ml))
(intf ())
(cmt (_build/default/static_lib/.static_lib.objs/byte/static_lib.cmt))
(cmti ()))))
(include_dirs (_build/default/static_lib/.static_lib.objs/byte))))
(library
((name stdlib-shims)
(uid dc50e9309dbe56e9ba5a145dd0c7d272)
(local false)
(requires ())
(source_dir /FINDLIB/stdlib-shims)
(modules ())
(include_dirs (/FINDLIB/stdlib-shims)))))

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,2 @@
(library
(name simple2))

View file

@ -0,0 +1,9 @@
(library
(name simple))
(rule
(targets (dir d))
(action
(progn
(run mkdir d)
(run cat > d/foo))))

View file

@ -0,0 +1,2 @@
(lang dune 3.8)
(using directory-targets 0.1)

View file

@ -0,0 +1,91 @@
Testing the "dune show targets" command in a simple OCaml project with an
additional directory target to see the behaviour there.
We have two libraries with one in a subdirectory. We also have a directory
target d to see how the command will behave.
With no directory provided to the command, it should default to the current
working directory.
$ dune show targets
a.ml
d/
dune
dune-project
simple.a
simple.cma
simple.cmxa
simple.cmxs
simple.ml-gen
Multiple directories can be provided to the command. Also subdirectories may be
used, and only the targets available in that directory will be displayed.
$ dune show targets . b/
.:
a.ml
d/
dune
dune-project
simple.a
simple.cma
simple.cmxa
simple.cmxs
simple.ml-gen
b:
c.ml
dune
simple2.a
simple2.cma
simple2.cmxa
simple2.cmxs
simple2.ml-gen
The command also works with files in the _build directory.
$ dune show targets _build/default/
a.ml
d/
dune
dune-project
simple.a
simple.cma
simple.cmxa
simple.cmxs
simple.ml-gen
$ dune show targets _build/default/b
c.ml
dune
simple2.a
simple2.cma
simple2.cmxa
simple2.cmxs
simple2.ml-gen
We cannot see inside directory targets
$ dune show targets d
Error: Directory d is a directory target. This command does not support the
inspection of directory targets.
And we error on non-existent directories
$ dune show targets non-existent
Error: Directory non-existent does not exist.
We error if we are in the wrong context
$ dune show targets _build/other_context
Error: Directory _build/other_context is not in context "default".
$ cat > dune-workspace << EOF
> (lang dune 3.9)
> (context
> (default
> (name other_context)))
> EOF
$ dune show targets --context other_context _build/default
Error: Directory _build/default is not in context "other_context".