scripts/wic: Be consistent about how we call bitbake

Whilst its tempting to call bitbake_main(), the script also directly executes
bitbake. By doing both this creates all kinds of races. Therefore
change to use subprocess execution in all cases.

(From OE-Core rev: 0507ec4c6069490c9a503e9e2b65f0e7b1962d34)

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Richard Purdie 2019-02-28 12:24:49 +00:00
parent 8c662e768f
commit 3d59df60a6

View File

@ -35,6 +35,7 @@ import os
import sys import sys
import argparse import argparse
import logging import logging
import subprocess
from collections import namedtuple from collections import namedtuple
from distutils import spawn from distutils import spawn
@ -63,10 +64,7 @@ if os.environ.get('SDKTARGETSYSROOT'):
bitbake_exe = spawn.find_executable('bitbake') bitbake_exe = spawn.find_executable('bitbake')
if bitbake_exe: if bitbake_exe:
bitbake_path = scriptpath.add_bitbake_lib_path() bitbake_path = scriptpath.add_bitbake_lib_path()
from bb import cookerdata import bb
from bb.main import bitbake_main, BitBakeConfigParameters
else:
bitbake_main = None
from wic import WicError from wic import WicError
from wic.misc import get_bitbake_var, BB_VARS from wic.misc import get_bitbake_var, BB_VARS
@ -124,7 +122,7 @@ def wic_create_subcommand(options, usage_str):
Command-line handling for image creation. The real work is done Command-line handling for image creation. The real work is done
by image.engine.wic_create() by image.engine.wic_create()
""" """
if options.build_rootfs and not bitbake_main: if options.build_rootfs and not bitbake_exe:
raise WicError("Can't build rootfs as bitbake is not in the $PATH") raise WicError("Can't build rootfs as bitbake is not in the $PATH")
if not options.image_name: if not options.image_name:
@ -160,9 +158,7 @@ def wic_create_subcommand(options, usage_str):
argv.append("--debug") argv.append("--debug")
logger.info("Building rootfs...\n") logger.info("Building rootfs...\n")
if bitbake_main(BitBakeConfigParameters(argv), subprocess.check_call(argv)
cookerdata.CookerConfiguration()):
raise WicError("bitbake exited with error")
rootfs_dir = get_bitbake_var("IMAGE_ROOTFS", options.image_name) rootfs_dir = get_bitbake_var("IMAGE_ROOTFS", options.image_name)
kernel_dir = get_bitbake_var("DEPLOY_DIR_IMAGE", options.image_name) kernel_dir = get_bitbake_var("DEPLOY_DIR_IMAGE", options.image_name)
@ -179,9 +175,7 @@ def wic_create_subcommand(options, usage_str):
if not options.vars_dir and (not native_sysroot or not os.path.isdir(native_sysroot)): if not options.vars_dir and (not native_sysroot or not os.path.isdir(native_sysroot)):
logger.info("Building wic-tools...\n") logger.info("Building wic-tools...\n")
if bitbake_main(BitBakeConfigParameters("bitbake wic-tools".split()), subprocess.check_call(["bitbake", "wic-tools"])
cookerdata.CookerConfiguration()):
raise WicError("bitbake wic-tools failed")
native_sysroot = get_bitbake_var("RECIPE_SYSROOT_NATIVE", "wic-tools") native_sysroot = get_bitbake_var("RECIPE_SYSROOT_NATIVE", "wic-tools")
if not native_sysroot: if not native_sysroot: