FD.io VPP  v19.01.3-6-g70449b9b9
Vector Packet Processing
version.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include <vlib/vlib.h>
16 #include <vppinfra/cpu.h>
17 #include <vpp/app/version.h>
18 
19 /** \file
20  Display image version information
21 */
22 
23 /*? %%clicmd:group_label Image Version Information %% ?*/
24 
25 /*
26  * Version variables are static to ensure that they're visible in core
27  * dumps, i.e., not in the rodata segment
28  */
29 
30 /** The image version string */
32  "vpp v" VPP_BUILD_VER
33  " built by " VPP_BUILD_USER " on " VPP_BUILD_HOST " at " VPP_BUILD_DATE;
34 
35 /** The name of the compiler */
36 static char *vpe_compiler =
37 #if defined(__INTEL_COMPILER)
38 #define __(x) #x
39 #define _(x) __(x)
40  "icc " _(__INTEL_COMPILER) " (" __VERSION__ ")";
41 #undef _
42 #undef __
43 #elif defined(__clang__)
44  "Clang/LLVM " __clang_version__;
45 #elif defined (__GNUC__)
46  "GCC " __VERSION__;
47 #else
48  "unknown compiler";
49 #endif
50 
51 /** \brief Display image version info, a debug CLI command function
52  */
53 static clib_error_t *
55  unformat_input_t * input,
56  vlib_cli_command_t * cmd)
57 {
58  int i;
59  int verbose = 0;
60  int cmdline = 0;
61  int indent = 2;
62  char **argv = (char **) vm->argv;
63 
65  {
66  if (unformat (input, "verbose %=", &verbose, 1))
67  ;
68  else if (unformat (input, "cmdline %=", &cmdline, 1))
69  ;
70  else
71  break;
72  }
73 
74  if (verbose)
75  {
76 #define _(a,b,c) vlib_cli_output (vm, "%-25s " b, a ":", c);
77  _("Version", "%s", "v" VPP_BUILD_VER);
78  _("Compiled by", "%s", VPP_BUILD_USER);
79  _("Compile host", "%s", VPP_BUILD_HOST);
80  _("Compile date", "%s", VPP_BUILD_DATE);
81  _("Compile location", "%s", VPP_BUILD_TOPDIR);
82  _("Compiler", "%s", vpe_compiler);
83  _("Current PID", "%d", getpid ());
84 #undef _
85  }
86  if (cmdline)
87  {
88  vlib_cli_output (vm, "%-25s", "Command line arguments:");
89 
90  for (i = 0; argv[i]; i++)
91  {
92  if (strstr (argv[i], "{"))
93  indent += 2;
94  vlib_cli_output (vm, "%U%s", format_white_space, indent, argv[i]);
95  if (strstr (argv[i], "}"))
96  indent -= 2;
97  }
98  }
99  if ((verbose + cmdline) == 0)
101  return 0;
102 }
103 
104 /*?
105  * This command displays image version and command line arguments
106  *
107  * @cliexpar
108  * How to display the image version string:
109  * @cliexstart{show version}
110  * vpp v18.07-rc0~509-gb9124828 built by vppuser on vppbuild at date
111  * @cliexend
112  *
113  * @cliexpar
114  * How to display verbose image version information:
115  * @cliexstart{show version verbose}
116  * Version: v18.07-rc0~509-gb9124828
117  * Compiled by: vppuser
118  * Compile host: vppbuild
119  * Compile date: Fri Jul 13 09:05:37 EDT 2018
120  * Compile location: /scratch/vpp-showversion
121  * Compiler: GCC 7.3.0
122  * Current PID: 5334
123  * @cliexend
124  *
125  * @cliexpar
126  * How to display the vpp command line arguments:
127  * @cliexstart{show version cmdline}
128  * vpp# show version cmdline
129  * Command line arguments:
130  * /scratch/vpp-showversion/build-root/install-vpp_debug-native/vpp/bin/vpp
131  * unix
132  * interactive
133  * @cliexend
134 ?*/
135 
136 /* *INDENT-OFF* */
137 VLIB_CLI_COMMAND (show_vpe_version_command, static) = {
138  .path = "show version",
139  .short_help = "show version [verbose] [cmdline]",
140  .function = show_vpe_version_command_fn,
141 };
142 /* *INDENT-ON* */
143 
144 /** Return the image build directory name */
145 char *
147 {
148  return VPP_BUILD_TOPDIR;
149 }
150 
151 /** Return the image version string */
152 char *
154 {
155  return VPP_BUILD_VER;
156 }
157 
158 /** return the build date */
159 char *
161 {
162  return VPP_BUILD_DATE;
163 }
164 
165 /*
166  * fd.io coding-style-patch-verification: ON
167  *
168  * Local Variables:
169  * eval: (c-set-style "gnu")
170  * End:
171  */
static char * vpe_compiler
The name of the compiler.
Definition: version.c:36
char * vpe_version_string
The image version string.
Definition: version.c:31
int i
u8 * format_white_space(u8 *s, va_list *va)
Definition: std-formats.c:113
char * vpe_api_get_version(void)
Return the image version string.
Definition: version.c:153
struct _unformat_input_t unformat_input_t
u8 ** argv
Definition: main.h:193
#define UNFORMAT_END_OF_INPUT
Definition: format.h:144
vlib_main_t * vm
Definition: buffer.c:301
static clib_error_t * show_vpe_version_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Display image version info, a debug CLI command function.
Definition: version.c:54
char * vpe_api_get_build_directory(void)
Return the image build directory name.
Definition: version.c:146
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:155
char * vpe_api_get_build_date(void)
return the build date
Definition: version.c:160
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:762
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:972
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:170