OPAM-ADMIN-ADD-CONSTRAINT(1)

πŸŽ€ OPAM-ADMIN-ADD-CONSTRAINT πŸŽ€

okay so bestie, this one lives in the Opam admin Manual, and its full government name is OPAM ADMIN-ADD-CONSTRAINT(1). It's a glow-up tool for your repo metadata. Let's get into it πŸ’…


✨ NAME ✨

opam admin-add-constraint β€” Adds version constraints on all dependencies towards a given package.


🌸 SYNOPSIS 🌸

opam admin add-constraint [--force] [--packages=PACKAGES] [OPTION]… PACKAGE

πŸ’– DESCRIPTION πŸ’–

So the way this works is: it goes and searches to all dependencies that point towards a given package, and then it slaps a version constraint on them. Iconic behavior, honestly.

It's particularly useful when you wanna add upper bounds to dependencies you already have β€” like when a brand-new, incompatible major version of a library drops into a repository and you need everyone to chill 🫢

The new version constraint gets merged with the existing one, and then simplified if possible. Example, because I know you love a concrete one: >=3 & >5 becomes >5. Math ate, periodt ✨


πŸ¦‹ ARGUMENTS πŸ¦‹

  • PACKAGE (required) β€” A package name with a version constraint, e.g. name>=version. And ngl, if you don't specify a version constraint, the command will just simplify the existing version constraints on dependencies to the named package. No constraint added, just tidying up 🧹

πŸ’… OPTIONS πŸ’…

  • --force β€” Forces the updating of constraints even if the resulting constraint is unsatisfiable (e.g. when adding >3 to the constraint <2). Without this, the default is to print a warning and keep the existing constraint unchanged. So yeah, this one is the "I know what I'm doing" button 😭
  • -p PACKAGES, --packages=PACKAGES β€” Only add constraints for the given packages.

πŸ‘‘ COMMON OPTIONS πŸ‘‘

These options are common to all commands. Yes, all of them. They're basically the group chat everyone's in.

  • --best-effort β€” Don't fail if all requested packages can't be installed: try to install as many as possible. Heads up though, not all external solvers may support this option (recent versions of aspcud or mccs should). This is equivalent to setting $OPAMBESTEFFORT environment variable.
  • --cli=MAJOR.MINOR (absent=2.6) β€” Use the command-line interface syntax and semantics of MAJOR.MINOR. Intended for any persistent use of opam (scripts, blog posts, etc.), any version of opam in the same MAJOR series will behave as for the specified MINOR release. The flag was not available in opam 2.0, so to select the 2.0 CLI, set the OPAMCLI environment variable to 2.0 instead of using this parameter.
  • --color=WHEN β€” Colorize the output. WHEN must be one of always, never or auto. 🌈
  • --confirm-level=LEVEL β€” Confirmation level, LEVEL must be one of ask, no, yes or unsafe-yes. Can be specified more than once. If --yes or --no are also given, the value of the last --confirm-level is taken into account. This is equivalent to setting `$OPAMCONFIRMLEVEL``.
  • --criteria=CRITERIA β€” Specify user preferences for dependency solving for this run. Overrides $OPAMCRITERIA, $OPAMFIXUPCRITERIA and $OPAMUPGRADECRITERIA. For details on the supported language, and the external solvers available, see http://opam.ocaml.org/doc/External_solvers.html. A general guide to using solver preferences can be found at http://www.dicosmo.org/Articles/usercriteria.pdf.
  • --cudf=FILENAME β€” Debug option: Save the CUDF requests sent to the solver to FILENAME-<n>.cudf where <n> is the n-th call to the solver during the opam run.
  • --debug β€” Print debug message to stderr. This is equivalent to setting $OPAMDEBUG to "true".
  • --debug-level=LEVEL β€” Like --debug, but allows specifying the debug level (--debug sets it to 1). Equivalent to setting $OPAMDEBUG to a positive integer.
  • --git-version β€” Print the git version of opam, if set (i.e. you are using a development version), and exit.
  • --help[=FMT] (default=auto) β€” Show this help in format FMT. The value FMT must be one of auto, pager, groff or plain. With auto, the format is pager or plain whenever the TERM env var is dumb or undefined.
  • --ignore-pin-depends β€” Ignore extra pins required by packages that get pinned, either manually through opam pin or through opam install DIR. This is equivalent to setting IGNOREPINDEPENDS=true.
  • --json=FILENAME β€” Save the results of the opam run in a computer-readable file. If the filename contains the character %, it will be replaced by an index that doesn't overwrite an existing file. Similar to setting the $OPAMJSON variable.
  • --no β€” Answer no to all opam yes/no questions without prompting. See also --confirm-level. This is equivalent to setting $OPAMNO to "true".
  • --no-aspcud β€” Removed in 2.1. πŸ’€
  • --no-auto-upgrade β€” When configuring or updating a repository that is written for an earlier opam version (1.2), opam internally converts it to the current format. This disables this behaviour. Note that repositories should define their format version in a 'repo' file at their root, or they will be assumed to be in the older format. It is, in any case, preferable to upgrade the repositories manually using opam admin upgrade [--mirror URL] when possible.
  • -q, --quiet β€” Disables --verbose.
  • --root=ROOT β€” Use ROOT as the current root path. This is equivalent to setting $OPAMROOT to ROOT.
  • --safe, --readonly β€” Make sure nothing will be automatically updated or rewritten. Useful for calling from completion scripts, for example. Will fail whenever such an operation is needed ; also avoids waiting for locks, skips interactive questions and overrides the $OPAMDEBUG variable. This is equivalent to set environment variable $OPAMSAFE.
  • --solver=CMD β€” Specify the CUDF solver to use for resolving package installation problems. This is either a predefined solver (this version of opam supports builtin-mccs+lp(), builtin-mccs+glpk, builtin-dummy-z3-solver, builtin-0install, aspcud, mccs, aspcud-old, packup), or a custom command that should contain the variables %{input}%, %{output}%, %{criteria}%, and optionally %{timeout}%. This is equivalent to setting $OPAMEXTERNALSOLVER.
  • --strict β€” Fail whenever an error is found in a package definition or a configuration file. The default is to continue silently if possible.
  • --switch=SWITCH β€” Use SWITCH as the current compiler switch. This is equivalent to setting $OPAMSWITCH to SWITCH.
  • --use-internal-solver β€” Disable any external solver, and use the built-in one (this requires that opam has been compiled with a built-in solver). This is equivalent to setting $OPAMNOASPCUD or $OPAMUSEINTERNALSOLVER.
  • -v, --verbose β€” Be more verbose. One -v shows all package commands, repeat to also display commands called internally (e.g. tar, curl, patch etc.) Repeating n times is equivalent to setting $OPAMVERBOSE to "n".
  • --version β€” Show version information.
  • -w, --working-dir β€” Whenever updating packages that are bound to a local, version-controlled directory, update to the current working state of their source instead of the last committed state, or the ref they are pointing to. As source directory is copied as it is, if it isn't clean it may result on a opam build failure. This only affects packages explicitly listed on the command-line. It can also be set with $OPAMWORKINGDIR.
  • -y, --yes β€” Answer yes to all opam yes/no questions without prompting. See also --confirm-level. This is equivalent to setting $OPAMYES to "true".

🌈 ENVIRONMENT 🌈

bestie. opam is deeply into env vars. it reads a whole little family of them and they shape how it behaves, so listen up.

for the boolean ones (the yes/no girlies): set them to "0", "no", "false" or the empty string to turn it OFF, and "1", "yes" or "true" to turn it ON. that's the whole rule, no cap.

  • OPAMALLPARENS β€” surrounds all filters with parenthesis. all of them. every single one 🫢
  • OPAMASSUMEDEPEXTS β€” go look at the --assume-depexts option, that's the one.
  • OPAMAUTOANSWER β€” internal use only 😭 like, genuinely do not mess with her.
  • OPAMAUTOREMOVE β€” see the remove option --auto-remove.
  • OPAMBESTEFFORT β€” see option --best-effort.
  • OPAMBESTEFFORTPREFIXCRITERIA β€” sets the string that must be prepended to the criteria when the --best-effort option is set, and it's expected to maximise the opam-query property in the solution.
  • OPAMBUILDDOC β€” Removed in 2.1. she's gone πŸ’€
  • OPAMBUILDTEST β€” Removed in 2.1. also gone.
  • OPAMCLI β€” see option --cli.
  • OPAMCOLOR β€” when set to always or never, she sets a default value for the --color option.
  • OPAMCONFIRMLEVEL β€” see option --confirm-level. ⚠️ OPAMCONFIRMLEVEL has priority over OPAMYES and OPAMNO.
  • OPAMCRITERIA β€” specifies your user preferences for dependency solving. the default value depends on the solver version, so run config report to know the current setting. see also option --criteria.
  • OPAMCUDFFILE β€” save the cudf graph to file-actions-explicit.dot.
  • OPAMCUDFTRIM β€” controls the filtering of unrelated packages during CUDF preprocessing.
  • OPAMCURL β€” can be used to select a given 'curl' program. see OPAMFETCH for more options.
  • OPAMDEBUG β€” see options --debug and --debug-level.
  • OPAMDEBUGSECTIONS β€” if set, limits debug messages to the space-separated list of sections. sections can optionally have a specific debug level (for example, CLIENT:2 or CLIENT CUDF:2), but otherwise use --debug-level.
  • OPAMDIGDEPTH β€” defines how aggressive the lookup for conflicts during CUDF preprocessing is. she will dig πŸ”
  • OPAMDOWNLOADJOBS β€” sets the maximum number of simultaneous downloads.
  • OPAMDROPWORKINGDIR β€” overrides packages previously updated with --working-dir on update. without this variable set, opam would keep them unchanged unless explicitly named on the command-line.
  • OPAMDRYRUN β€” see option --dry-run.
  • OPAMEDITOR β€” sets the editor to use for opam file editing, overrides $EDITOR and $VISUAL.
  • OPAMERRLOGLEN β€” sets the number of log lines printed when a sub-process fails. 0 to print all.
  • OPAMEXTERNALSOLVER β€” see option --solver.
  • OPAMFAKE β€” see option --fake.
  • OPAMFETCH β€” specifies how to download files: either wget, curl or a custom command where variables %{url}%, %{out}%, %{retry}%, %{compress}% and %{checksum}% will be replaced. overrides the 'download-command' value from the main config file.
  • OPAMFIXUPCRITERIA β€” same as OPAMUPGRADECRITERIA, but specific to fixup and reinstall.
  • OPAMIGNOREAVAILABLE β€” see install option --ignore-available-on.
  • OPAMIGNORECONSTRAINTS β€” see install option --ignore-constraints-on.
  • OPAMIGNOREPINDEPENDS β€” see option --ignore-pin-depends.
  • OPAMINPLACEBUILD β€” see option --inplace-build.
  • OPAMJOBS β€” sets the maximum number of parallel workers to run. she's multithreading, periodt πŸ”₯
  • OPAMJSON β€” log json output to the given file (use character % to index the files).
  • OPAMKEEPBUILDDIR β€” see install option --keep-build-dir.
  • OPAMKEEPLOGS β€” tells opam to not remove some temporary command logs and some backups. this skips some finalisers and may also help to get more reliable backtraces.
  • OPAMLOCKED β€” combination of --locked and --lock-suffix options.
  • OPAMLOGS β€” logdir sets log directory, default is a temporary directory in /tmp.
  • OPAMMAKECMD β€” set the system make command to use.
  • OPAMMERGEOUT β€” merge process outputs, stderr on stdout.
  • OPAMNO β€” answer no to any question asked, see options --no and --confirm-level. ⚠️ OPAMNO is ignored if either OPAMCONFIRMLEVEL or OPAMYES is set.
  • OPAMNOAGGREGATE β€” with opam admin check, don't aggregate packages.
  • OPAMNOASPCUD β€” Deprecated.
  • OPAMNOAUTOUPGRADE β€” disables automatic internal upgrade of repositories in an earlier format to the current one, on 'update' or 'init'.
  • OPAMNOCHECKSUMS β€” enables option --no-checksums when available.
  • OPAMNODEPEXTS β€” disables system dependencies handling, see option --no-depexts.
  • OPAMNOENVNOTICE β€” Internal.
  • OPAMNOSELFUPGRADE β€” see option --no-self-upgrade.
  • OPAMPINKINDAUTO β€” sets whether version control systems should be detected when pinning to a local path. enabled by default since 1.3.0.
  • OPAMPRECISETRACKING β€” fine grain tracking of directories.
  • OPAMPREPRO β€” set this to false to disable CUDF preprocessing. less efficient, but might help debugging solver issue.
  • OPAMREPOSITORYTARRING β€” internally store all non-vcs repositories as tar.gz files (by default, http repositories are stored as archive). this can be much faster on filesystems that don't cope well with scanning large trees. all operation are done in-memory, no I/O for scanning the repository. iconic, honestly ✨
  • OPAMREQUIRECHECKSUMS β€” enables option --require-checksums when available (e.g. for opam install).
  • OPAMRETRIES β€” sets the number of tries before failing downloads.
  • OPAMREUSEBUILDDIR β€” see option --reuse-build-dir.
  • OPAMROOT β€” see option --root. this is automatically set by opam env --root=DIR --set-root.
  • OPAMROOTISOK β€” don't complain when running as root.
  • OPAMSAFE β€” see option --safe.
  • OPAMSHOW β€” see option --show.
  • OPAMSKIPUPDATE β€” see option --skip-updates.
  • OPAMSKIPVERSIONCHECKS β€” bypasses some version checks. Unsafe, for compatibility testing only.
  • OPAMSOLVERALLOWSUBOPTIMAL β€” (default true) allows some solvers to still return a solution when they reach timeout; while the solution remains assured to be consistent, there is no guarantee in this case that it fits the expected optimisation criteria. if true, opam will continue with a warning; if false, a timeout is an error. currently only the builtin-z3 backend handles this degraded case.
  • OPAMSOLVERTIMEOUT β€” change the time allowance of the solver. default is 60.0, set to 0 for unlimited. note that all solvers may not support this option.
  • OPAMSOLVERTOLERANCE β€” changes the tolerance towards the solver choosing an unoptimized solution (i.e. might pull outdated packages). typical values range from 0.0 (best solution known to the solver) to 1.0 (unoptimized solution). default is 0.0. this option is useful in case the solver can't find a solution in a reasonable time (see $OPAMSOLVERTIMEOUT). note that all solvers may not support this option.
  • OPAMSTATS β€” Removed in 2.4.
  • OPAMSTATUSLINE β€” display a dynamic status line showing what's currently going on on the terminal (one of always, never or auto).
  • OPAMSTRICT β€” fail on inconsistencies (file reading, switch import, etc.).
  • OPAMSWITCH β€” see option --switch. automatically set by opam env --switch=SWITCH --set-switch.
  • OPAMUNLOCKBASE β€” see install option --unlock-base.
  • OPAMUPGRADECRITERIA β€” specifies user preferences for dependency solving when performing an upgrade. overrides OPAMCRITERIA in upgrades if both are set. see also option --criteria.
  • OPAMUSEINTERNALSOLVER β€” see option --use-internal-solver.
  • OPAMUSEOPENSSL β€” Removed in 2.2.
  • OPAMUTF8 β€” use UTF8 characters in output (one of always, never or auto). by default auto, which is determined from the locale.
  • OPAMUTF8MSGS β€” use extended UTF8 characters (camels) in opam messages πŸͺ implies OPAMUTF8. this is set by default on macOS only.
  • OPAMVALIDATIONHOOK β€” if set, uses the %{hook}% command to validate an opam repository update.
  • OPAMVERBOSE β€” see option --verbose.
  • OPAMVERBOSEON β€” see option --verbose-on.
  • OPAMVERSIONLAGPOWER β€” do not use. πŸ™ˆ that's it. that's the whole description.
  • OPAMWITHDEVSETUP β€” see install option --with-dev-setup.
  • OPAMWITHDOC β€” see install option --with-doc.
  • OPAMWITHTEST β€” see install option --with-test.
  • OPAMWORKINGDIR β€” see option --working-dir.
  • OPAMYES β€” see options --yes and --confirm-level. OPAMYES has priority over OPAMNO and is ignored if OPAMCONFIRMLEVEL is set.
  • OPAMVAR_var β€” overrides the contents of the variable var when substituting %{var}% strings in opam files.
  • OPAMVAR_package_var β€” overrides the contents of the variable package:var when substituting %{package:var}% strings in opam files.

πŸŽ€ CLI VERSION πŸŽ€

okay this one is important so put your phone down for a sec.

all scripts and programmatic invocations of opam should use --cli in order to ensure that they work seamlessly with future versions of the opam client. and it's not just for the nerds writing scripts β€” blog posts or other documentation can benefit too, because it prevents information from becoming stale. slay.

although opam only supports roots (~/.opam/) for the current version, it does provide backwards compatibility for its command-line interface.

since CLI version support was only added in opam 2.1, use OPAMCLI to select 2.0 support (as opam 2.0 will just ignore it), and --cli=2.1 for 2.1 (or later) versions, since an environment variable controlling the parsing of syntax is brittle. to this end, opam displays a warning if OPAMCLI specifies a valid version other than 2.0, and also if --cli=2.0 is specified. πŸ‘€

the command-line version is selected by using the --cli option or the OPAMCLI environment variable. --cli may be specified more than once, where the last instance takes precedence. OPAMCLI is only inspected if --cli is not given.

πŸ’€ EXIT STATUS πŸ’€

ok so here's the tea on exit codes, bestie β€” every program hands back a lil number when it's done and opam is no exception, so let's decode the whole alphabet soup 🫢

BIG exception first, don't skip this one!! unlike literally everything else below, the exec command is built different: it returns 127 if the command wasn't found or just couldn't be executed at all, and otherwise it returns the command's own exit value. that's the whole rule. iconic behavior honestly ✨

here's the full menu of exit codes:

  • 0 β€” Success πŸŽ‰ or true when it's a boolean query. win is win.
  • 1 β€” False. this one shows up when a boolean return value is what's expected, like when you're running with --check, or for queries like opam lint.
  • 2 β€” Bad command-line arguments πŸ’€, or command-line arguments that point at an invalid context (think: a file that doesn't follow the expected format).
  • 5 β€” Not found. you asked for something β€” a package, a version, a repository, whatever β€” and it Could Not Be Found. it's giving missing girl era 😭
  • 10 β€” Aborted. the operation needed confirmation and you (or something) didn't give it.
  • 15 β€” Could not acquire the locks required for the operation. locked out, not locked in πŸ”’
  • 20 β€” There's no solution to the user request. this can happen when you ask to install two incompatible packages, for example. the math said no, bestie.
  • 30 β€” Error in package definition, or in other metadata files. heads up: using --strict raises this error more often πŸ‘€
  • 31 β€” Package script error. some package operations were unsuccessful. this may be an error in the packages, or an incompatibility with your system. also: this can be a partial error.
  • 40 β€” Sync error. couldn't fetch some remotes from the network. also can be a partial error 🌐
  • 50 β€” Configuration error. opam or system configuration doesn't allow the operation, and it needs fixing. bestie the config is the problem not you πŸ’…
  • 60 β€” Solver failure. the solver failed to return a sound answer. this can be because of a broken external solver, or an error in solver configuration.
  • 99 β€” Internal error. something went wrong, and it's likely due to a bug in opam itself. not your fault babes, that's a them problem πŸ›
  • 130 β€” User interrupt. SIGINT was received, generally because the user pressed Ctrl+C. we've all been there πŸ™ˆ

and then there's this lil extra batch of status codes, keeping the same energy:

  • 0 on success.
  • 123 on indiscriminate errors reported on standard error.
  • 124 on command line parsing errors.
  • 125 on unexpected internal errors (bugs).

πŸ“š FURTHER DOCUMENTATION πŸ“š

want more? the docs live at https://opam.ocaml.org/doc β€” go drink from the firehose, you got this πŸ’–


πŸ‘‘ AUTHORS πŸ‘‘

these are the icons who built this, show some respect to the whole squad:

  • David Allsopp <david@tarides.com>
  • Vincent Bernardoff <vb@luminar.eu.org>
  • Raja Boujbel <raja.boujbel@ocamlpro.com>
  • Kate Deplaix <kit-ty-kate@exn.st>
  • Roberto Di Cosmo <roberto@dicosmo.org>
  • Thomas Gazagnaire <thomas@gazagnaire.org>
  • Louis Gesbert <louis.gesbert@ocamlpro.com>
  • Fabrice Le Fessant <Fabrice.Le_fessant@inria.fr>
  • Anil Madhavapeddy <anil@recoil.org>
  • Guillem Rieu <guillem.rieu@ocamlpro.com>
  • Ralf Treinen <ralf.treinen@pps.jussieu.fr>
  • Frederic Tuong <tuong@users.gforge.inria.fr>

πŸ”— SEE ALSO πŸ”—

  • opam admin(1) β€” the parent page, the main character, go read it next 🌸

πŸ› BUGS πŸ›

found something cursed? check the bug reports at https://github.com/ocaml/opam/issues β€” no cap, they actually want to hear about it πŸ’œ


and that's the whole page bestie!! πŸŽ€ this was Opam admin 2.6.1, page OPAM ADMIN-ADD-CONSTRAINT(1) β€” literally the full manual page, start to finish, and you read all of it. ate. periodt. go forth and constrain some packages responsibly βœ¨πŸ¦‹πŸ’…

πŸ“¦ where this page comes from