1.7.5 Module anvl_locate

This module provides a generic mechanism for resolving external dependencies. It doesn’t do anything on its own, but acts as a broker between dependency resolver plugins (such as Git, Builtin ANVL Plugin) and dependency consumers.

Consumer of the external dependency supplies the following parameters:

  1. Kind, a type of a dependency that needs resolution. Kinds serve as "namespaces" for dependencies, for example, they allow to distinguish dependencies for different languages used within the project.
  2. Dependency, a term identifying the dependency.
  3. SubDirFun, a function that can identify a sub-dependency by inspecting contents of a directory.

For each kind anvl_locate maintains a search path, that is a list of directories.

Dependency resolution works as following:

  1. SubDirFun is executed for each entry of the existing search path. If it returns a match (a subdirectory), then this subdirectory becomes the result of resolution, which gets cached for the future using ANVL’s standard memoization mechanism. Non-matches are cached as well.
  2. If the previous step did not succeed, then anvl_locate passes dependency kind and ID to the plugins. The plugins can inspect project config or any other source, download the dependency into some local directory, and add it to the search path.
  3. If the search path has been modified, then step 1. runs again.

Note: finding of a compatible set of the dependency versions, (i.e. solving a system of inequations foo_ver >= 1 && foo_ver < 3, ...) is not a responsibility of this module. This step is delegated to other plugins.

1.7.5.1 Types

locate_hook()
-type locate_hook() :: fun((kind(),
                            dependency()) -> locate_hook_ret()).
locate_hook_ret()
-type locate_hook_ret() :: {_Changed :: boolean(),
                            [{anvl_project:t(),
                              _Prio :: integer(),
                              file:filename()}]}.
subdirectory_fun()
-type subdirectory_fun() :: fun((kind(), dependency(),
                                 file:filename()) -> {value, file:filename()} |
                                                     false).

Not exported

A function that tries to locate a dependency in a local directory.

kind()
-type kind() :: atom().

Different path IDs allow to discriminate between types of dependencies.

dependency()
-type dependency() :: term().

External dependency that has to be resolved.

1.7.5.2 Functions

get_path(Consumer)
-spec get_path(kind() | '_') -> [{anvl_project:t(),
                                  file:filename()}].

Get local search path for the given dependency type or '_' (wildcard).

get_lock(Plugin, Kind, Package)
-spec get_lock(anvl_plugin:t(), kind(),
               _Package) -> binary().

Get cached value of lock for a dependency.

resolve_lock(Plugin, Resolve, Project, Kind, Package)
-spec resolve_lock(anvl_plugin:t(), fun(() -> Hash),
                   anvl_project:t(), kind(), Package) -> {Changed,
                                                          Hash} when Package ::
                                                                         atom() |
                                                                         binary() |
                                                                         string(),
                                                                     Changed ::
                                                                         boolean(),
                                                                     Hash ::
                                                                         binary().

A helper function that plugins can use to implement dependency locking.

If plugin uses this function, it must implement the following callback:

resolve_version(Package, Tag) -> binary()

add_path(Kind, Prio0, Owner, Path)
-spec add_path(kind(), integer(), anvl_project:t(),
               file:filename()) -> ok.

Add a local directory to the search path.

Entries with higher Prio are searched first.

add_hook(Fun, Priority)
-spec add_hook(locate_hook(), integer()) -> ok.

Add function Fun as a dependency discovery hook.

When multiple hooks are capable of resolving the dependency, hooks with higher Priority are chosen.

add_hook(Fun)
-spec add_hook(locate_hook()) -> ok.

Equivalent to add_hook(Fun, 0).

location(Kind, Id)
-spec location(kind(), dependency()) -> #{dir :=
                                              file:filename(),
                                          project := anvl_project:t()}.

Return location of a resolved dependency.

project field of the return map is set to a path entry where the dir is located if the path entry is an ANVL project or to parent project that declared the dependency otherwise.

located(Kind, SubDirFun, Dependency)
-spec located(kind(), subdirectory_fun(),
              dependency()) -> anvl_condition:t().

Condition: external dependency Dep has been located.


JavaScript license information