build-pkgs: Support to pass parameter 'jobs' to pkgbuilder

When sending the build request to pkgbuilder, 'serial'
will be searched in the meta-data.yaml of the package
to know whether the package supports parallel build.
If parallel build is supported, the number of jobs is
equal to the value of ENV variable MAX_CPUS

Test Plan:

Check the log file: /localdisk/pkgbuilder.log
Pass: pkgbuiler runs with '-j<MAX_CPUS>' if no 'serial'
      or 'serial: false' defined in the package's meta-data.yaml
Pass: pkgbuilder runs with '-j1', in other words serial build
      if 'serial: true' defined in the package's meta-data.yaml

Story: 2008846
Task: 44155

Signed-off-by: hbai <haiqing.bai@windriver.com>
Change-Id: I20db5bcacaffa00d476b2af8bc8212effa46e7c1
This commit is contained in:
hqbai 2021-12-09 02:51:28 +00:00 committed by hbai
parent 25cf603cc8
commit 00ef97f221

View File

@ -29,6 +29,7 @@ import subprocess
import sys
import time
import utils
import yaml
BUILDER_URL = os.environ.get('BUILDER_URL')
REPOMGR_URL = os.environ.get('REPOMGR_URL')
@ -247,6 +248,31 @@ def fetch_debian_folder(package):
return None
def get_package_jobs(package):
'''
Returns the number of parallel jobs of the package
If the serial build is not enabled by the meta file,
the default number of jobs is equal to the value of
environment variable MAX_CPUS.
'''
jobs = os.environ.get('MAX_CPUS', 1)
pkg_dir = fetch_debian_folder(package)
if pkg_dir:
pkg_meta_yaml = os.path.join(pkg_dir, 'debian/meta_data.yaml')
try:
with open(pkg_meta_yaml) as f:
yaml_doc = yaml.safe_load(f)
except Exception as e:
logger.error(str(e))
else:
# serial: true [Disable parallel build]
# No 'serial:' or 'serial: false' [Support parallel build]
if yaml_doc.get('serial'):
jobs = 1
logger.debug('Requires the number of jobs %s for %s', jobs, package)
return jobs
class BuildController():
"""
builderClient helps to create or refresh the debian build recipes
@ -477,6 +503,7 @@ class BuildController():
req_params['user'] = USER
req_params['name'] = package
req_params['dsc'] = dsc
req_params['jobs'] = get_package_jobs(package)
req_params['run_tests'] = self.attrs['run_tests']
try: