ocaml / dune

A composable build system for OCaml.
https://dune.build/
MIT License
1.63k stars 404 forks source link

pkg: inscrutable error when depending on a non-existent package #10987

Open v-gb opened 1 month ago

v-gb commented 1 month ago

Expected Behavior

If the dune-project file mentions a package that doesn't exist in the depends field, I'd expect an error saying so when calling dune pkg lock.

Actual Behavior

Instead, dune prints screenfuls of confusing information that mention various problems, almost all of which is irrelevant to the problem (but seems like it could be relevant).

Reproduction

Given a dune-project with:

(lang dune 3.15)
(name abc)
(package
 (name abc)
 (synopsis "A short synopsis")
 (description "A longer description")
 (depends
   ocaml
   dune
   base
   re
   unix
   core
   core_unix
   ocamlformat
   ocamlformat-lib
 )
 (tags
  (topics "to describe" your project)))

I get this error when running dune pkg lock:

$ dune --version
"Dune Developer Preview: build 2024-09-28T01:30:13+00:00, git revision
17071ec30d10390badcb6cb1f6a43984b1be54a6"
$ dune pkg lock
Error: Unable to solve dependencies for the following lock directories:
Lock directory dune.lock:
Can't find all required versions.
Selected: base.v0.17.1 base-threads.base base-unix.base
          base_bigstring.v0.17.0 base_quickcheck.v0.17.0 bin_prot.v0.17.0
          capitalization.v0.17.0 cmdliner.1.3.0 core.v0.17.1
          core_kernel.v0.17.0 core_unix.v0.17.0 csexp.1.5.2
          dune-configurator.3.16.0 expect_test_helpers_core.v0.17.0
          fieldslib.v0.17.0 gel.v0.17.0 int_repr.v0.17.0
          jane-street-headers.v0.17.0 jst-config.v0.17.0 migration.dev
          num.1.5-1 ocaml.5.4.0 ocaml-config.3
          ocaml_intrinsics_kernel.v0.17.1 ocamlformat.0.26.2 parsexp.v0.17.0
          ppx_assert.v0.17.0 ppx_base.v0.17.0 ppx_bench.v0.17.0
          ppx_bin_prot.v0.17.0 ppx_cold.v0.17.0 ppx_compare.v0.17.0
          ppx_custom_printf.v0.17.0 ppx_diff.v0.17.0
          ppx_disable_unused_warnings.v0.17.0 ppx_enumerate.v0.17.0
          ppx_expect.v0.17.0 ppx_fields_conv.v0.17.0
          ppx_fixed_literal.v0.17.0 ppx_globalize.v0.17.0 ppx_hash.v0.17.0
          ppx_here.v0.17.0 ppx_ignore_instrumentation.v0.17.0
          ppx_inline_test.v0.17.0 ppx_jane.v0.17.0 ppx_let.v0.17.0
          ppx_log.v0.17.0 ppx_module_timer.v0.17.0 ppx_optcomp.v0.17.0
          ppx_optional.v0.17.0 ppx_pipebang.v0.17.0 ppx_sexp_conv.v0.17.0
          ppx_sexp_message.v0.17.0 ppx_sexp_value.v0.17.0 ppx_stable.v0.17.0
          ppx_stable_witness.v0.17.0 ppx_string.v0.17.0
          ppx_string_conv.v0.17.0 ppx_tydi.v0.17.0 ppx_typerep_conv.v0.17.0
          ppx_variants_conv.v0.17.0 ppxlib_jane.v0.17.1 re.1.12.0 seq.base
          sexp_pretty.v0.17.0 sexplib.v0.17.0 sexplib0.v0.17.0 spawn.v0.15.1
          splittable_random.v0.17.0 stdio.v0.17.0 time_now.v0.17.0
          timezone.v0.17.0 uopt.v0.17.0 variantslib.v0.17.0
          ocaml-base-compiler ocaml-base-compiler ocaml
- dune -> dune.3.16.0
    User requested = 3.17
- ocaml-base-compiler -> (problem)
    Rejected candidates:
      ocaml-base-compiler.5.2.0: Requires ocaml = 5.2.0
      ocaml-base-compiler.5.1.1: Requires ocaml = 5.1.1
      ocaml-base-compiler.5.1.0: Requires ocaml = 5.1.0
      ocaml-base-compiler.5.0.0: Requires ocaml = 5.0.0
      ocaml-base-compiler.4.14.2: Requires ocaml = 4.14.2
      ...
- ocamlformat-lib -> (problem)
    ocamlformat 0.26.2 requires = 0.26.2
    Rejected candidates:
      ocamlformat-lib.0.26.2: Requires ocaml >= 4.08 & < 5.3
      ocamlformat-lib.0.26.1: Incompatible with restriction: = 0.26.2
      ocamlformat-lib.0.26.0: Incompatible with restriction: = 0.26.2
      ocamlformat-lib.0.25.1: Incompatible with restriction: = 0.26.2
- ppxlib -> (problem)
    base_quickcheck v0.17.0 requires >= 0.28.0
    Rejected candidates:
      ppxlib.0.33.0: Requires ocaml >= 4.04.1 & < 5.3.0
      ppxlib.0.32.1: Requires ocaml >= 4.04.1 & < 5.3.0
      ppxlib.0.32.0: Requires ocaml >= 4.04.1 & < 5.2.0 & <> 5.1.0~alpha1
      ppxlib.0.31.0: Requires ocaml >= 4.04.1 & < 5.2.0 & <> 5.1.0~alpha1
      ppxlib.0.30.0: Requires ocaml >= 4.04.1 & < 5.2.0 & <> 5.1.0~alpha1
      ...
- typerep -> (problem)
    core v0.17.1 requires >= v0.17 & < v0.18
    Rejected candidates:
      typerep.v0.17.0: Requires ocaml >= 5.1.0 & < 5.3
      typerep.v0.16.0: Incompatible with restriction: >= v0.17 & < v0.18
      typerep.v0.15.0: Incompatible with restriction: >= v0.17 & < v0.18
      typerep.v0.14.0: Incompatible with restriction: >= v0.17 & < v0.18
      typerep.v0.13.0: Incompatible with restriction: >= v0.17 & < v0.18
      ...
- unix -> (problem)
    No known implementations at all

The real problem here is

- unix -> (problem)
    No known implementations at all

but that's just one of many problem listed above. If unix is removed from the depends list, the command succeeds (because unix is in fact not a package, it's just a library in the ocaml package or something. Also if dune generated the depends list from the dune files, this confusion wouldn't need to exist in the first place).

maiste commented 3 weeks ago

Thanks for reporting the issue! This is an error we have because of the 0install solver, which computes the dependencies. Currently, we can't tweak the output and provide a better error. However, we are exploring some alternatives to make it better, such as having an output produced by 0install we could parse from dune or having an alternative solver.