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 vlib_global_main_t *vgm = vlib_get_global_main ();
63 char **argv = (char **) vgm->argv;
65 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
67 if (unformat (input, "verbose %=", &verbose, 1))
69 else if (unformat (input, "cmdline %=", &cmdline, 1))
77 #define _(a,b,c) vlib_cli_output (vm, "%-25s " b, a ":", c);
78 _("Version", "%s", "v" VPP_BUILD_VER);
79 _("Compiled by", "%s", VPP_BUILD_USER);
80 _("Compile host", "%s", VPP_BUILD_HOST);
81 _("Compile date", "%s", VPP_BUILD_DATE);
82 _("Compile location", "%s", VPP_BUILD_TOPDIR);
83 _("Compiler", "%s", vpe_compiler);
84 _("Current PID", "%d", getpid ());
89 vlib_cli_output (vm, "%-25s", "Command line arguments:");
91 for (i = 0; argv[i]; i++)
93 if (strstr (argv[i], "{"))
95 vlib_cli_output (vm, "%U%s", format_white_space, indent, argv[i]);
96 if (strstr (argv[i], "}"))
100 if ((verbose + cmdline) == 0)
101 vlib_cli_output (vm, "%s", vpe_version_string);
106 * This command displays image version and command line arguments
109 * How to display the image version string:
110 * @cliexstart{show version}
111 * vpp v18.07-rc0~509-gb9124828 built by vppuser on vppbuild at date
115 * How to display verbose image version information:
116 * @cliexstart{show version verbose}
117 * Version: v18.07-rc0~509-gb9124828
118 * Compiled by: vppuser
119 * Compile host: vppbuild
120 * Compile date: Fri Jul 13 09:05:37 EDT 2018
121 * Compile location: /scratch/vpp-showversion
122 * Compiler: GCC 7.3.0
127 * How to display the vpp command line arguments:
128 * @cliexstart{show version cmdline}
129 * vpp# show version cmdline
130 * Command line arguments:
131 * /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")