Skip to contentSkip to conversation

Documentation: Add ABI to the admin guide

PATCH In review Mauro Carvalho Chehab 4 participants 18 messages Apr 13, 2017 – Apr 21, 2017 1 message not in the archive

Subsystems (7)
lore
Share & tools
lore
#0 lore raw

v2 cover Documentation: Add ABI to the admin guide

That's the third attempt to add support for the Kernel ABI at the Documentation's admin guide.

The first approach was based on a generic extension that calls a random script. This one is based on a new Sphinx extension with adds a symbol specific for parsing ABI symbols.

It adds a new script (scripts/get_abi.pl) with can either search for ABI symbols that match a regular expression or outputs the entire documentation found inside a directory as a ReST book.

Adding the ABI description to the Linux documentation is as easy as adding a tab like:

.. kernel-abi:: $srctree/Documentation/ABI/obsolete

On version 3, I improved the script to better parse the ABI descriptions. On this version, it will identify if the description can be handled as a normal text. If so, it will escape characters that has special meaning on Sphinx. If it detects that the description syntax is too complex, it outputs inside a literal block.

Also on version 3, I opted to use 4 separate sections, one for each type of symbol. It also add an entry with the name of each ABI file, with has cross-references to the symbols defined on each file.

The parser was also improved to handle any content at the files that are before the ABI tags.

The first 3 patches on this series fix some syntax errors on some ABI description.

The next one makes sure that, when a table is present on the description, the preceding line will end with a colon (with is one of the ways the script uses to identify complex layouts).

-

IMHO, we should add another ABI tag to allow using an enriched text description, e. g. instead of:

Description: foo

One could use, instead, something like:

ReST-description: foo

On such case, the script wouldn't need to escape the description contents, as they can be just sent directly to the ABI ReST output.

Markus Heiser (1):
doc-rst: customize RTD theme; literal-block

Mauro Carvalho Chehab (10):
ABI: fix some syntax issues at the ABI database
ABI: sysfs-driver-hid: the "What" field doesn't parse fine
ABI: sysfs-class-uwb_rc: remove a duplicated incomplete entry
ABI: better identificate tables
scripts: add an script to parse the ABI files scripts/get_abi.pl: parse files with text at beginning scripts/get_abi.pl: avoid use literal blocks when not needed scripts/get_abi.pl: split label naming from xref logic scripts/get_abi.pl: add support for searching for ABI symbols
doc-rst: add ABI documentation to the admin-guide book

 .../ABI/obsolete/sysfs-driver-hid-roccat-pyra      |   2 +-
 Documentation/ABI/testing/pstore                   |   2 +-
 .../testing/sysfs-bus-event_source-devices-format  |   2 +-
 .../ABI/testing/sysfs-bus-i2c-devices-hm6352       |   6 +-
 .../ABI/testing/sysfs-bus-iio-distance-srf08       |   4 +-
 .../ABI/testing/sysfs-bus-iio-proximity-as3935     |   4 +-
 .../ABI/testing/sysfs-bus-pci-devices-cciss        |  22 +-
 .../ABI/testing/sysfs-bus-usb-devices-usbsevseg    |  12 +-
 .../testing/sysfs-class-backlight-driver-lm3533    |   6 +-
 Documentation/ABI/testing/sysfs-class-cxl          |   6 +-
 Documentation/ABI/testing/sysfs-class-devfreq      |   2 +-
 .../ABI/testing/sysfs-class-led-driver-lm3533      |   8 +-
 Documentation/ABI/testing/sysfs-class-leds-gt683r  |   4 +-
 Documentation/ABI/testing/sysfs-class-powercap     |   2 +-
 Documentation/ABI/testing/sysfs-class-uwb_rc       |   6 -
 Documentation/ABI/testing/sysfs-driver-hid         |  12 +-
 .../ABI/testing/sysfs-driver-hid-roccat-kone       |   2 +-
 Documentation/ABI/testing/sysfs-kernel-fscaps      |   2 +-
 Documentation/ABI/testing/sysfs-kernel-vmcoreinfo  |   2 +-
 Documentation/admin-guide/abi-obsolete.rst         |  10 +
 Documentation/admin-guide/abi-removed.rst          |   4 +
 Documentation/admin-guide/abi-stable.rst           |  13 +
 Documentation/admin-guide/abi-testing.rst          |  19 +
 Documentation/admin-guide/abi.rst                  |  11 +
 Documentation/admin-guide/index.rst                |   1 +
 Documentation/conf.py                              |   3 +-
 Documentation/sphinx-static/theme_overrides.css    |   7 +
 Documentation/sphinx/kernel_abi.py                 | 155 ++++++++
 scripts/get_abi.pl                                 | 419 +++++++++++++++++++++
 29 files changed, 691 insertions(+), 57 deletions(-)
 create mode 100644 Documentation/admin-guide/abi-obsolete.rst
 create mode 100644 Documentation/admin-guide/abi-removed.rst
 create mode 100644 Documentation/admin-guide/abi-stable.rst
 create mode 100644 Documentation/admin-guide/abi-testing.rst
 create mode 100644 Documentation/admin-guide/abi.rst
 create mode 100644 Documentation/sphinx/kernel_abi.py
 create mode 100755 scripts/get_abi.pl
Signature · 1 line
2.9.3
#1 lore raw

PATCH v2 1/11 doc-rst: customize RTD theme; literal-block

From: Markus Heiser <[email protected]>

From: Markus Heiser <[email protected]>

Format the literal-block like other code-block elements, with 12px and a line-high of 1.5.

---
 Documentation/sphinx-static/theme_overrides.css | 7 +++++++
 1 file changed, 7 insertions(+)
Documentation/sphinx-static/theme_overrides.css +7 -0
index d5764a4de5a2..7033d4c05e42 100644
@@ -69,4 +69,11 @@
     .rst-content tt.literal,.rst-content tt.literal,.rst-content code.literal {
         color: inherit;
     }
+
+    /* literal blocks (e.g. parsed-literal directive) */
+
+    pre.literal-block {
+        font-size: 12px;
+        line-height: 1.5;
+    }
 }
Signature · 1 line
2.9.3
#2 lore raw

PATCH v2 2/11 ABI: fix some syntax issues at the ABI database

In reply to Mauro Carvalho Chehab

On those three files, the ABI representation described at README are violated.

- at sysfs-bus-iio-proximity-as3935:
a ':' character is missing after "What"

- at sysfs-class-devfreq:
there's a typo at Description

- at sysfs-class-cxl, it is using the ":" character at a file preamble, causing it to be misinterpreted as a tag.

- On the other files, instead of "What", they use "Where".

---
 Documentation/ABI/testing/pstore                   |  2 +-
 .../testing/sysfs-bus-event_source-devices-format  |  2 +-
 .../ABI/testing/sysfs-bus-i2c-devices-hm6352       |  6 +++---
 .../ABI/testing/sysfs-bus-iio-distance-srf08       |  4 ++--
 .../ABI/testing/sysfs-bus-iio-proximity-as3935     |  4 ++--
 .../ABI/testing/sysfs-bus-pci-devices-cciss        | 22 +++++++++++-----------
 .../ABI/testing/sysfs-bus-usb-devices-usbsevseg    | 12 ++++++------
 Documentation/ABI/testing/sysfs-class-cxl          |  6 +++---
 Documentation/ABI/testing/sysfs-class-devfreq      |  2 +-
 Documentation/ABI/testing/sysfs-class-powercap     |  2 +-
 Documentation/ABI/testing/sysfs-kernel-fscaps      |  2 +-
 Documentation/ABI/testing/sysfs-kernel-vmcoreinfo  |  2 +-
 12 files changed, 33 insertions(+), 33 deletions(-)
Documentation/ABI/testing/pstore +1 -1
index 5fca9f5e10a3..8d6e48f4e8ef 100644
@@ -1,4 +1,4 @@
-Where:		/sys/fs/pstore/... (or /dev/pstore/...)
+What:		/sys/fs/pstore/... (or /dev/pstore/...)
 Date:		March 2011
 Kernel Version: 2.6.39
 Contact:	[email protected]
Documentation/ABI/testing/sysfs-bus-event_source-devices-format +1 -1
index 77f47ff5ee02..b6f8748e0200 100644
@@ -1,4 +1,4 @@
-Where:		/sys/bus/event_source/devices/<dev>/format
+What:		/sys/bus/event_source/devices/<dev>/format
 Date:		January 2012
 Kernel Version: 3.3
 Contact:	Jiri Olsa <[email protected]>
Documentation/ABI/testing/sysfs-bus-i2c-devices-hm6352 +3 -3
index feb2e4a87075..29bd447e50a0 100644
@@ -1,18 +1,18 @@
-Where:		/sys/bus/i2c/devices/.../heading0_input
+What:		/sys/bus/i2c/devices/.../heading0_input
 Date:		April 2010
 Kernel Version: 2.6.36?
 Contact:	[email protected]
 Description:	Reports the current heading from the compass as a floating
 		point value in degrees.
 
-Where:		/sys/bus/i2c/devices/.../power_state
+What:		/sys/bus/i2c/devices/.../power_state
 Date:		April 2010
 Kernel Version: 2.6.36?
 Contact:	[email protected]
 Description:	Sets the power state of the device. 0 sets the device into
 		sleep mode, 1 wakes it up.
 
-Where:		/sys/bus/i2c/devices/.../calibration
+What:		/sys/bus/i2c/devices/.../calibration
 Date:		April 2010
 Kernel Version: 2.6.36?
 Contact:	[email protected]
Documentation/ABI/testing/sysfs-bus-iio-distance-srf08 +2 -2
index 0a1ca1487fa9..a133fd8d081a 100644
@@ -1,4 +1,4 @@
-What		/sys/bus/iio/devices/iio:deviceX/sensor_sensitivity
+What:		/sys/bus/iio/devices/iio:deviceX/sensor_sensitivity
 Date:		January 2017
 KernelVersion:	4.11
 Contact:	[email protected]
@@ -6,7 +6,7 @@ Description:
 		Show or set the gain boost of the amp, from 0-31 range.
 		default 31
 
-What		/sys/bus/iio/devices/iio:deviceX/sensor_max_range
+What:		/sys/bus/iio/devices/iio:deviceX/sensor_max_range
 Date:		January 2017
 KernelVersion:	4.11
 Contact:	[email protected]
Documentation/ABI/testing/sysfs-bus-iio-proximity-as3935 +2 -2
index 33e96f740639..61a3c9fed07d 100644
@@ -1,4 +1,4 @@
-What		/sys/bus/iio/devices/iio:deviceX/in_proximity_input
+What:		/sys/bus/iio/devices/iio:deviceX/in_proximity_input
 Date:		March 2014
 KernelVersion:	3.15
 Contact:	Matt Ranostay <[email protected]>
@@ -6,7 +6,7 @@ Description:
 		Get the current distance in meters of storm (1km steps)
 		1000-40000 = distance in meters
 
-What		/sys/bus/iio/devices/iio:deviceX/sensor_sensitivity
+What:		/sys/bus/iio/devices/iio:deviceX/sensor_sensitivity
 Date:		March 2014
 KernelVersion:	3.15
 Contact:	Matt Ranostay <[email protected]>
Documentation/ABI/testing/sysfs-bus-pci-devices-cciss +11 -11
index 53d99edd1d75..eb449169c30b 100644
@@ -1,66 +1,66 @@
-Where:		/sys/bus/pci/devices/<dev>/ccissX/cXdY/model
+What:		/sys/bus/pci/devices/<dev>/ccissX/cXdY/model
 Date:		March 2009
 Kernel Version: 2.6.30
 Contact:	[email protected]
 Description:	Displays the SCSI INQUIRY page 0 model for logical drive
 		Y of controller X.
 
-Where:		/sys/bus/pci/devices/<dev>/ccissX/cXdY/rev
+What:		/sys/bus/pci/devices/<dev>/ccissX/cXdY/rev
 Date:		March 2009
 Kernel Version: 2.6.30
 Contact:	[email protected]
 Description:	Displays the SCSI INQUIRY page 0 revision for logical
 		drive Y of controller X.
 
-Where:		/sys/bus/pci/devices/<dev>/ccissX/cXdY/unique_id
+What:		/sys/bus/pci/devices/<dev>/ccissX/cXdY/unique_id
 Date:		March 2009
 Kernel Version: 2.6.30
 Contact:	[email protected]
 Description:	Displays the SCSI INQUIRY page 83 serial number for logical
 		drive Y of controller X.
 
-Where:		/sys/bus/pci/devices/<dev>/ccissX/cXdY/vendor
+What:		/sys/bus/pci/devices/<dev>/ccissX/cXdY/vendor
 Date:		March 2009
 Kernel Version: 2.6.30
 Contact:	[email protected]
 Description:	Displays the SCSI INQUIRY page 0 vendor for logical drive
 		Y of controller X.
 
-Where:		/sys/bus/pci/devices/<dev>/ccissX/cXdY/block:cciss!cXdY
+What:		/sys/bus/pci/devices/<dev>/ccissX/cXdY/block:cciss!cXdY
 Date:		March 2009
 Kernel Version: 2.6.30
 Contact:	[email protected]
 Description:	A symbolic link to /sys/block/cciss!cXdY
 
-Where:		/sys/bus/pci/devices/<dev>/ccissX/rescan
+What:		/sys/bus/pci/devices/<dev>/ccissX/rescan
 Date:		August 2009
 Kernel Version:	2.6.31
 Contact:	[email protected]
 Description:	Kicks of a rescan of the controller to discover logical
 		drive topology changes.
 
-Where:		/sys/bus/pci/devices/<dev>/ccissX/cXdY/lunid
+What:		/sys/bus/pci/devices/<dev>/ccissX/cXdY/lunid
 Date:		August 2009
 Kernel Version: 2.6.31
 Contact:	[email protected]
 Description:	Displays the 8-byte LUN ID used to address logical
 		drive Y of controller X.
 
-Where:		/sys/bus/pci/devices/<dev>/ccissX/cXdY/raid_level
+What:		/sys/bus/pci/devices/<dev>/ccissX/cXdY/raid_level
 Date:		August 2009
 Kernel Version: 2.6.31
 Contact:	[email protected]
 Description:	Displays the RAID level of logical drive Y of
 		controller X.
 
-Where:		/sys/bus/pci/devices/<dev>/ccissX/cXdY/usage_count
+What:		/sys/bus/pci/devices/<dev>/ccissX/cXdY/usage_count
 Date:		August 2009
 Kernel Version: 2.6.31
 Contact:	[email protected]
 Description:	Displays the usage count (number of opens) of logical drive Y
 		of controller X.
 
-Where:		/sys/bus/pci/devices/<dev>/ccissX/resettable
+What:		/sys/bus/pci/devices/<dev>/ccissX/resettable
 Date:		February 2011
 Kernel Version:	2.6.38
 Contact:	[email protected]
@@ -71,7 +71,7 @@ Description:	Value of 1 indicates the controller can honor the reset_devices
 		a dump device, as kdump requires resetting the device in order
 		to work reliably.
 
-Where:		/sys/bus/pci/devices/<dev>/ccissX/transport_mode
+What:		/sys/bus/pci/devices/<dev>/ccissX/transport_mode
 Date:		July 2011
 Kernel Version:	3.0
 Contact:	[email protected]
Documentation/ABI/testing/sysfs-bus-usb-devices-usbsevseg +6 -6
index 70d00dfa443d..f6199b314196 100644
@@ -1,12 +1,12 @@
-Where:		/sys/bus/usb/.../powered
+What:		/sys/bus/usb/.../powered
 Date:		August 2008
 Kernel Version:	2.6.26
 Contact:	Harrison Metzger <[email protected]>
 Description:	Controls whether the device's display will powered.
 		A value of 0 is off and a non-zero value is on.
 
-Where:		/sys/bus/usb/.../mode_msb
-Where:		/sys/bus/usb/.../mode_lsb
+What:		/sys/bus/usb/.../mode_msb
+What:		/sys/bus/usb/.../mode_lsb
 Date:		August 2008
 Kernel Version:	2.6.26
 Contact:	Harrison Metzger <[email protected]>
@@ -16,7 +16,7 @@ Description:	Controls the devices display mode.
 		for an 8 character display the values are
 			MSB 0x08; LSB 0xFF.
 
-Where:		/sys/bus/usb/.../textmode
+What:		/sys/bus/usb/.../textmode
 Date:		August 2008
 Kernel Version:	2.6.26
 Contact:	Harrison Metzger <[email protected]>
@@ -25,13 +25,13 @@ Description:	Controls the way the device interprets its text buffer.
 		hex:	each character is between 0-15
 		ascii:	each character is between '0'-'9' and 'A'-'F'.
 
-Where:		/sys/bus/usb/.../text
+What:		/sys/bus/usb/.../text
 Date:		August 2008
 Kernel Version:	2.6.26
 Contact:	Harrison Metzger <[email protected]>
 Description:	The text (or data) for the device to display
 
-Where:		/sys/bus/usb/.../decimals
+What:		/sys/bus/usb/.../decimals
 Date:		August 2008
 Kernel Version:	2.6.26
 Contact:	Harrison Metzger <[email protected]>
Documentation/ABI/testing/sysfs-class-cxl +3 -3
index 640f65e79ef1..d0b32452dfe1 100644
@@ -1,6 +1,6 @@
-Note: Attributes that are shared between devices are stored in the directory
-pointed to by the symlink device/.
-Example: The real path of the attribute /sys/class/cxl/afu0.0s/irqs_max is
+Please notice that attributes that are shared between devices are stored in
+the directory pointed to by the symlink device/.
+For example, the real path of the attribute /sys/class/cxl/afu0.0s/irqs_max is
 /sys/class/cxl/afu0.0s/device/irqs_max, i.e. /sys/class/cxl/afu0.0/irqs_max.
 
 
Documentation/ABI/testing/sysfs-class-devfreq +1 -1
index ee39acacf6f8..01196e19afca 100644
@@ -47,7 +47,7 @@ Description:
 What:		/sys/class/devfreq/.../trans_stat
 Date:		October 2012
 Contact:	MyungJoo Ham <[email protected]>
-Descrtiption:
+Description:
 		This ABI shows the statistics of devfreq behavior on a
 		specific device. It shows the time spent in each state and
 		the number of transitions between states.
Documentation/ABI/testing/sysfs-class-powercap +1 -1
index db3b3ff70d84..f333a0ccc29b 100644
@@ -147,6 +147,6 @@ What:		/sys/class/powercap/.../<power zone>/enabled
 Date:		September 2013
 KernelVersion:	3.13
 Contact:	[email protected]
-Description
+Description:
 		This allows to enable/disable power capping at power zone level.
 		This applies to current power zone and its children.
Documentation/ABI/testing/sysfs-kernel-fscaps +1 -1
index 50a3033b5e15..bcff34665192 100644
@@ -2,7 +2,7 @@ What:		/sys/kernel/fscaps
 Date:		February 2011
 KernelVersion:	2.6.38
 Contact:	Ludwig Nussel <[email protected]>
-Description
+Description:
 		Shows whether file system capabilities are honored
 		when executing a binary
 
Documentation/ABI/testing/sysfs-kernel-vmcoreinfo +1 -1
index 7bd81168e063..1f1087a5f075 100644
@@ -4,7 +4,7 @@ KernelVersion:	2.6.24
 Contact:	Ken'ichi Ohmichi <[email protected]>
 		Kexec Mailing List <[email protected]>
 		Vivek Goyal <[email protected]>
-Description
+Description:
 		Shows physical address and size of vmcoreinfo ELF note.
 		First value contains physical address of note in hex and
 		second value contains the size of note in hex. This ELF
Signature · 1 line
2.9.3
#3 lore raw

PATCH v2 3/11 ABI: sysfs-driver-hid: the "What" field doesn't parse fine

In reply to Mauro Carvalho Chehab

The What: field on this ABI description use a different syntax than expected, causing it to not be properly parsed by script.

Fix it.

---
 Documentation/ABI/testing/sysfs-driver-hid | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
Documentation/ABI/testing/sysfs-driver-hid +6 -6
index 48942cacb0bf..a59533410871 100644
@@ -1,6 +1,6 @@
-What:		For USB devices	: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/report_descriptor
-		For BT devices	: /sys/class/bluetooth/hci<addr>/<hid-bus>:<vendor-id>:<product-id>.<num>/report_descriptor
-		Symlink		: /sys/class/hidraw/hidraw<num>/device/report_descriptor
+What:		/sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/report_descriptor
+What:		/sys/class/bluetooth/hci<addr>/<hid-bus>:<vendor-id>:<product-id>.<num>/report_descriptor
+What:		/sys/class/hidraw/hidraw<num>/device/report_descriptor
 Date:		Jan 2011
 KernelVersion:	2.0.39
 Contact:	Alan Ott <[email protected]>
@@ -9,9 +9,9 @@ Description:	When read, this file returns the device's raw binary HID
 		This file cannot be written.
 Users:		HIDAPI library (http://www.signal11.us/oss/hidapi)
 
-What:		For USB devices	: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/country
-		For BT devices	: /sys/class/bluetooth/hci<addr>/<hid-bus>:<vendor-id>:<product-id>.<num>/country
-		Symlink		: /sys/class/hidraw/hidraw<num>/device/country
+What:		/sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/country
+What:		/sys/class/bluetooth/hci<addr>/<hid-bus>:<vendor-id>:<product-id>.<num>/country
+What:		/sys/class/hidraw/hidraw<num>/device/country
 Date:		February 2015
 KernelVersion:	3.19
 Contact:	Olivier Gay <[email protected]>
Signature · 1 line
2.9.3
#4 lore raw

PATCH v2 4/11 ABI: sysfs-class-uwb_rc: remove a duplicated incomplete entry

In reply to Mauro Carvalho Chehab

There are two entries for /sys/class/uwb_rc/uwbN/<EUI-48>/BPST. The second one has a missing description.

Get rid of it.

---
 Documentation/ABI/testing/sysfs-class-uwb_rc | 6 ------
 1 file changed, 6 deletions(-)
Documentation/ABI/testing/sysfs-class-uwb_rc +0 -6
index 85f4875d16ac..a0578751c1e3 100644
@@ -125,12 +125,6 @@ Description:
                 The EUI-48 of this device in colon separated hex
                 octets.
 
-What:           /sys/class/uwb_rc/uwbN/<EUI-48>/BPST
-Date:           July 2008
-KernelVersion:  2.6.27
-Contact:        [email protected]
-Description:
-
 What:           /sys/class/uwb_rc/uwbN/<EUI-48>/IEs
 Date:           July 2008
 KernelVersion:  2.6.27
Signature · 1 line
2.9.3
#5 lore raw

PATCH v2 5/11 ABI: better identificate tables

In reply to Mauro Carvalho Chehab

When parsing via script, it is important to know if the script should consider a description as a literal block that should be displayed as-is, or if the description can be considered as a normal text.

Change descriptions to ensure that the preceding line of a table ends with a colon. That makes easy to identify the need of a literal block.

---
 Documentation/ABI/obsolete/sysfs-driver-hid-roccat-pyra       | 2 +-
 Documentation/ABI/testing/sysfs-class-backlight-driver-lm3533 | 6 +++---
 Documentation/ABI/testing/sysfs-class-led-driver-lm3533       | 8 ++++----
 Documentation/ABI/testing/sysfs-class-leds-gt683r             | 4 ++--
 Documentation/ABI/testing/sysfs-driver-hid-roccat-kone        | 2 +-
 5 files changed, 11 insertions(+), 11 deletions(-)
Documentation/ABI/obsolete/sysfs-driver-hid-roccat-pyra +1 -1
index 16020b31ae64..5d41ebadf15e 100644
@@ -5,7 +5,7 @@ Description:	It is possible to switch the cpi setting of the mouse with the
 		press of a button.
 		When read, this file returns the raw number of the actual cpi
 		setting reported by the mouse. This number has to be further
-		processed to receive the real dpi value.
+		processed to receive the real dpi value:
 
 		VALUE DPI
 		1     400
Documentation/ABI/testing/sysfs-class-backlight-driver-lm3533 +3 -3
index 77cf7ac949af..c0e0a9ae7b3d 100644
@@ -4,7 +4,7 @@ KernelVersion:	3.5
 Contact:	Johan Hovold <[email protected]>
 Description:
 		Get the ALS output channel used as input in
-		ALS-current-control mode (0, 1), where
+		ALS-current-control mode (0, 1), where:
 
 		0 - out_current0 (backlight 0)
 		1 - out_current1 (backlight 1)
@@ -28,7 +28,7 @@ Date:		April 2012
 KernelVersion:	3.5
 Contact:	Johan Hovold <[email protected]>
 Description:
-		Set the brightness-mapping mode (0, 1), where
+		Set the brightness-mapping mode (0, 1), where:
 
 		0 - exponential mode
 		1 - linear mode
@@ -38,7 +38,7 @@ Date:		April 2012
 KernelVersion:	3.5
 Contact:	Johan Hovold <[email protected]>
 Description:
-		Set the PWM-input control mask (5 bits), where
+		Set the PWM-input control mask (5 bits), where:
 
 		bit 5 - PWM-input enabled in Zone 4
 		bit 4 - PWM-input enabled in Zone 3
Documentation/ABI/testing/sysfs-class-led-driver-lm3533 +4 -4
index 620ebb3b9baa..e4c89b261546 100644
@@ -4,7 +4,7 @@ KernelVersion:	3.5
 Contact:	Johan Hovold <[email protected]>
 Description:
 		Set the ALS output channel to use as input in
-		ALS-current-control mode (1, 2), where
+		ALS-current-control mode (1, 2), where:
 
 		1 - out_current1
 		2 - out_current2
@@ -22,7 +22,7 @@ Date:		April 2012
 KernelVersion:	3.5
 Contact:	Johan Hovold <[email protected]>
 Description:
-		Set the pattern generator fall and rise times (0..7), where
+		Set the pattern generator fall and rise times (0..7), where:
 
 		0 - 2048 us
 		1 - 262 ms
@@ -45,7 +45,7 @@ Date:		April 2012
 KernelVersion:	3.5
 Contact:	Johan Hovold <[email protected]>
 Description:
-		Set the brightness-mapping mode (0, 1), where
+		Set the brightness-mapping mode (0, 1), where:
 
 		0 - exponential mode
 		1 - linear mode
@@ -55,7 +55,7 @@ Date:		April 2012
 KernelVersion:	3.5
 Contact:	Johan Hovold <[email protected]>
 Description:
-		Set the PWM-input control mask (5 bits), where
+		Set the PWM-input control mask (5 bits), where:
 
 		bit 5 - PWM-input enabled in Zone 4
 		bit 4 - PWM-input enabled in Zone 3
Documentation/ABI/testing/sysfs-class-leds-gt683r +2 -2
index e4fae6026e79..6adab27f646e 100644
@@ -5,7 +5,7 @@ Contact:	Janne Kanniainen <[email protected]>
 Description:
 		Set the mode of LEDs. You should notice that changing the mode
 		of one LED will update the mode of its two sibling devices as
-		well.
+		well. Possible values are:
 
 		0 - normal
 		1 - audio
@@ -13,4 +13,4 @@ Description:
 
 		Normal: LEDs are fully on when enabled
 		Audio:  LEDs brightness depends on sound level
-		Breathing: LEDs brightness varies at human breathing rate
\ No newline at end of file
+		Breathing: LEDs brightness varies at human breathing rate
Documentation/ABI/testing/sysfs-driver-hid-roccat-kone +1 -1
index 3ca3971109bf..8f7982c70d72 100644
@@ -5,7 +5,7 @@ Description:	It is possible to switch the dpi setting of the mouse with the
 		press of a button.
 		When read, this file returns the raw number of the actual dpi
 		setting reported by the mouse. This number has to be further
-		processed to receive the real dpi value.
+		processed to receive the real dpi value:
 
 		VALUE DPI
 		1     800
Signature · 1 line
2.9.3
#6 lore raw

PATCH v2 6/11 scripts: add an script to parse the ABI files

In reply to Mauro Carvalho Chehab

Add a script to parse the Documentation/ABI files and produce an output with all entries inside an ABI (sub)directory.

Right now, it outputs its contents on ReST format. It shouldn't be hard to make it produce other kind of outputs, since the ABI file parser is implemented in separate than the output generator.

---
 scripts/get_abi.pl | 212 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 212 insertions(+)
 create mode 100755 scripts/get_abi.pl
scripts/get_abi.pl new file +212 -0
new file mode 100755
index 000000000000..f7c9944a833c
@@ -0,0 +1,212 @@
+#!/usr/bin/perl
+
+use strict;
+use Pod::Usage;
+use Getopt::Long;
+use File::Find;
+use Fcntl ':mode';
+
+my $help;
+my $man;
+my $debug;
+
+GetOptions(
+	"debug|d+" => \$debug,
+	'help|?' => \$help,
+	man => \$man
+) or pod2usage(2);
+
+pod2usage(1) if $help;
+pod2usage(-exitstatus => 0, -verbose => 2) if $man;
+
+pod2usage(2) if (scalar @ARGV != 1);
+
+my ($prefix) = @ARGV;
+
+require Data::Dumper if ($debug);
+
+my %data;
+
+#
+# Displays an error message, printing file name and line
+#
+sub parse_error($$$$) {
+	my ($file, $ln, $msg, $data) = @_;
+
+	print STDERR "file $file#$ln: $msg at\n\t$data";
+}
+
+#
+# Parse an ABI file, storing its contents at %data
+#
+sub parse_abi {
+	my $file = $File::Find::name;
+
+	my $mode = (stat($file))[2];
+	return if ($mode & S_IFDIR);
+	return if ($file =~ m,/README,);
+
+	my $name = $file;
+	$name =~ s,.*/,,;
+
+	my $type = $file;
+	$type =~ s,.*/(.*)/.*,$1,;
+
+	my $what;
+	my $new_what;
+	my $tag;
+	my $ln;
+
+	print STDERR "Opening $file\n" if ($debug > 1);
+	open IN, $file;
+	while(<IN>) {
+		$ln++;
+		if (m/^(\S+):\s*(.*)/i) {
+			my $new_tag = lc($1);
+			my $content = $2;
+
+			if (!($new_tag =~ m/(what|date|kernelversion|contact|description|users)/)) {
+				if ($tag eq "description") {
+					$data{$what}->{$tag} .= "\n$content";;
+					$data{$what}->{$tag} =~ s/\n+$//;
+					next;
+				} else {
+					parse_error($file, $ln, "tag '$tag' is invalid", $_);
+				}
+			}
+
+			if ($new_tag =~ m/what/) {
+				if ($tag =~ m/what/) {
+					$what .= ", " . $content;
+				} else {
+					$what = $content;
+					$new_what = 1;
+				}
+				$tag = $new_tag;
+				next;
+			}
+
+			$tag = $new_tag;
+
+			if ($new_what) {
+				$new_what = 0;
+
+				$data{$what}->{type} = $type;
+				$data{$what}->{file} = $name;
+				print STDERR "\twhat: $what\n" if ($debug > 1);
+			}
+
+			if (!$what) {
+				parse_error($file, $ln, "'What:' should come first:", $_);
+				next;
+			}
+			$data{$what}->{$tag} = $content;
+			next;
+		}
+
+		# Silently ignore any headers before the database
+		next if (!$tag);
+
+		if (m/^\s*(.*)/) {
+			$data{$what}->{$tag} .= "\n$1";
+			$data{$what}->{$tag} =~ s/\n+$//;
+			next;
+		}
+
+		# Everything else is error
+		parse_error($file, $ln, "Unexpected line:", $_);
+	}
+	close IN;
+}
+
+# Outputs the output on ReST format
+sub output_rest {
+	foreach my $what (sort keys %data) {
+		my $type = $data{$what}->{type};
+		my $file = $data{$what}->{file};
+
+		my $w = $what;
+		$w =~ s/([\(\)\_\-\*\=\^\~\\])/\\$1/g;
+
+		print "$w\n\n";
+		print "- defined on file $file (type: $type)\n\n::\n\n";
+
+		my $desc = $data{$what}->{description};
+		$desc =~ s/^\s+//;
+
+		# Remove title markups from the description, as they won't work
+		$desc =~ s/\n[\-\*\=\^\~]+\n/\n/g;
+
+		# put everything inside a code block
+		$desc =~ s/\n/\n /g;
+
+
+		if (!($desc =~ /^\s*$/)) {
+			print " $desc\n\n";
+		} else {
+			print " DESCRIPTION MISSING\n\n";
+		}
+	}
+}
+
+#
+# Parses all ABI files located at $prefix dir
+#
+find({wanted =>\&parse_abi, no_chdir => 1}, $prefix);
+
+print STDERR Data::Dumper->Dump([\%data], [qw(*data)]) if ($debug);
+
+#
+# Outputs an ReST file with the ABI contents
+#
+output_rest
+
+
+__END__
+
+=head1 NAME
+
+abi_book.pl - parse the Linux ABI files and produce a ReST book.
+
+=head1 SYNOPSIS
+
+B<abi_book.pl> [--debug] <ABI_DIR>]
+
+=head1 OPTIONS
+
+=over 8
+
+=item B<--debug>
+
+Put the script in verbose mode, useful for debugging. Can be called multiple
+times, to increase verbosity.
+
+=item B<--help>
+
+Prints a brief help message and exits.
+
+=item B<--man>
+
+Prints the manual page and exits.
+
+=back
+
+=head1 DESCRIPTION
+
+Parse the Linux ABI files from ABI DIR (usually located at Documentation/ABI)
+and produce a ReST book containing the Linux ABI.
+
+=head1 BUGS
+
+Report bugs to Mauro Carvalho Chehab <[email protected]>
+
+=head1 COPYRIGHT
+
+Copyright (c) 2016 by Mauro Carvalho Chehab <[email protected]>.
+
+License GPLv2: GNU GPL version 2 <http://gnu.org/licenses/gpl.html>.
+
+This is free software: you are free to change and redistribute it.
+There is NO WARRANTY, to the extent permitted by law.
+
+=cut
Signature · 1 line
2.9.3
#7 lore raw

PATCH v2 7/11 scripts/get_abi.pl: parse files with text at beginning

In reply to Mauro Carvalho Chehab

It sounds usefult o parse files with has some text at the beginning. Add support for it.

---
 scripts/get_abi.pl | 59 +++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 54 insertions(+), 5 deletions(-)
scripts/get_abi.pl +54 -5
index f7c9944a833c..ac0f057fa3ca 100755
@@ -55,7 +55,10 @@ sub parse_abi {
 	my $what;
 	my $new_what;
 	my $tag;
+	my $label;
 	my $ln;
+	my $has_file;
+	my $xrefs;
 
 	print STDERR "Opening $file\n" if ($debug > 1);
 	open IN, $file;
@@ -67,7 +70,7 @@ sub parse_abi {
 
 			if (!($new_tag =~ m/(what|date|kernelversion|contact|description|users)/)) {
 				if ($tag eq "description") {
-					$data{$what}->{$tag} .= "\n$content";;
+					$data{$what}->{$tag} .= "\n$content";
 					$data{$what}->{$tag} =~ s/\n+$//;
 					next;
 				} else {
@@ -83,6 +86,25 @@ sub parse_abi {
 					$new_what = 1;
 				}
 				$tag = $new_tag;
+
+				if ($has_file) {
+					$label = "abi_" . $content . " ";
+					$label =~ tr/A-Z/a-z/;
+
+					# Convert special chars to "_"
+					$label =~s/[\x00-\x2f]+/_/g;
+					$label =~s/[\x3a-\x40]+/_/g;
+					$label =~s/[\x7b-\xff]+/_/g;
+					$label =~ s,_+,_,g;
+					$label =~ s,_$,,;
+
+					$data{$what}->{label} .= $label;
+
+					# Escape special chars from content
+					$content =~s/([\x00-\x1f\x21-\x2f\x3a-\x40\x7b-\xff])/\\$1/g;
+
+					$xrefs .= "- :ref:`$content <$label>`\n\n";
+				}
 				next;
 			}
 
@@ -104,8 +126,18 @@ sub parse_abi {
 			next;
 		}
 
-		# Silently ignore any headers before the database
-		next if (!$tag);
+		# Store any contents before the database
+		if (!$tag) {
+			next if (/^\n/);
+
+			my $my_what = "File $name";
+			$data{$my_what}->{what} = "File $name";
+			$data{$my_what}->{type} = "File";
+			$data{$my_what}->{file} = $name;
+			$data{$my_what}->{description} .= $_;
+			$has_file = 1;
+			next;
+		}
 
 		if (m/^\s*(.*)/) {
 			$data{$what}->{$tag} .= "\n$1";
@@ -117,6 +149,11 @@ sub parse_abi {
 		parse_error($file, $ln, "Unexpected line:", $_);
 	}
 	close IN;
+
+	if ($has_file) {
+		my $my_what = "File $name";
+                $data{$my_what}->{xrefs} = $xrefs;
+	}
 }
 
 # Outputs the output on ReST format
@@ -128,8 +165,17 @@ sub output_rest {
 		my $w = $what;
 		$w =~ s/([\(\)\_\-\*\=\^\~\\])/\\$1/g;
 
+		if ($data{$what}->{label}) {
+			my @labels = split(/\s/, $data{$what}->{label});
+			foreach my $label (@labels) {
+				printf ".. _%s:\n\n", $label;
+			}
+		}
+
 		print "$w\n\n";
-		print "- defined on file $file (type: $type)\n\n::\n\n";
+
+		print "- defined on file $file (type: $type)\n\n" if ($type ne "File");
+		print "::\n\n";
 
 		my $desc = $data{$what}->{description};
 		$desc =~ s/^\s+//;
@@ -144,8 +190,11 @@ sub output_rest {
 		if (!($desc =~ /^\s*$/)) {
 			print " $desc\n\n";
 		} else {
-			print " DESCRIPTION MISSING\n\n";
+			print " DESCRIPTION MISSING for $what\n\n";
 		}
+
+		printf "Has the following ABI:\n\n%s", $data{$what}->{xrefs} if ($data{$what}->{xrefs});
+
 	}
 }
 
Signature · 1 line
2.9.3
#8 lore raw

PATCH v2 8/11 scripts/get_abi.pl: avoid use literal blocks when not needed

In reply to Mauro Carvalho Chehab

The usage of literal blocks make the document very complex, causing the browser to take a long time to load.

On most ABI descriptions, they're a plain text, and don't require a literal block.

So, add a logic there with identifies when a literal block is needed.

As, on literal blocks, we need to respect the original document space, the most complex part of this patch is to preserve the original spacing where needed.

---
 scripts/get_abi.pl | 104 +++++++++++++++++++++++++++++++++++++++--------------
 1 file changed, 78 insertions(+), 26 deletions(-)
scripts/get_abi.pl +78 -26
index ac0f057fa3ca..ba8a7466f896 100755
@@ -59,29 +59,34 @@ sub parse_abi {
 	my $ln;
 	my $has_file;
 	my $xrefs;
+	my $space;
 
 	print STDERR "Opening $file\n" if ($debug > 1);
 	open IN, $file;
 	while(<IN>) {
 		$ln++;
-		if (m/^(\S+):\s*(.*)/i) {
+		if (m/^(\S+)(:\s*)(.*)/i) {
 			my $new_tag = lc($1);
-			my $content = $2;
+			my $sep = $2;
+			my $content = $3;
 
 			if (!($new_tag =~ m/(what|date|kernelversion|contact|description|users)/)) {
 				if ($tag eq "description") {
-					$data{$what}->{$tag} .= "\n$content";
-					$data{$what}->{$tag} =~ s/\n+$//;
-					next;
+					# New "tag" is actually part of
+					# description. Don't consider it a tag
+					$new_tag = "";
 				} else {
 					parse_error($file, $ln, "tag '$tag' is invalid", $_);
 				}
 			}
 
 			if ($new_tag =~ m/what/) {
+				$space = "";
 				if ($tag =~ m/what/) {
 					$what .= ", " . $content;
 				} else {
+					parse_error($file, $ln, "What '$what' doesn't have a description", "") if ($what && !$data{$what}->{description});
+
 					$what = $content;
 					$new_what = 1;
 				}
@@ -108,25 +113,38 @@ sub parse_abi {
 				next;
 			}
 
-			$tag = $new_tag;
+			if ($new_tag) {
+				$tag = $new_tag;
 
-			if ($new_what) {
-				$new_what = 0;
+				if ($new_what) {
+					$new_what = 0;
 
-				$data{$what}->{type} = $type;
-				$data{$what}->{file} = $name;
-				print STDERR "\twhat: $what\n" if ($debug > 1);
-			}
+					$data{$what}->{type} = $type;
+					$data{$what}->{file} = $name;
+					print STDERR "\twhat: $what\n" if ($debug > 1);
+				}
 
-			if (!$what) {
-				parse_error($file, $ln, "'What:' should come first:", $_);
+				if (!$what) {
+					parse_error($file, $ln, "'What:' should come first:", $_);
+					next;
+				}
+				if ($tag eq "description") {
+					next if ($content =~ m/^\s*$/);
+					if ($content =~ m/^(\s*)(.*)/) {
+						my $new_content = $2;
+						$space = $new_tag . $sep . $1;
+						while ($space =~ s/\t+/' ' x (length($&) * 8 - length($`) % 8)/e) {}
+						$space =~ s/./ /g;
+						$data{$what}->{$tag} .= "$new_content\n";
+					}
+				} else {
+					$data{$what}->{$tag} = $content;
+				}
 				next;
 			}
-			$data{$what}->{$tag} = $content;
-			next;
 		}
 
-		# Store any contents before the database
+		# Store any contents before tags at the database
 		if (!$tag) {
 			next if (/^\n/);
 
@@ -139,6 +157,32 @@ sub parse_abi {
 			next;
 		}
 
+		if ($tag eq "description") {
+			if (!$data{$what}->{description}) {
+				next if (m/^\s*\n/);
+				if (m/^(\s*)(.*)/) {
+					$space = $1;
+					while ($space =~ s/\t+/' ' x (length($&) * 8 - length($`) % 8)/e) {}
+					$data{$what}->{$tag} .= "$2\n";
+				}
+			} else {
+				my $content = $_;
+				if (m/^\s*\n/) {
+					$data{$what}->{$tag} .= $content;
+					next;
+				}
+
+				while ($content =~ s/\t+/' ' x (length($&) * 8 - length($`) % 8)/e) {}
+				$space = "" if (!($content =~ s/^($space)//));
+
+				# Compress spaces with tabs
+				$content =~ s<^ {8}> <\t>;
+				$content =~ s<^ {1,7}\t> <\t>;
+				$content =~ s< {1,7}\t> <\t>;
+				$data{$what}->{$tag} .= $content;
+			}
+			next;
+		}
 		if (m/^\s*(.*)/) {
 			$data{$what}->{$tag} .= "\n$1";
 			$data{$what}->{$tag} =~ s/\n+$//;
@@ -165,6 +209,9 @@ sub output_rest {
 		my $w = $what;
 		$w =~ s/([\(\)\_\-\*\=\^\~\\])/\\$1/g;
 
+		my $bar = $w;
+		$bar =~ s/./-/g;
+
 		if ($data{$what}->{label}) {
 			my @labels = split(/\s/, $data{$what}->{label});
 			foreach my $label (@labels) {
@@ -172,10 +219,9 @@ sub output_rest {
 			}
 		}
 
-		print "$w\n\n";
+		print "$w\n$bar\n\n";
 
 		print "- defined on file $file (type: $type)\n\n" if ($type ne "File");
-		print "::\n\n";
 
 		my $desc = $data{$what}->{description};
 		$desc =~ s/^\s+//;
@@ -183,18 +229,24 @@ sub output_rest {
 		# Remove title markups from the description, as they won't work
 		$desc =~ s/\n[\-\*\=\^\~]+\n/\n/g;
 
-		# put everything inside a code block
-		$desc =~ s/\n/\n /g;
-
-
 		if (!($desc =~ /^\s*$/)) {
-			print " $desc\n\n";
+	                if ($desc =~ m/\:\n/ || $desc =~ m/\n[\t ]+/  || $desc =~ m/[\x00-\x08\x0b-\x1f\x7b-\xff]/) {
+				# put everything inside a code block
+				$desc =~ s/\n/\n /g;
+
+				print "::\n\n";
+				print " $desc\n\n";
+			} else {
+				# Escape any special chars from description
+				$desc =~s/([\x00-\x08\x0b-\x1f\x21-\x2a\x2d\x2f\x3c-\x40\x5c\x5e-\x60\x7b-\xff])/\\$1/g;
+
+				print "$desc\n\n";
+			}
 		} else {
-			print " DESCRIPTION MISSING for $what\n\n";
+			print "DESCRIPTION MISSING for $what\n\n";
 		}
 
 		printf "Has the following ABI:\n\n%s", $data{$what}->{xrefs} if ($data{$what}->{xrefs});
-
 	}
 }
 
Signature · 1 line
2.9.3
#9 lore raw

PATCH v2 9/11 scripts/get_abi.pl: split label naming from xref logic

In reply to Mauro Carvalho Chehab

Instead of using a ReST compilant label while parsing, move the label to ReST output. That makes the parsing logic more generic, allowing it to provide other types of output.

As a side effect, now all files used to generate the output will be output. We can later add command line arguments to filter.

---
 scripts/get_abi.pl | 94 ++++++++++++++++++++++++++++++------------------------
 1 file changed, 53 insertions(+), 41 deletions(-)
scripts/get_abi.pl +53 -41
index ba8a7466f896..d437e148b1c0 100755
@@ -49,17 +49,23 @@ sub parse_abi {
 	my $name = $file;
 	$name =~ s,.*/,,;
 
+	my $nametag = "File $name";
+	$data{$nametag}->{what} = "File $name";
+	$data{$nametag}->{type} = "File";
+	$data{$nametag}->{file} = $name;
+	$data{$nametag}->{is_file} = 1;
+
 	my $type = $file;
 	$type =~ s,.*/(.*)/.*,$1,;
 
 	my $what;
 	my $new_what;
 	my $tag;
-	my $label;
 	my $ln;
-	my $has_file;
 	my $xrefs;
 	my $space;
+	my @labels;
+	my $label;
 
 	print STDERR "Opening $file\n" if ($debug > 1);
 	open IN, $file;
@@ -88,28 +94,13 @@ sub parse_abi {
 					parse_error($file, $ln, "What '$what' doesn't have a description", "") if ($what && !$data{$what}->{description});
 
 					$what = $content;
+					$label = $content;
 					$new_what = 1;
 				}
+				push @labels, [($content, $label)];
 				$tag = $new_tag;
 
-				if ($has_file) {
-					$label = "abi_" . $content . " ";
-					$label =~ tr/A-Z/a-z/;
-
-					# Convert special chars to "_"
-					$label =~s/[\x00-\x2f]+/_/g;
-					$label =~s/[\x3a-\x40]+/_/g;
-					$label =~s/[\x7b-\xff]+/_/g;
-					$label =~ s,_+,_,g;
-					$label =~ s,_$,,;
-
-					$data{$what}->{label} .= $label;
-
-					# Escape special chars from content
-					$content =~s/([\x00-\x1f\x21-\x2f\x3a-\x40\x7b-\xff])/\\$1/g;
-
-					$xrefs .= "- :ref:`$content <$label>`\n\n";
-				}
+				push @{$data{$nametag}->{xrefs}}, [($content, $label)] if ($data{$nametag}->{what});
 				next;
 			}
 
@@ -117,6 +108,9 @@ sub parse_abi {
 				$tag = $new_tag;
 
 				if ($new_what) {
+					@{$data{$what}->{label}} = @labels if ($data{$nametag}->{what});
+					@labels = ();
+					$label = "";
 					$new_what = 0;
 
 					$data{$what}->{type} = $type;
@@ -145,15 +139,8 @@ sub parse_abi {
 		}
 
 		# Store any contents before tags at the database
-		if (!$tag) {
-			next if (/^\n/);
-
-			my $my_what = "File $name";
-			$data{$my_what}->{what} = "File $name";
-			$data{$my_what}->{type} = "File";
-			$data{$my_what}->{file} = $name;
-			$data{$my_what}->{description} .= $_;
-			$has_file = 1;
+		if (!$tag && $data{$nametag}->{what}) {
+			$data{$nametag}->{description} .= $_;
 			next;
 		}
 
@@ -192,12 +179,8 @@ sub parse_abi {
 		# Everything else is error
 		parse_error($file, $ln, "Unexpected line:", $_);
 	}
+	$data{$nametag}->{description} =~ s/^\n+//;
 	close IN;
-
-	if ($has_file) {
-		my $my_what = "File $name";
-                $data{$my_what}->{xrefs} = $xrefs;
-	}
 }
 
 # Outputs the output on ReST format
@@ -212,11 +195,22 @@ sub output_rest {
 		my $bar = $w;
 		$bar =~ s/./-/g;
 
-		if ($data{$what}->{label}) {
-			my @labels = split(/\s/, $data{$what}->{label});
-			foreach my $label (@labels) {
-				printf ".. _%s:\n\n", $label;
-			}
+		foreach my $p (@{$data{$what}->{label}}) {
+			my ($content, $label) = @{$p};
+			$label = "abi_" . $label . " ";
+			$label =~ tr/A-Z/a-z/;
+
+			# Convert special chars to "_"
+			$label =~s/([\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\xff])/_/g;
+			$label =~ s,_+,_,g;
+			$label =~ s,_$,,;
+
+			$data{$what}->{label} .= $label;
+
+			printf ".. _%s:\n\n", $label;
+
+			# only one label is enough
+			last;
 		}
 
 		print "$w\n$bar\n\n";
@@ -243,10 +237,28 @@ sub output_rest {
 				print "$desc\n\n";
 			}
 		} else {
-			print "DESCRIPTION MISSING for $what\n\n";
+			print "DESCRIPTION MISSING for $what\n\n" if (!$data{$what}->{is_file});
 		}
 
-		printf "Has the following ABI:\n\n%s", $data{$what}->{xrefs} if ($data{$what}->{xrefs});
+		if ($data{$what}->{xrefs}) {
+			printf "Has the following ABI:\n\n";
+
+			foreach my $p(@{$data{$what}->{xrefs}}) {
+				my ($content, $label) = @{$p};
+				$label = "abi_" . $label . " ";
+				$label =~ tr/A-Z/a-z/;
+
+				# Convert special chars to "_"
+				$label =~s/([\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\xff])/_/g;
+				$label =~ s,_+,_,g;
+				$label =~ s,_$,,;
+
+				# Escape special chars from content
+				$content =~s/([\x00-\x1f\x21-\x2f\x3a-\x40\x7b-\xff])/\\$1/g;
+
+				print "- :ref:`$content <$label>`\n\n";
+			}
+		}
 	}
 }
 
Signature · 1 line
2.9.3
#10 lore raw

PATCH v2 10/11 scripts/get_abi.pl: add support for searching for ABI symbols

In reply to Mauro Carvalho Chehab

Change its syntax to allow switching between ReST output mode and a new search mode, with allows to seek for ABI symbols using rejex.

---
 scripts/get_abi.pl | 112 ++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 103 insertions(+), 9 deletions(-)
scripts/get_abi.pl +103 -9
index d437e148b1c0..eb62385630e6 100755
@@ -9,9 +9,11 @@ use Fcntl ':mode';
 my $help;
 my $man;
 my $debug;
+my $prefix="Documentation/ABI";
 
 GetOptions(
 	"debug|d+" => \$debug,
+	"dir=s" => \$prefix,
 	'help|?' => \$help,
 	man => \$man
 ) or pod2usage(2);
@@ -19,9 +21,12 @@ GetOptions(
 pod2usage(1) if $help;
 pod2usage(-exitstatus => 0, -verbose => 2) if $man;
 
-pod2usage(2) if (scalar @ARGV != 1);
+pod2usage(2) if (scalar @ARGV < 1 || @ARGV > 2);
 
-my ($prefix) = @ARGV;
+my ($cmd, $arg) = @ARGV;
+
+pod2usage(2) if ($cmd ne "search" && $cmd ne "rest");
+pod2usage(2) if ($cmd eq "search" && !$arg);
 
 require Data::Dumper if ($debug);
 
@@ -53,6 +58,7 @@ sub parse_abi {
 	$data{$nametag}->{what} = "File $name";
 	$data{$nametag}->{type} = "File";
 	$data{$nametag}->{file} = $name;
+	$data{$nametag}->{filepath} = $file;
 	$data{$nametag}->{is_file} = 1;
 
 	my $type = $file;
@@ -115,6 +121,7 @@ sub parse_abi {
 
 					$data{$what}->{type} = $type;
 					$data{$what}->{file} = $name;
+					$data{$what}->{filepath} = $file;
 					print STDERR "\twhat: $what\n" if ($debug > 1);
 				}
 
@@ -183,7 +190,9 @@ sub parse_abi {
 	close IN;
 }
 
-# Outputs the output on ReST format
+#
+# Outputs the book on ReST format
+#
 sub output_rest {
 	foreach my $what (sort keys %data) {
 		my $type = $data{$what}->{type};
@@ -263,6 +272,45 @@ sub output_rest {
 }
 
 #
+# Searches for ABI symbols
+#
+sub search_symbols {
+	foreach my $what (sort keys %data) {
+		next if (!($what =~ m/($arg)/));
+
+		my $type = $data{$what}->{type};
+		next if ($type eq "File");
+
+		my $file = $data{$what}->{filepath};
+
+		my $bar = $what;
+		$bar =~ s/./-/g;
+
+		print "\n$what\n$bar\n\n";
+
+		my $kernelversion = $data{$what}->{kernelversion};
+		my $contact = $data{$what}->{contact};
+		my $users = $data{$what}->{users};
+		my $date = $data{$what}->{date};
+		my $desc = $data{$what}->{description};
+		$kernelversion =~ s/^\s+//;
+		$contact =~ s/^\s+//;
+		$users =~ s/^\s+//;
+		$users =~ s/\n//g;
+		$date =~ s/^\s+//;
+		$desc =~ s/^\s+//;
+
+		printf "Kernel version:\t\t%s\n", $kernelversion if ($kernelversion);
+		printf "Date:\t\t\t%s\n", $date if ($date);
+		printf "Contact:\t\t%s\n", $contact if ($contact);
+		printf "Users:\t\t\t%s\n", $users if ($users);
+		print "Defined on file:\t$file\n\n";
+		print "Description:\n\n$desc";
+	}
+}
+
+
+#
 # Parses all ABI files located at $prefix dir
 #
 find({wanted =>\&parse_abi, no_chdir => 1}, $prefix);
@@ -270,9 +318,13 @@ find({wanted =>\&parse_abi, no_chdir => 1}, $prefix);
 print STDERR Data::Dumper->Dump([\%data], [qw(*data)]) if ($debug);
 
 #
-# Outputs an ReST file with the ABI contents
+# Handles the command
 #
-output_rest
+if ($cmd eq "rest") {
+	output_rest;
+} else {
+	search_symbols;
+}
 
 
 __END__
@@ -283,12 +335,27 @@ abi_book.pl - parse the Linux ABI files and produce a ReST book.
 
 =head1 SYNOPSIS
 
-B<abi_book.pl> [--debug] <ABI_DIR>]
+B<abi_book.pl> [--debug] <COMAND> [<ARGUMENT>]
+
+Where <COMMAND> can be:
+
+=over 8
+
+B<search> [SEARCH_REJEX] - search for [SEARCH_REJEX] inside ABI
+
+B<rest>   - output the ABI in ReST markup language
+
+=back
 
 =head1 OPTIONS
 
 =over 8
 
+=item B<--dir>
+
+Changes the location of the ABI search. By default, it uses
+the Documentation/ABI directory.
+
 =item B<--debug>
 
 Put the script in verbose mode, useful for debugging. Can be called multiple
@@ -306,8 +373,35 @@ Prints the manual page and exits.
 
 =head1 DESCRIPTION
 
-Parse the Linux ABI files from ABI DIR (usually located at Documentation/ABI)
-and produce a ReST book containing the Linux ABI.
+Parse the Linux ABI files from ABI DIR (usually located at Documentation/ABI),
+allowing to search for ABI symbols or to produce a ReST book containing
+the Linux ABI documentation.
+
+=head1 EXAMPLES
+
+Search for all stable symbols with the word "usb":
+
+=over 8
+
+$ scripts/get_abi.pl search usb --dir Documentation/ABI/stable
+
+=back
+
+Search for all symbols that match the rejex expression "usb.*cap":
+
+=over 8
+
+$ scripts/get_abi.pl search usb.*cap
+
+=back
+
+Output all obsoleted symbols in ReST format
+
+=over 8
+
+$ scripts/get_abi.pl rest --dir Documentation/ABI/obsolete
+
+=back
 
 =head1 BUGS
 
@@ -315,7 +409,7 @@ Report bugs to Mauro Carvalho Chehab <[email protected]>
 
 =head1 COPYRIGHT
 
-Copyright (c) 2016 by Mauro Carvalho Chehab <[email protected]>.
+Copyright (c) 2016-2017 by Mauro Carvalho Chehab <[email protected]>.
 
 License GPLv2: GNU GPL version 2 <http://gnu.org/licenses/gpl.html>.
 
Signature · 1 line
2.9.3
#11 lore raw

PATCH v2 11/11 doc-rst: add ABI documentation to the admin-guide book

In reply to Mauro Carvalho Chehab

As we don't want a generic Sphinx extension to execute commands, change the one proposed to Markus to call the abi_book.pl script.

Use a script to parse the Documentation/ABI directory and output it at the admin-guide.

---
 Documentation/admin-guide/abi-obsolete.rst |  10 ++
 Documentation/admin-guide/abi-removed.rst  |   4 +
 Documentation/admin-guide/abi-stable.rst   |  13 +++
 Documentation/admin-guide/abi-testing.rst  |  19 ++++
 Documentation/admin-guide/abi.rst          |  11 ++
 Documentation/admin-guide/index.rst        |   1 +
 Documentation/conf.py                      |   3 +-
 Documentation/sphinx/kernel_abi.py         | 155 +++++++++++++++++++++++++++++
 8 files changed, 215 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/admin-guide/abi-obsolete.rst
 create mode 100644 Documentation/admin-guide/abi-removed.rst
 create mode 100644 Documentation/admin-guide/abi-stable.rst
 create mode 100644 Documentation/admin-guide/abi-testing.rst
 create mode 100644 Documentation/admin-guide/abi.rst
 create mode 100644 Documentation/sphinx/kernel_abi.py
Documentation/admin-guide/abi-obsolete.rst new file +10 -0
new file mode 100644
index 000000000000..cda9168445a5
@@ -0,0 +1,10 @@
+ABI obsolete symbols
+====================
+
+Documents interfaces that are still remaining in the kernel, but are
+marked to be removed at some later point in time.
+
+The description of the interface will document the reason why it is
+obsolete and when it can be expected to be removed.
+
+.. kernel-abi:: $srctree/Documentation/ABI/obsolete
Documentation/admin-guide/abi-removed.rst new file +4 -0
new file mode 100644
index 000000000000..497978fc9632
@@ -0,0 +1,4 @@
+ABI removed symbols
+===================
+
+.. kernel-abi:: $srctree/Documentation/ABI/removed
Documentation/admin-guide/abi-stable.rst new file +13 -0
new file mode 100644
index 000000000000..7495d7a35048
@@ -0,0 +1,13 @@
+ABI stable symbols
+==================
+
+Documents the interfaces that the developer has defined to be stable.
+
+Userspace programs are free to use these interfaces with no
+restrictions, and backward compatibility for them will be guaranteed
+for at least 2 years.
+
+Most interfaces (like syscalls) are expected to never change and always
+be available.
+
+.. kernel-abi:: $srctree/Documentation/ABI/stable
Documentation/admin-guide/abi-testing.rst new file +19 -0
new file mode 100644
index 000000000000..5c886fc50b9e
@@ -0,0 +1,19 @@
+ABI testing symbols
+===================
+
+Documents interfaces that are felt to be stable,
+as the main development of this interface has been completed.
+
+The interface can be changed to add new features, but the
+current interface will not break by doing this, unless grave
+errors or security problems are found in them.
+
+Userspace programs can start to rely on these interfaces, but they must
+be aware of changes that can occur before these interfaces move to
+be marked stable.
+
+Programs that use these interfaces are strongly encouraged to add their
+name to the description of these interfaces, so that the kernel
+developers can easily notify them if any changes occur.
+
+.. kernel-abi:: $srctree/Documentation/ABI/testing
Documentation/admin-guide/abi.rst new file +11 -0
new file mode 100644
index 000000000000..3b9645c77469
@@ -0,0 +1,11 @@
+=====================
+Linux ABI description
+=====================
+
+.. toctree::
+   :maxdepth: 1
+
+   abi-stable
+   abi-testing
+   abi-obsolete
+   abi-removed
Documentation/admin-guide/index.rst +1 -0
index 8c60a8a32a1a..da3b10941639 100644
@@ -16,6 +16,7 @@ etc.
    README
    kernel-parameters
    devices
+   abi
 
 Here is a set of documents aimed at users who are trying to track down
 problems and bugs in particular.
Documentation/conf.py +2 -1
index 08aef4595059..a9449875b79a 100644
@@ -34,7 +34,8 @@ needs_sphinx = '1.2'
 # Add any Sphinx extension module names here, as strings. They can be
 # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
 # ones.
-extensions = ['kerneldoc', 'rstFlatTable', 'kernel_include', 'cdomain', 'kfigure']
+extensions = ['kerneldoc', 'rstFlatTable', 'kernel_include', 'cdomain',
+	      'kfigure', 'kernel_abi']
 
 # The name of the math extension changed on Sphinx 1.4
 if major == 1 and minor > 3:
Documentation/sphinx/kernel_abi.py new file +155 -0

155 lines not on this page · raw message

Signature · 1 line
2.9.3
#12 lore raw
In reply to Mauro Carvalho Chehab

Em Thu, 13 Apr 2017 07:08:43 -0300
Mauro Carvalho Chehab <[email protected]> escreveu:

Quoted 25 lines

That's the third attempt to add support for the Kernel ABI at the Documentation's admin guide.

The first approach was based on a generic extension that calls a random script. This one is based on a new Sphinx extension with adds a symbol specific for parsing ABI symbols.

It adds a new script (scripts/get_abi.pl) with can either search for ABI symbols that match a regular expression or outputs the entire documentation found inside a directory as a ReST book.

Adding the ABI description to the Linux documentation is as easy as adding a tab like:

.. kernel-abi:: $srctree/Documentation/ABI/obsolete

On version 3, I improved the script to better parse the ABI descriptions. On this version, it will identify if the description can be handled as a normal text. If so, it will escape characters that has special meaning on Sphinx. If it detects that the description syntax is too complex, it outputs inside a literal block.

Quoted 7 lines

Also on version 3, I opted to use 4 separate sections, one for each type of symbol. It also add an entry with the name of each ABI file, with has cross-references to the symbols defined on each file.

The parser was also improved to handle any content at the files that are before the ABI tags.

The HTML formatted result can be seen at:
http://www.infradead.org/~mchehab/kernel_docs/admin-guide/abi.html

And the PDF formatted result at (pages 151 to 565):
http://www.infradead.org/~mchehab/kernel_docs_pdf/linux-user.pdf

Thanks,
Mauro

A message that is not in the archive (sent off-list or not yet received): [email protected]

Reviewed-by
#14 lore raw

Re: [PATCH v2 02/11] ABI: fix some syntax issues at the ABI database

Documentation/ABI/testing/sysfs-class-cxl line 4

Quoted 12 lines · Mauro Carvalho Chehab
Documentation/ABI/testing/sysfs-class-cxl +3 -3
index 640f65e79ef1..d0b32452dfe1 100644
@@ -1,6 +1,6 @@
-Note: Attributes that are shared between devices are stored in the directory
-pointed to by the symlink device/.
-Example: The real path of the attribute /sys/class/cxl/afu0.0s/irqs_max is
+Please notice that attributes that are shared between devices are stored in
+the directory pointed to by the symlink device/.
+For example, the real path of the attribute /sys/class/cxl/afu0.0s/irqs_max is
 /sys/class/cxl/afu0.0s/device/irqs_max, i.e. /sys/class/cxl/afu0.0/irqs_max.

If you end up respinning this, I'd prefer "Note that" or "Please note that" rather than "Please notice". Otherwise, for cxl:

Signature · 2 lines
Andrew Donnellan              OzLabs, ADL Canberra
[email protected]  IBM Australia Limited
maintainer
#15 lore raw
In reply to Mauro Carvalho Chehab
Quoted 8 lines · On Thu, 13 Apr 2017 07:08:43 -0300 Mauro Carvalho Chehab…

That's the third attempt to add support for the Kernel ABI at the Documentation's admin guide.

The first approach was based on a generic extension that calls a random script. This one is based on a new Sphinx extension with adds a symbol specific for parsing ABI symbols.

Quoted 4 lines

It adds a new script (scripts/get_abi.pl) with can either search for ABI symbols that match a regular expression or outputs the entire documentation found inside a directory as a ReST book.

So I've finally taken a quick look at this. I'm not quite ready to take it for 4.12 at this point, but I guess I'm running out of reasons to block it in general..:)

One question, though: is there a reason for the split between the sphinx extension and the Perl script that does the work? Could it all happen in the extension directly instead? It seems like a lot of moving parts.

Thanks,

jon

#16 lore raw

Em Thu, 20 Apr 2017 15:40:00 -0600
Jonathan Corbet <[email protected]> escreveu:

Quoted 11 lines
Quoted 8 lines · On Thu, 13 Apr 2017 07:08:43 -0300 Mauro Carvalho Chehab…

That's the third attempt to add support for the Kernel ABI at the Documentation's admin guide.

The first approach was based on a generic extension that calls a random script. This one is based on a new Sphinx extension with adds a symbol specific for parsing ABI symbols.

Quoted 8 lines
Quoted 4 lines

It adds a new script (scripts/get_abi.pl) with can either search for ABI symbols that match a regular expression or outputs the entire documentation found inside a directory as a ReST book.

So I've finally taken a quick look at this. I'm not quite ready to take it for 4.12 at this point, but I guess I'm running out of reasons to block it in general..:)

Good!

Quoted 4 lines

One question, though: is there a reason for the split between the sphinx extension and the Perl script that does the work? Could it all happen in the extension directly instead? It seems like a lot of moving parts.

There are a couple of reasons:

- On the last feedback from you and Jani about MAINTAINERS parser, you both suggested that, if we would be parsing MAINTAINERS, such functionality should be at get_maintainer.pl. So, I tried to follow the same way as get_maintainer: to have a single script that would be in charge of handling ABI parsing;

- get_abi.pl doesn't only generate ReST documentation. It also query the ABI database. So, with get_abi.pl, do things like:

	$ ./scripts/get_abi.pl search usbip_status

/sys/devices/platform/usbip-vudc.%d/usbip_status
------------------------------------------------

Kernel version: 4.6
Date: April 2016
Contact: Krzysztof Opasiak <[email protected]>
Defined on file: Documentation/ABI/testing/sysfs-platform-usbip-vudc

Description:

Current status of the device.
Allowed values:
1 - Device is available and can be exported 2 - Device is currently exported
3 - Fatal error occurred during communication
with peer

And even use regex, querying for multiple ABI symbols:

	$ ./scripts/get_abi.pl search .*bus.*devices/.*power.*usb.* 

/sys/bus/usb/devices/.../power/usb2_hardware_lpm
------------------------------------------------

Date: September 2011
Contact: Andiry Xu <[email protected]>
Defined on file: Documentation/ABI/testing/sysfs-bus-usb

Description:

If CONFIG_PM is set and a USB 2.0 lpm-capable device is plugged in to a xHCI host which support link PM, it will perform a LPM test; if the test is passed and host supports USB2 hardware LPM (xHCI 1.0 feature), USB2 hardware LPM will be enabled for the device and the USB device directory will contain a file named power/usb2_hardware_lpm. The file holds a string value (enable or disable) indicating whether or not USB2 hardware LPM is enabled for the device. Developer can write y/Y/1 or n/N/0 to the file to enable/disable the feature.

/sys/bus/usb/devices/.../power/usb2_lpm_besl
--------------------------------------------

Date: May 2013
Contact: Mathias Nyman <[email protected]>
Defined on file: Documentation/ABI/testing/sysfs-bus-usb

Description:

USB 2.0 devices that support hardware link power management (LPM) L1 sleep state now use a best effort service latency value (BESL) to indicate the best effort to resumption of service to the device after the initiation of the resume event.
If the device does not have a preferred besl value then the host can select one instead. This usb2_lpm_besl attribute allows to tune the host selected besl value in order to tune power saving and service latency.

Supported values are 0 - 15.
More information on how besl values map to microseconds can be found in USB 2.0 ECN Errata for Link Power Management, section 4.10)

/sys/bus/usb/devices/.../power/usb2_lpm_l1_timeout
--------------------------------------------------

Date: May 2013
Contact: Mathias Nyman <[email protected]>
Defined on file: Documentation/ABI/testing/sysfs-bus-usb

Description:

USB 2.0 devices may support hardware link power management (LPM) L1 sleep state. The usb2_lpm_l1_timeout attribute allows tuning the timeout for L1 inactivity timer (LPM timer), e.g. needed inactivity time before host requests the device to go to L1 sleep. Useful for power management tuning.
Supported values are 0 - 65535 microseconds.

/sys/bus/usb/devices/.../power/usb3_hardware_lpm_u1
---------------------------------------------------

Date: November 2015
Contact: Kevin Strasser <[email protected]>
Lu Baolu <[email protected]>
Defined on file: Documentation/ABI/testing/sysfs-bus-usb

Description:

If CONFIG_PM is set and a USB 3.0 lpm-capable device is plugged in to a xHCI host which supports link PM, it will check if U1 and U2 exit latencies have been set in the BOS descriptor; if the check is passed and the host supports USB3 hardware LPM, USB3 hardware LPM will be enabled for the device and the USB device directory will contain two files named power/usb3_hardware_lpm_u1 and power/usb3_hardware_lpm_u2. These files hold a string value (enable or disable) indicating whether or not USB3 hardware LPM U1 or U2 is enabled for the device.

(the output in this mode not ReST)

- I'm not a python programmer ;-) I just took Markus "generic" kernel-cmd code, hardcoding there a call to the script.

With (a lot of) time, I would likely be able to find a solution to add the entire ABI logic there, but, in this case, we would lose the capability of calling the script without Sphinx.

Thanks,
Mauro

#17 lore raw

Am 21.04.2017 um 01:21 schrieb Mauro Carvalho Chehab <[email protected]>:

Quoted 6 lines

- I'm not a python programmer ;-) I just took Markus "generic" kernel-cmd code, hardcoding there a call to the script.

With (a lot of) time, I would likely be able to find a solution to add the entire ABI logic there, but, in this case, we would lose the capability of calling the script without Sphinx.

Hi Mauro,

I have no problem with calling the perl script, but your last sentence is not correct: We can implement a python module, which is used by sphinx and we can add a command line as well.

--Markus--

#18 lore raw

Em Fri, 21 Apr 2017 08:37:45 +0200
Markus Heiser <[email protected]> escreveu:

Quoted 9 lines

Am 21.04.2017 um 01:21 schrieb Mauro Carvalho Chehab <[email protected]>:

Quoted 6 lines

- I'm not a python programmer ;-) I just took Markus "generic" kernel-cmd code, hardcoding there a call to the script.

With (a lot of) time, I would likely be able to find a solution to add the entire ABI logic there, but, in this case, we would lose the capability of calling the script without Sphinx.

Quoted 5 lines

Hi Mauro,

I have no problem with calling the perl script, but your last sentence is not correct: We can implement a python module, which is used by sphinx and we can add a command line as well.

Markus,

Yeah, I guess technically it would be possible to make a Sphinx plugin that would also allow have a command line interface. I don't like this kind of option, because the code can be come messy.

A better design would be to create a library and make two interfaces for it, one for the ReST plugin and another one to be called via a command line, but, in this case, we'll need to maintain 3 interdependent components (library, command line, Sphinx plugin) instead of two (almost) independent ones (a script and a Sphinx plugin).

So, IMO, the design I took is a good one, and it has a big advantage:
writing in perl is a way easier for me, and I can benefit from my knowledge to write a script that performs well. On my desktop, it can parse the entire ABI, search for a string there and output its result in 100ms:

$ time ./scripts/get_abi.pl search usbip_status

/sys/devices/platform/usbip-vudc.%d/usbip_status
------------------------------------------------

Kernel version: 4.6
Date: April 2016
Contact: Krzysztof Opasiak <[email protected]>
Defined on file: Documentation/ABI/testing/sysfs-platform-usbip-vudc

Description:

Current status of the device.
Allowed values:
1 - Device is available and can be exported
2 - Device is currently exported
3 - Fatal error occurred during communication
with peer

real 0m0.112s
user 0m0.106s
sys 0m0.005s

---

With regards to the decision of using perl instead of python, see below. One might thing it is rant. It isn't. It is just a matter of optimizing my development time.

I have lots of bad experiences with patchwork and even with cgit (running on an old LTS debian machine) due to the lack of a consistent backward compatible API on python.

Most of my bad experiences on python scripts is related to how badly it handles a file input with an unknown charset and unsigned chars > 0x7f. If Python can't recognize the a char as a valid ascii character (or the charset was not explicity defined - or the script doesn't
know what's the original encoding charset), the script crashes
(ok, one could add a "try" block, but it is very painful to do that all over the code). Also, the way the charset is specified on a python script changed several times during 2.x development (causing incompatible changes), and again on 3.x. It is even worse if a python script is called by some other script, as, in such case, Python (not sure if all versions) ignores script headers like:

	# -*- coding: utf-8 -*-

with would otherwise tell what's the default encoding.

If you look at patchwork git tree, you'll see that it took a really long time since when the first patch trying to address those issues until the last one was merged.

That's the first patch there[1]:

	commit ea39a9952e3fa647ebcb4bf16981ce941ec5236a
	Author: Mauro Carvalho Chehab <[email protected]>
	Date:   Tue Nov 18 23:00:32 2008 -0200

	    Fix non-ascii character encodings on xmlrpc interface

That seems to be the last one[2]:

	commit 880fc52d2d4ccdcbf4a7b76f1b4ba6b9e7482dff
	Author: Siddhesh Poyarekar <[email protected]>
	Date:   Mon Jul 14 10:21:32 2014 +0800

	    parsemail: Fallback to common charsets when charset is None or x-unknown

AFAIKT, none of those charset fixes are due to a code regression, but, instead, fixing parsing on different places of the code. So, it took at least 6 years to get it right there.

So, my decision of writing it in perl is basically due to the fact that I can write a reliable script it in a few hours, and won't need to be concerned that some weird char inside a file or some new scripting interpreter version would cause my script to crash.

[1] git://github.com/getpatchwork/patchwork
[2] I guess I hit other patchwork charset bugs after 2014.

Thanks,
Mauro