Skip to contentSkip to conversation

bitbake-setup: ensure that config_id is always an absolute path

PATCH New Alexander Kanavin 1 participant 3 messages Mar 9

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/3 bitbake-setup: ensure that config_id is always an absolute path

From: Alexander Kanavin <[email protected]>

If config_id (given on command line in 'init' operation) is provided and interpreted as a relative path to a local file (by checking for the file existence), it should be recorded into configuration instance as an absolute path.

Otherwise status/update operations will fail if executed from a different directory that the template file was in, as they won't be able to find the file.

Note that the patch context doesn't show where having the absolute path actually matters:
further down in the function, config_id is used to set a 'non-interactive-cmdline-options' property in configuration instance dictionary. This property is used by status/update operations.

---
 bin/bitbake-setup | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
bin/bitbake-setup +2 -1
index bdf134aea..54f2015a2 100755
@@ -600,9 +600,10 @@ def obtain_config(top_dir, registry, args, source_overrides, d):
         config_id = args.config[0]
         config_parameters = args.config[1:]
         if os.path.exists(config_id):
+            config_id = os.path.abspath(config_id)
             logger.info("Reading configuration from local file\n    {}".format(config_id))
             upstream_config = {'type':'local',
-                               'path':os.path.abspath(config_id),
+                               'path':config_id,
                                'name':get_config_name(config_id),
                                'data':json.load(open(config_id))
                                }
Signature · 1 line
2.47.3
#1 lore raw

PATCH v2 2/3 bitbake-setup: are_layers_changed(): calculate local_revision only once

From: Alexander Kanavin <[email protected]>

There's no need to repeatedly do it in the loop, as it doesn't change.

Also reposition 'remotes' and 'changed' variables assignments, as this will aid the code readability after the following commit.

---
 bin/bitbake-setup | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
bin/bitbake-setup +4 -4
index 54f2015a2..19a6b5373 100755
@@ -742,12 +742,14 @@ def get_diff(file1, file2):
 
 def are_layers_changed(layers, layerdir, d):
     def _is_git_remote_changed(r_remote, repodir):
-        changed = False
         rev = r_remote['rev']
         branch = r_remote.get('branch', None)
 
-        remotes = _get_remotes(r_remote)
+        rev_parse_result = bb.process.run('git -C {} rev-parse HEAD'.format(os.path.join(layerdir, repodir)))
+        local_revision = rev_parse_result[0].strip()
 
+        remotes = _get_remotes(r_remote)
+        changed = False
         for remote in remotes:
             type,host,path,user,pswd,params = bb.fetch.decodeurl(remote)
             fetchuri = bb.fetch.encodeurl(('git',host,path,user,pswd,params))
@@ -756,8 +758,6 @@ def are_layers_changed(layers, layerdir, d):
             else:
                 fetcher = bb.fetch.FetchData("{};protocol={};rev={};nobranch=1;destsuffix={}".format(fetchuri,type,rev,repodir), d)
             upstream_revision = fetcher.method.latest_revision(fetcher, d, 'default')
-            rev_parse_result = bb.process.run('git -C {} rev-parse HEAD'.format(os.path.join(layerdir, repodir)))
-            local_revision = rev_parse_result[0].strip()
             if upstream_revision != local_revision:
                 changed = True
                 logger.info('Layer repository {} checked out into {} updated revision {} from {} to {}'.format(remote, os.path.join(layerdir, repodir), rev, local_revision, upstream_revision))
Signature · 1 line
2.47.3
#2 lore raw

PATCH v2 3/3 bitbake-setup: correctly determine latest revision in status/update when it is fixed to a commit id

In reply to Alexander Kanavin

From: Alexander Kanavin <[email protected]>

The code was relying on git fetcher's latest_revision() method, which works properly if the revision in the json config template is set to a branch or a tag, but does not work if it is set to a fixed revision (the method will return the latest revision on the respective branch, and bitbake-setup will incorrectly determine that the layer needs to be updated to that revision).

Add a guard to check if the revision is a fixed commit id, and do a direct revision comparison if so, skipping the fetcher query.

[YOCTO #16190]

---
 bin/bitbake-setup | 7 +++++++
 1 file changed, 7 insertions(+)
bin/bitbake-setup +7 -0
index 19a6b5373..ca4461b1e 100755
@@ -742,11 +742,18 @@ def get_diff(file1, file2):
 
 def are_layers_changed(layers, layerdir, d):
     def _is_git_remote_changed(r_remote, repodir):
+        from bb.fetch2.git import sha1_re
+
         rev = r_remote['rev']
         branch = r_remote.get('branch', None)
 
         rev_parse_result = bb.process.run('git -C {} rev-parse HEAD'.format(os.path.join(layerdir, repodir)))
         local_revision = rev_parse_result[0].strip()
+        if sha1_re.match(rev):
+            if rev != local_revision:
+                logger.info('Layer repository checked out into {} is at revision {} but should be at {}'.format(os.path.join(layerdir, repodir),local_revision, rev))
+                return True
+            return False
 
         remotes = _get_remotes(r_remote)
         changed = False
Signature · 1 line
2.47.3