From 00ef97f221570cc462d195ead53385e54d28a4e3 Mon Sep 17 00:00:00 2001 From: hqbai Date: Thu, 9 Dec 2021 02:51:28 +0000 Subject: [PATCH] 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' 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 Change-Id: I20db5bcacaffa00d476b2af8bc8212effa46e7c1 --- build-tools/stx/build-pkgs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/build-tools/stx/build-pkgs b/build-tools/stx/build-pkgs index 4c33aa5a..ee890ecb 100755 --- a/build-tools/stx/build-pkgs +++ b/build-tools/stx/build-pkgs @@ -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: