Line data Source code
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 */
31 : char *vpe_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 *
54 1 : show_vpe_version_command_fn (vlib_main_t * vm,
55 : unformat_input_t * input,
56 : vlib_cli_command_t * cmd)
57 : {
58 : int i;
59 1 : int verbose = 0;
60 1 : int cmdline = 0;
61 1 : int indent = 2;
62 1 : vlib_global_main_t *vgm = vlib_get_global_main ();
63 1 : char **argv = (char **) vgm->argv;
64 :
65 1 : while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
66 : {
67 0 : if (unformat (input, "verbose %=", &verbose, 1))
68 : ;
69 0 : else if (unformat (input, "cmdline %=", &cmdline, 1))
70 : ;
71 : else
72 0 : break;
73 : }
74 :
75 1 : if (verbose)
76 : {
77 : #define _(a,b,c) vlib_cli_output (vm, "%-25s " b, a ":", c);
78 0 : _("Version", "%s", "v" VPP_BUILD_VER);
79 0 : _("Compiled by", "%s", VPP_BUILD_USER);
80 0 : _("Compile host", "%s", VPP_BUILD_HOST);
81 0 : _("Compile date", "%s", VPP_BUILD_DATE);
82 0 : _("Compile location", "%s", VPP_BUILD_TOPDIR);
83 0 : _("Compiler", "%s", vpe_compiler);
84 0 : _("Current PID", "%d", getpid ());
85 : #undef _
86 : }
87 1 : if (cmdline)
88 : {
89 0 : vlib_cli_output (vm, "%-25s", "Command line arguments:");
90 :
91 0 : for (i = 0; argv[i]; i++)
92 : {
93 0 : if (strstr (argv[i], "{"))
94 0 : indent += 2;
95 0 : vlib_cli_output (vm, "%U%s", format_white_space, indent, argv[i]);
96 0 : if (strstr (argv[i], "}"))
97 0 : indent -= 2;
98 : }
99 : }
100 1 : if ((verbose + cmdline) == 0)
101 1 : vlib_cli_output (vm, "%s", vpe_version_string);
102 1 : return 0;
103 : }
104 :
105 : /*?
106 : * This command displays image version and command line arguments
107 : *
108 : * @cliexpar
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
112 : * @cliexend
113 : *
114 : * @cliexpar
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
123 : * Current PID: 5334
124 : * @cliexend
125 : *
126 : * @cliexpar
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
132 : * unix
133 : * interactive
134 : * @cliexend
135 : ?*/
136 :
137 : /* *INDENT-OFF* */
138 272887 : VLIB_CLI_COMMAND (show_vpe_version_command, static) = {
139 : .path = "show version",
140 : .short_help = "show version [verbose] [cmdline]",
141 : .function = show_vpe_version_command_fn,
142 : .is_mp_safe = 1,
143 : };
144 : /* *INDENT-ON* */
145 :
146 : /** Return the image build directory name */
147 : char *
148 142 : vpe_api_get_build_directory (void)
149 : {
150 142 : return VPP_BUILD_TOPDIR;
151 : }
152 :
153 : /** Return the image version string */
154 : char *
155 142 : vpe_api_get_version (void)
156 : {
157 142 : return VPP_BUILD_VER;
158 : }
159 :
160 : /** return the build date */
161 : char *
162 142 : vpe_api_get_build_date (void)
163 : {
164 142 : return VPP_BUILD_DATE;
165 : }
166 :
167 : /*
168 : * fd.io coding-style-patch-verification: ON
169 : *
170 : * Local Variables:
171 : * eval: (c-set-style "gnu")
172 : * End:
173 : */
|