aboutsummaryrefslogtreecommitdiff
path: root/include/deliverable.h
blob: 02c13e1763505a4ee8fcdb55d0feb84f06c6b9dc (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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
/// @file deliverable.h

#ifndef OMC_DELIVERABLE_H
#define OMC_DELIVERABLE_H

#include <string.h>
#include <stdbool.h>
#include <unistd.h>
#include <sys/utsname.h>
#include "str.h"
#include "ini.h"
#include "environment.h"
#include "conda.h"

#define DELIVERY_DIR "delivery"
#define DELIVERY_PLATFORM_MAX 4
#define DELIVERY_PLATFORM_MAXLEN 65
#define DELIVERY_PLATFORM 0
#define DELIVERY_PLATFORM_CONDA_SUBDIR 1
#define DELIVERY_PLATFORM_CONDA_INSTALLER 2
#define DELIVERY_PLATFORM_RELEASE 3

#define INSTALL_PKG_CONDA 1 << 1            ///< Toggle conda package installation
#define INSTALL_PKG_CONDA_DEFERRED 1 << 2   ///< Toggle deferred conda package installation
#define INSTALL_PKG_PIP 1 << 3              ///< Toggle pip package installation
#define INSTALL_PKG_PIP_DEFERRED 1 << 4     ///< Toggle deferred package installation from source

#define DEFER_CONDA 0                       ///< Build conda packages
#define DEFER_PIP 1                         ///< Build python packages

/*! \struct Delivery
 *  \brief A structure describing a full delivery object
 */
struct Delivery {
    /*! \struct System
     * \brief System information
    */
    struct System {
        char *arch;
        ///< System CPU architecture ident
        char platform[DELIVERY_PLATFORM_MAX][DELIVERY_PLATFORM_MAXLEN];
        ///< System platform name
    } system;
    /*! \struct Storage
     * \brief Storage paths
     */
    struct Storage {
        char *delivery_dir;             ///< Delivery artifact output directory
        char *conda_install_prefix;     ///< Path to install Conda
        char *conda_artifact_dir;       ///< Base path to store compiled conda packages
        char *conda_staging_dir;        ///< Base path to copy compiled conda packages
        char *conda_staging_url;        ///< URL to access compiled conda packages
        char *wheel_artifact_dir;       ///< Base path to store compiled wheel packages (Unused)
        char *wheel_staging_dir;        ///< Base path to copy compiled wheel packages (Unused)
        char *wheel_staging_url;        ///< URL to access compiled wheel packages (Unused)
        char *build_dir;                ///< Base path to store source code and recipes
        char *build_recipes_dir;        ///< Path to store conda recipes
        char *build_sources_dir;        ///< Path to store source code
        char *build_testing_dir;        ///< Path to store test data (Unused)
    } storage;

    /*! \struct Meta
     * \brief Metadata related to the delivery
     */
    struct Meta {
        char *name;                ///< delivery name
        char *version;             ///< delivery version
        int rc;                    ///< build iteration
        char *python;              ///< version of python to use
        char *python_compact;      ///< shortened python identifier
        char *based_on;            ///< URL to previous final configuration
        char *mission;             ///< hst, jwst, roman
        char *codename;            ///< HST uses codenames
        bool final;                ///< is this a final release?
        bool continue_on_error;    ///< keep going, or don't
    } meta;

    /*! \struct Info
     * \brief Release information (name & datetime)
     */
    struct Info {
        char *release_name;        ///< The fully combined release string
        struct tm *time_info;
        time_t time_now;           ///< Time stamp for when OMC execution started
    } info;

    /*! \struct Conda
     * \brief Conda configuration
     *
     * This includes lists describing packages to be delivered
     */
    struct Conda {
        char *installer_baseurl;                ///< URL describing where Conda will be downloaded from
        char *installer_name;                   ///< Name of installer (Miniconda3, Miniforge3, etc)
        char *installer_version;                ///< Version of installer
        char *installer_platform;               ///< Platform/OS target of installer
        char *installer_arch;                   ///< CPU architecture target of installer
        char *tool_version;                     ///< Installed version of conda
        char *tool_build_version;               ///< Installed version of "build" package
        struct StrList *conda_packages;         ///< Conda packages to deliver
        struct StrList *conda_packages_defer;   ///< Conda recipes to be built for delivery
        struct StrList *pip_packages;           ///< Python packages to install (pip)
        struct StrList *pip_packages_defer;     ///< Python packages to be built for delivery
    } conda;

    /*! \struct Runtime
     *  \brief Global runtime variables
     */
    struct Runtime {
        RuntimeEnv *environ;        ///< Environment variables
    } runtime;

    /*! \struct Test
     * \brief Test information
     */
    struct Test {
        char *name;                 ///< Name of package
        char *version;              ///< Version of package
        char *repository;           ///< Git repository of package
        char *script;               ///< Commands to execute
        char *build_recipe;         ///< Conda recipe to build (optional)
        struct Runtime runtime;     ///< Environment variables specific to the test context
    } tests[1000]; ///< An array of tests
};

/**
 * Initializes a Deliver structure
 * @param ctx pointer to Delivery context
 * @param ini pointer to INIFILE describing a delivery
 * @param cfg pointer to INIFILE describing extra configuration data
 * @return `0` on success
 * @return Non-zero on error
 */
int delivery_init(struct Delivery *ctx, struct INIFILE *ini, struct INIFILE *cfg);

/**
 * Free memory allocated by delivery_init()
 * @param ctx pointer to Delivery context
 */
void delivery_free(struct Delivery *ctx);

/**
 * Print Delivery metadata
 * @param ctx pointer to Delivery context
 */
void delivery_meta_show(struct Delivery *ctx);

/**
 * Print Delivery conda configuration
 * @param ctx pointer to Delivery context
 */
void delivery_conda_show(struct Delivery *ctx);

/**
 * Print Delivery tests
 * @param ctx pointer to Delivery context
 */
void delivery_tests_show(struct Delivery *ctx);

/**
 * Build Conda recipes associated with the Delivery
 * @param ctx pointer to Delivery context
 * @return 0 on success
 * @return Non-zero on error
 */
int delivery_build_recipes(struct Delivery *ctx);

/**
 * Produce a list of wheels built for the Delivery (Unused)
 * @param ctx pointer to Delivery context
 * @return pointer to StrList
 * @return NULL on error
 */
struct StrList *delivery_build_wheels(struct Delivery *ctx);

/**
 * Copy wheel packages to artifact storage
 * @param ctx pointer to Delivery context
 * @return 0 on success
 * @return Non-zero on error
 */
int delivery_index_wheel_artifacts(struct Delivery *ctx);

/**
 * Generate a header block that is applied to delivery artifacts
 * @param ctx pointer to Delivery context
 * @return header on success
 * @return NULL on error
 */
char *delivery_get_spec_header(struct Delivery *ctx);

/**
 * Finalizes a delivery artifact for distribution
 * @param ctx poitner to Delivery context
 * @param filename path to delivery artifact (Conda YAML file)
 */
void delivery_rewrite_spec(struct Delivery *ctx, char *filename);

/**
 * Copy compiled wheels to artifact storage
 * @param ctx pointer to Delivery context
 * @return 0 on success
 * @return Non-zero on error
 */
int delivery_copy_wheel_artifacts(struct Delivery *ctx);

/**
 * Copy built Conda packages to artifact storage
 * @param ctx poitner to Delivery context
 * @return 0 on success
 * @return Non-zero on error
 */
int delivery_copy_conda_artifacts(struct Delivery *ctx);

/**
 * Retrieve Conda installer
 * @param installer_url URL to installation script
 */
void delivery_get_installer(char *installer_url);

/**
 * Generate URL based on Delivery context
 * @param delivery pointer to Delivery context
 * @param result pointer to char
 * @return in result
 */
void delivery_get_installer_url(struct Delivery *delivery, char *result);

/**
 * Install packages based on Delivery context
 * @param ctx pointer to Delivery context
 * @param conda_install_dir path to install Conda
 * @param env_name name of Conda environment to create
 * @param type INSTALL_PKG_CONDA
 * @param type INSTALL_PKG_CONDA_DEFERRED
 * @param type INSTALL_PKG_PIP
 * @param type INSTALL_PKG_PIP_DEFERRED
 * @param manifest pointer to array of StrList (package list(s))
 */
void delivery_install_packages(struct Delivery *ctx, char *conda_install_dir, char *env_name, int type, struct StrList *manifest[]);

/**
 * Update "conda index" on Conda artifact storage
 * @param ctx pointer to Delivery context
 * @return 0 on success
 * @return Non-zero on error
 */
int delivery_index_conda_artifacts(struct Delivery *ctx);

/**
 * Execute Delivery test array
 * @param ctx pointer to Delivery context
 */
void delivery_tests_run(struct Delivery *ctx);

/**
 * Determine which packages are to be installed directly from conda or pip,
 * and which packages need to be built locally
 * @param ctx pointer to Delivery context
 * @param type DEFER_CONDA (filter conda packages)
 * @param type DEFER_PIP (filter python packages)
 */
void delivery_defer_packages(struct Delivery *ctx, int type);

/**
 * Configure and activate a Conda installation based on Delivery context
 * @param ctx pointer to Delivery context
 * @param conda_install_dir path to Conda installation
 */
void delivery_conda_enable(struct Delivery *ctx, char *conda_install_dir);

/**
 * Install Conda
 * @param install_script path to Conda installation script
 * @param conda_install_dir path to install Conda
 */
void delivery_install_conda(char *install_script, char *conda_install_dir);

// helper function
void delivery_gather_tool_versions(struct Delivery *ctx);

#endif //OMC_DELIVERABLE_H