aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2024-08-27 13:07:49 -0400
committerJoseph Hunkeler <jhunkeler@gmail.com>2024-08-27 13:07:49 -0400
commitea8ec855c3c6870d29c55afe3787afb2c05026a1 (patch)
treee0de91c57d6a31b88f2085677fecbd6ea7cda423
parent0a4efe972a78378eba5c5fbc6819c39b3cc6c9cb (diff)
downloadstasis-ea8ec855c3c6870d29c55afe3787afb2c05026a1.tar.gz
Try a different approach using declare -f
-rw-r--r--include/conda.h1
-rw-r--r--src/conda.c43
-rw-r--r--src/delivery.c4
3 files changed, 26 insertions, 22 deletions
diff --git a/include/conda.h b/include/conda.h
index c546672..5e8b8d9 100644
--- a/include/conda.h
+++ b/include/conda.h
@@ -192,4 +192,5 @@ int conda_index(const char *path);
*/
int pip_index_provides(const char *index_url, const char *name, const char *version);
+char *conda_runtime_dump(const char *root);
#endif //STASIS_CONDA_H
diff --git a/src/conda.c b/src/conda.c
index ff55f14..07a39c2 100644
--- a/src/conda.c
+++ b/src/conda.c
@@ -178,20 +178,33 @@ int conda_exec(const char *args) {
return system(command);
}
+char *conda_runtime_dump(const char *root) {
+ const char *init_script_conda = "/etc/profile.d/conda.sh";
+ const char *init_script_mamba = "/etc/profile.d/mamba.sh";
+ int state = 0;
+ char cmd[BUFSIZ] = {0};
+ sprintf(cmd, "source %s%s; source %s%s; env; declare -f", root, init_script_conda, root, init_script_mamba);
+
+ char *output = shell_output(cmd, &state);
+ if (state) {
+ guard_free(output);
+ return NULL;
+ }
+ return output;
+}
+
int conda_activate(const char *root, const char *env_name) {
int fd = -1;
FILE *fp = NULL;
- const char *init_script_conda = "/etc/profile.d/conda.sh";
- const char *init_script_mamba = "/etc/profile.d/mamba.sh";
- char path_conda[PATH_MAX] = {0};
- char path_mamba[PATH_MAX] = {0};
char logfile[PATH_MAX] = {0};
struct Process proc;
memset(&proc, 0, sizeof(proc));
- // Where to find conda's init scripts
- sprintf(path_conda, "%s%s", root, init_script_conda);
- sprintf(path_mamba, "%s%s", root, init_script_mamba);
+ char *full_runtime = conda_runtime_dump(root);
+ if (!full_runtime) {
+ SYSERROR("%s", "Failed to read variables and functions from the runtime environment");
+ return -1;
+ }
// Set the path to our stdout log
// Emulate mktemp()'s behavior. Give us a unique file name, but don't use
@@ -207,22 +220,10 @@ int conda_activate(const char *root, const char *env_name) {
// Configure our process for output to a log file
strcpy(proc.f_stdout, logfile);
- // Verify conda's init scripts are available
- if (access(path_conda, F_OK) < 0) {
- perror(path_conda);
- remove(logfile);
- return -1;
- }
-
- if (access(path_mamba, F_OK) < 0) {
- perror(path_mamba);
- remove(logfile);
- return -1;
- }
-
// Fully activate conda and record its effect on the runtime environment
char command[PATH_MAX * 3];
- snprintf(command, sizeof(command) - 1, "source %s; source %s; conda activate %s &>/dev/null; env -0", path_conda, path_mamba, env_name);
+ snprintf(command, sizeof(command) - 1, "%s\nconda activate %s &>/dev/null\nenv -0\n", full_runtime, env_name);
+ guard_free(full_runtime);
int retval = shell(&proc, command);
if (retval) {
// it didn't work; drop out for cleanup
diff --git a/src/delivery.c b/src/delivery.c
index 6dcfb4b..2d2273c 100644
--- a/src/delivery.c
+++ b/src/delivery.c
@@ -1789,7 +1789,9 @@ void delivery_tests_run(struct Delivery *ctx) {
puts(cmd);
char runner_cmd[PATH_MAX] = {0};
- sprintf(runner_cmd, "set -x\n%s", cmd);
+ char *full_runtime = conda_runtime_dump(ctx->storage.conda_install_prefix);
+ sprintf(runner_cmd, "%s\nset -x\n%s", full_runtime, cmd);
+ guard_free(full_runtime);
status = shell(&proc, runner_cmd);
if (status) {
msg(STASIS_MSG_ERROR, "Script failure: %s\n%s\n\nExit code: %d\n", ctx->tests[i].name, ctx->tests[i].script, status);