Arbiter
Dependency manager library that supports decentralization
Resolver.h
Go to the documentation of this file.
1 #ifndef ARBITER_RESOLVER_H
2 #define ARBITER_RESOLVER_H
3 
4 #ifdef __cplusplus
5 extern "C" {
6 #endif
7 
8 #include <arbiter/Value.h>
9 
10 #include <stdbool.h>
11 
12 // forward declarations
13 struct ArbiterDependencyList;
14 struct ArbiterProjectIdentifier;
15 struct ArbiterResolvedDependencyGraph;
16 struct ArbiterSelectedVersion;
17 struct ArbiterSelectedVersionList;
18 
19 /**
20  * A dependency resolver which contains context about how to evaluate the
21  * dependency graph.
22  */
23 typedef struct ArbiterResolver ArbiterResolver;
24 
25 /**
26  * User-provided behaviors for how dependency resolution should work.
27  */
28 typedef struct
29 {
30  /**
31  * Requests the list of dependencies needed by a specific version of
32  * a project.
33  *
34  * Returns a dependency list, or NULL if an error occurs. Arbiter will be
35  * responsible for freeing the returned dependency list object. If returning
36  * NULL, `error` may be set to a string describing the error which occurred,
37  * in which case Arbiter will be responsible for freeing the string.
38  */
39  struct ArbiterDependencyList *(*createDependencyList)(const ArbiterResolver *resolver, const struct ArbiterProjectIdentifier *project, const struct ArbiterSelectedVersion *selectedVersion, char **error);
40 
41  /**
42  * Requests the list of versions available for a given project.
43  *
44  * Returns a version list, or NULL if an error occurs. Arbiter will be
45  * responsible for freeing the returned version list object. If returning
46  * NULL, `error` may be set to a string describing the error which occurred,
47  * in which case Arbiter will be responsible for freeing the string.
48  */
49  struct ArbiterSelectedVersionList *(*createAvailableVersionsList)(const ArbiterResolver *resolver, const struct ArbiterProjectIdentifier *project, char **error);
50 
51  /**
52  * Requests the selected version which corresponds to the given metadata.
53  *
54  * This behavior can be used to implement lookup of versions which are not
55  * known in advance (i.e., those which would not appear in the result of
56  * `createAvailableVersionsList`). For example, it is impractical to list all
57  * commit hashes from a version control system, but they could be looked up by
58  * hash here.
59  *
60  * This behavior is optional, and may be set to NULL if unsupported or
61  * unnecessary.
62  *
63  * Returns a selected version, or NULL if one corresponding to the metadata
64  * could not be found.
65  */
66  struct ArbiterSelectedVersion *(*createSelectedVersionForMetadata)(const ArbiterResolver *resolver, const void *metadata);
67 } ArbiterResolverBehaviors;
68 
69 /**
70  * Creates a dependency resolver, implemented using the given behaviors, which
71  * will attempt to pick compatible versions of all dependencies in
72  * `dependencyList` and transitive dependencies thereof.
73  *
74  * The returned dependency resolver must be freed with ArbiterFree().
75  */
76 ArbiterResolver *ArbiterCreateResolver (ArbiterResolverBehaviors behaviors, const struct ArbiterDependencyList *dependencyList, ArbiterUserContext context);
77 
78 /**
79  * Returns any context data which was provided to ArbiterCreateResolver().
80  *
81  * The returned pointer is only guaranteed to remain valid for the current
82  * scope.
83  */
84 const void *ArbiterResolverContext (const ArbiterResolver *resolver);
85 
86 /**
87  * Attempts to resolve all dependencies.
88  *
89  * Returns the graph of resolved dependencies, or NULL if an error occurred. The
90  * caller is responsible for freeing the returned graph. If NULL is returned and
91  * `error` is not NULL, it may be set to a string describing the error, which
92  * the caller is responsible for freeing.
93  */
94 struct ArbiterResolvedDependencyGraph *ArbiterResolverCreateResolvedDependencyGraph (ArbiterResolver *resolver, char **error);
95 
96 #ifdef __cplusplus
97 }
98 #endif
99 
100 #endif
struct ArbiterResolvedDependencyGraph * ArbiterResolverCreateResolvedDependencyGraph(ArbiterResolver *resolver, char **error)
Attempts to resolve all dependencies.
const void * ArbiterResolverContext(const ArbiterResolver *resolver)
Returns any context data which was provided to ArbiterCreateResolver().
ArbiterResolver * ArbiterCreateResolver(ArbiterResolverBehaviors behaviors, const struct ArbiterDependencyList *dependencyList, ArbiterUserContext context)
Creates a dependency resolver, implemented using the given behaviors, which will attempt to pick comp...