aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2023-10-26 19:53:29 -0400
committerJoseph Hunkeler <jhunkeler@gmail.com>2023-10-26 19:53:29 -0400
commit17178535cc9df5e834dfd43e3b2b919e02e5798d (patch)
tree5e55e8b2c2453ccf6271b190cf45e90d2c25179d /include
downloadstasis-17178535cc9df5e834dfd43e3b2b919e02e5798d.tar.gz
Initial commit
Diffstat (limited to 'include')
-rw-r--r--include/conda.h23
-rw-r--r--include/deliverable.h117
-rw-r--r--include/download.h13
-rw-r--r--include/environment.h23
-rw-r--r--include/ini.h54
-rw-r--r--include/ohmycal.h24
-rw-r--r--include/recipe.h20
-rw-r--r--include/relocation.h16
-rw-r--r--include/str.h47
-rw-r--r--include/strlist.h47
-rw-r--r--include/system.h28
-rw-r--r--include/utils.h43
-rw-r--r--include/wheel.h21
13 files changed, 476 insertions, 0 deletions
diff --git a/include/conda.h b/include/conda.h
new file mode 100644
index 0000000..a642702
--- /dev/null
+++ b/include/conda.h
@@ -0,0 +1,23 @@
+//
+// Created by jhunk on 5/14/23.
+//
+
+#ifndef OHMYCAL_CONDA_H
+#define OHMYCAL_CONDA_H
+
+#include <stdio.h>
+#include <string.h>
+#include "ohmycal.h"
+
+#define CONDA_INSTALL_PREFIX "conda"
+
+int python_exec(const char *args);
+int pip_exec(const char *args);
+int conda_exec(const char *args);
+int conda_activate(const char *root, const char *env_name);
+void conda_env_create_from_uri(char *name, char *uri);
+void conda_env_create(char *name, char *python_version, char *packages);
+void conda_env_remove(char *name);
+void conda_env_export(char *name, char *output_dir, char *output_filename);
+int conda_index(const char *path);
+#endif //OHMYCAL_CONDA_H
diff --git a/include/deliverable.h b/include/deliverable.h
new file mode 100644
index 0000000..1487ace
--- /dev/null
+++ b/include/deliverable.h
@@ -0,0 +1,117 @@
+//
+// Created by jhunk on 10/5/23.
+//
+
+#ifndef OHMYCAL_DELIVERABLE_H
+#define OHMYCAL_DELIVERABLE_H
+
+#include <string.h>
+#include <stdbool.h>
+#include <unistd.h>
+#include <sys/utsname.h>
+#include "str.h"
+#include "ini.h"
+#include "environment.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
+#define INSTALL_PKG_CONDA_DEFERRED 1 << 2
+#define INSTALL_PKG_PIP 1 << 3
+#define INSTALL_PKG_PIP_DEFERRED 1 << 4
+
+struct Delivery {
+ struct System {
+ char *arch;
+ char platform[DELIVERY_PLATFORM_MAX][DELIVERY_PLATFORM_MAXLEN];
+ } system;
+ struct Storage {
+ char *delivery_dir;
+ char *conda_install_prefix;
+ char *conda_artifact_dir;
+ char *conda_staging_dir;
+ char *conda_staging_url;
+ char *wheel_artifact_dir;
+ char *wheel_staging_dir;
+ char *wheel_staging_url;
+ char *build_dir;
+ char *build_recipes_dir;
+ char *build_sources_dir;
+ char *build_testing_dir;
+ } storage;
+ struct Meta {
+ // delivery name
+ char *name;
+ // delivery version
+ char *version;
+ // build iteration
+ int rc;
+ // version of python to use
+ char *python;
+ // URL to previous final configuration
+ char *based_on;
+ // hst, jwst, roman
+ char *mission;
+ // HST uses codenames
+ char *codename;
+ // is this a final release?
+ bool final;
+ // keep going, or don't
+ bool continue_on_error;
+ } meta;
+
+ struct Conda {
+ char *installer_baseurl;
+ char *installer_name;
+ char *installer_version;
+ char *installer_platform;
+ char *installer_arch;
+ // packages to install
+ struct StrList *conda_packages;
+ // conda recipes to be built
+ struct StrList *conda_packages_defer;
+ // packages to install
+ struct StrList *pip_packages;
+ // packages to be built
+ struct StrList *pip_packages_defer;
+ } conda;
+
+ // global runtime variables
+ struct Runtime {
+ RuntimeEnv *environ;
+ } runtime;
+
+ struct Test {
+ char *name;
+ char *version;
+ char *repository;
+ char *script;
+ char *build_recipe;
+ // test-specific runtime variables
+ struct Runtime runtime;
+ } tests[1000];
+};
+
+int delivery_init(struct Delivery *ctx, struct INIFILE *ini, struct INIFILE *cfg);
+void delivery_meta_show(struct Delivery *ctx);
+void delivery_conda_show(struct Delivery *ctx);
+void delivery_tests_show(struct Delivery *ctx);
+int delivery_build_recipes(struct Delivery *ctx);
+struct StrList *delivery_build_wheels(struct Delivery *ctx);
+int delivery_index_wheel_artifacts(struct Delivery *ctx);
+void delivery_rewrite_spec(struct Delivery *ctx, char *filename);
+int delivery_copy_wheel_artifacts(struct Delivery *ctx);
+int delivery_copy_conda_artifacts(struct Delivery *ctx);
+void delivery_get_installer(char *installer_url);
+void delivery_get_installer_url(struct Delivery *delivery, char *result);
+void delivery_install_packages(struct Delivery *ctx, char *conda_install_dir, char *env_name, int type, struct StrList *manifest[]);
+int delivery_index_conda_artifacts(struct Delivery *ctx);
+void delivery_tests_run(struct Delivery *ctx);
+
+#endif //OHMYCAL_DELIVERABLE_H
diff --git a/include/download.h b/include/download.h
new file mode 100644
index 0000000..0522aee
--- /dev/null
+++ b/include/download.h
@@ -0,0 +1,13 @@
+//
+// Created by jhunk on 10/5/23.
+//
+
+#ifndef OHMYCAL_DOWNLOAD_H
+#define OHMYCAL_DOWNLOAD_H
+
+#include <curl/curl.h>
+
+size_t download_writer(void *fp, size_t size, size_t nmemb, void *stream);
+int download(char *url, const char *filename);
+
+#endif //OHMYCAL_DOWNLOAD_H
diff --git a/include/environment.h b/include/environment.h
new file mode 100644
index 0000000..db15d27
--- /dev/null
+++ b/include/environment.h
@@ -0,0 +1,23 @@
+/**
+ * @file environment.h
+ */
+#ifndef SPM_ENVIRONMENT_H
+#define SPM_ENVIRONMENT_H
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <dirent.h>
+#include "environment.h"
+
+typedef struct StrList RuntimeEnv;
+
+ssize_t runtime_contains(RuntimeEnv *env, const char *key);
+RuntimeEnv *runtime_copy(char **env);
+int runtime_replace(RuntimeEnv **dest, char **src);
+char *runtime_get(RuntimeEnv *env, const char *key);
+void runtime_set(RuntimeEnv *env, const char *_key, const char *_value);
+char *runtime_expand_var(RuntimeEnv *env, const char *input);
+void runtime_export(RuntimeEnv *env, char **keys);
+void runtime_apply(RuntimeEnv *env);
+void runtime_free(RuntimeEnv *env);
+#endif //SPM_ENVIRONMENT_H
diff --git a/include/ini.h b/include/ini.h
new file mode 100644
index 0000000..06004e3
--- /dev/null
+++ b/include/ini.h
@@ -0,0 +1,54 @@
+#ifndef OHMYCAL_INI_H
+#define OHMYCAL_INI_H
+#include <stddef.h>
+#include <stdbool.h>
+
+#define INIVAL_TYPE_INT 1
+#define INIVAL_TYPE_UINT 2
+#define INIVAL_TYPE_LONG 3
+#define INIVAL_TYPE_ULONG 4
+#define INIVAL_TYPE_LLONG 5
+#define INIVAL_TYPE_ULLONG 6
+#define INIVAL_TYPE_DOUBLE 7
+#define INIVAL_TYPE_FLOAT 8
+#define INIVAL_TYPE_STR 9
+#define INIVAL_TYPE_STR_ARRAY 10
+#define INIVAL_TYPE_BOOL 11
+
+#define INIVAL_TO_LIST 1 << 1
+
+union INIVal {
+ int as_int;
+ unsigned as_uint;
+ long as_long;
+ unsigned long as_ulong;
+ long long as_llong;
+ unsigned long long as_ullong;
+ double as_double;
+ float as_float;
+ char *as_char_p;
+ char **as_char_array_p;
+ bool as_bool;
+};
+
+
+struct INIData {
+ char *key;
+ char *value;
+};
+struct INISection {
+ size_t data_count;
+ char *key;
+ struct INIData **data;
+};
+struct INIFILE {
+ size_t section_count;
+ struct INISection **section;
+};
+
+struct INIFILE *ini_open(const char *filename);
+struct INIData *ini_getall(struct INIFILE *ini, char *section_name);
+int ini_getval(struct INIFILE *ini, char *section_name, char *key, int type, union INIVal *result);
+void ini_show(struct INIFILE *ini);
+void ini_free(struct INIFILE **ini);
+#endif //OHMYCAL_INI_H
diff --git a/include/ohmycal.h b/include/ohmycal.h
new file mode 100644
index 0000000..d3e86ec
--- /dev/null
+++ b/include/ohmycal.h
@@ -0,0 +1,24 @@
+#ifndef OHMYCAL_OHMYCAL_H
+#define OHMYCAL_OHMYCAL_H
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <limits.h>
+#include <unistd.h>
+
+#define SYSERROR stderr, "%s:%s:%d: %s\n", path_basename(__FILE__), __FUNCTION__, __LINE__, strerror(errno)
+#define OHMYCAL_BUFSIZ 8192
+
+#include "utils.h"
+#include "ini.h"
+#include "conda.h"
+#include "environment.h"
+#include "deliverable.h"
+#include "str.h"
+#include "strlist.h"
+#include "system.h"
+#include "download.h"
+#include "recipe.h"
+#include "relocation.h"
+
+#endif //OHMYCAL_OHMYCAL_H
diff --git a/include/recipe.h b/include/recipe.h
new file mode 100644
index 0000000..2a0fe4b
--- /dev/null
+++ b/include/recipe.h
@@ -0,0 +1,20 @@
+//
+// Created by jhunk on 10/7/23.
+//
+
+#ifndef OHMYCAL_RECIPE_H
+#define OHMYCAL_RECIPE_H
+
+#include "str.h"
+#include "utils.h"
+
+#define RECIPE_DIR "recipes"
+#define RECIPE_TYPE_UNKNOWN 0
+#define RECIPE_TYPE_CONDA_FORGE 1
+#define RECIPE_TYPE_ASTROCONDA 2
+#define RECIPE_TYPE_GENERIC 3
+
+int recipe_clone(char *recipe_dir, char *url, char *gitref, char **result);
+int recipe_get_type(char *repopath);
+
+#endif //OHMYCAL_RECIPE_H
diff --git a/include/relocation.h b/include/relocation.h
new file mode 100644
index 0000000..ecbb38b
--- /dev/null
+++ b/include/relocation.h
@@ -0,0 +1,16 @@
+/**
+ * @file relocation.h
+ */
+#ifndef OHMYCAL_RELOCATION_H
+#define OHMYCAL_RELOCATION_H
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <linux/limits.h>
+#include <unistd.h>
+
+void replace_text(char *original, const char *target, const char *replacement);
+void file_replace_text(const char* filename, const char* target, const char* replacement);
+
+#endif //OHMYCAL_RELOCATION_H
diff --git a/include/str.h b/include/str.h
new file mode 100644
index 0000000..1c67eda
--- /dev/null
+++ b/include/str.h
@@ -0,0 +1,47 @@
+/**
+ * @file str.h
+ */
+#ifndef SPM_STR_H
+#define SPM_STR_H
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdarg.h>
+#include <ctype.h>
+#include "ohmycal.h"
+
+#define SPM_SORT_ALPHA 1 << 0
+#define SPM_SORT_NUMERIC 1 << 1
+#define SPM_SORT_LEN_ASCENDING 1 << 2
+#define SPM_SORT_LEN_DESCENDING 1 << 3
+
+int num_chars(const char *sptr, int ch);
+int startswith(const char *sptr, const char *pattern);
+int endswith(const char *sptr, const char *pattern);
+char *normpath(const char *path);
+void strchrdel(char *sptr, const char *chars);
+long int strchroff(const char *sptr, int ch);
+void strdelsuffix(char *sptr, const char *suffix);
+char** split(char *sptr, const char* delim, size_t max);
+void split_free(char **ptr);
+char *join(char **arr, const char *separator);
+char *join_ex(char *separator, ...);
+char *substring_between(char *sptr, const char *delims);
+void strsort(char **arr, unsigned int sort_mode);
+int isrelational(char ch);
+void print_banner(const char *s, int len);
+char *strstr_array(char **arr, const char *str);
+char **strdeldup(char **arr);
+char *lstrip(char *sptr);
+char *strip(char *sptr);
+int isempty(char *sptr);
+int isquoted(char *sptr);
+char *normalize_space(char *s);
+char **strdup_array(char **array);
+int strcmp_array(const char **a, const char **b);
+int isdigit_s(const char *s);
+char *tolower_s(char *s);
+char *to_short_version(const char *s);
+
+#endif //SPM_STR_H
diff --git a/include/strlist.h b/include/strlist.h
new file mode 100644
index 0000000..84019b9
--- /dev/null
+++ b/include/strlist.h
@@ -0,0 +1,47 @@
+/**
+ * String array convenience functions
+ * @file strlist.h
+ */
+#ifndef SPM_STRLIST_H
+#define SPM_STRLIST_H
+#include <stdlib.h>
+#include "utils.h"
+#include "str.h"
+
+struct StrList {
+ size_t num_alloc;
+ size_t num_inuse;
+ char **data;
+};
+
+struct StrList *strlist_init();
+void strlist_remove(struct StrList *pStrList, size_t index);
+long double strlist_item_as_long_double(struct StrList *pStrList, size_t index);
+double strlist_item_as_double(struct StrList *pStrList, size_t index);
+float strlist_item_as_float(struct StrList *pStrList, size_t index);
+unsigned long long strlist_item_as_ulong_long(struct StrList *pStrList, size_t index);
+long long strlist_item_as_long_long(struct StrList *pStrList, size_t index);
+unsigned long strlist_item_as_ulong(struct StrList *pStrList, size_t index);
+long strlist_item_as_long(struct StrList *pStrList, size_t index);
+unsigned int strlist_item_as_uint(struct StrList *pStrList, size_t index);
+int strlist_item_as_int(struct StrList *pStrList, size_t index);
+unsigned short strlist_item_as_ushort(struct StrList *pStrList, size_t index);
+short strlist_item_as_short(struct StrList *pStrList, size_t index);
+unsigned char strlist_item_as_uchar(struct StrList *pStrList, size_t index);
+char strlist_item_as_char(struct StrList *pStrList, size_t index);
+char *strlist_item_as_str(struct StrList *pStrList, size_t index);
+char *strlist_item(struct StrList *pStrList, size_t index);
+void strlist_set(struct StrList *pStrList, size_t index, char *value);
+size_t strlist_count(struct StrList *pStrList);
+void strlist_reverse(struct StrList *pStrList);
+void strlist_sort(struct StrList *pStrList, unsigned int mode);
+int strlist_append_file(struct StrList *pStrList, char *path, ReaderFn *readerFn);
+void strlist_append_strlist(struct StrList *pStrList1, struct StrList *pStrList2);
+void strlist_append(struct StrList *pStrList, char *str);
+void strlist_append_array(struct StrList *pStrList, char **arr);
+void strlist_append_tokenize(struct StrList *pStrList, char *str, char *delim);
+struct StrList *strlist_copy(struct StrList *pStrList);
+int strlist_cmp(struct StrList *a, struct StrList *b);
+void strlist_free(struct StrList *pStrList);
+
+#endif //SPM_STRLIST_H
diff --git a/include/system.h b/include/system.h
new file mode 100644
index 0000000..a922c69
--- /dev/null
+++ b/include/system.h
@@ -0,0 +1,28 @@
+//
+// Created by jhunk on 10/4/23.
+//
+
+#ifndef OHMYCAL_SYSTEM_H
+#define OHMYCAL_SYSTEM_H
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <unistd.h>
+#include <limits.h>
+#include <sys/wait.h>
+#include <sys/stat.h>
+
+struct Process {
+ char stdout[PATH_MAX];
+ char stderr[PATH_MAX];
+ int redirect_stderr;
+ int returncode;
+};
+
+int shell(struct Process *proc, char *args[]);
+int shell2(struct Process *proc, char *args);
+int shell_safe(struct Process *proc, char *args[]);
+
+#endif //OHMYCAL_SYSTEM_H
diff --git a/include/utils.h b/include/utils.h
new file mode 100644
index 0000000..eb7604c
--- /dev/null
+++ b/include/utils.h
@@ -0,0 +1,43 @@
+#ifndef OHMYCAL_UTILS_H
+#define OHMYCAL_UTILS_H
+#include <stdio.h>
+#include <stdlib.h>
+#include <dirent.h>
+#include <string.h>
+#include <unistd.h>
+#include <limits.h>
+#include <errno.h>
+#include "system.h"
+
+#if defined(__WIN32__)
+#define PATH_ENV_VAR "path"
+#define DIR_SEP "\\"
+#define PATH_SEP ";"
+#else
+#define PATH_ENV_VAR "PATH"
+#define DIR_SEP "/"
+#define PATH_SEP ":"
+#endif
+
+typedef int (ReaderFn)(size_t line, char **);
+
+int pushd(const char *path);
+int popd(void);
+char *expandpath(const char *_path);
+int rmtree(char *_path);
+char **file_readlines(const char *filename, size_t start, size_t limit, ReaderFn *readerFn);
+char *path_basename(char *path);
+char *find_program(const char *name);
+int touch(const char *filename);
+int git_clone(struct Process *proc, char *url, char *destdir, char *gitref);
+char *git_describe(const char *path);
+
+#define OMC_MSG_NOP 1 << 0
+#define OMC_MSG_ERROR 1 << 1
+#define OMC_MSG_WARN 1 << 2
+#define OMC_MSG_L1 1 << 3
+#define OMC_MSG_L2 1 << 4
+#define OMC_MSG_L3 1 << 5
+int msg(unsigned type, char *fmt, ...);
+
+#endif //OHMYCAL_UTILS_H
diff --git a/include/wheel.h b/include/wheel.h
new file mode 100644
index 0000000..20ac641
--- /dev/null
+++ b/include/wheel.h
@@ -0,0 +1,21 @@
+#ifndef OHMYCAL_WHEEL_H
+#define OHMYCAL_WHEEL_H
+
+#include <dirent.h>
+#include <string.h>
+#include <stdio.h>
+#include "str.h"
+
+struct Wheel {
+ char *distribution;
+ char *version;
+ char *build_tag;
+ char *python_tag;
+ char *abi_tag;
+ char *platform_tag;
+ char *path_name;
+ char *file_name;
+};
+
+struct Wheel *get_wheel_file(const char *basepath, const char *name, char *to_match[]);
+#endif //OHMYCAL_WHEEL_H