Bug 9318

Summary: sanity_conf_update() will erroneously find a var name match in comments
Product: [Build System, Metadata & Runtime] OE-Core Reporter: Bill Randle <bill.randle>
Component: Scripts and ToolsAssignee: Bill Randle <bill.randle>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: Medium+ CC: ross.burton
Version: 2.1   
Target Milestone: 2.1 M4   
Hardware: x86   
OS: Multiple   
Whiteboard:
OS type for building Yocto: --- Type of Regression: ---
Verified: Documentation change: No (bug/feature does not impact docs)

Description Bill Randle 2016-03-21 20:04:52 UTC
In sanity_conf_update(), in file meta/classes/sanity.bbclass, a call is made to sanity_conf_find_line(version_var_name, lines) with the intent to find a line like 'CONF_VERSION = "1"' and update the version number. However, the search is not anchored to the beginning of a line, so the search will find the var name in a comment and replace the comment with the new string. E.g., in the poky bblayers.conf file, the first three lines look like:

# POKY_BBLAYERS_CONF_VERSION is increased each time build/conf/bblayers.conf
# changes incompatibly
POKY_BBLAYERS_CONF_VERSION = "1"

If sanity_conf_update() is called to change the version to "2", the result will be:

POKY_BBLAYERS_CONF_VERSION = "2"
# changes incompatibly
POKY_BBLAYERS_CONF_VERSION = "1"

which is certainly not the expected result.

A simple fix is to anchor the search to the beginning of a line:

--- a/meta/classes/sanity.bbclass
+++ b/meta/classes/sanity.bbclass
@@ -20,7 +20,7 @@ def sanity_conf_find_line(pattern, lines): 
         if re.search(pattern, line)), (None, None))
 
 def sanity_conf_update(fn, lines, version_var_name, new_version):
-    index, line = sanity_conf_find_line(version_var_name, lines)
+    index, line = sanity_conf_find_line(r"^%s" % version_var_name, lines)
     lines[index] = '%s = "%d"\n' % (version_var_name, new_version)
     with open(fn, "w") as f:
         f.write(''.join(lines))
Comment 1 Bill Randle 2016-03-21 20:26:13 UTC
Submitted patch as outlined in the bug description to the oe-core mailing list. Also included some other minor cleanups in the same patch.