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 0BE0AC61DA4 for ; Thu, 16 Feb 2023 10:49:36 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1734E85777; Thu, 16 Feb 2023 11:49:33 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=ti.com 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=ti.com header.i=@ti.com header.b="VN7FcbBm"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3F61785777; Thu, 16 Feb 2023 11:49:30 +0100 (CET) Received: from lelv0142.ext.ti.com (lelv0142.ext.ti.com [198.47.23.249]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 3C5678595D for ; Thu, 16 Feb 2023 11:49:26 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=n-francis@ti.com Received: from lelv0266.itg.ti.com ([10.180.67.225]) by lelv0142.ext.ti.com (8.15.2/8.15.2) with ESMTP id 31GAnFo7039888; Thu, 16 Feb 2023 04:49:15 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1676544555; bh=BELZV4bn9QT9v9SKPsk8mKYUY/FYWhIynPQf69xEnZE=; h=From:To:CC:Subject:Date; b=VN7FcbBmsFqQr00VENLxUwvcDyTORJfp9jLVXWgUEfGNvXKM0YShLt7kDn8DUDceW p2MGB97/nuqz7BPTC2qBynFGXcjZmVAjgSZuCUBjKEPBG94EQBbo4ZS/mEpel30A+k 23dxbgaXFoYJS+mvLIVvc7yZaUu+MvDqOJiE7gfo= Received: from DFLE113.ent.ti.com (dfle113.ent.ti.com [10.64.6.34]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 31GAnFb9071025 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 16 Feb 2023 04:49:15 -0600 Received: from DFLE108.ent.ti.com (10.64.6.29) by DFLE113.ent.ti.com (10.64.6.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.16; Thu, 16 Feb 2023 04:49:15 -0600 Received: from lelv0326.itg.ti.com (10.180.67.84) by DFLE108.ent.ti.com (10.64.6.29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.16 via Frontend Transport; Thu, 16 Feb 2023 04:49:14 -0600 Received: from ula0497641.dhcp.ti.com (ileaxei01-snat2.itg.ti.com [10.180.69.6]) by lelv0326.itg.ti.com (8.15.2/8.15.2) with ESMTP id 31GAnBip007411; Thu, 16 Feb 2023 04:49:12 -0600 From: Neha Malcom Francis To: , , , , CC: , , Subject: [PATCH] binman: bintool: Add support for tool directories Date: Thu, 16 Feb 2023 16:19:11 +0530 Message-ID: <20230216104911.351548-1-n-francis@ti.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 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.6 at phobos.denx.de X-Virus-Status: Clean Currently, bintool supports external compilable tools as single executable files. Adding support for git repos that can be used to run non-compilable scripting tools that cannot otherwise be present in binman. Signed-off-by: Neha Malcom Francis --- tools/binman/bintool.py | 42 ++++++++++++++++++++++++++++++++++------- tools/patman/tools.py | 2 ++ 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/tools/binman/bintool.py b/tools/binman/bintool.py index 8fda13ff01..a1e37699aa 100644 --- a/tools/binman/bintool.py +++ b/tools/binman/bintool.py @@ -32,12 +32,13 @@ FORMAT = '%-16.16s %-12.12s %-26.26s %s' modules = {} # Possible ways of fetching a tool (FETCH_COUNT is number of ways) -FETCH_ANY, FETCH_BIN, FETCH_BUILD, FETCH_COUNT = range(4) +FETCH_ANY, FETCH_BIN, FETCH_BUILD, FETCH_NO_BUILD, FETCH_COUNT = range(5) FETCH_NAMES = { FETCH_ANY: 'any method', FETCH_BIN: 'binary download', - FETCH_BUILD: 'build from source' + FETCH_BUILD: 'build from source', + FETCH_NO_BUILD: 'download source without building' } # Status of tool fetching @@ -206,7 +207,7 @@ class Bintool: result = try_fetch(method) if not result: return FAIL - if result is not True: + if result is not True and method != FETCH_NO_BUILD: fname, tmpdir = result dest = os.path.join(DOWNLOAD_DESTDIR, self.name) print(f"- writing to '{dest}'") @@ -261,7 +262,7 @@ class Bintool: show_status(col.RED, 'Failures', status[FAIL]) return not status[FAIL] - def run_cmd_result(self, *args, binary=False, raise_on_error=True): + def run_cmd_result(self, *args, binary=False, raise_on_error=True, add_name=True): """Run the bintool using command-line arguments Args: @@ -278,7 +279,10 @@ class Bintool: if self.name in self.missing_list: return None name = os.path.expanduser(self.name) # Expand paths containing ~ - all_args = (name,) + args + if add_name: + all_args = (name,) + args + else: + all_args = args env = tools.get_env_with_path() tout.detail(f"bintool: {' '.join(all_args)}") result = command.run_pipe( @@ -304,7 +308,7 @@ class Bintool: tout.debug(result.stderr) return result - def run_cmd(self, *args, binary=False): + def run_cmd(self, *args, binary=False, add_name=True): """Run the bintool using command-line arguments Args: @@ -315,7 +319,7 @@ class Bintool: Returns: str or bytes: Resulting stdout from the bintool """ - result = self.run_cmd_result(*args, binary=binary) + result = self.run_cmd_result(*args, binary=binary, add_name=add_name) if result: return result.stdout @@ -354,6 +358,30 @@ class Bintool: return None return fname, tmpdir + @classmethod + def fetch_from_git(cls, git_repo): + """Fetch a bintool git repo + + This clones the repo and returns + + Args: + git_repo (str): URL of git repo + bintool_path (str): Relative path of the tool in the repo, after + build is complete + + Returns: + str: Directory of fetched repo + or None on error + """ + dir = os.path.join(DOWNLOAD_DESTDIR, cls.name) + os.mkdir(dir) + print(f"- clone git repo '{git_repo}' to '{dir}'") + tools.run('git', 'clone', '--depth', '1', git_repo, dir) + if not os.path.exists(dir): + print(f"- Repo '{dir}' was not produced") + return None + return dir + @classmethod def fetch_from_url(cls, url): """Fetch a bintool from a URL diff --git a/tools/patman/tools.py b/tools/patman/tools.py index 2ac814d476..b8533c72b2 100644 --- a/tools/patman/tools.py +++ b/tools/patman/tools.py @@ -399,6 +399,8 @@ def tool_find(name): fname = os.path.join(path, name) if os.path.isfile(fname) and os.access(fname, os.X_OK): return fname + if os.path.isdir(fname) and os.access(fname, os.X_OK): + return fname def run(name, *args, **kwargs): """Run a tool with some arguments -- 2.34.1