diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/CMakeLists.txt | 47 | ||||
| -rw-r--r-- | src/cli/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/cli/stasis/CMakeLists.txt | 12 | ||||
| -rw-r--r-- | src/cli/stasis/args.c | 102 | ||||
| -rw-r--r-- | src/cli/stasis/args.h | 23 | ||||
| -rw-r--r-- | src/cli/stasis/callbacks.c | 31 | ||||
| -rw-r--r-- | src/cli/stasis/callbacks.h | 10 | ||||
| -rw-r--r-- | src/cli/stasis/stasis_main.c (renamed from src/stasis_main.c) | 266 | ||||
| -rw-r--r-- | src/cli/stasis/system_requirements.c | 82 | ||||
| -rw-r--r-- | src/cli/stasis/system_requirements.h | 13 | ||||
| -rw-r--r-- | src/cli/stasis/tpl.c | 46 | ||||
| -rw-r--r-- | src/cli/stasis/tpl.h | 10 | ||||
| -rw-r--r-- | src/cli/stasis_indexer/CMakeLists.txt | 6 | ||||
| -rw-r--r-- | src/cli/stasis_indexer/stasis_indexer.c (renamed from src/stasis_indexer.c) | 3 | ||||
| -rw-r--r-- | src/lib/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | src/lib/core/CMakeLists.txt | 38 | ||||
| -rw-r--r-- | src/lib/core/artifactory.c (renamed from src/artifactory.c) | 2 | ||||
| -rw-r--r-- | src/lib/core/conda.c (renamed from src/conda.c) | 1 | ||||
| -rw-r--r-- | src/lib/core/copy.c (renamed from src/copy.c) | 0 | ||||
| -rw-r--r-- | src/lib/core/delivery.c (renamed from src/delivery.c) | 2 | ||||
| -rw-r--r-- | src/lib/core/delivery_artifactory.c (renamed from src/delivery_artifactory.c) | 0 | ||||
| -rw-r--r-- | src/lib/core/delivery_build.c (renamed from src/delivery_build.c) | 1 | ||||
| -rw-r--r-- | src/lib/core/delivery_conda.c (renamed from src/delivery_conda.c) | 0 | ||||
| -rw-r--r-- | src/lib/core/delivery_docker.c (renamed from src/delivery_docker.c) | 0 | ||||
| -rw-r--r-- | src/lib/core/delivery_init.c (renamed from src/delivery_init.c) | 0 | ||||
| -rw-r--r-- | src/lib/core/delivery_install.c (renamed from src/delivery_install.c) | 0 | ||||
| -rw-r--r-- | src/lib/core/delivery_populate.c (renamed from src/delivery_populate.c) | 0 | ||||
| -rw-r--r-- | src/lib/core/delivery_postprocess.c (renamed from src/delivery_postprocess.c) | 0 | ||||
| -rw-r--r-- | src/lib/core/delivery_show.c (renamed from src/delivery_show.c) | 0 | ||||
| -rw-r--r-- | src/lib/core/delivery_test.c (renamed from src/delivery_test.c) | 0 | ||||
| -rw-r--r-- | src/lib/core/docker.c (renamed from src/docker.c) | 1 | ||||
| -rw-r--r-- | src/lib/core/download.c (renamed from src/download.c) | 2 | ||||
| -rw-r--r-- | src/lib/core/envctl.c (renamed from src/envctl.c) | 1 | ||||
| -rw-r--r-- | src/lib/core/environment.c (renamed from src/environment.c) | 0 | ||||
| -rw-r--r-- | src/lib/core/github.c (renamed from src/github.c) | 1 | ||||
| -rw-r--r-- | src/lib/core/globals.c (renamed from src/globals.c) | 1 | ||||
| -rw-r--r-- | src/lib/core/ini.c (renamed from src/ini.c) | 0 | ||||
| -rw-r--r-- | src/lib/core/junitxml.c (renamed from src/junitxml.c) | 0 | ||||
| -rw-r--r-- | src/lib/core/multiprocessing.c (renamed from src/multiprocessing.c) | 1 | ||||
| -rw-r--r-- | src/lib/core/package.c | 41 | ||||
| -rw-r--r-- | src/lib/core/recipe.c (renamed from src/recipe.c) | 0 | ||||
| -rw-r--r-- | src/lib/core/relocation.c (renamed from src/relocation.c) | 0 | ||||
| -rw-r--r-- | src/lib/core/rules.c (renamed from src/rules.c) | 0 | ||||
| -rw-r--r-- | src/lib/core/str.c (renamed from src/str.c) | 0 | ||||
| -rw-r--r-- | src/lib/core/strlist.c (renamed from src/strlist.c) | 1 | ||||
| -rw-r--r-- | src/lib/core/system.c (renamed from src/system.c) | 0 | ||||
| -rw-r--r-- | src/lib/core/template.c (renamed from src/template.c) | 0 | ||||
| -rw-r--r-- | src/lib/core/template_func_proto.c (renamed from src/template_func_proto.c) | 2 | ||||
| -rw-r--r-- | src/lib/core/utils.c (renamed from src/utils.c) | 1 | ||||
| -rw-r--r-- | src/lib/core/wheel.c (renamed from src/wheel.c) | 0 | 
50 files changed, 438 insertions, 312 deletions
| diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5c5bc6e..bfee276 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -2,49 +2,6 @@ include_directories(${CMAKE_BINARY_DIR}/include)  include_directories(${CMAKE_SOURCE_DIR}/include)  include_directories(${PROJECT_BINARY_DIR}) -add_library(stasis_core STATIC -        globals.c -        str.c -        strlist.c -        ini.c -        conda.c -        environment.c -        utils.c -        system.c -        download.c -        delivery_postprocess.c -        delivery_conda.c -        delivery_docker.c -        delivery_install.c -        delivery_artifactory.c -        delivery_test.c -        delivery_build.c -        delivery_show.c -        delivery_populate.c -        delivery_init.c -        delivery.c -        recipe.c -        relocation.c -        wheel.c -        copy.c -        artifactory.c -        template.c -        rules.c -        docker.c -        junitxml.c -        github.c -        template_func_proto.c -        envctl.c -        multiprocessing.c -) +add_subdirectory(lib) +add_subdirectory(cli) -add_executable(stasis -        stasis_main.c -) -target_link_libraries(stasis PRIVATE stasis_core) -target_link_libraries(stasis PUBLIC LibXml2::LibXml2) -add_executable(stasis_indexer -        stasis_indexer.c -) -target_link_libraries(stasis_indexer PRIVATE stasis_core) -install(TARGETS stasis stasis_indexer RUNTIME) diff --git a/src/cli/CMakeLists.txt b/src/cli/CMakeLists.txt new file mode 100644 index 0000000..92a21b7 --- /dev/null +++ b/src/cli/CMakeLists.txt @@ -0,0 +1,2 @@ +add_subdirectory(stasis) +add_subdirectory(stasis_indexer)
\ No newline at end of file diff --git a/src/cli/stasis/CMakeLists.txt b/src/cli/stasis/CMakeLists.txt new file mode 100644 index 0000000..ff7fd88 --- /dev/null +++ b/src/cli/stasis/CMakeLists.txt @@ -0,0 +1,12 @@ +include_directories(${CMAKE_SOURCE_DIR}) +add_executable(stasis +        stasis_main.c +        args.c +        callbacks.c +        system_requirements.c +        tpl.c +) +target_link_libraries(stasis PRIVATE stasis_core) +target_link_libraries(stasis PUBLIC LibXml2::LibXml2) + +install(TARGETS stasis RUNTIME) diff --git a/src/cli/stasis/args.c b/src/cli/stasis/args.c new file mode 100644 index 0000000..ed11ab9 --- /dev/null +++ b/src/cli/stasis/args.c @@ -0,0 +1,102 @@ +#include "core.h" +#include "args.h" + +struct option long_options[] = { +    {"help", no_argument, 0, 'h'}, +    {"version", no_argument, 0, 'V'}, +    {"continue-on-error", no_argument, 0, 'C'}, +    {"config", required_argument, 0, 'c'}, +    {"cpu-limit", required_argument, 0, 'l'}, +    {"pool-status-interval", required_argument, 0, OPT_POOL_STATUS_INTERVAL}, +    {"python", required_argument, 0, 'p'}, +    {"verbose", no_argument, 0, 'v'}, +    {"unbuffered", no_argument, 0, 'U'}, +    {"update-base", no_argument, 0, OPT_ALWAYS_UPDATE_BASE}, +    {"fail-fast", no_argument, 0, OPT_FAIL_FAST}, +    {"overwrite", no_argument, 0, OPT_OVERWRITE}, +    {"no-docker", no_argument, 0, OPT_NO_DOCKER}, +    {"no-artifactory", no_argument, 0, OPT_NO_ARTIFACTORY}, +    {"no-artifactory-build-info", no_argument, 0, OPT_NO_ARTIFACTORY_BUILD_INFO}, +    {"no-testing", no_argument, 0, OPT_NO_TESTING}, +    {"no-parallel", no_argument, 0, OPT_NO_PARALLEL}, +    {"no-rewrite", no_argument, 0, OPT_NO_REWRITE_SPEC_STAGE_2}, +    {0, 0, 0, 0}, +}; + +const char *long_options_help[] = { +    "Display this usage statement", +    "Display program version", +    "Allow tests to fail", +    "Read configuration file", +    "Number of processes to spawn concurrently (default: cpus - 1)", +    "Report task status every n seconds (default: 30)", +    "Override version of Python in configuration", +    "Increase output verbosity", +    "Disable line buffering", +    "Update conda installation prior to STASIS environment creation", +    "On error, immediately terminate all tasks", +    "Overwrite an existing release", +    "Do not build docker images", +    "Do not upload artifacts to Artifactory", +    "Do not upload build info objects to Artifactory", +    "Do not execute test scripts", +    "Do not execute tests in parallel", +    "Do not rewrite paths and URLs in output files", +    NULL, +}; + +static int get_option_max_width(struct option option[]) { +    int i = 0; +    int max = 0; +    const int indent = 4; +    while (option[i].name != 0) { +        int len = (int) strlen(option[i].name); +        if (option[i].has_arg) { +            len += indent; +        } +        if (len > max) { +            max = len; +        } +        i++; +    } +    return max; +} + +void usage(char *progname) { +    printf("usage: %s ", progname); +    printf("[-"); +    for (int x = 0; long_options[x].val != 0; x++) { +        if (long_options[x].has_arg == no_argument && long_options[x].val <= 'z') { +            putchar(long_options[x].val); +        } +    } +    printf("] {DELIVERY_FILE}\n"); + +    int width = get_option_max_width(long_options); +    for (int x = 0; long_options[x].name != 0; x++) { +        char tmp[STASIS_NAME_MAX] = {0}; +        char output[sizeof(tmp)] = {0}; +        char opt_long[50] = {0};        // --? [ARG]? +        char opt_short[50] = {0};        // -? [ARG]? + +        strcat(opt_long, "--"); +        strcat(opt_long, long_options[x].name); +        if (long_options[x].has_arg) { +            strcat(opt_long, " ARG"); +        } + +        if (long_options[x].val <= 'z') { +            strcat(opt_short, "-"); +            opt_short[1] = (char) long_options[x].val; +            if (long_options[x].has_arg) { +                strcat(opt_short, " ARG"); +            } +        } else { +            strcat(opt_short, "  "); +        } + +        sprintf(tmp, "  %%-%ds\t%%s\t\t%%s", width + 4); +        sprintf(output, tmp, opt_long, opt_short, long_options_help[x]); +        puts(output); +    } +} diff --git a/src/cli/stasis/args.h b/src/cli/stasis/args.h new file mode 100644 index 0000000..932eac7 --- /dev/null +++ b/src/cli/stasis/args.h @@ -0,0 +1,23 @@ +#ifndef STASIS_ARGS_H +#define STASIS_ARGS_H + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <getopt.h> + +#define OPT_ALWAYS_UPDATE_BASE 1000 +#define OPT_NO_DOCKER 1001 +#define OPT_NO_ARTIFACTORY 1002 +#define OPT_NO_ARTIFACTORY_BUILD_INFO 1003 +#define OPT_NO_TESTING 1004 +#define OPT_OVERWRITE 1005 +#define OPT_NO_REWRITE_SPEC_STAGE_2 1006 +#define OPT_FAIL_FAST 1007 +#define OPT_NO_PARALLEL 1008 +#define OPT_POOL_STATUS_INTERVAL 1009 + +extern struct option long_options[]; +void usage(char *progname); + +#endif //STASIS_ARGS_H diff --git a/src/cli/stasis/callbacks.c b/src/cli/stasis/callbacks.c new file mode 100644 index 0000000..aeaa25d --- /dev/null +++ b/src/cli/stasis/callbacks.c @@ -0,0 +1,31 @@ +#include "callbacks.h" + +int callback_except_jf(const void *a, const void *b) { +    const struct EnvCtl_Item *item = a; +    const char *name = b; + +    if (!globals.enable_artifactory) { +        return STASIS_ENVCTL_RET_IGNORE; +    } + +    if (envctl_check_required(item->flags)) { +        const char *content = getenv(name); +        if (!content || isempty((char *) content)) { +            return STASIS_ENVCTL_RET_FAIL; +        } +    } + +    return STASIS_ENVCTL_RET_SUCCESS; +} + +int callback_except_gh(const void *a, const void *b) { +    const struct EnvCtl_Item *item = a; +    const char *name = b; +    //printf("GH exception check: %s\n", name); +    if (envctl_check_required(item->flags) && envctl_check_present(item, name)) { +        return STASIS_ENVCTL_RET_SUCCESS; +    } + +    return STASIS_ENVCTL_RET_FAIL; +} + diff --git a/src/cli/stasis/callbacks.h b/src/cli/stasis/callbacks.h new file mode 100644 index 0000000..369ce56 --- /dev/null +++ b/src/cli/stasis/callbacks.h @@ -0,0 +1,10 @@ +#ifndef STASIS_CALLBACKS_H +#define STASIS_CALLBACKS_H + +#include "core.h" +#include "envctl.h" + +int callback_except_jf(const void *a, const void *b); +int callback_except_gh(const void *a, const void *b); + +#endif //STASIS_CALLBACKS_H diff --git a/src/stasis_main.c b/src/cli/stasis/stasis_main.c index eecc419..5325892 100644 --- a/src/stasis_main.c +++ b/src/cli/stasis/stasis_main.c @@ -2,215 +2,14 @@  #include <stdlib.h>  #include <string.h>  #include <limits.h> -#include <getopt.h>  #include "core.h" +#include "delivery.h" -#define OPT_ALWAYS_UPDATE_BASE 1000 -#define OPT_NO_DOCKER 1001 -#define OPT_NO_ARTIFACTORY 1002 -#define OPT_NO_ARTIFACTORY_BUILD_INFO 1003 -#define OPT_NO_TESTING 1004 -#define OPT_OVERWRITE 1005 -#define OPT_NO_REWRITE_SPEC_STAGE_2 1006 -#define OPT_FAIL_FAST 1007 -#define OPT_NO_PARALLEL 1008 -#define OPT_POOL_STATUS_INTERVAL 1009 - -static struct option long_options[] = { -        {"help", no_argument, 0, 'h'}, -        {"version", no_argument, 0, 'V'}, -        {"continue-on-error", no_argument, 0, 'C'}, -        {"config", required_argument, 0, 'c'}, -        {"cpu-limit", required_argument, 0, 'l'}, -        {"pool-status-interval", required_argument, 0, OPT_POOL_STATUS_INTERVAL}, -        {"python", required_argument, 0, 'p'}, -        {"verbose", no_argument, 0, 'v'}, -        {"unbuffered", no_argument, 0, 'U'}, -        {"update-base", no_argument, 0, OPT_ALWAYS_UPDATE_BASE}, -        {"fail-fast", no_argument, 0, OPT_FAIL_FAST}, -        {"overwrite", no_argument, 0, OPT_OVERWRITE}, -        {"no-docker", no_argument, 0, OPT_NO_DOCKER}, -        {"no-artifactory", no_argument, 0, OPT_NO_ARTIFACTORY}, -        {"no-artifactory-build-info", no_argument, 0, OPT_NO_ARTIFACTORY_BUILD_INFO}, -        {"no-testing", no_argument, 0, OPT_NO_TESTING}, -        {"no-parallel", no_argument, 0, OPT_NO_PARALLEL}, -        {"no-rewrite", no_argument, 0, OPT_NO_REWRITE_SPEC_STAGE_2}, -        {0, 0, 0, 0}, -}; - -const char *long_options_help[] = { -        "Display this usage statement", -        "Display program version", -        "Allow tests to fail", -        "Read configuration file", -        "Number of processes to spawn concurrently (default: cpus - 1)", -        "Report task status every n seconds (default: 30)", -        "Override version of Python in configuration", -        "Increase output verbosity", -        "Disable line buffering", -        "Update conda installation prior to STASIS environment creation", -        "On error, immediately terminate all tasks", -        "Overwrite an existing release", -        "Do not build docker images", -        "Do not upload artifacts to Artifactory", -        "Do not upload build info objects to Artifactory", -        "Do not execute test scripts", -        "Do not execute tests in parallel", -        "Do not rewrite paths and URLs in output files", -        NULL, -}; - -static int get_option_max_width(struct option option[]) { -    int i = 0; -    int max = 0; -    const int indent = 4; -    while (option[i].name != 0) { -        int len = (int) strlen(option[i].name); -        if (option[i].has_arg) { -            len += indent; -        } -        if (len > max) { -            max = len; -        } -        i++; -    } -    return max; -} - -static void usage(char *progname) { -    printf("usage: %s ", progname); -    printf("[-"); -    for (int x = 0; long_options[x].val != 0; x++) { -        if (long_options[x].has_arg == no_argument && long_options[x].val <= 'z') { -            putchar(long_options[x].val); -        } -    } -    printf("] {DELIVERY_FILE}\n"); +// local includes +#include "args.h" +#include "system_requirements.h" +#include "tpl.h" -    int width = get_option_max_width(long_options); -    for (int x = 0; long_options[x].name != 0; x++) { -        char tmp[STASIS_NAME_MAX] = {0}; -        char output[sizeof(tmp)] = {0}; -        char opt_long[50] = {0};        // --? [ARG]? -        char opt_short[50] = {0};        // -? [ARG]? - -        strcat(opt_long, "--"); -        strcat(opt_long, long_options[x].name); -        if (long_options[x].has_arg) { -            strcat(opt_long, " ARG"); -        } - -        if (long_options[x].val <= 'z') { -            strcat(opt_short, "-"); -            opt_short[1] = (char) long_options[x].val; -            if (long_options[x].has_arg) { -                strcat(opt_short, " ARG"); -            } -        } else { -            strcat(opt_short, "  "); -        } - -        sprintf(tmp, "  %%-%ds\t%%s\t\t%%s", width + 4); -        sprintf(output, tmp, opt_long, opt_short, long_options_help[x]); -        puts(output); -    } -} - -static int callback_except_jf(const void *a, const void *b) { -    const struct EnvCtl_Item *item = a; -    const char *name = b; - -    if (!globals.enable_artifactory) { -        return STASIS_ENVCTL_RET_IGNORE; -    } - -    if (envctl_check_required(item->flags)) { -        const char *content = getenv(name); -        if (!content || isempty((char *) content)) { -            return STASIS_ENVCTL_RET_FAIL; -        } -    } - -    return STASIS_ENVCTL_RET_SUCCESS; -} - -static int callback_except_gh(const void *a, const void *b) { -    const struct EnvCtl_Item *item = a; -    const char *name = b; -    //printf("GH exception check: %s\n", name); -    if (envctl_check_required(item->flags) && envctl_check_present(item, name)) { -        return STASIS_ENVCTL_RET_SUCCESS; -    } - -    return STASIS_ENVCTL_RET_FAIL; -} - -static void check_system_env_requirements() { -    msg(STASIS_MSG_L1, "Checking environment\n"); -    globals.envctl = envctl_init(); -    envctl_register(&globals.envctl, STASIS_ENVCTL_PASSTHRU, NULL, "TMPDIR"); -    envctl_register(&globals.envctl, STASIS_ENVCTL_PASSTHRU, NULL, "STASIS_ROOT"); -    envctl_register(&globals.envctl, STASIS_ENVCTL_PASSTHRU, NULL, "STASIS_SYSCONFDIR"); -    envctl_register(&globals.envctl, STASIS_ENVCTL_PASSTHRU, NULL, "STASIS_CPU_COUNT"); -    envctl_register(&globals.envctl, STASIS_ENVCTL_REQUIRED | STASIS_ENVCTL_REDACT, callback_except_gh, "STASIS_GH_TOKEN"); -    envctl_register(&globals.envctl, STASIS_ENVCTL_REQUIRED, callback_except_jf, "STASIS_JF_ARTIFACTORY_URL"); -    envctl_register(&globals.envctl, STASIS_ENVCTL_REDACT, NULL, "STASIS_JF_ACCESS_TOKEN"); -    envctl_register(&globals.envctl, STASIS_ENVCTL_PASSTHRU, NULL, "STASIS_JF_USER"); -    envctl_register(&globals.envctl, STASIS_ENVCTL_REDACT, NULL, "STASIS_JF_PASSWORD"); -    envctl_register(&globals.envctl, STASIS_ENVCTL_REDACT, NULL, "STASIS_JF_SSH_KEY_PATH"); -    envctl_register(&globals.envctl, STASIS_ENVCTL_REDACT, NULL, "STASIS_JF_SSH_PASSPHRASE"); -    envctl_register(&globals.envctl, STASIS_ENVCTL_REDACT, NULL, "STASIS_JF_CLIENT_CERT_CERT_PATH"); -    envctl_register(&globals.envctl, STASIS_ENVCTL_REDACT, NULL, "STASIS_JF_CLIENT_CERT_KEY_PATH"); -    envctl_register(&globals.envctl, STASIS_ENVCTL_REQUIRED, callback_except_jf, "STASIS_JF_REPO"); -    envctl_do_required(globals.envctl, globals.verbose); -} - -static void check_system_requirements(struct Delivery *ctx) { -    const char *tools_required[] = { -        "rsync", -        NULL, -    }; - -    msg(STASIS_MSG_L1, "Checking system requirements\n"); -    for (size_t i = 0; tools_required[i] != NULL; i++) { -        if (!find_program(tools_required[i])) { -            msg(STASIS_MSG_L2 | STASIS_MSG_ERROR, "'%s' must be installed.\n", tools_required[i]); -            exit(1); -        } -    } - -    if (!globals.tmpdir && !ctx->storage.tmpdir) { -        delivery_init_tmpdir(ctx); -    } - -    struct DockerCapabilities dcap; -    if (!docker_capable(&dcap)) { -        msg(STASIS_MSG_L2 | STASIS_MSG_WARN, "Docker is broken\n"); -        msg(STASIS_MSG_L3, "Available: %s\n", dcap.available ? "Yes" : "No"); -        msg(STASIS_MSG_L3, "Usable: %s\n", dcap.usable ? "Yes" : "No"); -        msg(STASIS_MSG_L3, "Podman [Docker Emulation]: %s\n", dcap.podman ? "Yes" : "No"); -        msg(STASIS_MSG_L3, "Build plugin(s): "); -        if (dcap.usable) { -            if (dcap.build & STASIS_DOCKER_BUILD) { -                printf("build "); -            } -            if (dcap.build & STASIS_DOCKER_BUILD_X) { -                printf("buildx "); -            } -            puts(""); -        } else { -            printf("N/A\n"); -        } - -        // disable docker builds -        globals.enable_docker = false; -    } -} - -static void check_requirements(struct Delivery *ctx) { -    check_system_requirements(ctx); -    check_system_env_requirements(); -}  int main(int argc, char *argv[]) {      struct Delivery ctx; @@ -336,45 +135,8 @@ int main(int argc, char *argv[]) {      msg(STASIS_MSG_L1, "Setup\n"); -    // Expose variables for use with the template engine -    // NOTE: These pointers are populated by delivery_init() so please avoid using -    // tpl_render() until then. -    tpl_register("meta.name", &ctx.meta.name); -    tpl_register("meta.version", &ctx.meta.version); -    tpl_register("meta.codename", &ctx.meta.codename); -    tpl_register("meta.mission", &ctx.meta.mission); -    tpl_register("meta.python", &ctx.meta.python); -    tpl_register("meta.python_compact", &ctx.meta.python_compact); -    tpl_register("info.time_str_epoch", &ctx.info.time_str_epoch); -    tpl_register("info.release_name", &ctx.info.release_name); -    tpl_register("info.build_name", &ctx.info.build_name); -    tpl_register("info.build_number", &ctx.info.build_number); -    tpl_register("storage.tmpdir", &ctx.storage.tmpdir); -    tpl_register("storage.output_dir", &ctx.storage.output_dir); -    tpl_register("storage.delivery_dir", &ctx.storage.delivery_dir); -    tpl_register("storage.conda_artifact_dir", &ctx.storage.conda_artifact_dir); -    tpl_register("storage.wheel_artifact_dir", &ctx.storage.wheel_artifact_dir); -    tpl_register("storage.build_sources_dir", &ctx.storage.build_sources_dir); -    tpl_register("storage.build_docker_dir", &ctx.storage.build_docker_dir); -    tpl_register("storage.results_dir", &ctx.storage.results_dir); -    tpl_register("storage.tools_dir", &ctx.storage.tools_dir); -    tpl_register("conda.installer_baseurl", &ctx.conda.installer_baseurl); -    tpl_register("conda.installer_name", &ctx.conda.installer_name); -    tpl_register("conda.installer_version", &ctx.conda.installer_version); -    tpl_register("conda.installer_arch", &ctx.conda.installer_arch); -    tpl_register("conda.installer_platform", &ctx.conda.installer_platform); -    tpl_register("deploy.jfrog.repo", &globals.jfrog.repo); -    tpl_register("deploy.jfrog.url", &globals.jfrog.url); -    tpl_register("deploy.docker.registry", &ctx.deploy.docker.registry); -    tpl_register("workaround.conda_reactivate", &globals.workaround.conda_reactivate); - -    // Expose function(s) to the template engine -    // Prototypes can be found in template_func_proto.h -    tpl_register_func("get_github_release_notes", &get_github_release_notes_tplfunc_entrypoint, 3, NULL); -    tpl_register_func("get_github_release_notes_auto", &get_github_release_notes_auto_tplfunc_entrypoint, 1, &ctx); -    tpl_register_func("junitxml_file", &get_junitxml_file_entrypoint, 1, &ctx); -    tpl_register_func("basetemp_dir", &get_basetemp_dir_entrypoint, 1, &ctx); -    tpl_register_func("tox_run", &tox_run_entrypoint, 2, &ctx); +    tpl_setup_vars(&ctx); +    tpl_setup_funcs(&ctx);      // Set up PREFIX/etc directory information      // The user may manipulate the base directory path with STASIS_SYSCONFDIR @@ -482,19 +244,7 @@ int main(int argc, char *argv[]) {      msg(STASIS_MSG_L2, "Configuring: %s\n", ctx.storage.conda_install_prefix);      delivery_conda_enable(&ctx, ctx.storage.conda_install_prefix); - -    char *pathvar = NULL; -    pathvar = getenv("PATH"); -    if (!pathvar) { -        msg(STASIS_MSG_ERROR | STASIS_MSG_L2, "PATH variable is not set. Cannot continue.\n"); -        exit(1); -    } else { -        char pathvar_tmp[STASIS_BUFSIZ]; -        sprintf(pathvar_tmp, "%s/bin:%s", ctx.storage.conda_install_prefix, pathvar); -        setenv("PATH", pathvar_tmp, 1); -        pathvar = NULL; -    } - +    check_pathvar(&ctx);      //      // Implied environment creation modes/actions diff --git a/src/cli/stasis/system_requirements.c b/src/cli/stasis/system_requirements.c new file mode 100644 index 0000000..4554b93 --- /dev/null +++ b/src/cli/stasis/system_requirements.c @@ -0,0 +1,82 @@ +#include "system_requirements.h" + +void check_system_env_requirements() { +    msg(STASIS_MSG_L1, "Checking environment\n"); +    globals.envctl = envctl_init(); +    envctl_register(&globals.envctl, STASIS_ENVCTL_PASSTHRU, NULL, "TMPDIR"); +    envctl_register(&globals.envctl, STASIS_ENVCTL_PASSTHRU, NULL, "STASIS_ROOT"); +    envctl_register(&globals.envctl, STASIS_ENVCTL_PASSTHRU, NULL, "STASIS_SYSCONFDIR"); +    envctl_register(&globals.envctl, STASIS_ENVCTL_PASSTHRU, NULL, "STASIS_CPU_COUNT"); +    envctl_register(&globals.envctl, STASIS_ENVCTL_REQUIRED | STASIS_ENVCTL_REDACT, callback_except_gh, "STASIS_GH_TOKEN"); +    envctl_register(&globals.envctl, STASIS_ENVCTL_REQUIRED, callback_except_jf, "STASIS_JF_ARTIFACTORY_URL"); +    envctl_register(&globals.envctl, STASIS_ENVCTL_REDACT, NULL, "STASIS_JF_ACCESS_TOKEN"); +    envctl_register(&globals.envctl, STASIS_ENVCTL_PASSTHRU, NULL, "STASIS_JF_USER"); +    envctl_register(&globals.envctl, STASIS_ENVCTL_REDACT, NULL, "STASIS_JF_PASSWORD"); +    envctl_register(&globals.envctl, STASIS_ENVCTL_REDACT, NULL, "STASIS_JF_SSH_KEY_PATH"); +    envctl_register(&globals.envctl, STASIS_ENVCTL_REDACT, NULL, "STASIS_JF_SSH_PASSPHRASE"); +    envctl_register(&globals.envctl, STASIS_ENVCTL_REDACT, NULL, "STASIS_JF_CLIENT_CERT_CERT_PATH"); +    envctl_register(&globals.envctl, STASIS_ENVCTL_REDACT, NULL, "STASIS_JF_CLIENT_CERT_KEY_PATH"); +    envctl_register(&globals.envctl, STASIS_ENVCTL_REQUIRED, callback_except_jf, "STASIS_JF_REPO"); +    envctl_do_required(globals.envctl, globals.verbose); +} + +void check_system_requirements(struct Delivery *ctx) { +    const char *tools_required[] = { +        "rsync", +        NULL, +    }; + +    msg(STASIS_MSG_L1, "Checking system requirements\n"); +    for (size_t i = 0; tools_required[i] != NULL; i++) { +        if (!find_program(tools_required[i])) { +            msg(STASIS_MSG_L2 | STASIS_MSG_ERROR, "'%s' must be installed.\n", tools_required[i]); +            exit(1); +        } +    } + +    if (!globals.tmpdir && !ctx->storage.tmpdir) { +        delivery_init_tmpdir(ctx); +    } + +    struct DockerCapabilities dcap; +    if (!docker_capable(&dcap)) { +        msg(STASIS_MSG_L2 | STASIS_MSG_WARN, "Docker is broken\n"); +        msg(STASIS_MSG_L3, "Available: %s\n", dcap.available ? "Yes" : "No"); +        msg(STASIS_MSG_L3, "Usable: %s\n", dcap.usable ? "Yes" : "No"); +        msg(STASIS_MSG_L3, "Podman [Docker Emulation]: %s\n", dcap.podman ? "Yes" : "No"); +        msg(STASIS_MSG_L3, "Build plugin(s): "); +        if (dcap.usable) { +            if (dcap.build & STASIS_DOCKER_BUILD) { +                printf("build "); +            } +            if (dcap.build & STASIS_DOCKER_BUILD_X) { +                printf("buildx "); +            } +            puts(""); +        } else { +            printf("N/A\n"); +        } + +        // disable docker builds +        globals.enable_docker = false; +    } +} + +void check_requirements(struct Delivery *ctx) { +    check_system_requirements(ctx); +    check_system_env_requirements(); +} + +char *check_pathvar(struct Delivery *ctx) { +    char *pathvar = NULL; +    pathvar = getenv("PATH"); +    if (!pathvar) { +        msg(STASIS_MSG_ERROR | STASIS_MSG_L2, "PATH variable is not set. Cannot continue.\n"); +        exit(1); +    } else { +        char pathvar_tmp[STASIS_BUFSIZ]; +        sprintf(pathvar_tmp, "%s/bin:%s", ctx->storage.conda_install_prefix, pathvar); +        setenv("PATH", pathvar_tmp, 1); +        pathvar = NULL; +    } +}
\ No newline at end of file diff --git a/src/cli/stasis/system_requirements.h b/src/cli/stasis/system_requirements.h new file mode 100644 index 0000000..4c2231a --- /dev/null +++ b/src/cli/stasis/system_requirements.h @@ -0,0 +1,13 @@ +#ifndef STASIS_SYSTEM_REQUIREMENTS_H +#define STASIS_SYSTEM_REQUIREMENTS_H + +#include "delivery.h" +#include "callbacks.h" +#include "envctl.h" + +void check_system_env_requirements(); +void check_system_requirements(struct Delivery *ctx); +void check_requirements(struct Delivery *ctx); +char *check_pathvar(struct Delivery *ctx); + +#endif //STASIS_SYSTEM_REQUIREMENTS_H diff --git a/src/cli/stasis/tpl.c b/src/cli/stasis/tpl.c new file mode 100644 index 0000000..08eb1f3 --- /dev/null +++ b/src/cli/stasis/tpl.c @@ -0,0 +1,46 @@ +#include "delivery.h" +#include "tpl.h" + +void tpl_setup_vars(struct Delivery *ctx) { +    // Expose variables for use with the template engine +    // NOTE: These pointers are populated by delivery_init() so please avoid using +    // tpl_render() until then. +    tpl_register("meta.name", &ctx->meta.name); +    tpl_register("meta.version", &ctx->meta.version); +    tpl_register("meta.codename", &ctx->meta.codename); +    tpl_register("meta.mission", &ctx->meta.mission); +    tpl_register("meta.python", &ctx->meta.python); +    tpl_register("meta.python_compact", &ctx->meta.python_compact); +    tpl_register("info.time_str_epoch", &ctx->info.time_str_epoch); +    tpl_register("info.release_name", &ctx->info.release_name); +    tpl_register("info.build_name", &ctx->info.build_name); +    tpl_register("info.build_number", &ctx->info.build_number); +    tpl_register("storage.tmpdir", &ctx->storage.tmpdir); +    tpl_register("storage.output_dir", &ctx->storage.output_dir); +    tpl_register("storage.delivery_dir", &ctx->storage.delivery_dir); +    tpl_register("storage.conda_artifact_dir", &ctx->storage.conda_artifact_dir); +    tpl_register("storage.wheel_artifact_dir", &ctx->storage.wheel_artifact_dir); +    tpl_register("storage.build_sources_dir", &ctx->storage.build_sources_dir); +    tpl_register("storage.build_docker_dir", &ctx->storage.build_docker_dir); +    tpl_register("storage.results_dir", &ctx->storage.results_dir); +    tpl_register("storage.tools_dir", &ctx->storage.tools_dir); +    tpl_register("conda.installer_baseurl", &ctx->conda.installer_baseurl); +    tpl_register("conda.installer_name", &ctx->conda.installer_name); +    tpl_register("conda.installer_version", &ctx->conda.installer_version); +    tpl_register("conda.installer_arch", &ctx->conda.installer_arch); +    tpl_register("conda.installer_platform", &ctx->conda.installer_platform); +    tpl_register("deploy.jfrog.repo", &globals.jfrog.repo); +    tpl_register("deploy.jfrog.url", &globals.jfrog.url); +    tpl_register("deploy.docker.registry", &ctx->deploy.docker.registry); +    tpl_register("workaround.conda_reactivate", &globals.workaround.conda_reactivate); +} + +void tpl_setup_funcs(struct Delivery *ctx) { +    // Expose function(s) to the template engine +    // Prototypes can be found in template_func_proto.h +    tpl_register_func("get_github_release_notes", &get_github_release_notes_tplfunc_entrypoint, 3, NULL); +    tpl_register_func("get_github_release_notes_auto", &get_github_release_notes_auto_tplfunc_entrypoint, 1, ctx); +    tpl_register_func("junitxml_file", &get_junitxml_file_entrypoint, 1, ctx); +    tpl_register_func("basetemp_dir", &get_basetemp_dir_entrypoint, 1, ctx); +    tpl_register_func("tox_run", &tox_run_entrypoint, 2, ctx); +}
\ No newline at end of file diff --git a/src/cli/stasis/tpl.h b/src/cli/stasis/tpl.h new file mode 100644 index 0000000..398f0fe --- /dev/null +++ b/src/cli/stasis/tpl.h @@ -0,0 +1,10 @@ +#ifndef STASIS_TPL_H +#define STASIS_TPL_H + +#include "template.h" +#include "template_func_proto.h" + +void tpl_setup_vars(struct Delivery *ctx); +void tpl_setup_funcs(struct Delivery *ctx); + +#endif //STASIS_TPL_H diff --git a/src/cli/stasis_indexer/CMakeLists.txt b/src/cli/stasis_indexer/CMakeLists.txt new file mode 100644 index 0000000..eae1394 --- /dev/null +++ b/src/cli/stasis_indexer/CMakeLists.txt @@ -0,0 +1,6 @@ +add_executable(stasis_indexer +        stasis_indexer.c +) +target_link_libraries(stasis_indexer PRIVATE stasis_core) + +install(TARGETS stasis_indexer RUNTIME) diff --git a/src/stasis_indexer.c b/src/cli/stasis_indexer/stasis_indexer.c index 05b9e39..bd59920 100644 --- a/src/stasis_indexer.c +++ b/src/cli/stasis_indexer/stasis_indexer.c @@ -1,6 +1,7 @@  #include <getopt.h>  #include <fnmatch.h> -#include "core.h" +#include "delivery.h" +#include "junitxml.h"  static struct option long_options[] = {          {"help", no_argument, 0, 'h'}, diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt new file mode 100644 index 0000000..82bfe4a --- /dev/null +++ b/src/lib/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(core)
\ No newline at end of file diff --git a/src/lib/core/CMakeLists.txt b/src/lib/core/CMakeLists.txt new file mode 100644 index 0000000..c569187 --- /dev/null +++ b/src/lib/core/CMakeLists.txt @@ -0,0 +1,38 @@ +include_directories(${PROJECT_BINARY_DIR}) + +add_library(stasis_core STATIC +        globals.c +        str.c +        strlist.c +        ini.c +        conda.c +        environment.c +        utils.c +        system.c +        download.c +        delivery_postprocess.c +        delivery_conda.c +        delivery_docker.c +        delivery_install.c +        delivery_artifactory.c +        delivery_test.c +        delivery_build.c +        delivery_show.c +        delivery_populate.c +        delivery_init.c +        delivery.c +        recipe.c +        relocation.c +        wheel.c +        copy.c +        artifactory.c +        template.c +        rules.c +        docker.c +        junitxml.c +        github.c +        template_func_proto.c +        envctl.c +        multiprocessing.c +) + diff --git a/src/artifactory.c b/src/lib/core/artifactory.c index 6c4079a..6b9635d 100644 --- a/src/artifactory.c +++ b/src/lib/core/artifactory.c @@ -1,4 +1,4 @@ -#include "core.h" +#include "artifactory.h"  extern struct STASIS_GLOBAL globals; diff --git a/src/conda.c b/src/lib/core/conda.c index e60abc7..35caf02 100644 --- a/src/conda.c +++ b/src/lib/core/conda.c @@ -2,7 +2,6 @@  // Created by jhunk on 5/14/23.  // -#include <unistd.h>  #include "conda.h"  int micromamba(struct MicromambaInfo *info, char *command, ...) { diff --git a/src/copy.c b/src/lib/core/copy.c index f69a756..f69a756 100644 --- a/src/copy.c +++ b/src/lib/core/copy.c diff --git a/src/delivery.c b/src/lib/core/delivery.c index 07e04c8..e32ed4c 100644 --- a/src/delivery.c +++ b/src/lib/core/delivery.c @@ -1,4 +1,4 @@ -#include "core.h" +#include "delivery.h"  void delivery_free(struct Delivery *ctx) {      guard_free(ctx->system.arch); diff --git a/src/delivery_artifactory.c b/src/lib/core/delivery_artifactory.c index 27f4823..27f4823 100644 --- a/src/delivery_artifactory.c +++ b/src/lib/core/delivery_artifactory.c diff --git a/src/delivery_build.c b/src/lib/core/delivery_build.c index 3777a4c..b4d610a 100644 --- a/src/delivery_build.c +++ b/src/lib/core/delivery_build.c @@ -1,4 +1,3 @@ -#include <fnmatch.h>  #include "delivery.h"  int delivery_build_recipes(struct Delivery *ctx) { diff --git a/src/delivery_conda.c b/src/lib/core/delivery_conda.c index 93a06fc..93a06fc 100644 --- a/src/delivery_conda.c +++ b/src/lib/core/delivery_conda.c diff --git a/src/delivery_docker.c b/src/lib/core/delivery_docker.c index e1d7f60..e1d7f60 100644 --- a/src/delivery_docker.c +++ b/src/lib/core/delivery_docker.c diff --git a/src/delivery_init.c b/src/lib/core/delivery_init.c index e914f99..e914f99 100644 --- a/src/delivery_init.c +++ b/src/lib/core/delivery_init.c diff --git a/src/delivery_install.c b/src/lib/core/delivery_install.c index 76c3f4a..76c3f4a 100644 --- a/src/delivery_install.c +++ b/src/lib/core/delivery_install.c diff --git a/src/delivery_populate.c b/src/lib/core/delivery_populate.c index b37f677..b37f677 100644 --- a/src/delivery_populate.c +++ b/src/lib/core/delivery_populate.c diff --git a/src/delivery_postprocess.c b/src/lib/core/delivery_postprocess.c index 1a902e3..1a902e3 100644 --- a/src/delivery_postprocess.c +++ b/src/lib/core/delivery_postprocess.c diff --git a/src/delivery_show.c b/src/lib/core/delivery_show.c index adfa1be..adfa1be 100644 --- a/src/delivery_show.c +++ b/src/lib/core/delivery_show.c diff --git a/src/delivery_test.c b/src/lib/core/delivery_test.c index cb78f64..cb78f64 100644 --- a/src/delivery_test.c +++ b/src/lib/core/delivery_test.c diff --git a/src/docker.c b/src/lib/core/docker.c index 2d5e2cc..5834ef9 100644 --- a/src/docker.c +++ b/src/lib/core/docker.c @@ -1,4 +1,3 @@ -#include "core.h"  #include "docker.h" diff --git a/src/download.c b/src/lib/core/download.c index f83adda..bfb323e 100644 --- a/src/download.c +++ b/src/lib/core/download.c @@ -2,8 +2,6 @@  // Created by jhunk on 10/5/23.  // -#include <string.h> -#include <stdlib.h>  #include "download.h"  size_t download_writer(void *fp, size_t size, size_t nmemb, void *stream) { diff --git a/src/envctl.c b/src/lib/core/envctl.c index 78dd760..9037d9d 100644 --- a/src/envctl.c +++ b/src/lib/core/envctl.c @@ -1,5 +1,4 @@  #include "envctl.h" -#include "core.h"  struct EnvCtl *envctl_init() {      struct EnvCtl *result; diff --git a/src/environment.c b/src/lib/core/environment.c index 580062c..580062c 100644 --- a/src/environment.c +++ b/src/lib/core/environment.c diff --git a/src/github.c b/src/lib/core/github.c index 36e2e7c..c5e4534 100644 --- a/src/github.c +++ b/src/lib/core/github.c @@ -2,6 +2,7 @@  #include <stdlib.h>  #include <string.h>  #include "core.h" +#include "github.h"  struct GHContent {      char *data; diff --git a/src/globals.c b/src/lib/core/globals.c index 1b682cb..83465f1 100644 --- a/src/globals.c +++ b/src/lib/core/globals.c @@ -1,6 +1,7 @@  #include <stdlib.h>  #include <stdbool.h>  #include "core.h" +#include "envctl.h"  const char *VERSION = "1.0.0";  const char *AUTHOR = "Joseph Hunkeler"; diff --git a/src/ini.c b/src/lib/core/ini.c index d44e1cc..d44e1cc 100644 --- a/src/ini.c +++ b/src/lib/core/ini.c diff --git a/src/junitxml.c b/src/lib/core/junitxml.c index c7d0834..c7d0834 100644 --- a/src/junitxml.c +++ b/src/lib/core/junitxml.c diff --git a/src/multiprocessing.c b/src/lib/core/multiprocessing.c index 2a1b350..484c566 100644 --- a/src/multiprocessing.c +++ b/src/lib/core/multiprocessing.c @@ -1,4 +1,5 @@  #include "core.h" +#include "multiprocessing.h"  /// The sum of all tasks started by mp_task()  size_t mp_global_task_count = 0; diff --git a/src/lib/core/package.c b/src/lib/core/package.c new file mode 100644 index 0000000..e34673b --- /dev/null +++ b/src/lib/core/package.c @@ -0,0 +1,41 @@ +#include <stdlib.h> +#include "package.h" +#include "core.h" + +struct Package *stasis_package_init() { +    struct Package *result; +    result = calloc(1, sizeof(*result)); +    return result; +} + +void stasis_package_set_name(struct Package *pkg, const char *name) { +    if (pkg->meta.name) { +        guard_free(pkg->meta.name); +    } +    pkg->meta.name = strdup(name); +} + +void stasis_package_set_version(struct Package *pkg, const char *version) { +    if (pkg->meta.version) { +        guard_free(pkg->meta.version); +    } +    pkg->meta.version = strdup(version); +} + +void stasis_package_set_version_spec(struct Package *pkg, const char *version_spec) { +    if (pkg->meta.version_spec) { +        guard_free(pkg->meta.version_spec); +    } +    pkg->meta.version_spec = strdup(version_spec); +} + +void stasis_package_set_uri(struct Package *pkg, const char *uri) { +    if (pkg->source.uri) { +        guard_free(pkg->source.uri); +    } +    pkg->source.uri = uri; +} + +void stasis_package_set_handler(struct Package *pkg, unsigned handler) { +    pkg->source.handler = handler; +}
\ No newline at end of file diff --git a/src/recipe.c b/src/lib/core/recipe.c index 833908c..833908c 100644 --- a/src/recipe.c +++ b/src/lib/core/recipe.c diff --git a/src/relocation.c b/src/lib/core/relocation.c index 852aca4..852aca4 100644 --- a/src/relocation.c +++ b/src/lib/core/relocation.c diff --git a/src/rules.c b/src/lib/core/rules.c index e42ee07..e42ee07 100644 --- a/src/rules.c +++ b/src/lib/core/rules.c diff --git a/src/str.c b/src/lib/core/str.c index 868a6c7..868a6c7 100644 --- a/src/str.c +++ b/src/lib/core/str.c diff --git a/src/strlist.c b/src/lib/core/strlist.c index 7a045f1..f0bffa8 100644 --- a/src/strlist.c +++ b/src/lib/core/strlist.c @@ -2,6 +2,7 @@   * String array convenience functions   * @file strlist.c   */ +#include "download.h"  #include "strlist.h"  #include "utils.h" diff --git a/src/system.c b/src/lib/core/system.c index 4e605ec..4e605ec 100644 --- a/src/system.c +++ b/src/lib/core/system.c diff --git a/src/template.c b/src/lib/core/template.c index a412fa8..a412fa8 100644 --- a/src/template.c +++ b/src/lib/core/template.c diff --git a/src/template_func_proto.c b/src/lib/core/template_func_proto.c index 9c325bb..3305b4d 100644 --- a/src/template_func_proto.c +++ b/src/lib/core/template_func_proto.c @@ -1,4 +1,6 @@  #include "template_func_proto.h" +#include "delivery.h" +#include "github.h"  int get_github_release_notes_tplfunc_entrypoint(void *frame, void *data_out) {      int result; diff --git a/src/utils.c b/src/lib/core/utils.c index 6381cea..89950df 100644 --- a/src/utils.c +++ b/src/lib/core/utils.c @@ -1,5 +1,6 @@  #include <stdarg.h>  #include "core.h" +#include "utils.h"  char *dirstack[STASIS_DIRSTACK_MAX];  const ssize_t dirstack_max = sizeof(dirstack) / sizeof(dirstack[0]); diff --git a/src/wheel.c b/src/lib/core/wheel.c index 4692d0a..4692d0a 100644 --- a/src/wheel.c +++ b/src/lib/core/wheel.c | 
