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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
15 #include <vlib/vlib.h>
16 #include <vppinfra/cpu.h>
17 #include <vpp/app/version.h>
20 Display image version information
23 /*? %%clicmd:group_label Image Version Information %% ?*/
26 * Version variables are static to ensure that they're visible in core
27 * dumps, i.e., not in the rodata segment
30 /** The image version string */
31 char *vpe_version_string =
33 " built by " VPP_BUILD_USER " on " VPP_BUILD_HOST " at " VPP_BUILD_DATE;
35 /** The name of the compiler */
36 static char *vpe_compiler =
37 #if defined(__INTEL_COMPILER)
40 "icc " _(__INTEL_COMPILER) " (" __VERSION__ ")";
43 #elif defined(__clang__)
44 "Clang/LLVM " __clang_version__;
45 #elif defined (__GNUC__)
51 /** \brief Display image version info, a debug CLI command function
54 show_vpe_version_command_fn (vlib_main_t * vm,
55 unformat_input_t * input,
56 vlib_cli_command_t * cmd)
62 char **argv = (char **) vm->argv;
64 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
66 if (unformat (input, "verbose %=", &verbose, 1))
68 else if (unformat (input, "cmdline %=", &cmdline, 1))
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 ());
88 vlib_cli_output (vm, "%-25s", "Command line arguments:");
90 for (i = 0; argv[i]; i++)
92 if (strstr (argv[i], "{"))
94 vlib_cli_output (vm, "%U%s", format_white_space, indent, argv[i]);
95 if (strstr (argv[i], "}"))
99 if ((verbose + cmdline) == 0)
100 vlib_cli_output (vm, "%s", vpe_version_string);
105 * This command displays image version and command line arguments
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
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
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
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,
144 /** Return the image build directory name */
146 vpe_api_get_build_directory (void)
148 return VPP_BUILD_TOPDIR;
151 /** Return the image version string */
153 vpe_api_get_version (void)
155 return VPP_BUILD_VER;
158 /** return the build date */
160 vpe_api_get_build_date (void)
162 return VPP_BUILD_DATE;
166 * fd.io coding-style-patch-verification: ON
169 * eval: (c-set-style "gnu")