[bitbake-devel,2/2] bitbake: siggen: clean_basepath: improve perfo and readability

Submitted by Jean-Francois Dagenais on Aug. 24, 2020, 3:48 p.m. | Patch ID: 175615

Details

Message ID 20200824154836.23600-2-jeff.dagenais@gmail.com
State Accepted
Commit 27b53186fa67d281d29b2f8e15bcff8dc2557b8a
Headers show

Commit Message

Jean-Francois Dagenais Aug. 24, 2020, 3:48 p.m.
This change improves performance by reducing runtime about 33% for typical
inputs. (using test_clean_basepath_performance)

It is also easier to read, and slightly more resilient to future changes since it doesn't
mention 'virtual' anymore.

Signed-off-by: Jean-Francois Dagenais <jeff.dagenais@gmail.com>
Co-Developed-by: Maxime Roussin-Bélanger <maxime.roussinbelanger@gmail.com>
Sigend-off-by: Maxime Roussin-Bélanger <maxime.roussinbelanger@gmail.com>
---
 lib/bb/siggen.py | 30 ++++++++++++++++++++----------
 1 file changed, 20 insertions(+), 10 deletions(-)

Patch hide | download patch | download mbox

diff --git a/lib/bb/siggen.py b/lib/bb/siggen.py
index ad49d1e2..1456324a 100644
--- a/lib/bb/siggen.py
+++ b/lib/bb/siggen.py
@@ -746,16 +746,26 @@  def list_inline_diff(oldlist, newlist, colors=None):
             ret.append(item)
     return '[%s]' % (', '.join(ret))
 
-def clean_basepath(a):
-    mc = None
-    if a.startswith("mc:"):
-        _, mc, a = a.split(":", 2)
-    b = a.rsplit("/", 2)[1] + '/' + a.rsplit("/", 2)[2]
-    if a.startswith("virtual:"):
-        b = b + ":" + a.rsplit(":", 2)[0]
-    if mc:
-        b = b + ":mc:" + mc
-    return b
+def clean_basepath(basepath):
+    basepath, dir, recipe_task = basepath.rsplit("/", 2)
+    cleaned = dir + '/' + recipe_task
+
+    if basepath[0] == '/':
+        return cleaned
+
+    if basepath.startswith("mc:"):
+        mc, mc_name, basepath = basepath.split(":", 2)
+        mc_suffix = ':mc:' + mc_name
+    else:
+        mc_suffix = ''
+
+    # mc stuff now removed from basepath. Whatever was next, if present will be the first
+    # suffix. ':/', recipe path start, marks the end of this. Something like
+    # 'virtual:a[:b[:c]]:/path...' (b and c being optional)
+    if basepath[0] != '/':
+        cleaned += ':' + basepath.split(':/', 1)[0]
+
+    return cleaned + mc_suffix
 
 def clean_basepaths(a):
     b = {}

Comments

Jean-Francois Dagenais Aug. 24, 2020, 3:51 p.m.
> On Aug 24, 2020, at 11:48, Jean-Francois Dagenais <jeff.dagenais@gmail.com> wrote:
> 
> Sigend-off-by: Maxime Roussin-Bélanger <maxime.roussinbelanger@gmail.com>

Typo here... sorry. Resend?
-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.

View/Reply Online (#11622): https://lists.openembedded.org/g/bitbake-devel/message/11622
Mute This Topic: https://lists.openembedded.org/mt/76388042/3617530
Group Owner: bitbake-devel+owner@lists.openembedded.org
Unsubscribe: https://lists.openembedded.org/g/bitbake-devel/unsub  [oe-patchwork@oe-patch.openembedded.org]
-=-=-=-=-=-=-=-=-=-=-=-