aboutsummaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@users.noreply.github.com>2025-03-20 12:11:35 -0400
committerGitHub <noreply@github.com>2025-03-20 12:11:35 -0400
commit629f18d3cdea6340f4a76d9e997ef80b6e17ada4 (patch)
tree25c60be20c78b5d339e4421458799a021bdcb0c2 /src/lib
parent2ffd817603ecc713988fe2796c9562a857a92ef4 (diff)
parent5126b191b6d1a53d3a402478472fd1d357ace293 (diff)
downloadstasis-629f18d3cdea6340f4a76d9e997ef80b6e17ada4.tar.gz
Merge pull request #100 from jhunkeler/without-extras-in-spec
delivery_overlay_packages_from_env: remove extras from spec
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/core/conda.c2
-rw-r--r--src/lib/core/docker.c2
-rw-r--r--src/lib/core/environment.c10
-rw-r--r--src/lib/core/include/core_mem.h15
-rw-r--r--src/lib/core/include/utils.h4
-rw-r--r--src/lib/core/ini.c2
-rw-r--r--src/lib/core/str.c23
-rw-r--r--src/lib/core/strlist.c2
-rw-r--r--src/lib/core/template.c2
-rw-r--r--src/lib/core/wheel.c4
-rw-r--r--src/lib/delivery/delivery.c2
-rw-r--r--src/lib/delivery/delivery_build.c1
-rw-r--r--src/lib/delivery/delivery_install.c16
-rw-r--r--src/lib/delivery/delivery_postprocess.c2
14 files changed, 67 insertions, 20 deletions
diff --git a/src/lib/core/conda.c b/src/lib/core/conda.c
index b2caa63f..80d280a 100644
--- a/src/lib/core/conda.c
+++ b/src/lib/core/conda.c
@@ -265,7 +265,7 @@ static int env0_to_runtime(const char *logfile) {
} else {
setenv(part[0], part[1], 1);
}
- GENERIC_ARRAY_FREE(part);
+ guard_array_free(part);
}
fclose(fp);
return 0;
diff --git a/src/lib/core/docker.c b/src/lib/core/docker.c
index 3035b01..4723446 100644
--- a/src/lib/core/docker.c
+++ b/src/lib/core/docker.c
@@ -191,6 +191,6 @@ int docker_validate_compression_program(char *prog) {
result = find_program(parts[0]) ? 0 : -1;
invalid:
- GENERIC_ARRAY_FREE(parts);
+ guard_array_free(parts);
return result;
}
diff --git a/src/lib/core/environment.c b/src/lib/core/environment.c
index 45fef2b..f5e8566 100644
--- a/src/lib/core/environment.c
+++ b/src/lib/core/environment.c
@@ -117,7 +117,7 @@ void runtime_export(RuntimeEnv *env, char **keys) {
puts(output);
}
guard_free(value);
- GENERIC_ARRAY_FREE(pair);
+ guard_array_free(pair);
}
}
@@ -210,10 +210,10 @@ ssize_t runtime_contains(RuntimeEnv *env, const char *key) {
}
if (strcmp(pair[0], key) == 0) {
result = i;
- GENERIC_ARRAY_FREE(pair);
+ guard_array_free(pair);
break;
}
- GENERIC_ARRAY_FREE(pair);
+ guard_array_free(pair);
}
return result;
}
@@ -246,7 +246,7 @@ char *runtime_get(RuntimeEnv *env, const char *key) {
if (key_offset != -1) {
char **pair = split(strlist_item(env, key_offset), "=", 0);
result = join(&pair[1], "=");
- GENERIC_ARRAY_FREE(pair);
+ guard_array_free(pair);
}
return result;
}
@@ -425,7 +425,7 @@ void runtime_apply(RuntimeEnv *env) {
for (size_t i = 0; i < strlist_count(env); i++) {
char **pair = split(strlist_item(env, i), "=", 1);
setenv(pair[0], pair[1], 1);
- GENERIC_ARRAY_FREE(pair);
+ guard_array_free(pair);
}
}
diff --git a/src/lib/core/include/core_mem.h b/src/lib/core/include/core_mem.h
index 362715f..dd79e72 100644
--- a/src/lib/core/include/core_mem.h
+++ b/src/lib/core/include/core_mem.h
@@ -5,10 +5,17 @@
#include "environment.h"
#include "strlist.h"
-#define guard_runtime_free(X) do { if (X) { runtime_free(X); (X) = NULL; } } while (0)
-#define guard_strlist_free(X) do { if ((*X)) { strlist_free(X); (*X) = NULL; } } while (0)
-#define guard_free(X) do { if (X) { free(X); X = NULL; } } while (0)
-#define GENERIC_ARRAY_FREE(ARR) do { \
+#define guard_runtime_free(X) do { runtime_free(X); (X) = NULL; } while (0)
+#define guard_strlist_free(X) do { strlist_free(X); (*X) = NULL; } while (0)
+#define guard_free(X) do { free(X); (X) = NULL; } while (0)
+#define ARRAY_COUNT(ARR) sizeof((ARR)) / sizeof((*ARR))
+#define guard_array_free_by_count(ARR, COUNT) do { \
+ for (size_t ARR_I = 0; (ARR) && ARR_I < (COUNT); ARR_I++) { \
+ guard_free((ARR)[ARR_I]); \
+ } \
+ guard_free((ARR)); \
+} while (0)
+#define guard_array_free(ARR) do { \
for (size_t ARR_I = 0; ARR && ARR[ARR_I] != NULL; ARR_I++) { \
guard_free(ARR[ARR_I]); \
} \
diff --git a/src/lib/core/include/utils.h b/src/lib/core/include/utils.h
index 87f28cc..1906808 100644
--- a/src/lib/core/include/utils.h
+++ b/src/lib/core/include/utils.h
@@ -413,4 +413,8 @@ int env_manipulate_pathstr(const char *key, char *path, int mode);
*/
int gen_file_extension_str(char *filename, const char *extension);
+/**
+ * Remove [extra]s from a spec string
+ */
+char *remove_extras(char *s);
#endif //STASIS_UTILS_H
diff --git a/src/lib/core/ini.c b/src/lib/core/ini.c
index 4f449c6..cf6f670 100644
--- a/src/lib/core/ini.c
+++ b/src/lib/core/ini.c
@@ -465,7 +465,7 @@ int ini_write(struct INIFILE *ini, FILE **stream, unsigned mode) {
guard_free(render);
}
}
- GENERIC_ARRAY_FREE(parts);
+ guard_array_free(parts);
strip(outvalue);
strcat(outvalue, LINE_SEP);
fprintf(*stream, "%s = %s%s", ini->section[x]->data[y]->key, *hint == INIVAL_TYPE_STR_ARRAY ? LINE_SEP : "", outvalue);
diff --git a/src/lib/core/str.c b/src/lib/core/str.c
index 6457afe..1d0b268 100644
--- a/src/lib/core/str.c
+++ b/src/lib/core/str.c
@@ -671,4 +671,25 @@ void unindent(char *s) {
pos++;
}
}
-} \ No newline at end of file
+}
+
+char *remove_extras(char *s) {
+ // an "extra" is a string encapsulated by square brackets "text[toremove]"
+ char *extra_stop = NULL;
+ char *extra_start = strchr(s, '[');
+ size_t len = strlen(s);
+ if (extra_start) {
+ extra_stop = strchr(extra_start, ']');
+ if (extra_stop) {
+ size_t last = strlen(s);
+ if (last) {
+ extra_stop++;
+ last = strlen(extra_stop);
+ }
+ memmove(extra_start, extra_stop, last);
+ s[len - (extra_stop - extra_start)] = 0;
+ }
+ }
+ return s;
+}
+
diff --git a/src/lib/core/strlist.c b/src/lib/core/strlist.c
index 08f5893..5655da9 100644
--- a/src/lib/core/strlist.c
+++ b/src/lib/core/strlist.c
@@ -222,7 +222,7 @@ void strlist_append_strlist(struct StrList *pStrList1, struct StrList *pStrList2
lstrip(token[i]);
strlist_append(&pStrList, token[i]);
}
- GENERIC_ARRAY_FREE(token);
+ guard_array_free(token);
}
guard_free(tmp);
}
diff --git a/src/lib/core/template.c b/src/lib/core/template.c
index f3eab62..ba45a5a 100644
--- a/src/lib/core/template.c
+++ b/src/lib/core/template.c
@@ -275,7 +275,7 @@ char *tpl_render(char *str) {
SYSDEBUG("Returned from function: %s (status: %d)\nData OUT\n--------\n'%s'", k, func_status, value);
guard_free(func_result);
}
- GENERIC_ARRAY_FREE(params);
+ guard_array_free(params);
} else {
// Read replacement value
value = strdup(tpl_getval(key) ? tpl_getval(key) : "");
diff --git a/src/lib/core/wheel.c b/src/lib/core/wheel.c
index 32091cd..c7e485a 100644
--- a/src/lib/core/wheel.c
+++ b/src/lib/core/wheel.c
@@ -99,12 +99,12 @@ struct Wheel *get_wheel_info(const char *basepath, const char *name, char *to_ma
} else {
SYSERROR("Unknown wheel name format: %s. Expected 5 or 6 strings "
"separated by '-', but got %zu instead", filename, parts_total);
- GENERIC_ARRAY_FREE(parts);
+ guard_array_free(parts);
wheel_free(&result);
closedir(dp);
return NULL;
}
- GENERIC_ARRAY_FREE(parts);
+ guard_array_free(parts);
break;
}
closedir(dp);
diff --git a/src/lib/delivery/delivery.c b/src/lib/delivery/delivery.c
index 41be64c..7ae2b01 100644
--- a/src/lib/delivery/delivery.c
+++ b/src/lib/delivery/delivery.c
@@ -2,7 +2,7 @@
void delivery_free(struct Delivery *ctx) {
guard_free(ctx->system.arch);
- GENERIC_ARRAY_FREE(ctx->system.platform);
+ guard_array_free(ctx->system.platform);
guard_free(ctx->meta.name);
guard_free(ctx->meta.version);
guard_free(ctx->meta.codename);
diff --git a/src/lib/delivery/delivery_build.c b/src/lib/delivery/delivery_build.c
index 03f2d4c..2d891d2 100644
--- a/src/lib/delivery/delivery_build.c
+++ b/src/lib/delivery/delivery_build.c
@@ -141,6 +141,7 @@ struct StrList *delivery_build_wheels(struct Delivery *ctx) {
char name[100] = {0};
char *fullspec = strlist_item(ctx->conda.pip_packages_defer, p);
strncpy(name, fullspec, sizeof(name) - 1);
+ remove_extras(name);
char *spec = find_version_spec(name);
if (spec) {
*spec = '\0';
diff --git a/src/lib/delivery/delivery_install.c b/src/lib/delivery/delivery_install.c
index bb9bb48..cf6ccaa 100644
--- a/src/lib/delivery/delivery_install.c
+++ b/src/lib/delivery/delivery_install.c
@@ -9,6 +9,7 @@ static struct Test *requirement_from_test(struct Delivery *ctx, const char *name
if (spec) {
*spec = '\0';
}
+ remove_extras(package_name);
if (ctx->tests[i].name && !strcmp(package_name, ctx->tests[i].name)) {
result = &ctx->tests[i];
@@ -80,6 +81,7 @@ int delivery_overlay_packages_from_env(struct Delivery *ctx, const char *env_nam
} else {
strncpy(spec_name, spec, sizeof(spec_name) - 1);
}
+
struct Test *test_block = requirement_from_test(ctx, spec_name);
if (!test_block) {
msg(STASIS_MSG_L2 | STASIS_MSG_WARN, "from config without test: %s\n", spec);
@@ -272,9 +274,21 @@ int delivery_install_packages(struct Delivery *ctx, char *conda_install_dir, cha
}
wheel_free(&whl);
}
+
+ char req[255] = {0};
+ if (!strcmp(name, info->name)) {
+ strcpy(req, info->name);
+ } else {
+ strcpy(req, name);
+ char *spec = find_version_spec(req);
+ if (spec) {
+ *spec = 0;
+ }
+ }
+
snprintf(cmd + strlen(cmd),
sizeof(cmd) - strlen(cmd) - strlen(info->name) - strlen(info->version) + 5,
- " '%s==%s'", info->name, info->version);
+ " '%s==%s'", req, info->version);
} else {
fprintf(stderr, "Deferred package '%s' is not present in the tested package list!\n", name);
return -1;
diff --git a/src/lib/delivery/delivery_postprocess.c b/src/lib/delivery/delivery_postprocess.c
index b43e247..5029e02 100644
--- a/src/lib/delivery/delivery_postprocess.c
+++ b/src/lib/delivery/delivery_postprocess.c
@@ -120,7 +120,7 @@ void delivery_rewrite_spec(struct Delivery *ctx, char *filename, unsigned stage)
}
fprintf(tp, "%s", contents[i]);
}
- GENERIC_ARRAY_FREE(contents);
+ guard_array_free(contents);
guard_free(header);
fflush(tp);
fclose(tp);