Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp2258614ybi; Thu, 20 Jun 2019 11:46:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqywEs06St8iVxHxUc2JLvtF/Z131d4J174sMxcCk9xozCq9jVLDnVWPWkz20y80AcIa5Cni X-Received: by 2002:a17:902:8203:: with SMTP id x3mr42835086pln.304.1561056373669; Thu, 20 Jun 2019 11:46:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561056373; cv=none; d=google.com; s=arc-20160816; b=cBuraxRyZN4K9vnA9qTN71LA8X9fBl3HTP31imYLSk4QZpUqqSLtc81uDGsI05+DJg Syit2+IbmVZjAXeP30zcN9uS48ZXX7HbUZfmxRAPGDiwaxDb8N4cVvniIrzmXggso/ft STA1aAidUyvk2VGRdzoGdMZDHbqomSPUomNUswnJ6pHiOaT8d8OFev//aAdffuskVCHA xCiRfraVp1UHkHWuKJmdc6WdTb4sg5PyaViu4MR/7NXZtSvc8ivOUgkaRVOtPoAiMPnu TLOKdF6jLCekRUHmwfYqzDLteSp8tBGCbjYP5cGRgEW3Oi/pI6n23cVt4gsuFuVGUrmo 74vg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=CanJNwThf8ELfY9fNk51EXnlSwekoumuBB46HW57fEw=; b=tfurD1a7W+2NsVKv9pmAbSTxMihUv355cPzOmU0mYg3V/Cqp3Cl1tXlw2GxCcC//cn xeqys4oXZKUZzeA6GOZfGHAmCny+wkxXnzRLE6kL4cwOZ44soe/IqmzhP/e+K8v1q711 BhVqRRmeze+0092r07D05GodGiz1MgqxbrZQT+h/toAgm+dkSSQD2chCfrgA2c0PU3AL KFNZfyjYz4Gm99rRh6O9VQSgoCf96xzj3ioHeHPXEk6yhMqHrQJxu2tsMWT+4YtdQrqt +JG8ruG1FaFC5pyonWE6eEFIVxJRzqNYxIRTQ3yDVLwF1S4OT9fSSzmjlB6A/M7AZH/h dnPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=PZSadPCP; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w188si244166pfd.283.2019.06.20.11.45.58; Thu, 20 Jun 2019 11:46:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=PZSadPCP; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726584AbfFTSpi (ORCPT + 99 others); Thu, 20 Jun 2019 14:45:38 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:33550 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726118AbfFTSph (ORCPT ); Thu, 20 Jun 2019 14:45:37 -0400 Received: by mail-pg1-f195.google.com with SMTP id m4so1428435pgk.0 for ; Thu, 20 Jun 2019 11:45:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=CanJNwThf8ELfY9fNk51EXnlSwekoumuBB46HW57fEw=; b=PZSadPCPR6eltmM8/aShVS9rd+YTu6zkA5luYU275a1bwiQuWPAEaVOfzkVho7QWG+ qH2JVpJOqAaF/qKXZhfMXgZXDKmgOTvjIzYiLy9azhMx9k26zDvtPHEwB6i6rZnb07dV C+4YFdaMKZ5e7HyDzx0ufX3wPY+IsIbhlMF3E= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=CanJNwThf8ELfY9fNk51EXnlSwekoumuBB46HW57fEw=; b=gHMa4kPg3MzmU3GSlroIPuktssKpEAJENcAhbyfSgpn5FEV2OCTvPXQFMB/jlweK8m O+RZ38kIM/V5ZIZX8G0Xv8BDF6Xvt+GLCJd8i5tUFqTqsxU5wLkjjjr+/kDs5u7Mubt+ guXdD7KHmipQ02NLWud3IIWAhD7F5QBVFp7jsYBSxZSw8Jc0UrmLfDl+pyYqQBQzJWZe rpNPNunO2PuDdhXl/cN6aF15Zsf07iFvz1blnX9AcJDVDN21Id0JHEqhk9TfPeGRPCwk pygdS5E46MfCwe0qtqzUAzt9Q1F9jCbXJxW18iXSt9E+aEFCOXc24x47ODHOVq2czCUT +7/A== X-Gm-Message-State: APjAAAWVNAj5ycdX3JZItL1ShoZfdVRwIUKajmDFad0t8l3mizCWoXeh 0JqUw6FVrMV0jMWVRwrAWnmDKQ== X-Received: by 2002:a65:44c8:: with SMTP id g8mr14039151pgs.443.1561056336821; Thu, 20 Jun 2019 11:45:36 -0700 (PDT) Received: from localhost ([2620:15c:202:1:75a:3f6e:21d:9374]) by smtp.gmail.com with ESMTPSA id s43sm472252pjb.10.2019.06.20.11.45.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Jun 2019 11:45:36 -0700 (PDT) From: Matthias Kaehlcke To: Tom Roeder , Masahiro Yamada Cc: linux-kernel@vger.kernel.org, Raul E Rangel , Nick Desaulniers , Tom Hughes , Douglas Anderson , Ryan Case , Yu Liu , Matthias Kaehlcke Subject: [PATCH] gen_compile_command: Add support for separate KBUILD_OUTPUT directory Date: Thu, 20 Jun 2019 11:45:23 -0700 Message-Id: <20190620184523.155756-1-mka@chromium.org> X-Mailer: git-send-email 2.22.0.410.gd8fdbe21b5-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org gen_compile_command.py currently assumes that the .cmd files and the source code live in the same directory, which is not the case when a separate KBUILD_OUTPUT directory is used. Add a new option to specify the kbuild output directory. If the option is not set the kernel source directory is used. Signed-off-by: Matthias Kaehlcke --- Feel free to bikeshed about the option names ;-) scripts/gen_compile_commands.py | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/scripts/gen_compile_commands.py b/scripts/gen_compile_commands.py index 7915823b92a5..5a738ec66cc7 100755 --- a/scripts/gen_compile_commands.py +++ b/scripts/gen_compile_commands.py @@ -31,15 +31,21 @@ def parse_arguments(): Returns: log_level: A logging level to filter log output. - directory: The directory to search for .cmd files. + source_directory: The kernel source directory. + kbuild_output_directory: The directory to search for .cmd files. output: Where to write the compile-commands JSON file. """ usage = 'Creates a compile_commands.json database from kernel .cmd files' parser = argparse.ArgumentParser(description=usage) - directory_help = ('Path to the kernel source directory to search ' + directory_help = ('Path to the kernel source directory' '(defaults to the working directory)') parser.add_argument('-d', '--directory', type=str, help=directory_help) + kbuild_output_directory_help = ('Path to the directory to search for ' + '.cmd files' + '(defaults to the kernel source directory)') + parser.add_argument('-k', '--kbuild-output-directory', type=str, + help=kbuild_output_directory_help) output_help = ('The location to write compile_commands.json (defaults to ' 'compile_commands.json in the search directory)') @@ -58,11 +64,14 @@ def parse_arguments(): if log_level not in _VALID_LOG_LEVELS: raise ValueError('%s is not a valid log level' % log_level) - directory = args.directory or os.getcwd() - output = args.output or os.path.join(directory, _DEFAULT_OUTPUT) - directory = os.path.abspath(directory) + source_directory = args.directory or os.getcwd() + output = args.output or os.path.join(source_directory, _DEFAULT_OUTPUT) + source_directory = os.path.abspath(source_directory) - return log_level, directory, output + kbuild_output_directory = args.kbuild_output_directory or source_directory + kbuild_output_directory = os.path.abspath(kbuild_output_directory) + + return log_level, source_directory, kbuild_output_directory, output def process_line(root_directory, file_directory, command_prefix, relative_path): @@ -109,7 +118,8 @@ def process_line(root_directory, file_directory, command_prefix, relative_path): def main(): """Walks through the directory and finds and parses .cmd files.""" - log_level, directory, output = parse_arguments() + log_level, source_directory, kbuild_output_directory, output = \ + parse_arguments() level = getattr(logging, log_level) logging.basicConfig(format='%(levelname)s: %(message)s', level=level) @@ -118,7 +128,7 @@ def main(): line_matcher = re.compile(_LINE_PATTERN) compile_commands = [] - for dirpath, _, filenames in os.walk(directory): + for dirpath, _, filenames in os.walk(kbuild_output_directory): for filename in filenames: if not filename_matcher.match(filename): continue @@ -131,7 +141,7 @@ def main(): continue try: - entry = process_line(directory, dirpath, + entry = process_line(source_directory, dirpath, result.group(1), result.group(2)) compile_commands.append(entry) except ValueError as err: -- 2.22.0.410.gd8fdbe21b5-goog