From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 72932459D8; Thu, 19 Sep 2024 21:41:18 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B38A5433F4; Thu, 19 Sep 2024 21:40:52 +0200 (CEST) Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2062.outbound.protection.outlook.com [40.107.21.62]) by mails.dpdk.org (Postfix) with ESMTP id ADC27433DE for ; Thu, 19 Sep 2024 21:40:47 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=fLlCXbosRE2oigGBKQVlhtQ/90A1oJWPARyxFjxFkMLcDdgPvceWgoxQm6S10DNCWi/6LHU60CHTdxxC2DQaGQBWY+vdCu01c2d5J6ecJu55CVowMAxyO2iFQu0VmQy2EbRTmnagvkaxx/L5X0wbD/iydtjGXaBDALI7I4dkdiXct3gq5OBEfH28AsXgIXQEcXv3YSfHXTTmqBnAkLN57Q6XbZqimw+ydMXOj4ptz46RfexLS/xeAGAXbGTyEu55giXSuQY7r5ZmGdq3N5LbvG9EKKP40BQ1ZAGQtL7TBb0t1xq3Qbdg6+w1g0euOR+70mvmHfzSCilhoyRKzcej3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=BiKjm3MSodBwedrp7dB/69lY7uvEfC0kU4R64P00x4A=; b=DhCtWGlRdltTOGHJ8LMejRu/o6ymbGTtqEq2EXDECzK7nB/UAecr5Qrk/Rg/uKLC0YYULvN1A0Qo5zRALWAmIYvMcsROKWMq/CRJs4kG3Er+n/yvRQocF7klK3IuC1DpUGriuQ43TBO+MX8N0sSOH2tSCgcYQHk+sgoT3lrPf63DfuIMu+SueYRSZnUDeE6AODh94n3i0k4/M58tqKqGOHauuma7wNaiZqAtkklTPBaoOV+D/YmxDIt0hfoxICDigQ2k79W4oCxz3IZpH/TBgVJXH5/UKhNCZgu7cbbK5pJpo4BNTiCEYy2TYMFL7Gwgmzd8oyFOzhNuygA3Oc3XzQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 192.176.1.74) smtp.rcpttodomain=dpdk.org smtp.mailfrom=ericsson.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=ericsson.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ericsson.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=BiKjm3MSodBwedrp7dB/69lY7uvEfC0kU4R64P00x4A=; b=EFGYngnEcO7Lllk9iygWAw14nyYqS0aC3bYm66loPvLyOUcmIjjrU4k8ZUyT6o1HcYXthiFOabrKJe4Olym4WglQ+PYZy0YSxK9n9HrxLNiNlswSyhWS18zYFFFoXJvvZZL25+obu9Joe181VmtgAolJOAukOYZhWb4yHK6lUi3UBPeuX2qBJTjBAfP6Jyz0tVUIJ5bwUtEW8tH6AlRINsoMDe9HxO+wtgS89V/NhhNkudaw0Fmijj/BPKc3ZHT3dLYDwaEKo2MwIF27qxPoOFdt66kIekOPHbFYPO7XwM89xCbul9A3Idy0DC26OfO3P/Ccfk0Qc75WewFdQc9xpQ== Received: from DBBPR09CA0009.eurprd09.prod.outlook.com (2603:10a6:10:c0::21) by AS1PR07MB8565.eurprd07.prod.outlook.com (2603:10a6:20b:481::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7982.22; Thu, 19 Sep 2024 19:40:43 +0000 Received: from DB3PEPF0000885E.eurprd02.prod.outlook.com (2603:10a6:10:c0:cafe::fe) by DBBPR09CA0009.outlook.office365.com (2603:10a6:10:c0::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.30 via Frontend Transport; Thu, 19 Sep 2024 19:40:43 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 192.176.1.74) smtp.mailfrom=ericsson.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=ericsson.com; Received-SPF: Pass (protection.outlook.com: domain of ericsson.com designates 192.176.1.74 as permitted sender) receiver=protection.outlook.com; client-ip=192.176.1.74; helo=oa.msg.ericsson.com; pr=C Received: from oa.msg.ericsson.com (192.176.1.74) by DB3PEPF0000885E.mail.protection.outlook.com (10.167.242.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.13 via Frontend Transport; Thu, 19 Sep 2024 19:40:41 +0000 Received: from seliicinfr00050.seli.gic.ericsson.se (153.88.142.248) by smtp-central.internal.ericsson.com (100.87.178.69) with Microsoft SMTP Server id 15.2.1544.11; Thu, 19 Sep 2024 21:40:41 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00050.seli.gic.ericsson.se (Postfix) with ESMTP id 44D6A1C006D; Thu, 19 Sep 2024 21:40:41 +0200 (CEST) From: =?UTF-8?q?Mattias=20R=C3=B6nnblom?= To: CC: , Heng Wang , "Stephen Hemminger" , Tyler Retzlaff , =?UTF-8?q?Morten=20Br=C3=B8rup?= , Jack Bond-Preston , David Marchand , Chengwen Feng , =?UTF-8?q?Mattias=20R=C3=B6nnblom?= Subject: [PATCH v10 1/7] buildtools/chkincs: relax C linkage requirement Date: Thu, 19 Sep 2024 21:31:18 +0200 Message-ID: <20240919193124.737943-2-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240919193124.737943-1-mattias.ronnblom@ericsson.com> References: <20240918090445.725283-2-mattias.ronnblom@ericsson.com> <20240919193124.737943-1-mattias.ronnblom@ericsson.com> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB3PEPF0000885E:EE_|AS1PR07MB8565:EE_ X-MS-Office365-Filtering-Correlation-Id: 1f1a5a0f-887f-4459-ce68-08dcd8e2f257 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|376014|36860700013|82310400026; X-Microsoft-Antispam-Message-Info: =?utf-8?B?N29YMzlRK0ZKaklYQ2JBbW5JM0pkT1k3bHRveXdFWlhqMFJXdk9yVGgwUERM?= =?utf-8?B?V1BUVThmMU9tTFMzdnlCZUJpZmhwL24rbnpBTkxBRFFxVTJPSHFKREtBNlg5?= =?utf-8?B?N0pCUW5mQmYvTDhCWHhkSTErSlltazF3UE42WlhQWUFHMnZXaDUyOXBQcDBn?= =?utf-8?B?TkhvYkwydlBWSnh2TmJtMXkybFNYbU4wTTRtZWpjWXNjZkFiK2xGNWNmcFJM?= =?utf-8?B?REdjZEU2UzI1eENaV2VHT2h4Mytqai9kZTJIZjJwRUxQV2VUdnZjMWRoYis5?= =?utf-8?B?TnhBQzBBaHlRS05rQ3NmVzZvcGZOaFQ1aStvUSthOHZFK1VVby9kMndOanBa?= =?utf-8?B?RHF6UDVIOElSeDNrMDNLc013b3FaS0lpL2NpSmhVdThMdXRuL2IwUzRrSHIr?= =?utf-8?B?WHV6VkpkZ2ZBSHZCekoyQmRkL0x4ZUEwOEtyamZDbk9GZWxDb080RlpEOXJ0?= =?utf-8?B?ekhYU3lGRUlNVzhUUGxFdVByak9tcFdzdWFud1JldEwwQ2R3Ti9DUURlNkxn?= =?utf-8?B?dVNiUHVwNWlzUmQrMU16MjJFRjNtRk96Q0s3RzhuOF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nIzZ3hzeW0zc2lBUDUyTGNJdXBLTVN4Y1g4RE5iUHpl?= =?utf-8?B?SXlNYjl6djVLQXJEYjMraHhkNWM2cnFLZko4RUcwbUZtVFlpQ3lvVDB3Ky9q?= =?utf-8?B?R0tvK2tSMXMvb1IwOUZTeFprb3c3TVZDOTVzN20zRFRiTVVHQXJ4a0dXL1pU?= =?utf-8?B?T2JqNkhhQmxkWVBPWS9rb2tUd0MzYy9ZV3NnUEkzSzhZWGtjTER4OXF0dEsx?= =?utf-8?B?NmpNUHJlalhEYlBPMkxUNzQ0OEZLQThjU1hnR0lxOWZ4VEZZb2ZRRTFHZ2pK?= =?utf-8?B?dUp1em5KUzI4RnZreWF3MTdEN040QmVtQ0VtaXNSMEF5QklaR3A3Mk5KUTRP?= =?utf-8?B?L3Fia2JxUWU2T05NRG0zdkVxRFlqTXB0N1VyRTVaUzRDQm1hVkVuMkdKWVpZ?= =?utf-8?Q?u6Ln6zAdJNmbZ?= X-Forefront-Antispam-Report: CIP:192.176.1.74; CTRY:SE; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:oa.msg.ericsson.com; PTR:office365.se.ericsson.net; CAT:NONE; SFS:(13230040)(1800799024)(376014)(36860700013)(82310400026); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Sep 2024 19:40:41.9035 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1f1a5a0f-887f-4459-ce68-08dcd8e2f257 X-MS-Exchange-CrossTenant-Id: 92e84ceb-fbfd-47ab-be52-080c6b87953f X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=92e84ceb-fbfd-47ab-be52-080c6b87953f; Ip=[192.176.1.74]; Helo=[oa.msg.ericsson.com] X-MS-Exchange-CrossTenant-AuthSource: DB3PEPF0000885E.eurprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS1PR07MB8565 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Relax chkincs requirement of all DPDK header files having to contain 'extern "C"'. Instructing a C++ toolchain to use C linkage is only necessarily if the header file declares symbols (i.e., functions or global variables). With this change, chkincs tries to find if any functions or references to global variables are declared in the header file, and if not, no C linkage is required. Signed-off-by: Mattias Rönnblom --- buildtools/chkincs/chkextern.py | 84 +++++++++++++++++++++++++++++++++ buildtools/chkincs/meson.build | 14 +++--- 2 files changed, 91 insertions(+), 7 deletions(-) create mode 100755 buildtools/chkincs/chkextern.py diff --git a/buildtools/chkincs/chkextern.py b/buildtools/chkincs/chkextern.py new file mode 100755 index 0000000000..c9747fad1e --- /dev/null +++ b/buildtools/chkincs/chkextern.py @@ -0,0 +1,84 @@ +#! /usr/bin/env python3 +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2024 Ericsson AB + +import sys +import re + +def strip_cpp(header): + no_cpp = "" + header = header.replace("\\\n", " ") + + for line in header.split("\n"): + if re.match(r'^\s*#.*', line) is None and len(line) > 0: + no_cpp += "%s\n" % line + + return no_cpp + + +def strip_comments(header): + no_c_comments = re.sub(r'/\*.*?\*/', '', header, flags=re.DOTALL) + no_cxx_comments = re.sub(r'//.*', '', no_c_comments) + return no_cxx_comments + + +def strip(header): + header = strip_comments(header) + header = strip_cpp(header) + return header + + +def has_extern_c(header): + return header.find('extern "C"') != -1 + + +def has_vars(header): + return re.search(r'^extern\s+[a-z0-9_]+\s.*;', header, flags=re.MULTILINE) is not None + + +FUNCTION_RES = [ + r'rte_[a-z0-9_]+\(', + r'cmdline_[a-z0-9_]+\(', + r'vt100_[a-z0-9_]+\(', + r'rdline_[a-z0-9_]+\(', + r'cirbuf_[a-z0-9_]+\(' +] + + +def has_functions(header): + for function_re in FUNCTION_RES: + if re.search(function_re, header) is not None: + return True + return False + + +def has_symbols(header): + return has_functions(header) or has_vars(header) + + +def chk_missing(filename): + header = open(filename).read() + if has_symbols(header) and not has_extern_c(header): + print(filename) + + +def chk_redundant(filename): + header = open(filename).read() + if not has_symbols(header) and has_extern_c(header): + print(filename) + +if len(sys.argv) < 3: + print("%s missing|redundant ..." % sys.argv[0]) + sys.exit(1) + +op = sys.argv[1] +headers = sys.argv[2:] + +for header in headers: + if op == 'missing': + chk_missing(header) + elif op == 'redundant': + chk_redundant(header) + else: + print("Unknown operation.") + sys.exit(1) diff --git a/buildtools/chkincs/meson.build b/buildtools/chkincs/meson.build index f2dadcae18..762f85efe5 100644 --- a/buildtools/chkincs/meson.build +++ b/buildtools/chkincs/meson.build @@ -38,13 +38,13 @@ if not add_languages('cpp', required: false) endif # check for extern C in files, since this is not detected as an error by the compiler -grep = find_program('grep', required: false) -if grep.found() - errlist = run_command([grep, '--files-without-match', '^extern "C"', dpdk_chkinc_headers], - check: false, capture: true).stdout().split() - if errlist != [] - error('Files missing C++ \'extern "C"\' guards:\n- ' + '\n- '.join(errlist)) - endif +chkextern = find_program('chkextern.py') + +missing_extern_headers = run_command(chkextern, 'missing', dpdk_chkinc_headers, + capture: true, check: true).stdout().split() + +if missing_extern_headers != [] + error('Files missing C++ \'extern "C"\' guards:\n- ' + '\n- '.join(missing_extern_headers)) endif gen_cpp_files = generator(gen_c_file_for_header, -- 2.34.1