diff options
author | Paul Eggleton <paul.eggleton@linux.intel.com> | 2013-05-07 12:12:03 +0100 |
---|---|---|
committer | Paul Eggleton <paul.eggleton@linux.intel.com> | 2013-07-28 18:43:11 +0100 |
commit | 1a9f73d4a75a6c64fd90d10532b030a880c11353 (patch) | |
tree | 43ea93198f6736ceb9632a9272aa3084f97ee7f1 /layerindex/recipeparse.py | |
parent | 8be1adddb677e1d67f64158f949798c69096ef40 (diff) | |
download | openembedded-core-contrib-1a9f73d4a75a6c64fd90d10532b030a880c11353.tar.gz |
Split out recipe parsing and utility functions to a separate module
To allow re-use outside of the update script, split out parsing setup
code to a new recipeparse module. Also split out runcmd, get_layer,
get_branch and logger_create functions to a separate utils module.
Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
Diffstat (limited to 'layerindex/recipeparse.py')
-rw-r--r-- | layerindex/recipeparse.py | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/layerindex/recipeparse.py b/layerindex/recipeparse.py new file mode 100644 index 0000000000..2f9a6684de --- /dev/null +++ b/layerindex/recipeparse.py @@ -0,0 +1,111 @@ +# Utility functions for parsing recipes using bitbake within layerindex-web +# +# Copyright (C) 2013 Intel Corporation +# Author: Paul Eggleton <paul.eggleton@linux.intel.com> +# +# Licensed under the MIT license, see COPYING.MIT for details + +import sys +import os +import os.path +import utils +import tempfile + +class RecipeParseError(Exception): + def __init__(self, msg): + self.msg = msg + + def __str__(self): + return self.msg + +def _setup_tinfoil(bitbakepath, enable_tracking): + sys.path.insert(0, bitbakepath + '/lib') + import bb.tinfoil + import bb.cooker + import bb.data + 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): + if not nocheckout: + # Check out the branch of BitBake appropriate for this branch and clean out any stale files (e.g. *.pyc) + out = utils.runcmd("git checkout origin/%s" % branch.bitbake_branch, bitbakepath) + out = utils.runcmd("git clean -f -x", bitbakepath) + + # Skip sanity checks + os.environ['BB_ENV_EXTRAWHITE'] = 'DISABLE_SANITY_CHECKS' + os.environ['DISABLE_SANITY_CHECKS'] = '1' + + fetchdir = settings.LAYER_FETCH_DIR + + # Ensure we have OE-Core set up to get some base configuration + core_layer = utils.get_layer(settings.CORE_LAYER_NAME) + if not core_layer: + raise RecipeParseError("Unable to find core layer %s in database; check CORE_LAYER_NAME setting" % settings.CORE_LAYER_NAME) + core_layerbranch = core_layer.get_layerbranch(branch.name) + core_branchname = branch.name + if core_layerbranch: + core_subdir = core_layerbranch.vcs_subdir + if core_layerbranch.actual_branch: + core_branchname = core_layerbranch.actual_branch + else: + core_subdir = 'meta' + core_urldir = core_layer.get_fetch_dir() + core_repodir = os.path.join(fetchdir, core_urldir) + core_layerdir = os.path.join(core_repodir, core_subdir) + if not nocheckout: + out = utils.runcmd("git checkout origin/%s" % core_branchname, core_repodir) + out = utils.runcmd("git clean -f -x", core_repodir) + # The directory above where this script exists should contain our conf/layer.conf, + # so add it to BBPATH along with the core layer directory + confparentdir = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..')) + os.environ['BBPATH'] = str("%s:%s" % (confparentdir, core_layerdir)) + + # Change into a temporary directory so we don't write the cache and other files to the current dir + if not os.path.exists(settings.TEMP_BASE_DIR): + os.makedirs(settings.TEMP_BASE_DIR) + tempdir = tempfile.mkdtemp(dir=settings.TEMP_BASE_DIR) + os.chdir(tempdir) + + tinfoil = _setup_tinfoil(bitbakepath, enable_tracking) + + # Ensure TMPDIR exists (or insane.bbclass will blow up trying to write to the QA log) + oe_tmpdir = tinfoil.config_data.getVar('TMPDIR', True) + os.makedirs(oe_tmpdir) + + return (tinfoil, tempdir) + +def setup_layer(config_data, fetchdir, layerdir, layer, layerbranch): + # Parse layer.conf files for this layer and its dependencies + # This is necessary not just because BBPATH needs to be set in order + # for include/require/inherit to work outside of the current directory + # or across layers, but also because custom variable values might be + # set in layer.conf. + config_data_copy = bb.data.createCopy(config_data) + _parse_layer_conf(layerdir, config_data_copy) + for dep in layerbranch.dependencies_set.all(): + depurldir = dep.dependency.get_fetch_dir() + deprepodir = os.path.join(fetchdir, depurldir) + deplayerbranch = dep.dependency.get_layerbranch(layerbranch.branch.name) + 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)) + deplayerdir = os.path.join(deprepodir, deplayerbranch.vcs_subdir) + _parse_layer_conf(deplayerdir, config_data_copy) + config_data_copy.delVar('LAYERDIR') + return config_data_copy + |