diff mbox series

[v4,2/7] v4l2-compliance: Add version command

Message ID 20200714055915.640438-2-paul.elder@ideasonboard.com (mailing list archive)
State New, archived
Headers show
Series [v4,1/7] configure.ac: Export git commit count | expand

Commit Message

Paul Elder July 14, 2020, 5:59 a.m. UTC
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@ideasonboard.com>

---
Changes in v4:
- add git commit count to version

Changes in v3:
- embed PACKAGE_VERSION instead of string concatenation
---
 utils/v4l2-compliance/v4l2-compliance.cpp | 30 ++++++++++++++++++-----
 1 file changed, 24 insertions(+), 6 deletions(-)

Comments

Hans Verkuil July 14, 2020, 7:54 a.m. UTC | #1
On 14/07/2020 07:59, 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@ideasonboard.com>
> 
> ---
> Changes in v4:
> - add git commit count to version
> 
> Changes in v3:
> - embed PACKAGE_VERSION instead of string concatenation
> ---
>  utils/v4l2-compliance/v4l2-compliance.cpp | 30 ++++++++++++++++++-----

Ah, I almost forgot: the man pages also need to be updated with the new option.
Sorry for mentioning this so late, if it is any consolation, I also regularly
forget to update a man page :-) Note that media-ctl doesn't have a man page,
so I'll take the first and last patch and skip the others.

>  1 file changed, 24 insertions(+), 6 deletions(-)
> 
> diff --git a/utils/v4l2-compliance/v4l2-compliance.cpp b/utils/v4l2-compliance/v4l2-compliance.cpp
> index 825f2aa6..97c79e40 100644
> --- a/utils/v4l2-compliance/v4l2-compliance.cpp
> +++ b/utils/v4l2-compliance/v4l2-compliance.cpp
> @@ -76,6 +76,7 @@ enum Option {
>  	OptMediaBusInfo = 'z',
>  	OptStreamFrom = 128,
>  	OptStreamFromHdr,
> +	OptVersion,
>  	OptLast = 256
>  };
>  
> @@ -150,9 +151,24 @@ 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()
> +{
> +#define STR(x) #x
> +#define STRING(x) STR(x)

Since that means that there will be a v5, I would prefer that the #defines come before
the function since STRING is used in two functions, not just print_sha(), which the
current placement suggests.

Ditto for cec-compliance.

Regards,

	Hans

> +	printf("v4l2-compliance SHA: %s", STRING(GIT_SHA));
> +	printf(", %zd bits, %zd-bit time_t\n", sizeof(void *) * 8, sizeof(time_t) * 8);
> +	printf("\n");
> +}
> +
> +static void print_version()
> +{
> +	printf("v4l2-compliance %s%s\n", PACKAGE_VERSION, STRING(GIT_COMMIT_CNT));
> +}
> +
>  static void usage()
>  {
>  	printf("Usage:\n");
> @@ -241,6 +257,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
> @@ -1482,12 +1499,6 @@ int main(int argc, char **argv)
>  	char *value, *subs;
>  	int idx = 0;
>  
> -#define STR(x) #x
> -#define STRING(x) STR(x)
> -	printf("v4l2-compliance SHA: %s", STRING(GIT_SHA));
> -	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"))
> @@ -1656,6 +1667,10 @@ int main(int argc, char **argv)
>  		case OptNoProgress:
>  			no_progress = true;
>  			break;
> +		case OptVersion:
> +			print_version();
> +			print_sha();
> +			std::exit(EXIT_SUCCESS);
>  		case ':':
>  			fprintf(stderr, "Option `%s' requires a value\n",
>  				argv[optind]);
> @@ -1677,6 +1692,9 @@ int main(int argc, char **argv)
>  		usage();
>  		std::exit(EXIT_FAILURE);
>  	}
> +
> +	print_sha();
> +
>  	bool direct = !options[OptUseWrapper];
>  	int fd;
>  
>
diff mbox series

Patch

diff --git a/utils/v4l2-compliance/v4l2-compliance.cpp b/utils/v4l2-compliance/v4l2-compliance.cpp
index 825f2aa6..97c79e40 100644
--- a/utils/v4l2-compliance/v4l2-compliance.cpp
+++ b/utils/v4l2-compliance/v4l2-compliance.cpp
@@ -76,6 +76,7 @@  enum Option {
 	OptMediaBusInfo = 'z',
 	OptStreamFrom = 128,
 	OptStreamFromHdr,
+	OptVersion,
 	OptLast = 256
 };
 
@@ -150,9 +151,24 @@  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()
+{
+#define STR(x) #x
+#define STRING(x) STR(x)
+	printf("v4l2-compliance SHA: %s", STRING(GIT_SHA));
+	printf(", %zd bits, %zd-bit time_t\n", sizeof(void *) * 8, sizeof(time_t) * 8);
+	printf("\n");
+}
+
+static void print_version()
+{
+	printf("v4l2-compliance %s%s\n", PACKAGE_VERSION, STRING(GIT_COMMIT_CNT));
+}
+
 static void usage()
 {
 	printf("Usage:\n");
@@ -241,6 +257,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
@@ -1482,12 +1499,6 @@  int main(int argc, char **argv)
 	char *value, *subs;
 	int idx = 0;
 
-#define STR(x) #x
-#define STRING(x) STR(x)
-	printf("v4l2-compliance SHA: %s", STRING(GIT_SHA));
-	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"))
@@ -1656,6 +1667,10 @@  int main(int argc, char **argv)
 		case OptNoProgress:
 			no_progress = true;
 			break;
+		case OptVersion:
+			print_version();
+			print_sha();
+			std::exit(EXIT_SUCCESS);
 		case ':':
 			fprintf(stderr, "Option `%s' requires a value\n",
 				argv[optind]);
@@ -1677,6 +1692,9 @@  int main(int argc, char **argv)
 		usage();
 		std::exit(EXIT_FAILURE);
 	}
+
+	print_sha();
+
 	bool direct = !options[OptUseWrapper];
 	int fd;