Skip to content

Commit

Permalink
[DEV] Read CONF_VERSION from local.conf.sample file. (#107)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cpb- authored Feb 12, 2022
1 parent ce39e43 commit 0820b21
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 16 deletions.
34 changes: 25 additions & 9 deletions cooker/cooker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"


Expand Down Expand Up @@ -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())

Expand Down Expand Up @@ -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'))
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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')

Expand All @@ -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)
Expand Down
9 changes: 8 additions & 1 deletion test/basic/clean/test
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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": [],
Expand Down
2 changes: 1 addition & 1 deletion test/basic/dry-run/output.ref
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 0 additions & 2 deletions test/basic/dry-run/test
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -13,7 +12,6 @@ EOF
chmod +x bitbake

# Mock `git`

cat > git <<-EOF
#! /bin/sh
exit 0
Expand Down
18 changes: 15 additions & 3 deletions test/basic/generate/test
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

Expand Down

0 comments on commit 0820b21

Please sign in to comment.