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 CC96543CBA; Fri, 15 Mar 2024 15:15:13 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 49B2642ED0; Fri, 15 Mar 2024 15:15:13 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mails.dpdk.org (Postfix) with ESMTP id 211FB42E6B for ; Fri, 15 Mar 2024 15:15:11 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710512110; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=6u1tcOLcEOk7+/h0S8x7bFt8a3V4jhCerqWqq0ekuSE=; b=fd4/a979lpz2jPEjvGt9dfo5Wa5HhQB7ygrZCCTOIPoOrYm53Q8a3i+8MH/UCZhtGb2Y2X /uU3xK7lJKc5QOfHtJgpkBM4g5EunSNUXx1oYxLwNesml6fYTjeaDS3g0Nnm6XZTiMJs7p ETsty+fXiqt34Srvv5W6fpUyH3pOd+c= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-687-auiT8PFpN1e5VUZAyy6kWQ-1; Fri, 15 Mar 2024 10:15:08 -0400 X-MC-Unique: auiT8PFpN1e5VUZAyy6kWQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D18C58007A2 for ; Fri, 15 Mar 2024 14:15:07 +0000 (UTC) Received: from ringo.redhat.com (unknown [10.39.208.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id 34E2C40C6DB3; Fri, 15 Mar 2024 14:15:07 +0000 (UTC) From: Robin Jarry To: dev@dpdk.org Subject: [PATCH] devtools: download scripts from linux if not found Date: Fri, 15 Mar 2024 15:14:42 +0100 Message-ID: <20240315141441.259594-2-rjarry@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true 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 Both checkpatches.sh and get-maintainer.sh require scripts that come from the linux sources. And they require DPDK_*_PATH variables to be set to point at these scripts locally. For new contributors this can be tedious since they will have to clone the whole linux sources just to have simple perl scripts. Update checkpatches.sh and get-maintainer.sh to have them download the upstream scripts if they are not found locally. Store the downloaded scripts in the .git/ folder so that they are found for future runs. If either DPDK_CHECKPATCH_PATH or DPDK_GETMAINTAINER_PATH are set, they will be used in priority. Signed-off-by: Robin Jarry --- devtools/checkpatches.sh | 6 ++++ devtools/get-maintainer.sh | 9 ++++++ devtools/load-devel-config | 45 +++++++++++++++++++++++++++++ doc/guides/contributing/patches.rst | 1 + 4 files changed, 61 insertions(+) diff --git a/devtools/checkpatches.sh b/devtools/checkpatches.sh index 8f245ebdabc4..bfacd77f398a 100755 --- a/devtools/checkpatches.sh +++ b/devtools/checkpatches.sh @@ -43,6 +43,8 @@ print_usage () { Run Linux kernel checkpatch.pl with DPDK options. The environment variable DPDK_CHECKPATCH_PATH can be set, if not we will try to find the script in the sources of the currently running kernel. + If the script cannot be found, you will be prompted for downloading it + from the upstream linux sources. The patches to check can be from stdin, files specified on the command line, latest git commits limited with -n option, or commits in the git range @@ -376,10 +378,14 @@ while getopts hn:qr:v ARG ; do done shift $(($OPTIND - 1)) +url="https://raw.githubusercontent.com/torvalds/linux/master/scripts/checkpatch.pl" + if [ ! -f "$DPDK_CHECKPATCH_PATH" ] || [ ! -x "$DPDK_CHECKPATCH_PATH" ] ; then default_path="/lib/modules/$(uname -r)/source/scripts/checkpatch.pl" if [ -f "$default_path" ] && [ -x "$default_path" ] ; then DPDK_CHECKPATCH_PATH="$default_path" + elif download_script DPDK_CHECKPATCH_PATH "$url"; then + true else print_usage >&2 echo diff --git a/devtools/get-maintainer.sh b/devtools/get-maintainer.sh index bba4d3f68db8..010aef221226 100755 --- a/devtools/get-maintainer.sh +++ b/devtools/get-maintainer.sh @@ -18,10 +18,19 @@ print_usage () { the get_maintainer.pl script located in Linux kernel sources. Example: DPDK_GETMAINTAINER_PATH=~/linux/scripts/get_maintainer.pl + If the script cannot be found, you will be prompted for downloading it + from the upstream linux sources. + Also refer to devtools/load-devel-config to store your configuration. END_OF_HELP } +if [ ! -f "$DPDK_GETMAINTAINER_PATH" ] || + [ ! -x "$DPDK_GETMAINTAINER_PATH" ] ; then + download_script DPDK_GETMAINTAINER_PATH \ + "https://raw.githubusercontent.com/torvalds/linux/master/scripts/get_maintainer.pl" +fi + # Requires DPDK_GETMAINTAINER_PATH devel config option set if [ ! -f "$DPDK_GETMAINTAINER_PATH" ] || [ ! -x "$DPDK_GETMAINTAINER_PATH" ] ; then diff --git a/devtools/load-devel-config b/devtools/load-devel-config index 69a0ac623a6e..46baf73fc0b3 100644 --- a/devtools/load-devel-config +++ b/devtools/load-devel-config @@ -1,4 +1,5 @@ # SPDX-License-Identifier: BSD-3-Clause +# vim: ft=sh # This file is intended to be sourced into shell @@ -14,3 +15,47 @@ test ! -r $(dirname $(readlink -f $0))/../.develconfig || . $(dirname $(readlink -f $0))/../.develconfig # The config files must export variables in the shell style + +# This function is called to download missing scripts by subcommands +# +# Example: +# download_script DPDK_CHECKPATCH_PATH \ +# https://raw.githubusercontent.com/torvalds/linux/master/scripts/checkpatch.pl +download_script() { # + var_name=$1 + url=$2 + + script_name=$(basename "$url") + git_dir=$(git rev-parse --git-dir) || return 1 + dl_path="$git_dir/$script_name" + + if [ -f "$dl_path" ] && [ -x "$dl_path" ]; then + eval "$var_name='$dl_path'" + return 0 + fi + + if ! [ -t 0 ]; then + # not in an interactive terminal, abort + return 1 + fi + prompt="Download $url and set $var_name=$dl_path? [y/n] " + + while printf '%s' "$prompt" && read y && ! [ "$y" = y ]; do + if [ "$y" = n ]; then + return 1 + fi + done + + if which curl >/dev/null 2>&1; then + curl -Lo "$dl_path" "$url" || return 1 + elif which wget >/dev/null 2>&1; then + wget -O "$dl_path" "$url" || return 1 + else + echo "error: neither curl nor wget are available." >&2 + return 1 + fi + chmod 755 "$dl_path" || return 1 + + eval "$var_name='$dl_path'" + return 0 +} diff --git a/doc/guides/contributing/patches.rst b/doc/guides/contributing/patches.rst index e286d9e6d59e..d24327bebb6c 100644 --- a/doc/guides/contributing/patches.rst +++ b/doc/guides/contributing/patches.rst @@ -462,6 +462,7 @@ This uses the Linux kernel development tool ``checkpatch.pl`` which can be obta updating the Linux kernel sources. The path to the original Linux script must be set in the environment variable ``DPDK_CHECKPATCH_PATH``. +If this variable is not set, ``checkpatches.sh`` will prompt before downloading it locally. Spell checking of commonly misspelled words is enabled by default if installed in ``/usr/share/codespell/dictionary.txt``. -- 2.44.0