@@ -109,6 +109,18 @@ def get_dependency_layer(depname, version_str=None, logger=None):
return None
+def remove_layerdeps(layer_name, need_remove, logger):
+ if need_remove:
+ import settings
+ remove_layer_dependencies = getattr(settings, 'REMOVE_LAYER_DEPENDENCIES', False)
+ if remove_layer_dependencies:
+ logger.info('Removing obsolete dependencies "%s" for layer %s' % (need_remove, layer_name))
+ need_remove.delete()
+ else:
+ logger.warn('Dependencies "%s" are not in %s\'s conf/layer.conf' % (need_remove, layer_name))
+ logger.warn('Either set REMOVE_LAYER_DEPENDENCIES to remove them from the database, or fix conf/layer.conf')
+
+
def add_dependencies(layerbranch, config_data, logger=None):
_add_dependency("LAYERDEPENDS", 'dependency', layerbranch, config_data, logger=logger)
@@ -124,10 +136,15 @@ def _add_dependency(var, name, layerbranch, config_data, logger=None, required=T
if layerbranch.collection:
var_name = layerbranch.collection
-
dep_list = config_data.getVar("%s_%s" % (var, var_name), True)
+ need_remove = LayerDependency.objects.filter(layerbranch=layerbranch).filter(required=required)
+
if not dep_list:
+ # The need_remove contains all of the deps or recs according to
+ # required is True or False, remove deps or recs immediately if
+ # there are no deps or recs in conf/layer.conf
+ remove_layerdeps(layer_name, need_remove, logger)
return
try:
@@ -136,7 +153,6 @@ def _add_dependency(var, name, layerbranch, config_data, logger=None, required=T
logger.debug('Error parsing %s_%s for %s\n%s' % (var, var_name, layer_name, str(vse)))
return
- need_remove = LayerDependency.objects.filter(layerbranch=layerbranch).filter(required=required)
for dep, ver_list in list(dep_dict.items()):
ver_str = None
if ver_list:
@@ -177,15 +193,7 @@ def _add_dependency(var, name, layerbranch, config_data, logger=None, required=T
layerdep.required = required
layerdep.save()
- if need_remove:
- import settings
- remove_layer_dependencies = getattr(settings, 'REMOVE_LAYER_DEPENDENCIES', False)
- if remove_layer_dependencies:
- logger.info('Removing obsolete dependencies "%s" for layer %s' % (need_remove, layer_name))
- need_remove.delete()
- else:
- logger.warn('Dependencies "%s" are not in %s\'s conf/layer.conf' % (need_remove, layer_name))
- logger.warn('Either set REMOVE_LAYER_DEPENDENCIES to remove them from the database, or fix conf/layer.conf')
+ remove_layerdeps(layer_name, need_remove, logger)
def set_layerbranch_collection_version(layerbranch, config_data, logger=None):
layerbranch.collection = get_layer_var(config_data, 'BBFILE_COLLECTIONS', logger)
The previous code didn't work when there is no deps or recs, it would return immediately without removing the on-existed dependencies, this patch fixes the problem. Signed-off-by: Robert Yang <liezhi.yang@windriver.com> --- layerindex/utils.py | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-)