From abe87056faa6ed02aff3bbf77c1fd78b713a0864 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Mon, 24 Jun 2024 11:23:26 -0400 Subject: Pass .ci_support/plat_arch_.yaml to conda-build (#8) * Pass .ci_support/plat_arch_.yaml to conda-build * Fixes a few outstanding leaks in delivery context * Move micromamba function out of stasis_indexer.c * Adjust code in the indexer to accommodate the move. The function now expects a MicromambaInfo structure as its first argument. * Add missing warning message * User is informed when pandoc is not available for HTML page generation * Initialize workdir_template string to zero * Add micromamba program to runtime PATH * Expose storage.tools_dir to template engine * Remove dead code * Fix wording in comment * Fix conda-forge builds * Pass their .ci_support configurations to conda-build in order to fully set up their build runtime environment * Add get_cpu_count() * Exposes STASIS_CPU_COUNT and CPU_COUNT to the runtime environment * Implements conda reactivation template string * {{ workaround.conda_reactivate }} * This is useful to call after installing any conda packages within a test.script * Fix conda runtime inside of test.script * This ensures conda and mamba are fully initialized. * Previous behavior only placed the commands on the PATH but didn't provide any shell macros (i.e. undefined behavior) * Document CPU_COUNT and workaround.conda_reactivate --- src/stasis_indexer.c | 80 ++++++++++++++-------------------------------------- 1 file changed, 21 insertions(+), 59 deletions(-) (limited to 'src/stasis_indexer.c') diff --git a/src/stasis_indexer.c b/src/stasis_indexer.c index fb231e0..a7b0fce 100644 --- a/src/stasis_indexer.c +++ b/src/stasis_indexer.c @@ -200,57 +200,6 @@ struct Delivery **get_latest_deliveries(struct Delivery ctx[], size_t nelem) { return result; } -int micromamba(const char *write_to, const char *prefix, char *command, ...) { - struct utsname sys; - uname(&sys); - - tolower_s(sys.sysname); - if (!strcmp(sys.sysname, "darwin")) { - strcpy(sys.sysname, "osx"); - } - - if (!strcmp(sys.machine, "x86_64")) { - strcpy(sys.machine, "64"); - } - - char url[PATH_MAX]; - sprintf(url, "https://micro.mamba.pm/api/micromamba/%s-%s/latest", sys.sysname, sys.machine); - if (access("latest", F_OK)) { - download(url, "latest", NULL); - } - - char mmbin[PATH_MAX]; - sprintf(mmbin, "%s/micromamba", write_to); - - if (access(mmbin, F_OK)) { - char untarcmd[PATH_MAX]; - mkdirs(write_to, 0755); - sprintf(untarcmd, "tar -xvf latest -C %s --strip-components=1 bin/micromamba 1>/dev/null", write_to); - system(untarcmd); - } - - char cmd[STASIS_BUFSIZ]; - memset(cmd, 0, sizeof(cmd)); - sprintf(cmd, "%s -r %s -p %s ", mmbin, prefix, prefix); - va_list args; - va_start(args, command); - vsprintf(cmd + strlen(cmd), command, args); - va_end(args); - - mkdirs(prefix, 0755); - - char rcpath[PATH_MAX]; - sprintf(rcpath, "%s/.condarc", prefix); - touch(rcpath); - - setenv("CONDARC", rcpath, 1); - setenv("MAMBA_ROOT_PREFIX", prefix, 1); - int status = system(cmd); - unsetenv("MAMBA_ROOT_PREFIX"); - - return status; -} - int indexer_make_website(struct Delivery *ctx) { char cmd[PATH_MAX]; char *inputs[] = { @@ -259,6 +208,7 @@ int indexer_make_website(struct Delivery *ctx) { }; if (!find_program("pandoc")) { + fprintf(stderr, "pandoc is not installed: unable to generate HTML indexes\n"); return 0; } @@ -291,16 +241,17 @@ int indexer_make_website(struct Delivery *ctx) { int indexer_conda(struct Delivery *ctx) { int status = 0; - char prefix[PATH_MAX]; - sprintf(prefix, "%s/%s", ctx->storage.tmpdir, "indexer"); + char micromamba_prefix[PATH_MAX] = {0}; + sprintf(micromamba_prefix, "%s/bin", ctx->storage.tools_dir); + struct MicromambaInfo m = {.conda_prefix = globals.conda_install_prefix, .micromamba_prefix = micromamba_prefix}; - status += micromamba(ctx->storage.tmpdir, prefix, "config prepend --env channels conda-forge"); + status += micromamba(&m, "config prepend --env channels conda-forge"); if (!globals.verbose) { - status += micromamba(ctx->storage.tmpdir, prefix, "config set --env quiet true"); + status += micromamba(&m, "config set --env quiet true"); } - status += micromamba(ctx->storage.tmpdir, prefix, "config set --env always_yes true"); - status += micromamba(ctx->storage.tmpdir, prefix, "install conda-build"); - status += micromamba(ctx->storage.tmpdir, prefix, "run conda index %s", ctx->storage.conda_artifact_dir); + status += micromamba(&m, "config set --env always_yes true"); + status += micromamba(&m, "install conda-build"); + status += micromamba(&m, "run conda index %s", ctx->storage.conda_artifact_dir); return status; } @@ -558,6 +509,8 @@ void indexer_init_dirs(struct Delivery *ctx, const char *workdir) { exit(1); } path_store(&ctx->storage.output_dir, PATH_MAX, ctx->storage.root, "output"); + path_store(&ctx->storage.tools_dir, PATH_MAX, ctx->storage.output_dir, "tools"); + path_store(&globals.conda_install_prefix, PATH_MAX, ctx->storage.tools_dir, "conda"); path_store(&ctx->storage.cfgdump_dir, PATH_MAX, ctx->storage.output_dir, "config"); path_store(&ctx->storage.meta_dir, PATH_MAX, ctx->storage.output_dir, "meta"); path_store(&ctx->storage.delivery_dir, PATH_MAX, ctx->storage.output_dir, "delivery"); @@ -565,6 +518,15 @@ void indexer_init_dirs(struct Delivery *ctx, const char *workdir) { path_store(&ctx->storage.results_dir, PATH_MAX, ctx->storage.output_dir, "results"); path_store(&ctx->storage.wheel_artifact_dir, PATH_MAX, ctx->storage.package_dir, "wheels"); path_store(&ctx->storage.conda_artifact_dir, PATH_MAX, ctx->storage.package_dir, "conda"); + + char newpath[PATH_MAX] = {0}; + if (getenv("PATH")) { + sprintf(newpath, "%s/bin:%s", ctx->storage.tools_dir, getenv("PATH")); + setenv("PATH", newpath, 1); + } else { + SYSERROR("%s", "environment variable PATH is undefined. Unable to continue."); + exit(1); + } } int main(int argc, char *argv[]) { @@ -627,7 +589,7 @@ int main(int argc, char *argv[]) { } char *workdir; - char workdir_template[PATH_MAX]; + char workdir_template[PATH_MAX] = {0}; char *system_tmp = getenv("TMPDIR"); if (system_tmp) { strcat(workdir_template, system_tmp); -- cgit