From 0820b2193a427b15dbf13ee606cbef24c43c1d1b Mon Sep 17 00:00:00 2001 From: Christophe BLAESS Date: Sat, 12 Feb 2022 10:18:11 +0100 Subject: [PATCH] [DEV] Read `CONF_VERSION` from `local.conf.sample` file. (#107) The path to this file is in `templateconf.cfg`, relative to `poky` directory (or `openembedded-core` for Arago-based systems). If the file is missing (for example when running with `--dry-run`) we use the `DEFAULT_CONF_VERSION` from the Distro config. --- cooker/cooker.py | 34 +++++++++++++++++++++++++--------- test/basic/clean/test | 9 ++++++++- test/basic/dry-run/output.ref | 2 +- test/basic/dry-run/test | 2 -- test/basic/generate/test | 18 +++++++++++++++--- 5 files changed, 49 insertions(+), 16 deletions(-) diff --git a/cooker/cooker.py b/cooker/cooker.py index 1de9c28..4438174 100644 --- a/cooker/cooker.py +++ b/cooker/cooker.py @@ -3,8 +3,9 @@ import argparse import json -import sys import os +import re +import sys from urllib.parse import urlparse import jsonschema import pkg_resources @@ -296,21 +297,23 @@ def resolve_parents(): class PokyDistro: DISTRO_NAME = "poky" - BUILD_SCRIPT = "poky/oe-init-build-env" + BASE_DIRECTORY = "poky" + BUILD_SCRIPT = "oe-init-build-env" TEMPLATE_CONF = "meta-poky/conf" + DEFAULT_CONF_VERSION = "1" LAYER_CONF_NAME = "POKY_BBLAYERS_CONF_VERSION" LAYER_CONF_VERSION = "2" - LOCAL_CONF_VERSION = "1" PACKAGE_FORMAT = "package_rpm" class AragoDistro: DISTRO_NAME = "arago" - BUILD_SCRIPT = "openembedded-core/oe-init-build-env" + BASE_DIRECTORY = "openembedded-core" + BUILD_SCRIPT = "oe-init-build-env" TEMPLATE_CONF = "meta/conf" + DEFAULT_CONF_VERSION = "1" LAYER_CONF_NAME = "LCONF_VERSION" LAYER_CONF_VERSION = "7" - LOCAL_CONF_VERSION = "1" PACKAGE_FORMAT = "package_ipk" @@ -444,10 +447,23 @@ def update_directory(self, method, local_dir, has_remote, branch, rev): def generate(self): info('Generating dirs for all build-configurations') + self.read_local_conf_version() + for build in BuildConfiguration.ALL.values(): if build.buildable(): self.prepare_build_directory(build) + def read_local_conf_version(self): + try: + self.local_conf_version = str(self.distro.DEFAULT_CONF_VERSION) + file = open(self.config.layer_dir() + self.distro.BASE_DIRECTORY + "/" + self.distro.TEMPLATE_CONF + "/local.conf.sample") + for line in file: + if line.lstrip().startswith("CONF_VERSION"): + self.local_conf_version = re.search(r'\d+', line).group(0) + return + except: + return + def prepare_build_directory(self, build): debug('Preparing directory:', build.dir()) @@ -480,7 +496,7 @@ def prepare_build_directory(self, build): CookerCall.os.file_write(file, '\tABORT,${DL_DIR},100M,1K \\') CookerCall.os.file_write(file, '\tABORT,${SSTATE_DIR},100M,1K \\') CookerCall.os.file_write(file, '\tABORT,/tmp,10M,1K"') - CookerCall.os.file_write(file, 'CONF_VERSION = "{}"'.format(self.distro.LOCAL_CONF_VERSION)) + CookerCall.os.file_write(file, 'CONF_VERSION ?= "{}"'.format(self.local_conf_version)) CookerCall.os.file_close(file) file = CookerCall.os.file_open(os.path.join(conf_path, 'bblayers.conf')) @@ -541,7 +557,7 @@ def show(self, builds, layers, conf, tree, build_arg, sources): if build_arg: if build.targets(): info(' .', - os.path.relpath(self.config.layer_dir(self.distro.BUILD_SCRIPT), os.getcwd()), + os.path.relpath(self.config.layer_dir(self.distro.BASE_DIRECTORY + "/" + self.distro.BUILD_SCRIPT), os.getcwd()), os.path.relpath(build.dir(), os.getcwd())) else: info('build', build.name(), 'has no target') @@ -608,7 +624,7 @@ def get_buildable_builds(self, builds: List[str]): def run_bitbake(self, build_config, bb_task, bb_target): directory = build_config.dir() - init_script = self.config.layer_dir(self.distro.BUILD_SCRIPT) + init_script = self.config.layer_dir(self.distro.BASE_DIRECTORY + "/" + self.distro.BUILD_SCRIPT) if not CookerCall.os.file_exists(init_script): fatal_error('init-script', init_script, 'not found') @@ -619,7 +635,7 @@ def run_bitbake(self, build_config, bb_task, bb_target): def shell(self, build_names: List[str]): build_dir = self.get_buildable_builds(build_names)[0].dir() - init_script = self.config.layer_dir(self.distro.BUILD_SCRIPT) + init_script = self.config.layer_dir(self.distro.BASE_DIRECTORY + "/" + self.distro.BUILD_SCRIPT) shell = os.environ.get('SHELL', '/bin/sh') debug('running interactive, poky-initialized shell {} {} {}', build_dir, init_script, shell) diff --git a/test/basic/clean/test b/test/basic/clean/test index 6961394..722f3dd 100644 --- a/test/basic/clean/test +++ b/test/basic/clean/test @@ -37,6 +37,7 @@ cooker init -f menu.json # `cooker clean recipe` fails without Poky `oe-init-build-env` script. rm -f layers/poky/oe-init-build-env +rm -f layers/poky/meta-poky expect_fail cooker clean recipe @@ -50,6 +51,12 @@ EOF chmod +x bitbake PATH=.:$PATH +# Add `local.conf.sample` file +mkdir -p layers/poky/meta-poky/conf +cat > layers/poky/meta-poky/conf/local.conf.sample <<- EOF + CONF_VERSION = "1" +EOF + # `cooker clean recipe` succeeds when bitbake succeeds. export bitbake_result=0 cooker clean recipe @@ -79,7 +86,7 @@ cooker generate cooker clean recipe -# `cooker clean recipe buid-config` fails when build-config doesn't exist. +# `cooker clean recipe build-config` fails when build-config doesn't exist. cat > menu.json <<-EOF { "sources": [], diff --git a/test/basic/dry-run/output.ref b/test/basic/dry-run/output.ref index 12bd796..3284d84 100644 --- a/test/basic/dry-run/output.ref +++ b/test/basic/dry-run/output.ref @@ -39,7 +39,7 @@ cat > /builds/build-pi2-base/conf/local.conf <<-EOF ABORT,\${DL_DIR},100M,1K \ ABORT,\${SSTATE_DIR},100M,1K \ ABORT,/tmp,10M,1K" - CONF_VERSION = "1" + CONF_VERSION ?= "1" EOF cat > /builds/build-pi2-base/conf/bblayers.conf <<-EOF # DO NOT EDIT! - This file is automatically created by cooker. diff --git a/test/basic/dry-run/test b/test/basic/dry-run/test index e3730cc..5b2f59b 100644 --- a/test/basic/dry-run/test +++ b/test/basic/dry-run/test @@ -4,7 +4,6 @@ expect_fail cooker --dry-run 2> error.txt linesInFile error.txt 2 rm -f error.txt - # Mock `bitbake` cat > bitbake <<-EOF #! /bin/sh @@ -13,7 +12,6 @@ EOF chmod +x bitbake # Mock `git` - cat > git <<-EOF #! /bin/sh exit 0 diff --git a/test/basic/generate/test b/test/basic/generate/test index 912c88d..2e32533 100644 --- a/test/basic/generate/test +++ b/test/basic/generate/test @@ -1,9 +1,9 @@ -# fail is no init done -! cooker generate +# fail if no init done +expect_fail cooker generate # empty menu, nothing is generated -cooker init $S/empty-menu.json +cooker init -f $S/empty-menu.json cooker generate filesExist . builds 0 @@ -22,13 +22,25 @@ dirsExist builds build-first 1 # bblayers as expected diff builds/build-first/conf/bblayers.conf $S/one-target-first-bblayers.conf +# local.conf as expected textInFile builds/build-first/conf/local.conf 'COOKER_LAYER_DIR = "\${TOPDIR}/../../layers"' 1 textInFile builds/build-first/conf/local.conf 'DL_DIR = "\${TOPDIR}/../../downloads"' 1 textInFile builds/build-first/conf/local.conf 'SSTATE_DIR = "\${TOPDIR}/../../sstate-cache"' 1 +# Default value for CONF_VERSION is 1 +textInFile builds/build-first/conf/local.conf 'CONF_VERSION \?= "1"' 1 +# regenerate with CONF_VERSION = 2 +mkdir -p layers/poky/meta-poky/conf +cat > layers/poky/meta-poky/conf/local.conf.sample <<- EOF + CONF_VERSION = "2" +EOF +cooker generate +textInFile builds/build-first/conf/local.conf 'CONF_VERSION \?= "2"' 1 + # regenerate after layers-dir-change cooker init -f -l layers_dir $S/menu.json cooker generate + textInFile builds/build-first/conf/local.conf 'COOKER_LAYER_DIR = "\${TOPDIR}/../../layers"' 0 textInFile builds/build-first/conf/local.conf 'COOKER_LAYER_DIR = "\${TOPDIR}/../../layers_dir"' 1