summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'bitbake/lib/bb/utils.py')
-rw-r--r--bitbake/lib/bb/utils.py78
1 files changed, 64 insertions, 14 deletions
diff --git a/bitbake/lib/bb/utils.py b/bitbake/lib/bb/utils.py
index 9b28952231..31ec2b7c9a 100644
--- a/bitbake/lib/bb/utils.py
+++ b/bitbake/lib/bb/utils.py
@@ -1201,7 +1201,19 @@ def edit_metadata_file(meta_file, variables, varfunc):
1201 1201
1202 1202
1203def edit_bblayers_conf(bblayers_conf, add, remove): 1203def edit_bblayers_conf(bblayers_conf, add, remove):
1204 """Edit bblayers.conf, adding and/or removing layers""" 1204 """Edit bblayers.conf, adding and/or removing layers
1205 Parameters:
1206 bblayers_conf: path to bblayers.conf file to edit
1207 add: layer path (or list of layer paths) to add; None or empty
1208 list to add nothing
1209 remove: layer path (or list of layer paths) to remove; None or
1210 empty list to remove nothing
1211 Returns a tuple:
1212 notadded: list of layers specified to be added but weren't
1213 (because they were already in the list)
1214 notremoved: list of layers that were specified to be removed
1215 but weren't (because they weren't in the list)
1216 """
1205 1217
1206 import fnmatch 1218 import fnmatch
1207 1219
@@ -1210,6 +1222,13 @@ def edit_bblayers_conf(bblayers_conf, add, remove):
1210 pth = pth[:-1] 1222 pth = pth[:-1]
1211 return pth 1223 return pth
1212 1224
1225 approved = bb.utils.approved_variables()
1226 def canonicalise_path(pth):
1227 pth = remove_trailing_sep(pth)
1228 if 'HOME' in approved and '~' in pth:
1229 pth = os.path.expanduser(pth)
1230 return pth
1231
1213 def layerlist_param(value): 1232 def layerlist_param(value):
1214 if not value: 1233 if not value:
1215 return [] 1234 return []
@@ -1218,49 +1237,80 @@ def edit_bblayers_conf(bblayers_conf, add, remove):
1218 else: 1237 else:
1219 return [remove_trailing_sep(value)] 1238 return [remove_trailing_sep(value)]
1220 1239
1221 notadded = []
1222 notremoved = []
1223
1224 addlayers = layerlist_param(add) 1240 addlayers = layerlist_param(add)
1225 removelayers = layerlist_param(remove) 1241 removelayers = layerlist_param(remove)
1226 1242
1227 # Need to use a list here because we can't set non-local variables from a callback in python 2.x 1243 # Need to use a list here because we can't set non-local variables from a callback in python 2.x
1228 bblayercalls = [] 1244 bblayercalls = []
1245 removed = []
1246 plusequals = False
1247 orig_bblayers = []
1248
1249 def handle_bblayers_firstpass(varname, origvalue, op, newlines):
1250 bblayercalls.append(op)
1251 if op == '=':
1252 del orig_bblayers[:]
1253 orig_bblayers.extend([canonicalise_path(x) for x in origvalue.split()])
1254 return (origvalue, None, 2, False)
1229 1255
1230 def handle_bblayers(varname, origvalue, op, newlines): 1256 def handle_bblayers(varname, origvalue, op, newlines):
1231 bblayercalls.append(varname)
1232 updated = False 1257 updated = False
1233 bblayers = [remove_trailing_sep(x) for x in origvalue.split()] 1258 bblayers = [remove_trailing_sep(x) for x in origvalue.split()]
1234 if removelayers: 1259 if removelayers:
1235 for removelayer in removelayers: 1260 for removelayer in removelayers:
1236 matched = False
1237 for layer in bblayers: 1261 for layer in bblayers:
1238 if fnmatch.fnmatch(layer, removelayer): 1262 if fnmatch.fnmatch(canonicalise_path(layer), canonicalise_path(removelayer)):
1239 updated = True 1263 updated = True
1240 matched = True
1241 bblayers.remove(layer) 1264 bblayers.remove(layer)
1265 removed.append(removelayer)
1242 break 1266 break
1243 if not matched: 1267 if addlayers and not plusequals:
1244 notremoved.append(removelayer)
1245 if addlayers:
1246 for addlayer in addlayers: 1268 for addlayer in addlayers:
1247 if addlayer not in bblayers: 1269 if addlayer not in bblayers:
1248 updated = True 1270 updated = True
1249 bblayers.append(addlayer) 1271 bblayers.append(addlayer)
1250 else:
1251 notadded.append(addlayer)
1252 del addlayers[:] 1272 del addlayers[:]
1253 1273
1254 if updated: 1274 if updated:
1275 if op == '+=' and not bblayers:
1276 bblayers = None
1255 return (bblayers, None, 2, False) 1277 return (bblayers, None, 2, False)
1256 else: 1278 else:
1257 return (origvalue, None, 2, False) 1279 return (origvalue, None, 2, False)
1258 1280
1259 edit_metadata_file(bblayers_conf, ['BBLAYERS'], handle_bblayers) 1281 with open(bblayers_conf, 'r') as f:
1282 (_, newlines) = edit_metadata(f, ['BBLAYERS'], handle_bblayers_firstpass)
1260 1283
1261 if not bblayercalls: 1284 if not bblayercalls:
1262 raise Exception('Unable to find BBLAYERS in %s' % bblayers_conf) 1285 raise Exception('Unable to find BBLAYERS in %s' % bblayers_conf)
1263 1286
1287 # Try to do the "smart" thing depending on how the user has laid out
1288 # their bblayers.conf file
1289 if bblayercalls.count('+=') > 1:
1290 plusequals = True
1291
1292 removelayers_canon = [canonicalise_path(layer) for layer in removelayers]
1293 notadded = []
1294 for layer in addlayers:
1295 layer_canon = canonicalise_path(layer)
1296 if layer_canon in orig_bblayers and not layer_canon in removelayers_canon:
1297 notadded.append(layer)
1298 notadded_canon = [canonicalise_path(layer) for layer in notadded]
1299 addlayers[:] = [layer for layer in addlayers if canonicalise_path(layer) not in notadded_canon]
1300
1301 (updated, newlines) = edit_metadata(newlines, ['BBLAYERS'], handle_bblayers)
1302 if addlayers:
1303 # Still need to add these
1304 for addlayer in addlayers:
1305 newlines.append('BBLAYERS += "%s"\n' % addlayer)
1306 updated = True
1307
1308 if updated:
1309 with open(bblayers_conf, 'w') as f:
1310 f.writelines(newlines)
1311
1312 notremoved = list(set(removelayers) - set(removed))
1313
1264 return (notadded, notremoved) 1314 return (notadded, notremoved)
1265 1315
1266 1316