diff --git a/pym/bob/cmds/layers.py b/pym/bob/cmds/layers.py index 98cda854..ffcca12d 100644 --- a/pym/bob/cmds/layers.py +++ b/pym/bob/cmds/layers.py @@ -2,8 +2,9 @@ from ..input import RecipeSet from ..layers import Layers, updateLayers -from ..utils import EventLoopWrapper, processDefines from ..tty import NORMAL, setVerbosity +from ..utils import EventLoopWrapper, processDefines +from .build.status import PackagePrinter def doLayers(argv, bobRoot): parser = argparse.ArgumentParser(prog="bob layers", description='Handle layers') @@ -32,5 +33,6 @@ def doLayers(argv, bobRoot): layers = Layers(recipes, loop) layers.collect(False, args.verbose) if args.action == "status": - layers.status(args.verbose) + pp = PackagePrinter(args.verbose, False, False) + layers.status(pp.show) diff --git a/pym/bob/input.py b/pym/bob/input.py index 22618eb9..12440d34 100644 --- a/pym/bob/input.py +++ b/pym/bob/input.py @@ -35,6 +35,9 @@ from yaml import load as yamlLoad, SafeLoader as YamlSafeLoader +class LayerNotFoundError(ParseError): + pass + def isPrefixPath(p1, p2): """Check if the initial elements of ``p2`` equal ``p1``. @@ -3436,6 +3439,7 @@ def __parse(self, envOverrides, platform, recipesRoot="", dryRun=False): if platform not in ('cygwin', 'darwin', 'linux', 'msys', 'win32'): raise ParseError("Invalid platform: " + platform) self.__platform = platform + self.__layers = [] self.__whiteList = set() if platform == 'win32': self.__whiteList |= set(["ALLUSERSPROFILE", "APPDATA", @@ -3518,9 +3522,6 @@ def __parse(self, envOverrides, platform, recipesRoot="", dryRun=False): self.__rootRecipe = Recipe.createVirtualRoot(self, sorted(filteredRoots), self.__properties) self.__addRecipe(self.__rootRecipe) - def resetLayers(self): - self.__layers = [] - def __parseLayer(self, layerSpec, maxVer, recipesRoot, dryRun): layer = layerSpec.getName() @@ -3530,7 +3531,8 @@ def __parseLayer(self, layerSpec, maxVer, recipesRoot, dryRun): rootDir = os.path.join(recipesRoot, os.path.join("layers", layer) if layer != "" else "") if not os.path.isdir(rootDir or "."): - raise ParseError(f"Layer '{layer}' does not exist!") + raise LayerNotFoundError(f"Layer '{layer}' does not exist!", + help="You probably want to run 'bob layers update' to fetch missing layers.") configYaml = os.path.join(rootDir, "config.yaml") def preValidate(data): diff --git a/pym/bob/layers.py b/pym/bob/layers.py index eb37dfd4..8e5e1932 100644 --- a/pym/bob/layers.py +++ b/pym/bob/layers.py @@ -1,10 +1,9 @@ import datetime import os -from .cmds.build.status import PackagePrinter -from .errors import BuildError, ParseError +from .errors import BuildError from .invoker import CmdFailedError, InvocationError, Invoker from .state import BobState -from .input import RecipeSet, Scm, YamlCache +from .input import LayerNotFoundError, RecipeSet, Scm, YamlCache from .utils import INVALID_CHAR_TRANS from .tty import DEBUG, EXECUTED, INFO, NORMAL, IMPORTANT, SKIPPED, WARNING, log @@ -92,6 +91,7 @@ async def __checkoutTask(self, verbose): os.makedirs(atticPath) atticPath = os.path.join(atticPath, atticName) os.rename(layerSrcPath, atticPath) + BobState().delLayerState(layerSrcPath) if not os.path.isdir(layerSrcPath): os.makedirs(layerSrcPath) @@ -137,12 +137,11 @@ def parse(self): def getSubLayers(self): return self.__subLayers - def status(self, verbose): + def status(self, printer): if self.__scm is None: return - pp = PackagePrinter(verbose, False, False) status = self.__scm.status(self.__layerDir) - pp.show(status, self.__layerDir) + printer(status, self.__layerDir) class Layers: def __init__(self, recipes, loop): @@ -173,28 +172,25 @@ def __collect(self, depth, update, verbose): self.__collect(depth + 1, update, verbose) def collect(self, update, verbose=0): - if self.__yamlCache is not None: - self.__yamlCache.open() + self.__yamlCache.open() try: rootLayers = Layer("", os.getcwd(), self.__recipes, self.__yamlCache) rootLayers.parse() self.__layers[0] = rootLayers.getSubLayers(); self.__collect(0, update, verbose) finally: - if self.__yamlCache is not None: - self.__yamlCache.close() + self.__yamlCache.close() - def status(self, verbose): - for level in self.__layers: + def status(self, printer): + for level in sorted(self.__layers.keys()): for layer in self.__layers[level]: - layer.status(verbose) + layer.status(printer) def updateLayers(recipes, loop, defines, verbose): try: recipes.parse(defines, dryRun=True) - except ParseError: + except LayerNotFoundError: pass - recipes.resetLayers() layers = Layers(recipes, loop) layers.collect(True, verbose) diff --git a/pym/bob/state.py b/pym/bob/state.py index 7c73aec1..daa912ca 100644 --- a/pym/bob/state.py +++ b/pym/bob/state.py @@ -558,6 +558,11 @@ def setLayerState(self, path, digest): self.__layerStates[path] = digest self.__save() + def delLayerState(self, path): + if path in self.__layerStates: + del self.__layerStates[path] + self.__save() + def getDirectories(self): return list(self.__dirStates.keys())