ocaml / opam

opam is a source-based package manager. It supports multiple simultaneous compiler installations, flexible package constraints, and a Git-friendly development workflow.
https://opam.ocaml.org
Other
1.21k stars 347 forks source link

opam install . --deps-only --working-dir incorrectly reports "Nothing to do" #5567

Open jonsterling opened 1 year ago

jonsterling commented 1 year ago

As far as I can tell, the --working-dir option of opam is not functional. I cannot tell if this is my own misunderstanding of what --working-dir or --deps-only are supposed to do, but this has happened often enough for me that I thought I would report it as a bug.

What happens

I have a program I am developing, and I have added a new dependency to my .opam file. In this case, I added a dependency on ptime. I now wish to bring my current switch into alignment with the dependencies specified by my project. Note that I have not committed this change in git. Therefore, I run the command opam install . --deps-only --working-dir, which the documentation has led me to believe will do the following: it should install the dependencies of the package specified in the current directory, and it should read the version of the .opam file that is currently in the working directory rather than the one that is committed to version control.

Here is what actually happens:

$ opam install . --deps-only --working-dir
Nothing to do.

I believe this behavior is either wrong or highly unintuitive; in the latter case, maybe we could come up with something to add to the documentation to clarify the intended function of these options.

What if I commit the change and don't use --working-dir?

When I commit the change to my .opam file and run opam install . --deps-only, then opam correctly offers to install ptime.

Diagnostic information

My .opam file

# This file is generated by dune, edit dune-project instead
opam-version: "2.0"
version: "2.1"
synopsis: "A tool for tending mathematical forests"
maintainer: ["Jonathan Sterling"]
authors: ["Jonathan Sterling"]
license: "GPL-3.0-or-later"
homepage: "https://github.com/jonsterling/ocaml-forester"
bug-reports: "https://github.com/jonsterling/ocaml-forester/issues"
depends: [
  "menhir"
  "ocamlgraph"
  "ocaml"
  "dune" {>= "3.7"}
  "xmlm"
  "ppx_deriving"
  "domainslib"
  "ptime"
  "yuujinchou" {>= "5.0.1"}
  "algaeff"
  "odoc" {with-doc}
]
build: [
  ["dune" "subst"] {dev}
  [
    "dune"
    "build"
    "-p"
    name
    "-j"
    jobs
    "@install"
    "@runtest" {with-test}
    "@doc" {with-doc}
  ]
]
dev-repo: "git+https://github.com/jonsterling/ocaml-forester.git"

You can also find the source repository here if you wish to reproduce on your own: https://github.com/jonsterling/ocaml-forester

opam config report:

# opam config report
# opam-version         2.1.4
# self-upgrade         no
# system               arch=arm64 os=macos os-distribution=homebrew os-version=13.4
# solver               builtin-mccs+glpk
# install-criteria     -removed,-count[avoid-version,changed],-count[version-lag,request],-count[version-lag,changed],-count[missing-depexts,changed],-changed
# upgrade-criteria     -removed,-count[avoid-version,changed],-count[version-lag,solution],-count[missing-depexts,changed],-new
# jobs                 7
# repositories         1 (http) (default repo at 1dce70f3)
# pinned               1 (git)
# current-switch       /Users/au598479/Source/ocaml-forester
# ocaml:native         true
# ocaml:native-tools   true
# ocaml:native-dynlink true
# ocaml:stubsdir       /Users/au598479/Source/ocaml-forester/_opam/lib/ocaml/stublibs:/Users/au598479/Source/ocaml-forester/_opam/lib/ocaml
# ocaml:preinstalled   false
# ocaml:compiler       5.0.0

opam list

# Packages matching: installed
# Name                # Installed # Synopsis
alcotest              1.7.0       Alcotest is a lightweight and colourful test framework
algaeff               0.2.1       Reusable Effects-Based Components
astring               0.8.5       Alternative String module for OCaml
base-bigarray         base
base-bytes            base        Bytes library distributed with the OCaml compiler
base-domains          base
base-nnp              base        Naked pointers prohibited in the OCaml heap
base-threads          base
base-unix             base
bwd                   2.1.0       Backward lists
chrome-trace          3.8.0       Chrome trace event generation library
cmdliner              1.2.0       Declarative definition of command line interfaces for OCaml
cppo                  1.6.9       Code preprocessor like cpp for OCaml
csexp                 1.5.2       Parsing and printing of S-expressions in Canonical form
domain_shims          0.1.0       A non-parallel implementation of Domains compatible with OCaml 4
domainslib            0.5.0       Nested-parallel programming library
dune                  3.8.0       Fast, portable, and opinionated build system
dune-build-info       3.8.0       Embed build information inside executable
dune-rpc              3.6.2       Communicate with dune using rpc
dyn                   3.6.2       Dynamic type
fiber                 3.6.2       Structured concurrency library
fmt                   0.9.0       OCaml Format pretty-printer combinators
lockfree              0.3.1       Lock-free data structures for multicore OCaml
menhir                20230415    An LR(1) parser generator
menhirLib             20230415    Runtime support library for parsers generated by Menhir
menhirSdk             20230415    Compile-time library for auxiliary tools related to Menhir
ocaml                 5.0.0       The OCaml compiler (virtual package)
ocaml-base-compiler   5.0.0       Official release 5.0.0
ocaml-compiler-libs   v0.12.4     OCaml compiler libraries repackaged
ocaml-config          3           OCaml Switch Configuration
ocaml-lsp-server      1.15.1-5.0  LSP Server for OCaml
ocaml-options-vanilla 1           Ensure that OCaml is compiled with no special options enabled
ocaml-syntax-shims    1.0.0       Backport new syntax to older OCaml versions
ocamlbuild            0.14.2      OCamlbuild is a build system with builtin rules to easily build most OCaml pro
ocamlc-loc            3.6.2       Parse ocaml compiler output into structured form
ocamlfind             1.9.6       A library manager for OCaml
ocamlformat-rpc-lib   0.25.1      Auto-formatter for OCaml code (RPC mode)
ocamlgraph            2.0.0       A generic graph library for OCaml
ocp-indent            1.8.1       A simple tool to indent OCaml programs
octavius              1.2.2       Ocamldoc comment syntax parser
omd                   1.3.2       A Markdown frontend in pure OCaml
ordering              3.6.2       Element ordering
pp                    1.1.2       Pretty-printing library
ppx_derivers          1.2.1       Shared [@@deriving] plugin registry
ppx_deriving          5.2.1       Type-driven code generation for OCaml
ppx_yojson_conv_lib   v0.15.0     Runtime lib for ppx_yojson_conv
ppxlib                0.29.1      Standard library for ppx rewriters
re                    1.10.4      RE is a regular expression library for OCaml
result                1.5         Compatibility Result module
seq                   base        Compatibility package for OCaml's standard iterator type starting from 4.07.
sexplib0              v0.16.0     Library containing the definition of S-expressions and some base converters
spawn                 v0.15.1     Spawning sub-processes
stdlib-shims          0.3.0       Backport some of the new stdlib features to older compiler
stdune                3.6.2       Dune's unstable standard library
topkg                 1.0.7       The transitory OCaml software packager
uutf                  1.0.3       Non-blocking streaming Unicode codec for OCaml
xdg                   3.8.0       XDG Base Directory Specification
xmlm                  1.4.0       Streaming XML codec for OCaml
yojson                2.1.0       Yojson is an optimized parsing and printing library for the JSON format
yuujinchou            5.0.1       A library for hierarchical names and lexical scoping

As you can see, the package ptime is not installed.

AltGr commented 9 months ago

Thanks for reporting! I had a similar issue with just opam install . --deps-only while the opam file with updated dependencies was properly committed.

It follows that this is unlikely to be related to --working-dir, and more probably due to the way the local opam file needs to be picked in advance when using a directory for package...

eponier commented 1 month ago

I had the same bug with Jasmin, without --working-dir. opam install . --deps-only at the root does not install coq-mathcomp-algebra (among others), and moreover does not report the package as unknown when it does not know it (I initially forgot to add https://coq.inria.fr/opam/released as another remote, so coq-mathcomp-algebra was unknown).

Version: 2.2.0~beta1