Skip to contentSkip to conversation

keytable: Add source information in generated keymaps

PATCH NAK Bastien Nocera 2 participants 9 messages Jul 1, 2019 – Jul 4, 2019 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 keytable: Add source information in generated keymaps

Add comments to mention that keymap files are generated, and that they shouldn't be modified by hand. Also list which tool was used to generate them and the kernel source filename.

---
 utils/keytable/gen_keytables.pl | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
utils/keytable/gen_keytables.pl +8 -1
index 4124e366..3dc74ba6 100755
@@ -36,10 +36,17 @@ sub flush($$)
 	my $filename = shift;
 	my $legacy = shift;
 	my $defined;
+	my $relative_filename = $filename;
 
 	return if (!$keyname || !$out);
-	print "Creating $dir/$keyname.toml\n";
+	$relative_filename =~ s/^$kernel_dir//;
+	$relative_filename =~ s/^\///;
+	print "Creating $dir/$keyname.toml from $relative_filename\n";
 	open OUT, ">$dir/$keyname.toml";
+	print OUT "# This file is a generated data file, do not modify manually\n";
+	print OUT "#\n";
+	print OUT "# Generated with gen_keytables.pl in v4l-utils\n";
+	print OUT "# using $relative_filename as a source file\n";
 	print OUT "[[protocols]]\n";
 	print OUT "name = \"$keyname\"\n";
 	print OUT "protocol = \"$type\"\n";
Signature · 1 line
2.21.0
#1 lore raw

PATCH 2/2 keytable: Remove comments before processing keymaps

Do our best to remove comments from each line we process from the keymap sources, so as to avoid commented duplicates and false positives sneaking in to the keymap definitions.

---
 utils/keytable/gen_keytables.pl | 3 +++
 1 file changed, 3 insertions(+)
utils/keytable/gen_keytables.pl +3 -0
index 3dc74ba6..d73daf58 100755
@@ -138,6 +138,9 @@ sub parse_file($$)
 		}
 
 		if ($read) {
+			# Remove comments
+			~ s#/\*.*?\*/##sg;
+			~ s#.*\*/##sg;
 			if (m/(0x[\dA-Fa-f]+)[\s\,]+(KEY|BTN)(\_[^\s\,\}]+)/) {
 				$out .= "$1 = \"$2$3\"\n";
 				next;
Signature · 1 line
2.21.0
#2 lore raw

Re: [PATCH 2/2] keytable: Remove comments before processing keymaps

Quoted 14 lines · Bastien Nocera

Do our best to remove comments from each line we process from the keymap sources, so as to avoid commented duplicates and false positives sneaking in to the keymap definitions.

---
 utils/keytable/gen_keytables.pl | 3 +++
 1 file changed, 3 insertions(+)
utils/keytable/gen_keytables.pl +0 -0
index 3dc74ba6..d73daf58 100755

utils/keytable/gen_keytables.pl sub parse_file($$) · line 143

Quoted 6 lines
utils/keytable/gen_keytables.pl +3 -0
@@ -138,6 +138,9 @@ sub parse_file($$)
 		}
 
 		if ($read) {
+			# Remove comments
+			~ s#/\*.*?\*/##sg;
+			~ s#.*\*/##sg;

This doesn't solve the

	/* { 0x800ff40b, KEY_ENTER },
	   not used */

case. Or // comments.

Quoted 5 lines
utils/keytable/gen_keytables.pl +0 -0
 			if (m/(0x[\dA-Fa-f]+)[\s\,]+(KEY|BTN)(\_[^\s\,\}]+)/) {
 				$out .= "$1 = \"$2$3\"\n";
 				next;
Signature · 1 line
2.21.0
#3 lore raw

Re: [PATCH 2/2] keytable: Remove comments before processing keymaps

Quoted 26 lines · Sean Young
Quoted 16 lines · Bastien Nocera

Do our best to remove comments from each line we process from the keymap
sources, so as to avoid commented duplicates and false positives sneaking in to the keymap definitions.

---
 utils/keytable/gen_keytables.pl | 3 +++
 1 file changed, 3 insertions(+)
utils/keytable/gen_keytables.pl +0 -0
index 3dc74ba6..d73daf58 100755

utils/keytable/gen_keytables.pl sub parse_file($$) · line 143

Quoted 6 lines
utils/keytable/gen_keytables.pl +3 -0
@@ -138,6 +138,9 @@ sub parse_file($$)
 		}
 
 		if ($read) {
+			# Remove comments
+			~ s#/\*.*?\*/##sg;
+			~ s#.*\*/##sg;

This doesn't solve the

Quoted 4 lines
	/* { 0x800ff40b, KEY_ENTER },
	   not used */

case. Or // comments.

Those weren't problems I was aware of, or that I was trying to solve...

The presence of a "0x800ff40b = KEY_ENTER" won't stop the remote definition from loading, or the remote to work correctly, and // comments usually don't get merged into the kernel sources.

Quoted 6 lines
Quoted 6 lines
utils/keytable/gen_keytables.pl +0 -0
 			if (m/(0x[\dA-Fa-
 f]+)[\s\,]+(KEY|BTN)(\_[^\s\,\}]+)/) {
 				$out .= "$1 = \"$2$3\"\n";

next;

Signature · 1 line
2.21.0
#4 lore raw

Re: [PATCH 2/2] keytable: Remove comments before processing keymaps

In reply to Sean Young
Quoted 26 lines · Sean Young
Quoted 16 lines · Bastien Nocera

Do our best to remove comments from each line we process from the keymap
sources, so as to avoid commented duplicates and false positives sneaking in to the keymap definitions.

---
 utils/keytable/gen_keytables.pl | 3 +++
 1 file changed, 3 insertions(+)
utils/keytable/gen_keytables.pl +0 -0
index 3dc74ba6..d73daf58 100755

utils/keytable/gen_keytables.pl sub parse_file($$) · line 143

Quoted 6 lines
utils/keytable/gen_keytables.pl +3 -0
@@ -138,6 +138,9 @@ sub parse_file($$)
 		}
 
 		if ($read) {
+			# Remove comments
+			~ s#/\*.*?\*/##sg;
+			~ s#.*\*/##sg;

This doesn't solve the

Quoted 2 lines
	/* { 0x800ff40b, KEY_ENTER },
	   not used */

This isn't in the current Linus kernel.

Quoted 1 line

case. Or // comments.

And this isn't used anywhere in the kernel either.

Those are the 2 lines that would remove those comments but I can't test it. Note that if this was done properly, instead of fixing the bugs we encounter, the whole parsing would need to be redone.

+ ~ s#/\*.*?##sg;
+ ~ s#//.*##sg;

Quoted 6 lines
Quoted 6 lines
utils/keytable/gen_keytables.pl +0 -0
 			if (m/(0x[\dA-Fa-
 f]+)[\s\,]+(KEY|BTN)(\_[^\s\,\}]+)/) {
 				$out .= "$1 = \"$2$3\"\n";

next;

Signature · 1 line
2.21.0
#5 lore raw

Re: [PATCH 2/2] keytable: Remove comments before processing keymaps

Quoted 27 lines · Bastien Nocera
Quoted 26 lines · Sean Young
Quoted 16 lines · Bastien Nocera

Do our best to remove comments from each line we process from the keymap
sources, so as to avoid commented duplicates and false positives sneaking in to the keymap definitions.

---
 utils/keytable/gen_keytables.pl | 3 +++
 1 file changed, 3 insertions(+)
utils/keytable/gen_keytables.pl +0 -0
index 3dc74ba6..d73daf58 100755

utils/keytable/gen_keytables.pl sub parse_file($$) · line 143

Quoted 6 lines
utils/keytable/gen_keytables.pl +3 -0
@@ -138,6 +138,9 @@ sub parse_file($$)
 		}
 
 		if ($read) {
+			# Remove comments
+			~ s#/\*.*?\*/##sg;
+			~ s#.*\*/##sg;

This doesn't solve the

Quoted 4 lines
Quoted 2 lines
	/* { 0x800ff40b, KEY_ENTER },
	   not used */

This isn't in the current Linus kernel.

We might as well solve this properly and handle all cases.

Quoted 3 lines
Quoted 1 line

case. Or // comments.

And this isn't used anywhere in the kernel either.

That's wrong. They are used.

Review

Quoted 6 lines

Those are the 2 lines that would remove those comments but I can't test it. Note that if this was done properly, instead of fixing the bugs we encounter, the whole parsing would need to be redone.

(quoted diff) +2 -0
+                       ~ s#/\*.*?##sg;
+                       ~ s#//.*##sg;

If you are unable to test it, I will fix it.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
utils/keytable/gen_keytables.pl +0 -0
 			if (m/(0x[\dA-Fa-
 f]+)[\s\,]+(KEY|BTN)(\_[^\s\,\}]+)/) {
 				$out .= "$1 = \"$2$3\"\n";

next;

Signature · 1 line
2.21.0

Sean

#6 lore raw

Re: [PATCH 2/2] keytable: Remove comments before processing keymaps

Quoted 35 lines · Sean Young
Quoted 29 lines · Bastien Nocera
Quoted 28 lines · Sean Young
Quoted 18 lines · Bastien Nocera

Do our best to remove comments from each line we process from the
keymap
sources, so as to avoid commented duplicates and false positives
sneaking in to the keymap definitions.

---
 utils/keytable/gen_keytables.pl | 3 +++
 1 file changed, 3 insertions(+)
utils/keytable/gen_keytables.pl +0 -0
index 3dc74ba6..d73daf58 100755

utils/keytable/gen_keytables.pl sub parse_file($$) · line 143

Quoted 6 lines
utils/keytable/gen_keytables.pl +3 -0
@@ -138,6 +138,9 @@ sub parse_file($$)
 		}
 
 		if ($read) {
+			# Remove comments
+			~ s#/\*.*?\*/##sg;
+			~ s#.*\*/##sg;

This doesn't solve the

Quoted 4 lines
Quoted 2 lines
	/* { 0x800ff40b, KEY_ENTER },
	   not used */

This isn't in the current Linus kernel.

Quoted 7 lines

We might as well solve this properly and handle all cases.

Quoted 3 lines
Quoted 1 line

case. Or // comments.

And this isn't used anywhere in the kernel either.

That's wrong. They are used.

Use in the keymap definitions? I don't think so. Either that or the 2 additional lines underneath here don't work. I think they do.

Quoted 10 lines

Review

Quoted 8 lines

Those are the 2 lines that would remove those comments but I can't test
it. Note that if this was done properly, instead of fixing the bugs we
encounter, the whole parsing would need to be redone.

(quoted diff) +2 -0
+                       ~ s#/\*.*?##sg;
+                       ~ s#//.*##sg;

If you are unable to test it, I will fix it.

#7 lore raw
In reply to Bastien Nocera
Quoted 19 lines · Bastien Nocera

Add comments to mention that keymap files are generated, and that they shouldn't be modified by hand. Also list which tool was used to generate them and the kernel source filename.

---
 utils/keytable/gen_keytables.pl | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
utils/keytable/gen_keytables.pl +1 -0
index 4124e366..3dc74ba6 100755
@@ -36,10 +36,17 @@ sub flush($$)
 	my $filename = shift;
 	my $legacy = shift;
 	my $defined;
+	my $relative_filename = $filename;
 

utils/keytable/gen_keytables.pl sub flush($$) · line 49

Quoted 10 lines
utils/keytable/gen_keytables.pl +7 -1
 	return if (!$keyname || !$out);
-	print "Creating $dir/$keyname.toml\n";
+	$relative_filename =~ s/^$kernel_dir//;
+	$relative_filename =~ s/^\///;
+	print "Creating $dir/$keyname.toml from $relative_filename\n";
 	open OUT, ">$dir/$keyname.toml";
+	print OUT "# This file is a generated data file, do not modify manually\n";
+	print OUT "#\n";
+	print OUT "# Generated with gen_keytables.pl in v4l-utils\n";
+	print OUT "# using $relative_filename as a source file\n";

This is only relevant for a developer who is wanting to upstream their keymap changes to v4l-utils. If it should be documented somewhere it should be in the v4l-utils repo itself, so that anyone generating patches will notice before spending too much time making a patch on the keymaps directory.

Also some remotes do not have definitions in the kernel, only in v4l-utils.

For an end user who is trying to patch their keymap this is confusing. Someone who just wants to patch their keymap for their remote might be put off by this message; can they not simply edit the toml file?

NAK, I'm afraid.

Quoted 5 lines
utils/keytable/gen_keytables.pl +0 -0
 	print OUT "[[protocols]]\n";
 	print OUT "name = \"$keyname\"\n";
 	print OUT "protocol = \"$type\"\n";
Signature · 1 line
2.21.0

Sean

#8 lore raw
Quoted 21 lines · Sean Young
Quoted 20 lines · Bastien Nocera

Add comments to mention that keymap files are generated, and that they shouldn't be modified by hand. Also list which tool was used to generate them and the kernel source filename.

---
 utils/keytable/gen_keytables.pl | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
utils/keytable/gen_keytables.pl +1 -0
index 4124e366..3dc74ba6 100755
@@ -36,10 +36,17 @@ sub flush($$)
 	my $filename = shift;
 	my $legacy = shift;
 	my $defined;
+	my $relative_filename = $filename;
 
Quoted 15 lines

utils/keytable/gen_keytables.pl sub flush($$) · line 49

Quoted 11 lines
utils/keytable/gen_keytables.pl +7 -1
 	return if (!$keyname || !$out);
-	print "Creating $dir/$keyname.toml\n";
+	$relative_filename =~ s/^$kernel_dir//;
+	$relative_filename =~ s/^\///;
+	print "Creating $dir/$keyname.toml from $relative_filename\n";
 	open OUT, ">$dir/$keyname.toml";
+	print OUT "# This file is a generated data file, do not modify
 manually\n";
+	print OUT "#\n";
+	print OUT "# Generated with gen_keytables.pl in v4l-utils\n";
+	print OUT "# using $relative_filename as a source file\n";

This is only relevant for a developer who is wanting to upstream their
keymap changes to v4l-utils.

It's only relevant to you. Or the chump that tried to do things well (me). I wouldn't have wasted this much time writing tests, or making patches if there had been a bit of guidance on how you wanted those problems fixed. I'll let you create a README for that instead.

I'll send the "check" patch again.