summaryrefslogtreecommitdiff
path: root/meta-phosphor/classes/obmc-xmlpatch.bbclass
diff options
context:
space:
mode:
authorMatt Spinler <spinler@us.ibm.com>2016-08-25 21:04:09 +0300
committerPatrick Williams <patrick@stwcx.xyz>2016-09-13 21:15:51 +0300
commit1b8b9042df9bf87054a91891ef7513900b2b1eda (patch)
treeb6797e3314c197c9ee457ec92e76f06583d5f795 /meta-phosphor/classes/obmc-xmlpatch.bbclass
parent3337d89d2a020bb6657cdc328cf307ce0b113346 (diff)
downloadopenbmc-1b8b9042df9bf87054a91891ef7513900b2b1eda.tar.xz
Add XML patching bitbake class.
This commit adds a new obmc-xmlpatch class that can be inherited in a recipe to provide a do_patch task to patch XML files. The patch files are themselves XML, and must end in .patch.xml for do_patch to find them. This commit also includes Palmetto patches specified in palmetto.xml.patch.xml that are required to build the system inventory. Change-Id: Idae6ffd8e7a3aa247115ff3a840e047727ff0d1a Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Diffstat (limited to 'meta-phosphor/classes/obmc-xmlpatch.bbclass')
-rw-r--r--meta-phosphor/classes/obmc-xmlpatch.bbclass74
1 files changed, 74 insertions, 0 deletions
diff --git a/meta-phosphor/classes/obmc-xmlpatch.bbclass b/meta-phosphor/classes/obmc-xmlpatch.bbclass
new file mode 100644
index 000000000..9dc37507a
--- /dev/null
+++ b/meta-phosphor/classes/obmc-xmlpatch.bbclass
@@ -0,0 +1,74 @@
+#This class applies patches to an XML file during do_patch(). The
+#patches themselves are specified in XML in a separate file that must
+#be in SRC_URI and end in .patch.xml. The patch XML file must also
+#have a <targetFile> element that specifies the base name of the file
+#that needs to be patched.
+#
+#See patchxml.py for details on the XML patch format.
+#
+
+inherit pythonnative
+inherit obmc-phosphor-utils
+do_patch[depends] = "mrw-patch-native:do_populate_sysroot"
+
+
+def find_patch_files(d):
+ all_patches = listvar_to_list(d, 'SRC_URI')
+ xml_patches = filter(lambda x: x.endswith('.patch.xml') and
+ x.startswith('file://'), all_patches)
+
+ return [x.lstrip('file://') for x in xml_patches]
+
+
+def apply_xml_patch(base_patch_name, d):
+ import xml.etree.ElementTree as et
+ import subprocess
+
+ patch_file = os.path.join(d.getVar("WORKDIR", True), base_patch_name)
+
+ if not os.path.exists(patch_file):
+ bb.fatal("Could not find patch file " + patch_file +
+ " specified in SRC_URI")
+
+ patch_tree = et.parse(patch_file)
+ patch_root = patch_tree.getroot()
+ target_file_element = patch_root.find("targetFile")
+
+ if target_file_element is None:
+ bb.fatal("Could not find <targetFile> element in patch file "
+ + patch_file)
+ else:
+ xml = target_file_element.text
+
+ xml = os.path.join(d.getVar("S", True), xml)
+
+ if not os.path.exists(xml):
+ bb.fatal("Could not find XML file to patch: " + xml)
+
+ print("Applying XML fixes found in " + patch_file + " to " + xml)
+
+ cmd = []
+ cmd.append(os.path.join(d.getVar("bindir", True), "obmc-mrw/patchxml.py"))
+ cmd.append("-x")
+ cmd.append(xml)
+ cmd.append("-p")
+ cmd.append(patch_file)
+ cmd.append("-o")
+ cmd.append(xml + ".patched")
+
+ try:
+ subprocess.check_call(cmd)
+ except subprocess.CalledProcessError as e:
+ bb.fatal("Failed patching XML:\n%s" % e.output)
+
+ os.rename(xml, xml + ".orig")
+ os.rename(xml + ".patched", xml)
+
+
+python xmlpatch_do_patch() {
+
+ for patch in find_patch_files(d):
+ apply_xml_patch(patch, d)
+}
+
+do_patch[postfuncs] += "xmlpatch_do_patch"