Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 963ECC001DC for ; Thu, 20 Jul 2023 00:00:36 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 33F05868B7; Thu, 20 Jul 2023 01:52:44 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="MbT7B5P2"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 12161867B9; Thu, 20 Jul 2023 01:50:53 +0200 (CEST) Received: from mail-il1-x129.google.com (mail-il1-x129.google.com [IPv6:2607:f8b0:4864:20::129]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 4B25F86675 for ; Thu, 20 Jul 2023 01:50:46 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-il1-x129.google.com with SMTP id e9e14a558f8ab-346129c9512so735615ab.1 for ; Wed, 19 Jul 2023 16:50:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1689810645; x=1690415445; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Myv91WZtSgPOmY8tx/4PakHGPobOhehKf+blxZKKLVo=; b=MbT7B5P2MtiNxJk9u+wuUS+zUjb0KsZBt44OvutpVl1W/DXnHAvF/4teyV7VOTFCga weDjuUBqjQQ2+TdJU+RirJsxsKB3jcs3ZwFcYGZguBuMrOre1TymBmseLwXaOSeSkLyx agGWRZxavacLN/wOurIeB/sLhaL9jsZ+FA8hg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689810645; x=1690415445; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Myv91WZtSgPOmY8tx/4PakHGPobOhehKf+blxZKKLVo=; b=NJmd2yaCliPOjdGeMzkLPCFhHW7amHecHVAe70iZIWik2quUnvn1CHUpC95MzZOg3t HHopRLFZBg53JGMkbG2wBfEQgqUvPg+tfKqCY/7QS/8Q0tcnlIv9RuwwSGmrBjP3hkfV EpBSIr377GgPJXyhx7gm9KoIhSZEFnZyBsoi5MvcNYXNzgvgkKHrvRTBhKW/1QR9rJCr u0oVqUCiWdB4RhZhK41aWUd2zTo9OnLJb5nhj1D3+g4q7GozXyAe7o5Ca25Xz5cesoKe eGeGwci7kwSMgcUJGcY4Z6DbzdCiI00A8MNfyRhX4bzAFHKshuAJCRGRQ3DPe7UdIgUR ZfAw== X-Gm-Message-State: ABy/qLbtALdU7njjdUl+jua3y4rlFABC7EtHnUyumhzVtYXx0QIIRQir 2hWz9EBe55lLtCjGqyEGkk50xMXioUK51vAXIMc= X-Google-Smtp-Source: APBJJlEaQF0iGH/GjDeK8ssJXoNz05LnySihfCCxqHk+/NgwsVHiSXRob0I9wXUVomFL8u7oZKid8A== X-Received: by 2002:a92:c266:0:b0:346:23b0:3725 with SMTP id h6-20020a92c266000000b0034623b03725mr2963185ild.13.1689810644729; Wed, 19 Jul 2023 16:50:44 -0700 (PDT) Received: from sjg1.lan (c-73-14-173-85.hsd1.co.comcast.net. [73.14.173.85]) by smtp.gmail.com with ESMTPSA id ed16-20020a056638291000b0042bb1779c18sm1551779jab.151.2023.07.19.16.50.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Jul 2023 16:50:44 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Mike Frysinger , Simon Glass Subject: [PATCH v4 61/83] buildman: Correct most pylint warnings in builderthread Date: Wed, 19 Jul 2023 17:49:09 -0600 Message-ID: <20230719234953.796101-62-sjg@chromium.org> X-Mailer: git-send-email 2.41.0.487.g6d72f3e995-goog In-Reply-To: <20230719234953.796101-1-sjg@chromium.org> References: <20230719234953.796101-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Fix the easy warnings in this file. Signed-off-by: Simon Glass --- (no changes since v1) tools/buildman/builderthread.py | 95 ++++++++++++++++++--------------- 1 file changed, 51 insertions(+), 44 deletions(-) diff --git a/tools/buildman/builderthread.py b/tools/buildman/builderthread.py index 3f52d95fed9f..179fc477c008 100644 --- a/tools/buildman/builderthread.py +++ b/tools/buildman/builderthread.py @@ -2,6 +2,12 @@ # Copyright (c) 2014 Google, Inc # +"""Implementation the bulider threads + +This module provides the BuilderThread class, which handles calling the builder +based on the jobs provided. +""" + import errno import glob import os @@ -30,12 +36,12 @@ def mkdir(dirname, parents = False): except OSError as err: if err.errno == errno.EEXIST: if os.path.realpath('.') == os.path.realpath(dirname): - print("Cannot create the current working directory '%s'!" % dirname) + print(f"Cannot create the current working directory '{dirname}'!") sys.exit(1) - pass else: raise +# pylint: disable=R0903 class BuilderJob: """Holds information about a job to be performed by a thread @@ -107,6 +113,7 @@ class BuilderThread(threading.Thread): self.mrproper = mrproper self.per_board_out_dir = per_board_out_dir self.test_exception = test_exception + self.toolchain = None def make(self, commit, brd, stage, cwd, *args, **kwargs): """Run 'make' on a particular commit and board. @@ -182,9 +189,9 @@ class BuilderThread(threading.Thread): not result.already_done) if result.already_done: # Get the return code from that build and use it - with open(done_file, 'r') as fd: + with open(done_file, 'r', encoding='utf-8') as outf: try: - result.return_code = int(fd.readline()) + result.return_code = int(outf.readline()) except ValueError: # The file may be empty due to running out of disk space. # Try a rebuild @@ -240,11 +247,11 @@ class BuilderThread(threading.Thread): # Symlinks can confuse U-Boot's Makefile since # we may use '..' in our path, so remove them. out_dir = os.path.realpath(out_dir) - args.append('O=%s' % out_dir) + args.append(f'O={out_dir}') cwd = None src_dir = os.getcwd() else: - args.append('O=%s' % out_rel_dir) + args.append(f'O={out_rel_dir}') if self.builder.verbose_build: args.append('V=1') else: @@ -260,7 +267,7 @@ class BuilderThread(threading.Thread): args.append('NO_LTO=1') if self.builder.reproducible_builds: args.append('SOURCE_DATE_EPOCH=0') - config_args = ['%s_defconfig' % brd.target] + config_args = [f'{brd.target}_defconfig'] config_out = '' args.extend(self.builder.toolchains.GetMakeArguments(brd)) args.extend(self.toolchain.MakeArgs()) @@ -270,7 +277,6 @@ class BuilderThread(threading.Thread): # SPL image. If we don't remove it (i.e. see do_config and # self.mrproper below) then it will appear to be the output of # this build, even if it does not produce SPL images. - build_dir = self.builder.get_build_dir(commit_upto, brd.target) for elf in BASE_ELF_FILENAMES: fname = os.path.join(out_dir, elf) if os.path.exists(fname): @@ -317,7 +323,7 @@ class BuilderThread(threading.Thread): result.cmd_list = cmd_list else: result.return_code = 1 - result.stderr = 'No tool chain for %s\n' % brd.arch + result.stderr = f'No tool chain for {brd.arch}\n' result.already_done = False result.toolchain = self.toolchain @@ -352,15 +358,15 @@ class BuilderThread(threading.Thread): mkdir(build_dir) outfile = os.path.join(build_dir, 'log') - with open(outfile, 'w') as fd: + with open(outfile, 'w', encoding='utf-8') as outf: if result.stdout: - fd.write(result.stdout) + outf.write(result.stdout) errfile = self.builder.get_err_file(result.commit_upto, result.brd.target) if result.stderr: - with open(errfile, 'w') as fd: - fd.write(result.stderr) + with open(errfile, 'w', encoding='utf-8') as outf: + outf.write(result.stderr) elif os.path.exists(errfile): os.remove(errfile) @@ -372,43 +378,44 @@ class BuilderThread(threading.Thread): # Write the build result and toolchain information. done_file = self.builder.get_done_file(result.commit_upto, result.brd.target) - with open(done_file, 'w') as fd: + with open(done_file, 'w', encoding='utf-8') as outf: if maybe_aborted: # Special code to indicate we need to retry - fd.write('%s' % RETURN_CODE_RETRY) + outf.write(f'{RETURN_CODE_RETRY}') else: - fd.write('%s' % result.return_code) - with open(os.path.join(build_dir, 'toolchain'), 'w') as fd: - print('gcc', result.toolchain.gcc, file=fd) - print('path', result.toolchain.path, file=fd) - print('cross', result.toolchain.cross, file=fd) - print('arch', result.toolchain.arch, file=fd) - fd.write('%s' % result.return_code) + outf.write(f'{result.return_code}') + with open(os.path.join(build_dir, 'toolchain'), 'w', + encoding='utf-8') as outf: + print('gcc', result.toolchain.gcc, file=outf) + print('path', result.toolchain.path, file=outf) + print('cross', result.toolchain.cross, file=outf) + print('arch', result.toolchain.arch, file=outf) + outf.write(f'{result.return_code}') # Write out the image and function size information and an objdump env = result.toolchain.MakeEnvironment(self.builder.full_path) - with open(os.path.join(build_dir, 'out-env'), 'wb') as fd: + with open(os.path.join(build_dir, 'out-env'), 'wb') as outf: for var in sorted(env.keys()): - fd.write(b'%s="%s"' % (var, env[var])) + outf.write(b'%s="%s"' % (var, env[var])) with open(os.path.join(build_dir, 'out-cmd'), 'w', - encoding='utf-8') as fd: + encoding='utf-8') as outf: for cmd in result.cmd_list: - print(' '.join(cmd), file=fd) + print(' '.join(cmd), file=outf) lines = [] for fname in BASE_ELF_FILENAMES: - cmd = ['%snm' % self.toolchain.cross, '--size-sort', fname] + cmd = [f'{self.toolchain.cross}nm', '--size-sort', fname] nm_result = command.run_pipe([cmd], capture=True, capture_stderr=True, cwd=result.out_dir, raise_on_error=False, env=env) if nm_result.stdout: - nm = self.builder.get_func_sizes_file(result.commit_upto, - result.brd.target, fname) - with open(nm, 'w') as fd: - print(nm_result.stdout, end=' ', file=fd) + nm_fname = self.builder.get_func_sizes_file( + result.commit_upto, result.brd.target, fname) + with open(nm_fname, 'w', encoding='utf-8') as outf: + print(nm_result.stdout, end=' ', file=outf) - cmd = ['%sobjdump' % self.toolchain.cross, '-h', fname] + cmd = [f'{self.toolchain.cross}objdump', '-h', fname] dump_result = command.run_pipe([cmd], capture=True, capture_stderr=True, cwd=result.out_dir, raise_on_error=False, env=env) @@ -416,14 +423,14 @@ class BuilderThread(threading.Thread): if dump_result.stdout: objdump = self.builder.get_objdump_file(result.commit_upto, result.brd.target, fname) - with open(objdump, 'w') as fd: - print(dump_result.stdout, end=' ', file=fd) + with open(objdump, 'w', encoding='utf-8') as outf: + print(dump_result.stdout, end=' ', file=outf) for line in dump_result.stdout.splitlines(): fields = line.split() if len(fields) > 5 and fields[1] == '.rodata': rodata_size = fields[2] - cmd = ['%ssize' % self.toolchain.cross, fname] + cmd = [f'{self.toolchain.cross}size', fname] size_result = command.run_pipe([cmd], capture=True, capture_stderr=True, cwd=result.out_dir, raise_on_error=False, env=env) @@ -432,13 +439,12 @@ class BuilderThread(threading.Thread): rodata_size) # Extract the environment from U-Boot and dump it out - cmd = ['%sobjcopy' % self.toolchain.cross, '-O', 'binary', + cmd = [f'{self.toolchain.cross}objcopy', '-O', 'binary', '-j', '.rodata.default_environment', 'env/built-in.o', 'uboot.env'] command.run_pipe([cmd], capture=True, capture_stderr=True, cwd=result.out_dir, raise_on_error=False, env=env) - ubootenv = os.path.join(result.out_dir, 'uboot.env') if not work_in_output: self.copy_files(result.out_dir, build_dir, '', ['uboot.env']) @@ -446,11 +452,11 @@ class BuilderThread(threading.Thread): # of binutil's 'size' utility, but it omits the header line and # adds an additional hex value at the end of each line for the # rodata size - if len(lines): + if lines: sizes = self.builder.get_sizes_file(result.commit_upto, result.brd.target) - with open(sizes, 'w') as fd: - print('\n'.join(lines), file=fd) + with open(sizes, 'w', encoding='utf-8') as outf: + print('\n'.join(lines), file=outf) if not work_in_output: # Write out the configuration files, with a special case for SPL @@ -485,7 +491,7 @@ class BuilderThread(threading.Thread): if dirname: base, ext = os.path.splitext(target) if ext: - target = '%s-%s%s' % (base, dirname, ext) + target = f'{base}-{dirname}{ext}' shutil.copy(fname, os.path.join(build_dir, target)) def _send_result(self, result): @@ -598,7 +604,8 @@ class BuilderThread(threading.Thread): job = self.builder.queue.get() try: self.run_job(job) - except Exception as e: - print('Thread exception (use -T0 to run without threads):', e) - self.builder.thread_exceptions.append(e) + except Exception as exc: + print('Thread exception (use -T0 to run without threads):', + exc) + self.builder.thread_exceptions.append(exc) self.builder.queue.task_done() -- 2.41.0.487.g6d72f3e995-goog