aboutsummaryrefslogtreecommitdiff
path: root/include/recipe.h
blob: f1b4df1aa7c595260f70ffc36b807bb4d1017098 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//! @file recipe.h
#ifndef OMC_RECIPE_H
#define OMC_RECIPE_H

#include "str.h"
#include "utils.h"

//! Unable to determine recipe repo type
#define RECIPE_TYPE_UNKNOWN 0
//! Recipe repo is from conda-forge
#define RECIPE_TYPE_CONDA_FORGE 1
//! Recipe repo is from astroconda
#define RECIPE_TYPE_ASTROCONDA 2
//! Recipe repo provides the required build configurations but doesn't match conda-forge or astroconda's signature
#define RECIPE_TYPE_GENERIC 3

/**
 * Download a Conda package recipe
 *
 * ```c
 * char *recipe = NULL;
 *
 * if (recipe_clone("base/dir", "https://github.com/example/repo", "branch", &recipe)) {
 *     fprintf(stderr, "Failed to clone conda recipe\n");
 *     exit(1);
 * } else {
 *     chdir(recipe);
 * }
 * ```
 *
 * @param recipe_dir path to store repository
 * @param url remote address of git repository
 * @param gitref branch/tag/commit
 * @param result absolute path to downloaded repository
 * @return exit code from "git", -1 on error
 */
int recipe_clone(char *recipe_dir, char *url, char *gitref, char **result);

/**
 * Determine the layout/type of repository path
 *
 * ```c
 * if (recipe_clone("base/dir", "https://github.com/example/repo", "branch", &recipe)) {
 *     fprintf(stderr, "Failed to clone conda recipe\n");
 *     exit(1);
 * }
 *
 * int recipe_type;
 * recipe_type = recipe_get_type(recipe);
 * switch (recipe_type) {
 *     case RECIPE_TYPE_CONDA_FORGE:
 *         // do something specific for conda-forge directory structure
 *         break;
 *     case RECIPE_TYPE_ASTROCONDA:
 *         // do something specific for astroconda directory structure
 *         break;
 *     case RECIPE_TYPE_GENERIC:
 *         // do something specific for a directory containing a meta.yaml config
 *         break;
 *     case RECIPE_TYPE_UNKNOWN:
 *     default:
 *         // the structure is foreign or the path doesn't contain a conda recipe
 *         break;
 * }
 * ```
 *
 * @param repopath path to git repository containing conda recipe(s)
 * @return One of RECIPE_TYPE_UNKNOWN, RECIPE_TYPE_CONDA_FORGE, RECIPE_TYPE_ASTROCONDA, RECIPE_TYPE_GENERIC
 */
int recipe_get_type(char *repopath);

#endif //OMC_RECIPE_H