Skip to contentSkip to conversation

bitbake-setup: _symlink_local fix case when update

PATCH In review Anibal Limon 2 participants 6 messages Dec 22, 2025 – Jan 2

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bitbake-setup: _symlink_local fix case when update

When run an update with setup_dir containing a local symlinked source it fails because symlink already exists, so test for previous symlink existance and update it if not point to the same local source directory.

Fixes,

```
$ bitbake-setup update --setup_dir /home/workspaces/ls/meta-ls/bitbake-setup/ls-master/stm32-toolchain

...
Traceback (most recent call last):
  File "/home/workspaces/ls/meta-ls/bitbake/bin/bitbake-setup", line 1042, in <module>
    main()
    ~~~~^^
  File "/home/workspaces/ls/meta-ls/bitbake/bin/bitbake-setup", line 1035, in main
    args.func(top_dir, all_settings, args, d)
    ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/workspaces/ls/meta-ls/bitbake/bin/bitbake-setup", line 667, in build_update
    build_status(top_dir, settings, args, d, update=True)
    ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/workspaces/ls/meta-ls/bitbake/bin/bitbake-setup", line 652, in build_status
    update_build(new_upstream_config, confdir, setupdir, layerdir, d,
    ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                 update_bb_conf=args.update_bb_conf)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/workspaces/ls/meta-ls/bitbake/bin/bitbake-setup", line 340, in update_build
    sources_fixed_revisions = checkout_layers(layer_config, layerdir, d)
  File "/home/workspaces/ls/meta-ls/bitbake/bin/bitbake-setup", line 132, in checkout_layers
    _symlink_local(os.path.expanduser(r_local["path"]), os.path.join(layerdir,repodir))
    ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/workspaces/ls/meta-ls/bitbake/bin/bitbake-setup", line 114, in _symlink_local
    os.symlink(src, dst)
    ~~~~~~~~~~^^^^^^^^^^
FileExistsError: [Errno 17] File exists: '/home/workspaces/ls/meta-ls/layers' -> '/home/workspaces/ls/meta-ls/bitbake-setup/ls-master/stm32-toolc
hain/layers/ls-layers'
```
---
 bin/bitbake-setup | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
bin/bitbake-setup +13 -2
index 1ea6796b5..378fbdc91 100755
@@ -110,8 +110,19 @@ def checkout_layers(layers, layerdir, d):
             layers_fixed_revisions[r_name]['git-remote']['rev'] = revision
 
     def _symlink_local(src, dst):
-        logger.plain("Making a symbolic link {} pointing to {}".format(dst, src))
-        os.symlink(src, dst)
+        do_symlink = False
+
+        if os.path.islink(dst):
+            if not os.path.samefile(src, dst):
+                logger.plain("Updating symbolic link {} pointing to {}".format(dst, src))
+                os.remove(src)
+                do_symlink = True
+        else:
+            logger.plain("Making a symbolic link {} pointing to {}".format(dst, src))
+            do_symlink = True
+
+        if do_symlink:
+            os.symlink(src, dst)
 
     layers_fixed_revisions = copy.deepcopy(layers)
     repodirs = []
Signature · 1 line
2.47.3
#1 lore raw

bin/bitbake-setup def checkout_layers(layers, layerdir, d): · line 119

Quoted 5 lines · Anibal Limon
bin/bitbake-setup +5 -0
+        if os.path.islink(dst):
+            if not os.path.samefile(src, dst):
+                logger.plain("Updating symbolic link {} pointing to {}".format(dst, src))
+                os.remove(src)
+                do_symlink = True

dst is the symlink, but os.remove is taking src parameter. Is that correct?

bin/bitbake-setup def checkout_layers(layers, layerdir, d): · line 125

Quoted 6 lines
bin/bitbake-setup +6 -0
+        else:
+            logger.plain("Making a symbolic link {} pointing to {}".format(dst, src))
+            do_symlink = True
+
+        if do_symlink:
+            os.symlink(src, dst)

Is this logic complete? It seems to cover the use case when one local path is replaced with another local path in a json config, or when local path is unchanged, but maybe we should cover the situation where a git checkout is replaced by a local source as well?

This and the previous patch expose a gap in testing, perhaps status/update tests should be extended to cover local sources?

Alex

#2 lore raw
Quoted 12 lines · Alexander Kanavin

bin/bitbake-setup def checkout_layers(layers, layerdir, d):

Quoted 3 lines · Anibal Limon
bin/bitbake-setup +3 -0
+        if os.path.islink(dst):
+            if not os.path.samefile(src, dst):
+                logger.plain("Updating symbolic link {} pointing to

{}".format(dst, src))

Review

Quoted 2 lines
(quoted diff) +2 -0
+                os.remove(src)
+                do_symlink = True

dst is the symlink, but os.remove is taking src parameter. Is that correct?

It is wrong, updating.

Quoted 9 lines

Review

Quoted 3 lines
(quoted diff) +2 -0
+        else:
+            logger.plain("Making a symbolic link {} pointing to

{}".format(dst, src))

bin/bitbake-setup def checkout_layers(layers, layerdir, d): · line 125

Quoted 4 lines
bin/bitbake-setup +4 -0
+            do_symlink = True
+
+        if do_symlink:
+            os.symlink(src, dst)
Quoted 5 lines

Is this logic complete? It seems to cover the use case when one local path is replaced with another local path in a json config, or when local path is unchanged, but maybe we should cover the situation where a git checkout is replaced by a local source as well?

Right,
I think it should cover switching from local to remote or vice-versa too.

I'm using local sources, on the manifest:

```
....
        "ls-layers": {
            "local": {
                "path": "/home/workspaces/ls/meta-ls/layers'"
            }
        }
...
```

Then we run an update for a change on the manifest; it tries to make the symlink again and fails.

Quoted 4 lines

This and the previous patch expose a gap in testing, perhaps status/update tests should be extended to cover local sources?

Ack. I will look at the tests and send v2.

Quoted 3 lines

Alex

#3 lore raw
Quoted 5 lines · Anibal Limon
Quoted 2 lines

This and the previous patch expose a gap in testing, perhaps status/update tests should be extended to cover local sources?

Ack. I will look at the tests and send v2.

Just wanted to give a heads-up that I'm working on a more extensive set of fixes and test coverage improvements that incorporates both of your patches. So you don't need to complete a v2, but reviewing my patchset would be appreciated. I'll follow up with a link once I send it out.

Alex

#4 lore raw
Quoted 7 lines · Alexander Kanavin
Quoted 4 lines · Anibal Limon
Quoted 2 lines

This and the previous patch expose a gap in testing, perhaps status/update tests should be extended to cover local sources?

Quoted 8 lines
Quoted 1 line

Ack. I will look at the tests and send v2.

Just wanted to give a heads-up that I'm working on a more extensive set of fixes and test coverage improvements that incorporates both of your patches. So you don't need to complete a v2, but reviewing my patchset would be appreciated. I'll follow up with a link once I send it out.

Thanks for the heads up, and feel free to cc me.

Best!,
Anibal

Quoted 3 lines

Alex

#5 lore raw
Quoted 6 lines · Anibal Limon
Quoted 5 lines

Just wanted to give a heads-up that I'm working on a more extensive set of fixes and test coverage improvements that incorporates both of your patches. So you don't need to complete a v2, but reviewing my patchset would be appreciated. I'll follow up with a link once I send it out.

Thanks for the heads up, and feel free to cc me.

I just posted the set.

Alex