mirror of
git://git.yoctoproject.org/layerindex-web.git
synced 2025-07-19 20:59:01 +02:00
layerindex/recipeparse.py: refactor setup_tinfoil, checkout_layer_branch, parse_layer_conf to utils.py
Move functions to utils to be used by other classes. Signed-off-by: Liam R. Howlett <Liam.Howlett@WindRiver.com>
This commit is contained in:
parent
8915465007
commit
df492b1277
|
@ -42,9 +42,9 @@ def generate_patches(tinfoil, fetchdir, changeset, outputdir):
|
||||||
patchname = "%s.patch" % layer.name
|
patchname = "%s.patch" % layer.name
|
||||||
patches.append(patchname)
|
patches.append(patchname)
|
||||||
layerfetchdir = os.path.join(fetchdir, layer.get_fetch_dir())
|
layerfetchdir = os.path.join(fetchdir, layer.get_fetch_dir())
|
||||||
recipeparse.checkout_layer_branch(layerbranch, layerfetchdir)
|
utils.checkout_layer_branch(layerbranch, layerfetchdir)
|
||||||
layerdir = os.path.join(layerfetchdir, layerbranch.vcs_subdir)
|
layerdir = os.path.join(layerfetchdir, layerbranch.vcs_subdir)
|
||||||
config_data_copy = recipeparse.setup_layer(tinfoil.config_data, fetchdir, layerdir, layer, layerbranch)
|
config_data_copy = utils.setup_layer(tinfoil.config_data, fetchdir, layerdir, layer, layerbranch)
|
||||||
if outfile:
|
if outfile:
|
||||||
outfile.close()
|
outfile.close()
|
||||||
outfile = open(os.path.join(tmpoutdir, patchname), 'w')
|
outfile = open(os.path.join(tmpoutdir, patchname), 'w')
|
||||||
|
|
|
@ -20,31 +20,6 @@ class RecipeParseError(Exception):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.msg
|
return self.msg
|
||||||
|
|
||||||
def _setup_tinfoil(bitbakepath, enable_tracking):
|
|
||||||
sys.path.insert(0, bitbakepath + '/lib')
|
|
||||||
import bb.tinfoil
|
|
||||||
import bb.cooker
|
|
||||||
import bb.data
|
|
||||||
try:
|
|
||||||
tinfoil = bb.tinfoil.Tinfoil(tracking=enable_tracking)
|
|
||||||
except TypeError:
|
|
||||||
# old API
|
|
||||||
tinfoil = bb.tinfoil.Tinfoil()
|
|
||||||
if enable_tracking:
|
|
||||||
tinfoil.cooker.enableDataTracking()
|
|
||||||
tinfoil.prepare(config_only = True)
|
|
||||||
|
|
||||||
return tinfoil
|
|
||||||
|
|
||||||
def _parse_layer_conf(layerdir, data):
|
|
||||||
data.setVar('LAYERDIR', str(layerdir))
|
|
||||||
if hasattr(bb, "cookerdata"):
|
|
||||||
# Newer BitBake
|
|
||||||
data = bb.cookerdata.parse_config_file(os.path.join(layerdir, "conf", "layer.conf"), data)
|
|
||||||
else:
|
|
||||||
# Older BitBake (1.18 and below)
|
|
||||||
data = bb.cooker._parse(os.path.join(layerdir, "conf", "layer.conf"), data)
|
|
||||||
data.expandVarref('LAYERDIR')
|
|
||||||
|
|
||||||
|
|
||||||
def init_parser(settings, branch, bitbakepath, enable_tracking=False, nocheckout=False, classic=False, logger=None):
|
def init_parser(settings, branch, bitbakepath, enable_tracking=False, nocheckout=False, classic=False, logger=None):
|
||||||
|
@ -97,7 +72,7 @@ def init_parser(settings, branch, bitbakepath, enable_tracking=False, nocheckout
|
||||||
tempdir = tempfile.mkdtemp(dir=settings.TEMP_BASE_DIR)
|
tempdir = tempfile.mkdtemp(dir=settings.TEMP_BASE_DIR)
|
||||||
os.chdir(tempdir)
|
os.chdir(tempdir)
|
||||||
|
|
||||||
tinfoil = _setup_tinfoil(bitbakepath, enable_tracking)
|
tinfoil = utils.setup_tinfoil(bitbakepath, enable_tracking)
|
||||||
|
|
||||||
# Ensure TMPDIR exists (or insane.bbclass will blow up trying to write to the QA log)
|
# Ensure TMPDIR exists (or insane.bbclass will blow up trying to write to the QA log)
|
||||||
oe_tmpdir = tinfoil.config_data.getVar('TMPDIR', True)
|
oe_tmpdir = tinfoil.config_data.getVar('TMPDIR', True)
|
||||||
|
@ -110,14 +85,6 @@ def init_parser(settings, branch, bitbakepath, enable_tracking=False, nocheckout
|
||||||
|
|
||||||
return (tinfoil, tempdir)
|
return (tinfoil, tempdir)
|
||||||
|
|
||||||
def checkout_layer_branch(layerbranch, repodir, logger=None):
|
|
||||||
if layerbranch.actual_branch:
|
|
||||||
branchname = layerbranch.actual_branch
|
|
||||||
else:
|
|
||||||
branchname = layerbranch.branch.name
|
|
||||||
out = utils.runcmd("git checkout origin/%s" % branchname, repodir, logger=logger)
|
|
||||||
out = utils.runcmd("git clean -f -x", repodir, logger=logger)
|
|
||||||
|
|
||||||
def setup_layer(config_data, fetchdir, layerdir, layer, layerbranch):
|
def setup_layer(config_data, fetchdir, layerdir, layer, layerbranch):
|
||||||
# Parse layer.conf files for this layer and its dependencies
|
# Parse layer.conf files for this layer and its dependencies
|
||||||
# This is necessary not just because BBPATH needs to be set in order
|
# This is necessary not just because BBPATH needs to be set in order
|
||||||
|
@ -125,7 +92,7 @@ def setup_layer(config_data, fetchdir, layerdir, layer, layerbranch):
|
||||||
# or across layers, but also because custom variable values might be
|
# or across layers, but also because custom variable values might be
|
||||||
# set in layer.conf.
|
# set in layer.conf.
|
||||||
config_data_copy = bb.data.createCopy(config_data)
|
config_data_copy = bb.data.createCopy(config_data)
|
||||||
_parse_layer_conf(layerdir, config_data_copy)
|
utils.parse_layer_conf(layerdir, config_data_copy)
|
||||||
for dep in layerbranch.dependencies_set.all():
|
for dep in layerbranch.dependencies_set.all():
|
||||||
depurldir = dep.dependency.get_fetch_dir()
|
depurldir = dep.dependency.get_fetch_dir()
|
||||||
deprepodir = os.path.join(fetchdir, depurldir)
|
deprepodir = os.path.join(fetchdir, depurldir)
|
||||||
|
@ -133,7 +100,7 @@ def setup_layer(config_data, fetchdir, layerdir, layer, layerbranch):
|
||||||
if not deplayerbranch:
|
if not deplayerbranch:
|
||||||
raise RecipeParseError('Dependency %s of layer %s does not have branch record for branch %s' % (dep.dependency.name, layer.name, layerbranch.branch.name))
|
raise RecipeParseError('Dependency %s of layer %s does not have branch record for branch %s' % (dep.dependency.name, layer.name, layerbranch.branch.name))
|
||||||
deplayerdir = os.path.join(deprepodir, deplayerbranch.vcs_subdir)
|
deplayerdir = os.path.join(deprepodir, deplayerbranch.vcs_subdir)
|
||||||
_parse_layer_conf(deplayerdir, config_data_copy)
|
utils.parse_layer_conf(deplayerdir, config_data_copy)
|
||||||
config_data_copy.delVar('LAYERDIR')
|
config_data_copy.delVar('LAYERDIR')
|
||||||
return config_data_copy
|
return config_data_copy
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,54 @@ def get_layer(layername):
|
||||||
return res[0]
|
return res[0]
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def setup_tinfoil(bitbakepath, enable_tracking):
|
||||||
|
sys.path.insert(0, bitbakepath + '/lib')
|
||||||
|
import bb.tinfoil
|
||||||
|
import bb.cooker
|
||||||
|
import bb.data
|
||||||
|
try:
|
||||||
|
tinfoil = bb.tinfoil.Tinfoil(tracking=enable_tracking)
|
||||||
|
except TypeError:
|
||||||
|
# old API
|
||||||
|
tinfoil = bb.tinfoil.Tinfoil()
|
||||||
|
if enable_tracking:
|
||||||
|
tinfoil.cooker.enableDataTracking()
|
||||||
|
tinfoil.prepare(config_only = True)
|
||||||
|
|
||||||
|
return tinfoil
|
||||||
|
|
||||||
|
def checkout_layer_branch(layerbranch, repodir, logger=None):
|
||||||
|
|
||||||
|
branchname = layerbranch.branch.name
|
||||||
|
if layerbranch.actual_branch:
|
||||||
|
branchname = layerbranch.actual_branch
|
||||||
|
|
||||||
|
out = runcmd("git checkout origin/%s" % branchname, repodir, logger=logger)
|
||||||
|
out = runcmd("git clean -f -x", repodir, logger=logger)
|
||||||
|
|
||||||
|
def is_layer_valid(layerdir):
|
||||||
|
conf_file = os.path.join(layerdir, "conf", "layer.conf")
|
||||||
|
if not os.path.isfile(conf_file):
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
def parse_layer_conf(layerdir, data, logger=None):
|
||||||
|
conf_file = os.path.join(layerdir, "conf", "layer.conf")
|
||||||
|
|
||||||
|
if not is_layer_valid(layerdir):
|
||||||
|
if logger:
|
||||||
|
logger.error("Cannot find layer.conf: %s"% conf_file)
|
||||||
|
return
|
||||||
|
|
||||||
|
data.setVar('LAYERDIR', str(layerdir))
|
||||||
|
if hasattr(bb, "cookerdata"):
|
||||||
|
# Newer BitBake
|
||||||
|
data = bb.cookerdata.parse_config_file(conf_file, data)
|
||||||
|
else:
|
||||||
|
# Older BitBake (1.18 and below)
|
||||||
|
data = bb.cooker._parse(conf_file, data)
|
||||||
|
data.expandVarref('LAYERDIR')
|
||||||
|
|
||||||
def runcmd(cmd, destdir=None, printerr=True, logger=None):
|
def runcmd(cmd, destdir=None, printerr=True, logger=None):
|
||||||
"""
|
"""
|
||||||
execute command, raise CalledProcessError if fail
|
execute command, raise CalledProcessError if fail
|
||||||
|
|
Loading…
Reference in New Issue
Block a user