mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-14 21:49:34 +03:00
make-options-docs: don't sort the options XML file
we need the file itself as a dependency for the docbook build, but we don't need it to be properly sorted at the nix level. push the sort out to a python script instead to save eval time. on the machine used to write this `nix-instantiate <nixos/nixos> -A system` went down from 7.1s to 5.4s and GC heap size decreased by 50MB (or 70MB max RSS).
This commit is contained in:
parent
97774c0487
commit
24eb353907
2 changed files with 34 additions and 2 deletions
28
nixos/lib/make-options-doc/sortXML.py
Normal file
28
nixos/lib/make-options-doc/sortXML.py
Normal file
|
@ -0,0 +1,28 @@
|
|||
import xml.etree.ElementTree as ET
|
||||
import sys
|
||||
|
||||
tree = ET.parse(sys.argv[1])
|
||||
# the xml tree is of the form
|
||||
# <expr><list> {all options, each an attrs} </list></expr>
|
||||
options = list(tree.getroot().find('list'))
|
||||
|
||||
def sortKey(opt):
|
||||
def order(s):
|
||||
if s.startswith("enable"):
|
||||
return 0
|
||||
if s.startswith("package"):
|
||||
return 1
|
||||
return 2
|
||||
|
||||
return [
|
||||
(order(p.attrib['value']), p.attrib['value'])
|
||||
for p in opt.findall('attr[@name="loc"]/list/string')
|
||||
]
|
||||
|
||||
# always ensure that the sort order matches the order used in the nix expression!
|
||||
options.sort(key=sortKey)
|
||||
|
||||
doc = ET.Element("expr")
|
||||
newOptions = ET.SubElement(doc, "list")
|
||||
newOptions.extend(options)
|
||||
ET.ElementTree(doc).write(sys.argv[2], encoding='utf-8')
|
Loading…
Add table
Add a link
Reference in a new issue