Skip to content

Commit

Permalink
fixup! layers: SCM support
Browse files Browse the repository at this point in the history
  • Loading branch information
jkloetzke committed Aug 11, 2024
1 parent 9311b3e commit ad124b4
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 21 deletions.
6 changes: 4 additions & 2 deletions pym/bob/cmds/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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)

10 changes: 6 additions & 4 deletions pym/bob/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -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``.
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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()

Expand All @@ -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):
Expand Down
26 changes: 11 additions & 15 deletions pym/bob/layers.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)
5 changes: 5 additions & 0 deletions pym/bob/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down

0 comments on commit ad124b4

Please sign in to comment.