root/orte/tools/orte-info/version.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. orte_info_do_version
  2. orte_info_show_component_version
  3. show_mca_version
  4. make_version_str

   1 /*
   2  * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
   3  *                         University Research and Technology
   4  *                         Corporation.  All rights reserved.
   5  * Copyright (c) 2004-2006 The University of Tennessee and The University
   6  *                         of Tennessee Research Foundation.  All rights
   7  *                         reserved.
   8  * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
   9  *                         University of Stuttgart.  All rights reserved.
  10  * Copyright (c) 2004-2005 The Regents of the University of California.
  11  *                         All rights reserved.
  12  * Copyright (c) 2007      Sun Microsystems, Inc.  All rights reserved.
  13  * Copyright (c) 2010-2011 Cisco Systems, Inc.  All rights reserved.
  14  * Copyright (c) 2015      Research Organization for Information Science
  15  *                         and Technology (RIST). All rights reserved.
  16  * Copyright (c) 2018      Intel, Inc.  All rights reserved.
  17  * $COPYRIGHT$
  18  *
  19  * Additional copyrights may follow
  20  *
  21  * $HEADER$
  22  */
  23 
  24 #include "orte_config.h"
  25 
  26 #include <stdio.h>
  27 #include <string.h>
  28 
  29 #include "opal/version.h"
  30 #include "orte/version.h"
  31 #include "opal/mca/base/base.h"
  32 #include "opal/util/printf.h"
  33 
  34 #include "orte/runtime/orte_info_support.h"
  35 #include "orte/tools/orte-info/orte-info.h"
  36 
  37 /*
  38  * Public variables
  39  */
  40 
  41 const char *orte_info_ver_full = "full";
  42 const char *orte_info_ver_major = "major";
  43 const char *orte_info_ver_minor = "minor";
  44 const char *orte_info_ver_release = "release";
  45 const char *orte_info_ver_greek = "greek";
  46 const char *orte_info_ver_repo = "repo";
  47 
  48 /*
  49  * Private variables
  50  */
  51 
  52 static const char *orte_info_ver_all = "all";
  53 static const char *orte_info_ver_mca = "mca";
  54 static const char *orte_info_ver_type = "type";
  55 static const char *orte_info_ver_component = "component";
  56 
  57 
  58 /*
  59  * Private functions
  60  */
  61 
  62 static void show_mca_version(const mca_base_component_t *component,
  63                              const char *scope, const char *ver_type);
  64 static char *make_version_str(const char *scope,
  65                               int major, int minor, int release,
  66                               const char *greek,
  67                               bool want_repo, const char *repo);
  68 
  69 /*
  70  * do_version
  71  *
  72  * Determines the version information related to the orte components
  73  * being used.
  74  * Accepts:
  75  *      - want_all: True if all components' info is required.
  76  *      - cmd_line: The constructed command line argument
  77  */
  78 void orte_info_do_version(bool want_all, opal_cmd_line_t *cmd_line)
  79 {
  80     unsigned int count;
  81     size_t i;
  82     char *arg1, *scope, *type, *component;
  83     char *pos;
  84     int j;
  85 
  86     orte_info_components_open();
  87 
  88     if (want_all) {
  89         orte_info_show_orte_version(orte_info_ver_full);
  90         for (j = 0; j < mca_types.size; ++j) {
  91             if (NULL == (pos = (char*)opal_pointer_array_get_item(&mca_types, j))) {
  92                 continue;
  93             }
  94             orte_info_show_component_version(pos, orte_info_component_all, orte_info_ver_full, orte_info_type_all);
  95         }
  96     } else {
  97         count = opal_cmd_line_get_ninsts(cmd_line, "version");
  98         for (i = 0; i < count; ++i) {
  99             arg1 = opal_cmd_line_get_param(cmd_line, "version", (int)i, 0);
 100             scope = opal_cmd_line_get_param(cmd_line, "version", (int)i, 1);
 101 
 102             /* Version of Open MPI */
 103 
 104             if (0 == strcmp(orte_info_type_orte, arg1)) {
 105                 orte_info_show_orte_version(scope);
 106             }
 107 
 108             /* Specific type and component */
 109 
 110             else if (NULL != (pos = strchr(arg1, ':'))) {
 111                 *pos = '\0';
 112                 type = arg1;
 113                 pos++;
 114                 component = pos;
 115 
 116                 orte_info_show_component_version(type, component, scope, orte_info_ver_all);
 117 
 118             }
 119 
 120             /* All components of a specific type */
 121 
 122             else {
 123                 orte_info_show_component_version(arg1, orte_info_component_all, scope, orte_info_ver_all);
 124             }
 125         }
 126     }
 127 }
 128 
 129 
 130 /*
 131  * Show all the components of a specific type/component combo (component may be
 132  * a wildcard)
 133  */
 134 void orte_info_show_component_version(const char *type_name,
 135                                       const char *component_name,
 136                                       const char *scope, const char *ver_type)
 137 {
 138     bool want_all_components = false;
 139     bool found;
 140     opal_list_item_t *item;
 141     mca_base_component_list_item_t *cli;
 142     const mca_base_component_t *component;
 143     opal_list_t *components;
 144     int j;
 145     char *pos;
 146     orte_info_component_map_t *map;
 147 
 148     /* see if all components wanted */
 149     if (0 == strcmp(orte_info_type_all, component_name)) {
 150         want_all_components = true;
 151     }
 152 
 153     /* Check to see if the type is valid */
 154     for (found = false, j = 0; j < mca_types.size; ++j) {
 155         if (NULL == (pos = (char*)opal_pointer_array_get_item(&mca_types, j))) {
 156             continue;
 157         }
 158         if (0 == strcmp(pos, type_name)) {
 159             found = true;
 160             break;
 161         }
 162     }
 163 
 164     if (!found) {
 165         exit(1);
 166     }
 167 
 168     /* Now that we have a valid type, find the right component list */
 169     components = NULL;
 170     for (j=0; j < orte_component_map.size; j++) {
 171         if (NULL == (map = (orte_info_component_map_t*)opal_pointer_array_get_item(&orte_component_map, j))) {
 172             continue;
 173         }
 174         if (0 == strcmp(type_name, map->type)) {
 175             /* found it! */
 176             components = map->components;
 177             break;
 178         }
 179     }
 180 
 181     if (NULL != components) {
 182         if (opal_list_get_size(components) > 0){
 183             for (item = opal_list_get_first(components);
 184                  opal_list_get_end(components) != item;
 185                  item = opal_list_get_next(item)) {
 186                 cli = (mca_base_component_list_item_t *) item;
 187                 component = cli->cli_component;
 188                 if (want_all_components ||
 189                     0 == strcmp(component->mca_component_name, component_name)) {
 190                     show_mca_version(component, scope, ver_type);
 191                 }
 192             }
 193         }
 194     }
 195 }
 196 
 197 
 198 /*
 199  * Given a component, display its relevant version(s)
 200  */
 201 static void show_mca_version(const mca_base_component_t* component,
 202                              const char *scope, const char *ver_type)
 203 {
 204     bool printed;
 205     bool want_mca = false;
 206     bool want_type = false;
 207     bool want_component = false;
 208     char *message, *content;
 209     char *mca_version;
 210     char *api_version;
 211     char *component_version;
 212     char *tmp;
 213 
 214     if (0 == strcmp(ver_type, orte_info_ver_all) ||
 215         0 == strcmp(ver_type, orte_info_ver_mca)) {
 216         want_mca = true;
 217     }
 218 
 219     if (0 == strcmp(ver_type, orte_info_ver_all) ||
 220         0 == strcmp(ver_type, orte_info_ver_type)) {
 221         want_type = true;
 222     }
 223 
 224     if (0 == strcmp(ver_type, orte_info_ver_all) ||
 225         0 == strcmp(ver_type, orte_info_ver_component)) {
 226         want_component = true;
 227     }
 228 
 229     mca_version = make_version_str(scope, component->mca_major_version,
 230                                    component->mca_minor_version,
 231                                    component->mca_release_version, "",
 232                                    false, "");
 233     api_version = make_version_str(scope, component->mca_type_major_version,
 234                                    component->mca_type_minor_version,
 235                                    component->mca_type_release_version, "",
 236                                    false, "");
 237     component_version = make_version_str(scope, component->mca_component_major_version,
 238                                          component->mca_component_minor_version,
 239                                          component->mca_component_release_version,
 240                                          "", false, "");
 241 
 242     if (orte_info_pretty) {
 243         opal_asprintf(&message, "MCA %s", component->mca_type_name);
 244         printed = false;
 245         opal_asprintf(&content, "%s (", component->mca_component_name);
 246 
 247         if (want_mca) {
 248             opal_asprintf(&tmp, "%sMCA v%s", content, mca_version);
 249             free(content);
 250             content = tmp;
 251             printed = true;
 252         }
 253 
 254         if (want_type) {
 255             if (printed) {
 256                 opal_asprintf(&tmp, "%s, ", content);
 257                 free(content);
 258                 content = tmp;
 259             }
 260             opal_asprintf(&tmp, "%sAPI v%s", content, api_version);
 261             free(content);
 262             content = tmp;
 263             printed = true;
 264         }
 265 
 266         if (want_component) {
 267             if (printed) {
 268                 opal_asprintf(&tmp, "%s, ", content);
 269                 free(content);
 270                 content = tmp;
 271             }
 272             opal_asprintf(&tmp, "%sComponent v%s", content, component_version);
 273             free(content);
 274             content = tmp;
 275             printed = true;
 276         }
 277         if (NULL != content) {
 278             opal_asprintf(&tmp, "%s)", content);
 279             free(content);
 280         } else {
 281             opal_asprintf(&tmp, ")");
 282         }
 283 
 284         orte_info_out(message, NULL, tmp);
 285         free(message);
 286         free(tmp);
 287 
 288     } else {
 289         opal_asprintf(&message, "mca:%s:%s:version", component->mca_type_name, component->mca_component_name);
 290         if (want_mca) {
 291             opal_asprintf(&tmp, "mca:%s", mca_version);
 292             orte_info_out(NULL, message, tmp);
 293             free(tmp);
 294         }
 295         if (want_type) {
 296             opal_asprintf(&tmp, "api:%s", api_version);
 297             orte_info_out(NULL, message, tmp);
 298             free(tmp);
 299         }
 300         if (want_component) {
 301             opal_asprintf(&tmp, "component:%s", component_version);
 302             orte_info_out(NULL, message, tmp);
 303             free(tmp);
 304         }
 305         free(message);
 306     }
 307 
 308     free (mca_version);
 309     free (api_version);
 310     free (component_version);
 311 }
 312 
 313 
 314 static char *make_version_str(const char *scope,
 315                                int major, int minor, int release,
 316                                const char *greek,
 317                                bool want_repo, const char *repo)
 318 {
 319     char *str = NULL, *tmp;
 320     char temp[BUFSIZ];
 321 
 322     temp[BUFSIZ - 1] = '\0';
 323     if (0 == strcmp(scope, orte_info_ver_full) ||
 324         0 == strcmp(scope, orte_info_ver_all)) {
 325         snprintf(temp, BUFSIZ - 1, "%d.%d", major, minor);
 326         str = strdup(temp);
 327         if (release > 0) {
 328             snprintf(temp, BUFSIZ - 1, ".%d", release);
 329             opal_asprintf(&tmp, "%s%s", str, temp);
 330             free(str);
 331             str = tmp;
 332         }
 333         if (NULL != greek) {
 334             opal_asprintf(&tmp, "%s%s", str, greek);
 335             free(str);
 336             str = tmp;
 337         }
 338         if (want_repo && NULL != repo) {
 339             opal_asprintf(&tmp, "%s%s", str, repo);
 340             free(str);
 341             str = tmp;
 342         }
 343     } else if (0 == strcmp(scope, orte_info_ver_major)) {
 344         snprintf(temp, BUFSIZ - 1, "%d", major);
 345     } else if (0 == strcmp(scope, orte_info_ver_minor)) {
 346         snprintf(temp, BUFSIZ - 1, "%d", minor);
 347     } else if (0 == strcmp(scope, orte_info_ver_release)) {
 348         snprintf(temp, BUFSIZ - 1, "%d", release);
 349     } else if (0 == strcmp(scope, orte_info_ver_greek)) {
 350         str = strdup(greek);
 351     } else if (0 == strcmp(scope, orte_info_ver_repo)) {
 352         str = strdup(repo);
 353     }
 354 
 355     if (NULL == str) {
 356         str = strdup(temp);
 357     }
 358 
 359     return str;
 360 }

/* [<][>][^][v][top][bottom][index][help] */