diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/cli/stasis_indexer/callbacks.c | 4 | ||||
| -rw-r--r-- | src/cli/stasis_indexer/helpers.c | 22 | ||||
| -rw-r--r-- | src/cli/stasis_indexer/helpers.h | 2 | ||||
| -rw-r--r-- | src/cli/stasis_indexer/junitxml_report.c | 12 | ||||
| -rw-r--r-- | src/cli/stasis_indexer/readmes.c | 22 | ||||
| -rw-r--r-- | src/cli/stasis_indexer/stasis_indexer_main.c | 29 | 
6 files changed, 55 insertions, 36 deletions
| diff --git a/src/cli/stasis_indexer/callbacks.c b/src/cli/stasis_indexer/callbacks.c index 4790e09..0186e1c 100644 --- a/src/cli/stasis_indexer/callbacks.c +++ b/src/cli/stasis_indexer/callbacks.c @@ -23,9 +23,9 @@ int callback_sort_deliveries_cmpfn(const void *a, const void *b) {  // qsort callback to sort dynamically allocated delivery contexts by compact python version  int callback_sort_deliveries_dynamic_cmpfn(const void *a, const void *b) { -    const struct Delivery *delivery1 = *(struct Delivery **) a; +    const struct Delivery *delivery1 = a;      const size_t delivery1_python = strtoul(delivery1->meta.python_compact, NULL, 10); -    const struct Delivery *delivery2 = *(struct Delivery **) b; +    const struct Delivery *delivery2 = b;      const size_t delivery2_python = strtoul(delivery2->meta.python_compact, NULL, 10);      if (delivery2_python > delivery1_python) { diff --git a/src/cli/stasis_indexer/helpers.c b/src/cli/stasis_indexer/helpers.c index 1c51e8d..078be68 100644 --- a/src/cli/stasis_indexer/helpers.c +++ b/src/cli/stasis_indexer/helpers.c @@ -181,25 +181,35 @@ int get_latest_rc(struct Delivery ctx[], const size_t nelem) {      return result;  } -struct Delivery **get_latest_deliveries(struct Delivery ctx[], const size_t nelem) { -    struct Delivery **result = NULL; +int sort_by_latest_rc(const void *a, const void *b) { +    const struct Delivery *aa = a; +    const struct Delivery *bb = b; +    if (aa->meta.rc > bb->meta.rc) { +        return -1; +    } +    if (aa->meta.rc < bb->meta.rc) { +        return 1; +    } +    return 0; +} + +struct Delivery *get_latest_deliveries(struct Delivery ctx[], size_t nelem) {      int latest = 0;      size_t n = 0; -    result = calloc(nelem + 1, sizeof(result)); +    struct Delivery *result = calloc(nelem + 1, sizeof(*result));      if (!result) { -        fprintf(stderr, "Unable to allocate %zu bytes for result delivery array: %s\n", nelem * sizeof(result), strerror(errno)); +        fprintf(stderr, "Unable to allocate %zu bytes for result delivery array: %s\n", nelem * sizeof(*result), strerror(errno));          return NULL;      }      latest = get_latest_rc(ctx, nelem);      for (size_t i = 0; i < nelem; i++) {          if (ctx[i].meta.rc == latest) { -            result[n] = &ctx[i]; +            result[n] = ctx[i];              n++;          }      } -      return result;  } diff --git a/src/cli/stasis_indexer/helpers.h b/src/cli/stasis_indexer/helpers.h index ffd9f4d..733691d 100644 --- a/src/cli/stasis_indexer/helpers.h +++ b/src/cli/stasis_indexer/helpers.h @@ -18,7 +18,7 @@ struct StrList *get_platforms(struct Delivery ctx[], size_t nelem);  int get_pandoc_version(size_t *result);  int pandoc_exec(const char *in_file, const char *out_file, const char *css_file, const char *title);  int get_latest_rc(struct Delivery ctx[], size_t nelem); -struct Delivery **get_latest_deliveries(struct Delivery ctx[], size_t nelem); +struct Delivery *get_latest_deliveries(struct Delivery ctx[], size_t nelem);  int get_files(struct StrList **out, const char *path, const char *pattern, ...);  int load_metadata(struct Delivery *ctx, const char *filename);  int micromamba_configure(const struct Delivery *ctx, struct MicromambaInfo *m); diff --git a/src/cli/stasis_indexer/junitxml_report.c b/src/cli/stasis_indexer/junitxml_report.c index 7128331..90cae3b 100644 --- a/src/cli/stasis_indexer/junitxml_report.c +++ b/src/cli/stasis_indexer/junitxml_report.c @@ -8,8 +8,12 @@  #include "junitxml_report.h"  int indexer_junitxml_report(struct Delivery ctx[], const size_t nelem) { -    struct Delivery **latest = NULL; -    latest = get_latest_deliveries(ctx, nelem); +    struct Delivery *latest = get_latest_deliveries(ctx, nelem); +    if (!latest) { +        return -1; +    } +    size_t latest_count; +    ARRAY_COUNT_BY_STRUCT_MEMBER(latest, meta.name, latest_count);      char indexfile[PATH_MAX] = {0};      sprintf(indexfile, "%s/README.md", ctx->storage.results_dir); @@ -29,7 +33,9 @@ int indexer_junitxml_report(struct Delivery ctx[], const size_t nelem) {          struct StrList *archs = get_architectures(*latest, nelem);          struct StrList *platforms = get_platforms(*latest, nelem); -        qsort(latest, nelem, sizeof(*latest), callback_sort_deliveries_dynamic_cmpfn); +        struct StrList *archs = get_architectures(latest, nelem); +        struct StrList *platforms = get_platforms(latest, nelem); +        qsort(latest, latest_count, sizeof(*latest), callback_sort_deliveries_dynamic_cmpfn);          fprintf(indexfp, "# %s-%s Test Report\n\n", ctx->meta.name, ctx->meta.version);          fprintf(indexfp, "## Current Release\n\n");          size_t no_printable_data = 0; diff --git a/src/cli/stasis_indexer/readmes.c b/src/cli/stasis_indexer/readmes.c index 75e97a9..c98ecfc 100644 --- a/src/cli/stasis_indexer/readmes.c +++ b/src/cli/stasis_indexer/readmes.c @@ -2,7 +2,7 @@  #include "readmes.h"  int indexer_readmes(struct Delivery ctx[], const size_t nelem) { -    struct Delivery **latest = NULL; +    struct Delivery *latest = NULL;      latest = get_latest_deliveries(ctx, nelem);      char indexfile[PATH_MAX] = {0}; @@ -14,8 +14,8 @@ int indexer_readmes(struct Delivery ctx[], const size_t nelem) {              fprintf(stderr, "Unable to open %s for writing\n", indexfile);              return -1;          } -        struct StrList *archs = get_architectures(*latest, nelem); -        struct StrList *platforms = get_platforms(*latest, nelem); +        struct StrList *archs = get_architectures(latest, nelem); +        struct StrList *platforms = get_platforms(latest, nelem);          fprintf(indexfp, "# %s-%s\n\n", ctx->meta.name, ctx->meta.version);          fprintf(indexfp, "## Current Release\n\n"); @@ -25,9 +25,9 @@ int indexer_readmes(struct Delivery ctx[], const size_t nelem) {                  char *arch = strlist_item(archs, a);                  int have_combo = 0;                  for (size_t i = 0; i < nelem; i++) { -                    if (latest[i] && latest[i]->system.platform) { -                        if (strstr(latest[i]->system.platform[DELIVERY_PLATFORM_RELEASE], platform) && -                            strstr(latest[i]->system.arch, arch)) { +                    if (latest[i].system.platform) { +                        if (strstr(latest[i].system.platform[DELIVERY_PLATFORM_RELEASE], platform) && +                            strstr(latest[i].system.arch, arch)) {                              have_combo = 1;                          }                      } @@ -44,13 +44,13 @@ int indexer_readmes(struct Delivery ctx[], const size_t nelem) {                      char readme_name[PATH_MAX];                      char conf_name[PATH_MAX];                      char conf_name_relative[PATH_MAX]; -                    if (!latest[i]) { +                    if (!latest[i].meta.name) {                          continue;                      } -                    sprintf(link_name, "latest-py%s-%s-%s.yml", latest[i]->meta.python_compact, latest[i]->system.platform[DELIVERY_PLATFORM_RELEASE], latest[i]->system.arch); -                    sprintf(readme_name, "README-py%s-%s-%s.md", latest[i]->meta.python_compact, latest[i]->system.platform[DELIVERY_PLATFORM_RELEASE], latest[i]->system.arch); -                    sprintf(conf_name, "%s.ini", latest[i]->info.release_name); -                    sprintf(conf_name_relative, "../config/%s-rendered.ini", latest[i]->info.release_name); +                    sprintf(link_name, "latest-py%s-%s-%s.yml", latest[i].meta.python_compact, latest[i].system.platform[DELIVERY_PLATFORM_RELEASE], latest[i].system.arch); +                    sprintf(readme_name, "README-py%s-%s-%s.md", latest[i].meta.python_compact, latest[i].system.platform[DELIVERY_PLATFORM_RELEASE], latest[i].system.arch); +                    sprintf(conf_name, "%s.ini", latest[i].info.release_name); +                    sprintf(conf_name_relative, "../config/%s.ini", latest[i].info.release_name);                      if (strstr(link_name, platform) && strstr(link_name, arch)) {                          fprintf(indexfp, "|[%s](%s)|[%s](%s)|[%s](%s)|\n", link_name, link_name, readme_name, readme_name, conf_name, conf_name_relative);                      } diff --git a/src/cli/stasis_indexer/stasis_indexer_main.c b/src/cli/stasis_indexer/stasis_indexer_main.c index 6c318c9..016b26e 100644 --- a/src/cli/stasis_indexer/stasis_indexer_main.c +++ b/src/cli/stasis_indexer/stasis_indexer_main.c @@ -67,8 +67,8 @@ int indexer_conda(const struct Delivery *ctx, struct MicromambaInfo m) {      return status;  } -int indexer_symlinks(struct Delivery ctx[], const size_t nelem) { -    struct Delivery **data = NULL; +int indexer_symlinks(struct Delivery *ctx, const size_t nelem) { +    struct Delivery *data = NULL;      data = get_latest_deliveries(ctx, nelem);      //int latest = get_latest_rc(ctx, nelem); @@ -80,14 +80,14 @@ int indexer_symlinks(struct Delivery ctx[], const size_t nelem) {              char file_name_spec[PATH_MAX];              char file_name_readme[PATH_MAX]; -            if (!data[i]) { +            if (!data[i].meta.name) {                  continue;              } -            sprintf(link_name_spec, "latest-py%s-%s-%s.yml", data[i]->meta.python_compact, data[i]->system.platform[DELIVERY_PLATFORM_RELEASE], data[i]->system.arch); -            sprintf(file_name_spec, "%s.yml", data[i]->info.release_name); +            sprintf(link_name_spec, "latest-py%s-%s-%s.yml", data[i].meta.python_compact, data[i].system.platform[DELIVERY_PLATFORM_RELEASE], data[i].system.arch); +            sprintf(file_name_spec, "%s.yml", data[i].info.release_name); -            sprintf(link_name_readme, "README-py%s-%s-%s.md", data[i]->meta.python_compact, data[i]->system.platform[DELIVERY_PLATFORM_RELEASE], data[i]->system.arch); -            sprintf(file_name_readme, "README-%s.md", data[i]->info.release_name); +            sprintf(link_name_readme, "README-py%s-%s-%s.md", data[i].meta.python_compact, data[i].system.platform[DELIVERY_PLATFORM_RELEASE], data[i].system.arch); +            sprintf(file_name_readme, "README-%s.md", data[i].info.release_name);              if (!access(link_name_spec, F_OK)) {                  if (unlink(link_name_spec)) { @@ -316,18 +316,21 @@ int main(const int argc, char *argv[]) {      struct StrList *metafiles = NULL;      get_files(&metafiles, ctx.storage.meta_dir, "*.stasis");      strlist_sort(metafiles, STASIS_SORT_LEN_ASCENDING); -    struct Delivery local[strlist_count(metafiles)]; + +    struct Delivery *local = calloc(strlist_count(metafiles) + 1, sizeof(*local)); +    if (!local) { +        SYSERROR("%s", "Unable to allocate bytes for local delivery context array"); +        exit(1); +    }      for (size_t i = 0; i < strlist_count(metafiles); i++) {          char *item = strlist_item(metafiles, i); -        memset(&local[i], 0, sizeof(ctx)); +        // Copy the pre-filled contents of the main delivery context          memcpy(&local[i], &ctx, sizeof(ctx)); -        char path[PATH_MAX]; -        sprintf(path, "%s/%s", ctx.storage.meta_dir, item);          if (globals.verbose) { -            puts(path); +            puts(item);          } -        load_metadata(&local[i], path); +        load_metadata(&local[i], item);      }      qsort(local, strlist_count(metafiles), sizeof(*local), callback_sort_deliveries_cmpfn); | 
