From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124])
	by inbox.dpdk.org (Postfix) with ESMTP id 1A54245DAB;
	Tue, 26 Nov 2024 15:40:23 +0100 (CET)
Received: from mails.dpdk.org (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id BAFFE40EF0;
	Tue, 26 Nov 2024 15:40:07 +0100 (CET)
Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.19])
 by mails.dpdk.org (Postfix) with ESMTP id 0A6654064A
 for <dev@dpdk.org>; Tue, 26 Nov 2024 15:40:04 +0100 (CET)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple;
 d=intel.com; i=@intel.com; q=dns/txt; s=Intel;
 t=1732632005; x=1764168005;
 h=from:to:subject:date:message-id:in-reply-to:references:
 mime-version:content-transfer-encoding;
 bh=jZuzEVD67ftBHLFhkb4gHgEVAnctIIAy7gwzZz7EWys=;
 b=L+wkFpiyu6WTmIluZg7IS1QagJ4Rn7IKWrIdInHSEpFwumulV31ck+X7
 QdgrE9FKknoN1bRotJQcf/kJT63PZZ1lDffvN1N5hE1BKEVQ/yVXnrp0y
 qCS4T2TNqwZRWosAFc7EPpCInz6DXhROmTTxfnH48rf5y7Hs5vC43BpQ6
 emJyEVXFzk/zOm5GAq8hGz3TiJw4pbmQt4p6Vx5wXRIcOmj0WulRqj3pz
 6Rd5O/6piYNgzw9oUjNiBreh4IsQM8a3ZHVCr0SmqD+E/RHCkHXe017MV
 TYvGBeLxOziAi4PTB6AD8Ezt6HhVMRdpiEPk0rdasmqfjWRFFm5hvo5g3 w==;
X-CSE-ConnectionGUID: kvJB3Y3TS6qH7gjq2roMxA==
X-CSE-MsgGUID: oqA+RRCdShOcjC/2zq4Qtw==
X-IronPort-AV: E=McAfee;i="6700,10204,11268"; a="32169235"
X-IronPort-AV: E=Sophos;i="6.12,186,1728975600"; d="scan'208";a="32169235"
Received: from fmviesa009.fm.intel.com ([10.60.135.149])
 by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;
 26 Nov 2024 06:40:04 -0800
X-CSE-ConnectionGUID: pxOLQ/kZThWUxhLVN2ddnw==
X-CSE-MsgGUID: 0iDswd8SQlS90c26/vl5jQ==
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="6.12,186,1728975600"; d="scan'208";a="92103445"
Received: from silpixa00401119.ir.intel.com ([10.55.129.167])
 by fmviesa009.fm.intel.com with ESMTP; 26 Nov 2024 06:40:04 -0800
From: Anatoly Burakov <anatoly.burakov@intel.com>
To: dev@dpdk.org
Subject: [PATCH v4 3/8] devtools: add script to flag unneeded dependencies
Date: Tue, 26 Nov 2024 14:39:48 +0000
Message-ID: <05cbe298e189e89e8b99f993087508775b739c99.1732631953.git.anatoly.burakov@intel.com>
X-Mailer: git-send-email 2.43.5
In-Reply-To: <cover.1732631953.git.anatoly.burakov@intel.com>
References: <cover.1725462264.git.anatoly.burakov@intel.com>
 <cover.1732631953.git.anatoly.burakov@intel.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
Errors-To: dev-bounces@dpdk.org

From: Bruce Richardson <bruce.richardson@intel.com>

While not a serious problem, DPDK components often list more
dependencies than are actually necessary to build, due to the use of
recursive dependencies. In extreme cases, such as with core libraries,
this can lead to longer configuration times due to meson having to
deduplicate long lists of dependencies. Therefore we can add a script to
identify when a component has got unnecessary dependencies listed.

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
 devtools/find-duplicate-deps.py | 53 +++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)
 create mode 100755 devtools/find-duplicate-deps.py

diff --git a/devtools/find-duplicate-deps.py b/devtools/find-duplicate-deps.py
new file mode 100755
index 0000000000..b1eacf21ce
--- /dev/null
+++ b/devtools/find-duplicate-deps.py
@@ -0,0 +1,53 @@
+#! /usr/bin/env python3
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2024 Intel Corporation
+
+"""Identify any superfluous dependencies listed in DPDK deps graph."""
+
+import sys
+
+all_deps = {}
+
+
+class dep:
+    """Holds a component and its dependencies."""
+
+    def __init__(self, name, dep_names):
+        """Create and process a component and its deps."""
+        self.name = name.strip('" ')
+        self.base_deps = [all_deps[dn.strip('" ')] for dn in dep_names]
+        self.recursive_deps = []
+        for d in self.base_deps:
+            self.recursive_deps.extend(d.base_deps)
+            self.recursive_deps.extend(d.recursive_deps)
+        self.extra_deps = []
+        for d in self.base_deps:
+            if d in self.recursive_deps:
+                self.extra_deps.append(d.name)
+        if self.extra_deps:
+            print(f'{self.name}: extra deps {self.extra_deps}')
+
+    def dict_add(self, d):
+        """Add this object to a dictionary by name."""
+        d[self.name] = self
+
+
+def main(argv):
+    """Read the dependency tree from a dot file and process it."""
+    if len(argv) != 2:
+        print(f'Usage: {argv[0]} <build-directory>/deps.dot', file=sys.stderr)
+        sys.exit(1)
+
+    with open(argv[1]) as f:
+        for ln in f.readlines():
+            ln = ln.strip()
+            if '->' in ln:
+                name, deps = ln.split('->')
+                deps = deps.strip(' {}')
+                dep(name, deps.split(',')).dict_add(all_deps)
+            elif ln.startswith('"') and ln.endswith('"'):
+                dep(ln.strip('"'), []).dict_add(all_deps)
+
+
+if __name__ == '__main__':
+    main(sys.argv)
-- 
2.43.5