Re: [PATCH v3 1/6] v4l2-compliance: Add version command

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 11/07/2020 07:24, Paul Elder wrote:
> Add a --version option to v4l2-compliance to retrieve the version of
> v4l2-compliance. While at it, factor out and reorder printing the SHA to
> after argument parsing.
> 
> Signed-off-by: Paul Elder <paul.elder@xxxxxxxxxxxxxxxx>
> 
> ---
> Changes in v3:
> - embed PACKAGE_VERSION instead of string concatenation
> ---
>  utils/v4l2-compliance/v4l2-compliance.cpp | 40 ++++++++++++++++-------
>  1 file changed, 29 insertions(+), 11 deletions(-)
> 
> diff --git a/utils/v4l2-compliance/v4l2-compliance.cpp b/utils/v4l2-compliance/v4l2-compliance.cpp
> index df46e86f..38d77d07 100644
> --- a/utils/v4l2-compliance/v4l2-compliance.cpp
> +++ b/utils/v4l2-compliance/v4l2-compliance.cpp
> @@ -79,6 +79,7 @@ enum Option {
>  	OptMediaBusInfo = 'z',
>  	OptStreamFrom = 128,
>  	OptStreamFromHdr,
> +	OptVersion,
>  	OptLast = 256
>  };
>  
> @@ -153,9 +154,29 @@ static struct option long_options[] = {
>  	{"stream-all-formats", optional_argument, 0, OptStreamAllFormats},
>  	{"stream-all-io", no_argument, 0, OptStreamAllIO},
>  	{"stream-all-color", required_argument, 0, OptStreamAllColorTest},
> +	{"version", no_argument, 0, OptVersion},
>  	{0, 0, 0, 0}
>  };
>  
> +static void print_sha()
> +{
> +#ifdef SHA
> +#define STR(x) #x
> +#define STRING(x) STR(x)
> +	printf("v4l2-compliance SHA: %s", STRING(SHA));
> +#else
> +	printf("v4l2-compliance SHA: not available");
> +#endif
> +
> +	printf(", %zd bits, %zd-bit time_t\n", sizeof(void *) * 8, sizeof(time_t) * 8);
> +	printf("\n");
> +}
> +
> +static void version()

I'd rename this to print_version to correspond with print_sha.

> +{
> +	printf("v4l2-compliance %s\n", PACKAGE_VERSION);

Didn't we want to include the commit count in this as per the discussion with Laurent?

BTW, I've updated the v4l2/cec-compliance utils to obtain the SHA in simplified way
without having to create a version.h.

configure.ac now defines a GIT_SHA variable that makefiles can use to pass to the
compiler.

To do the same for the commit count you would add this to configure.ac:

# Obtain git commit count of HEAD
AC_SUBST(GIT_COMMIT_CNT, ["-DGIT_COMMIT_CNT=\$(shell if test -d \$(top_srcdir)/.git ; then printf '-'; git -C \$(top_srcdir) rev-list
--count HEAD ; fi)"])

In the Makefile.am you'd add $(GIT_COMMIT_CNT) to CPPFLAGS and the version function
would read like this:

static void print_version()
{
	printf("v4l2-compliance %s%s\n", PACKAGE_VERSION, STRING(GIT_COMMIT_CNT));
}

Regards,

	Hans

> +}
> +
>  static void usage()
>  {
>  	printf("Usage:\n");
> @@ -244,6 +265,7 @@ static void usage()
>  	printf("  -P, --no-progress  Turn off progress messages.\n");
>  	printf("  -T, --trace        Trace all called ioctls.\n");
>  	printf("  -v, --verbose      Turn on verbose reporting.\n");
> +	printf("  --version          Show version information.\n");
>  #ifndef NO_LIBV4L2
>  	printf("  -w, --wrapper      Use the libv4l2 wrapper library.\n");
>  #endif
> @@ -1485,17 +1507,6 @@ int main(int argc, char **argv)
>  	char *value, *subs;
>  	int idx = 0;
>  
> -#ifdef SHA
> -#define STR(x) #x
> -#define STRING(x) STR(x)
> -	printf("v4l2-compliance SHA: %s", STRING(SHA));
> -#else
> -	printf("v4l2-compliance SHA: not available");
> -#endif
> -
> -	printf(", %zd bits, %zd-bit time_t\n", sizeof(void *) * 8, sizeof(time_t) * 8);
> -	printf("\n");
> -
>  	if (!env_media_apps_color || !strcmp(env_media_apps_color, "auto"))
>  		show_colors = isatty(STDOUT_FILENO);
>  	else if (!strcmp(env_media_apps_color, "always"))
> @@ -1664,6 +1675,10 @@ int main(int argc, char **argv)
>  		case OptNoProgress:
>  			no_progress = true;
>  			break;
> +		case OptVersion:
> +			version();
> +			print_sha();
> +			std::exit(EXIT_SUCCESS);
>  		case ':':
>  			fprintf(stderr, "Option `%s' requires a value\n",
>  				argv[optind]);
> @@ -1685,6 +1700,9 @@ int main(int argc, char **argv)
>  		usage();
>  		std::exit(EXIT_FAILURE);
>  	}
> +
> +	print_sha();
> +
>  	bool direct = !options[OptUseWrapper];
>  	int fd;
>  
> 




[Index of Archives]     [Linux Input]     [Video for Linux]     [Gstreamer Embedded]     [Mplayer Users]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]

  Powered by Linux