Kaydet (Commit) 84ef6d82 authored tarafından Samuel Thibault's avatar Samuel Thibault Kaydeden (comit) Stephan Bergmann

Build external lxml if not provided by system

except on windows, where gla11y will resort to python's internal xml parser,
which does not provide line numbers.

This allows gla11y to be runnable on all systems.

Change-Id: Ica4eb90f59bddfcefd783fc2ed9c8c27357e7572
Reviewed-on: https://gerrit.libreoffice.org/50115Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarStephan Bergmann <sbergman@redhat.com>
üst e215310d
......@@ -163,6 +163,7 @@ $(WORKDIR)/download: $(BUILDDIR)/config_$(gb_Side).mk $(SRCDIR)/download.lst $(S
$(call fetch_Optional,LIBXSLT,LIBXSLT_TARBALL) \
$(call fetch_Optional,LPSOLVE,LPSOLVE_TARBALL) \
$(call fetch_Optional,LXML,LXML_TARBALL) \
$(call fetch_Optional,MDDS,MDDS_TARBALL) \
......@@ -4017,6 +4017,7 @@ else
define gb_ExternalExecutable__register_python
$(call gb_ExternalExecutable_set_external,python,$(PYTHON_FOR_BUILD))
$(call gb_ExternalExecutable_set_precommand,python,PYTHONPATH=$$$$PYTHONPATH$$$${PYTHONPATH:+$$$${PYPATH:+:}}$$$$PYPATH)
......@@ -31,33 +31,84 @@ from __future__ import print_function
import os
import sys
import getopt
import lxml.etree as ET
import lxml.etree as ET
lxml = True
except ImportError:
import xml.etree.ElementTree as ET
lxml = False
progname = os.path.basename(sys.argv[0])
outfile = None
Werror = False
Wnone = False
errors = 0
warnings = 0
def errstr(elm):
def step_elm(elm):
Return the XML class path step corresponding to elm.
This can be empty if the elm does not have any class or id.
step = elm.attrib.get('class')
if step is None:
step = ""
oid = elm.attrib.get('id')
if oid is not None:
oid = oid.encode('ascii','ignore').decode('ascii')
step += "[@id='%s']" % oid
if len(step) > 0:
step += '/'
return step
def find_elm(root, elm):
Print the line number of the element
Return the XML class path of the element from the given root.
This is the slow version used when getparent is not available.
if root == elm:
return ""
for o in root:
path = find_elm(o, elm)
if path is not None:
step = step_elm(o)
return step + path
return None
return str(elm.sourceline)
def err(filename, elm, msg):
def elm_prefix(filename, elm):
Return the display prefix of the element
if elm == None or not lxml:
return "%s:" % filename
return "%s:%u" % (filename, elm.sourceline)
def elm_name(elm):
Return a display name of the element
if elm is not None:
name = ""
if 'class' in elm.attrib:
name = "'%s' " % elm.attrib['class']
if 'id' in elm.attrib:
id = elm.attrib['id'].encode('ascii','ignore').decode('ascii')
name += "'%s' " % id
return name
return ""
def err(filename, tree, elm, msg):
global errors
if elm == None:
prefix = "%s:" % filename
prefix = "%s:%s" % (filename, errstr(elm))
prefix = elm_prefix(filename, elm)
errors += 1
msg = "%s ERROR: %s" % (prefix, msg)
print(msg.encode('ascii', 'ignore'))
msg = "%s ERROR: %s%s" % (prefix, elm_name(elm), msg)
if outfile is not None:
print(msg, file=outfile)
def warn(filename, elm, msg):
......@@ -66,61 +117,73 @@ def warn(filename, elm, msg):
if Wnone:
prefix = "%s:%s" % (filename, errstr(elm))
prefix = elm_prefix(filename, elm)
if Werror:
errors += 1