[PATCH 3/3] utils.py: Prefer the one which matches branchname for depends layer


Robert Yang
 

The meta-xilinx was mata-xilinx/meta-xilinx-bsps, and now upstream has changed
it to mata-xilinx/meta-xilinx-core, but get_dependency_layer always returns the
first one (mata-xilinx/meta-xilinx-bsps) found, which causes errors like:

$ ./update.py -b master-wr -l meta-xilinx-bsp
ERROR: Dependency meta-xilinx of layer meta-xilinx-bsp does not have branch record for branch master-wr

And for build:
Layer 'wr-xilinx-zynqmp' depends on layer 'xilinx', but this layer is not enabled in your configuration

Prefer the one which matches branchname to fix the problem

Signed-off-by: Robert Yang <liezhi.yang@...>
---
layerindex/utils.py | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/layerindex/utils.py b/layerindex/utils.py
index 4b6aeca..a1f689d 100644
--- a/layerindex/utils.py
+++ b/layerindex/utils.py
@@ -75,7 +75,7 @@ def is_deps_satisfied(req_col, req_ver, collections):
# Return False when not found
return False

-def get_dependency_layer(depname, version_str=None, logger=None):
+def get_dependency_layer(depname, layerbranch, version_str=None, logger=None):
from layerindex.models import LayerItem, LayerBranch

# Get any LayerBranch with a layer that has a name that matches depmod, or
@@ -87,13 +87,20 @@ def get_dependency_layer(depname, version_str=None, logger=None):
if not res:
return None

- # If there is no version constraint, return the first one found.
+ # If there is no version constraint:
if not version_str:
+ # Prefer the one which matches branchname
+ required_branchname = layerbranch.branch.name
+ for lb in res:
+ if required_branchname == lb.branch.name:
+ return lb.layer
+
+ # Or return the first one found.
return res[0].layer

(operator, dep_version) = version_str.split()
- for layerbranch in res:
- layer_ver = layerbranch.version
+ for lb in res:
+ layer_ver = lb.version

# If there is no version in the found layer, then don't use this layer.
if not layer_ver:
@@ -105,7 +112,7 @@ def get_dependency_layer(depname, version_str=None, logger=None):
raise vse

if success:
- return layerbranch.layer
+ return lb.layer

return None

@@ -159,7 +166,7 @@ def _add_dependency(var, name, layerbranch, config_data, logger=None, required=T
ver_str = ver_list[0]

try:
- dep_layer = get_dependency_layer(dep, ver_str, logger)
+ dep_layer = get_dependency_layer(dep, layerbranch, ver_str, logger)
except bb.utils.VersionStringException as vse:
if logger:
logger.error('Error getting %s %s for %s\n%s' %(name, dep. layer_name, str(vse)))
--
2.37.1