($INBOX_DIR/description missing)
 help / color / Atom feed
* Re: [PATCH v2 08/10] scripts: Coccinelle script for namespace dependencies.
       [not found]   ` <20190813121733.52480-9-maennich@google.com>
@ 2019-08-13 12:31     ` Julia Lawall
  2019-08-14  6:36     ` [Cocci] " Himanshu Jha
  2019-08-14 12:00     ` [v2 " Markus Elfring
  2 siblings, 0 replies; 5+ messages in thread
From: Julia Lawall @ 2019-08-13 12:31 UTC (permalink / raw)
  To: Matthias Maennich
  Cc: linux-kernel, maco, kernel-team, arnd, geert, gregkh, hpa, jeyu,
	joel, kstewart, linux-arch, linux-kbuild, linux-m68k,
	linux-modules, linux-scsi, linux-usb, lucas.de.marchi, maco,
	michal.lkml, mingo, oneukum, pombredanne, sam, sboyd, sspatil,
	stern, tglx, usb-storage, x86, yamada.masahiro, Julia Lawall,
	Gilles Muller



On Tue, 13 Aug 2019, Matthias Maennich wrote:

> A script that uses the '<module>.ns_deps' file generated by modpost to
> automatically add the required symbol namespace dependencies to each
> module.
>
> Usage:
> 1) Move some symbols to a namespace with EXPORT_SYMBOL_NS() or define
>    DEFAULT_SYMBOL_NAMESPACE
> 2) Run 'make' (or 'make modules') and get warnings about modules not
>    importing that namespace.
> 3) Run 'make nsdeps' to automatically add required import statements
>    to said modules.
>
> This makes it easer for subsystem maintainers to introduce and maintain
> symbol namespaces into their codebase.
>
> Co-developed-by: Martijn Coenen <maco@android.com>
> Signed-off-by: Martijn Coenen <maco@android.com>
> Signed-off-by: Matthias Maennich <maennich@google.com>

Acked-by: Julia Lawall <julia.lawall@lip6.fr>


> ---
>  MAINTAINERS                                 |  5 ++
>  Makefile                                    | 12 +++++
>  scripts/Makefile.modpost                    |  4 +-
>  scripts/coccinelle/misc/add_namespace.cocci | 23 +++++++++
>  scripts/nsdeps                              | 54 +++++++++++++++++++++
>  5 files changed, 97 insertions(+), 1 deletion(-)
>  create mode 100644 scripts/coccinelle/misc/add_namespace.cocci
>  create mode 100644 scripts/nsdeps
>
> diff --git a/MAINTAINERS b/MAINTAINERS
> index e81e60bd7c26..aa169070a052 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -11414,6 +11414,11 @@ S:	Maintained
>  T:	git git://git.kernel.org/pub/scm/linux/kernel/git/wtarreau/nolibc.git
>  F:	tools/include/nolibc/
>
> +NSDEPS
> +M:	Matthias Maennich <maennich@google.com>
> +S:	Maintained
> +F:	scripts/nsdeps
> +
>  NTB AMD DRIVER
>  M:	Shyam Sundar S K <Shyam-sundar.S-k@amd.com>
>  L:	linux-ntb@googlegroups.com
> diff --git a/Makefile b/Makefile
> index 1b23f95db176..c5c3356e133c 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -1500,6 +1500,9 @@ help:
>  	@echo  '  headerdep       - Detect inclusion cycles in headers'
>  	@echo  '  coccicheck      - Check with Coccinelle'
>  	@echo  ''
> +	@echo  'Tools:'
> +	@echo  '  nsdeps          - Generate missing symbol namespace dependencies'
> +	@echo  ''
>  	@echo  'Kernel selftest:'
>  	@echo  '  kselftest       - Build and run kernel selftest (run as root)'
>  	@echo  '                    Build, install, and boot kernel before'
> @@ -1687,6 +1690,15 @@ quiet_cmd_tags = GEN     $@
>  tags TAGS cscope gtags: FORCE
>  	$(call cmd,tags)
>
> +# Script to generate missing namespace dependencies
> +# ---------------------------------------------------------------------------
> +
> +PHONY += nsdeps
> +
> +nsdeps:
> +	$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost nsdeps
> +	$(Q)$(CONFIG_SHELL) $(srctree)/scripts/$@
> +
>  # Scripts to check various things for consistency
>  # ---------------------------------------------------------------------------
>
> diff --git a/scripts/Makefile.modpost b/scripts/Makefile.modpost
> index 26e6574ecd08..743fe3a2e885 100644
> --- a/scripts/Makefile.modpost
> +++ b/scripts/Makefile.modpost
> @@ -56,7 +56,8 @@ MODPOST = scripts/mod/modpost						\
>  	$(if $(KBUILD_EXTMOD),$(addprefix -e ,$(KBUILD_EXTRA_SYMBOLS)))	\
>  	$(if $(KBUILD_EXTMOD),-o $(modulesymfile))			\
>  	$(if $(CONFIG_SECTION_MISMATCH_WARN_ONLY),,-E)			\
> -	$(if $(KBUILD_MODPOST_WARN),-w)
> +	$(if $(KBUILD_MODPOST_WARN),-w)					\
> +	$(if $(filter nsdeps,$(MAKECMDGOALS)),-d)
>
>  ifdef MODPOST_VMLINUX
>
> @@ -134,6 +135,7 @@ $(modules): %.ko :%.o %.mod.o FORCE
>
>  targets += $(modules)
>
> +nsdeps: __modpost
>
>  # Add FORCE to the prequisites of a target to force it to be always rebuilt.
>  # ---------------------------------------------------------------------------
> diff --git a/scripts/coccinelle/misc/add_namespace.cocci b/scripts/coccinelle/misc/add_namespace.cocci
> new file mode 100644
> index 000000000000..c832bb6445a8
> --- /dev/null
> +++ b/scripts/coccinelle/misc/add_namespace.cocci
> @@ -0,0 +1,23 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +//
> +/// Adds missing MODULE_IMPORT_NS statements to source files
> +///
> +/// This script is usually called from scripts/nsdeps with -D ns=<namespace> to
> +/// add a missing namespace tag to a module source file.
> +///
> +
> +@has_ns_import@
> +declarer name MODULE_IMPORT_NS;
> +identifier virtual.ns;
> +@@
> +MODULE_IMPORT_NS(ns);
> +
> +// Add missing imports, but only adjacent to a MODULE_LICENSE statement.
> +// That ensures we are adding it only to the main module source file.
> +@do_import depends on !has_ns_import@
> +declarer name MODULE_LICENSE;
> +expression license;
> +identifier virtual.ns;
> +@@
> +MODULE_LICENSE(license);
> ++ MODULE_IMPORT_NS(ns);
> diff --git a/scripts/nsdeps b/scripts/nsdeps
> new file mode 100644
> index 000000000000..148db65a830f
> --- /dev/null
> +++ b/scripts/nsdeps
> @@ -0,0 +1,54 @@
> +#!/bin/bash
> +# SPDX-License-Identifier: GPL-2.0
> +# Linux kernel symbol namespace import generator
> +#
> +# This script requires at least spatch
> +# version 1.0.4.
> +SPATCH_REQ_VERSION="1.0.4"
> +
> +DIR="$(dirname $(readlink -f $0))/.."
> +SPATCH="`which ${SPATCH:=spatch}`"
> +if [ ! -x "$SPATCH" ]; then
> +    echo 'spatch is part of the Coccinelle project and is available at http://coccinelle.lip6.fr/'
> +    exit 1
> +fi
> +
> +SPATCH_REQ_VERSION_NUM=$(echo $SPATCH_REQ_VERSION | ${DIR}/scripts/ld-version.sh)
> +SPATCH_VERSION=$($SPATCH --version | head -1 | awk '{print $3}')
> +SPATCH_VERSION_NUM=$(echo $SPATCH_VERSION | ${DIR}/scripts/ld-version.sh)
> +
> +if [ "$SPATCH_VERSION_NUM" -lt "$SPATCH_REQ_VERSION_NUM" ] ; then
> +    echo 'spatch needs to be version 1.06 or higher'
> +    exit 1
> +fi
> +
> +generate_deps_for_ns() {
> +    $SPATCH --very-quiet --in-place --sp-file \
> +	    $srctree/scripts/coccinelle/misc/add_namespace.cocci -D ns=$1 $2
> +}
> +
> +generate_deps() {
> +    local mod_file=`echo $@ | sed -e 's/\.ns_deps/\.mod/'`
> +    local mod_name=`cat $mod_file | sed -n 1p | sed -e 's/\/[^.]*$//'`
> +    local mod_source_files=`cat $mod_file | sed -n 2p | sed -e 's/\.o/\.c/g'`
> +    for ns in `cat $@`; do
> +	echo "Adding namespace $ns to module $mod_name (if needed)."
> +        generate_deps_for_ns $ns $mod_source_files
> +	# sort the imports
> +        for source_file in $mod_source_files; do
> +            sed '/MODULE_IMPORT_NS/Q' $source_file > ${source_file}.tmp
> +            offset=$(wc -l ${source_file}.tmp | awk '{print $1;}')
> +            cat $source_file | grep MODULE_IMPORT_NS | sort -u >> ${source_file}.tmp
> +            tail -n +$((offset +1)) ${source_file} | grep -v MODULE_IMPORT_NS >> ${source_file}.tmp
> +            if ! diff -q ${source_file} ${source_file}.tmp; then
> +                mv ${source_file}.tmp ${source_file}
> +            else
> +                rm ${source_file}.tmp
> +            fi
> +        done
> +    done
> +}
> +
> +for f in `find $srctree/.tmp_versions/ -name *.ns_deps`; do
> +    generate_deps $f
> +done
> --
> 2.23.0.rc1.153.gdeed80330f-goog
>
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Cocci] [PATCH v2 08/10] scripts: Coccinelle script for namespace dependencies.
       [not found]   ` <20190813121733.52480-9-maennich@google.com>
  2019-08-13 12:31     ` [PATCH v2 08/10] scripts: Coccinelle script for namespace dependencies Julia Lawall
@ 2019-08-14  6:36     ` " Himanshu Jha
  2019-08-14  8:03       ` Matthias Maennich
  2019-08-14 12:00     ` [v2 " Markus Elfring
  2 siblings, 1 reply; 5+ messages in thread
From: Himanshu Jha @ 2019-08-14  6:36 UTC (permalink / raw)
  To: Matthias Maennich
  Cc: linux-kernel, maco, kstewart, linux-m68k, oneukum,
	Mauro Carvalho Chehab, usb-storage, hpa, joel, sam, cocci,
	linux-arch, linux-scsi, x86, lucas.de.marchi, mingo, geert,
	stern, kernel-team, sspatil, arnd, linux-kbuild, Nicolas Palix,
	jeyu, Jonathan Cameron, tglx, michal.lkml, gregkh, linux-usb,
	sboyd

On Tue, Aug 13, 2019 at 01:17:05PM +0100, Matthias Maennich wrote:
> A script that uses the '<module>.ns_deps' file generated by modpost to
> automatically add the required symbol namespace dependencies to each
> module.
> 
> Usage:
> 1) Move some symbols to a namespace with EXPORT_SYMBOL_NS() or define
>    DEFAULT_SYMBOL_NAMESPACE
> 2) Run 'make' (or 'make modules') and get warnings about modules not
>    importing that namespace.
> 3) Run 'make nsdeps' to automatically add required import statements
>    to said modules.
> 
> This makes it easer for subsystem maintainers to introduce and maintain
> symbol namespaces into their codebase.
> 
> Co-developed-by: Martijn Coenen <maco@android.com>
> Signed-off-by: Martijn Coenen <maco@android.com>
> Signed-off-by: Matthias Maennich <maennich@google.com>
> ---

[]

>  MAINTAINERS                                 |  5 ++
>  Makefile                                    | 12 +++++
>  scripts/Makefile.modpost                    |  4 +-
>  scripts/coccinelle/misc/add_namespace.cocci | 23 +++++++++
>  scripts/nsdeps                              | 54 +++++++++++++++++++++
>  5 files changed, 97 insertions(+), 1 deletion(-)
>  create mode 100644 scripts/coccinelle/misc/add_namespace.cocci
>  create mode 100644 scripts/nsdeps

[]

> +if [ "$SPATCH_VERSION_NUM" -lt "$SPATCH_REQ_VERSION_NUM" ] ; then
> +    echo 'spatch needs to be version 1.06 or higher'

Nitpick: 1.0.6

> +    exit 1
> +fi


-- 
Himanshu Jha
Undergraduate Student
Department of Electronics & Communication
Guru Tegh Bahadur Institute of Technology

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Cocci] [PATCH v2 08/10] scripts: Coccinelle script for namespace dependencies.
  2019-08-14  6:36     ` [Cocci] " Himanshu Jha
@ 2019-08-14  8:03       ` Matthias Maennich
  0 siblings, 0 replies; 5+ messages in thread
From: Matthias Maennich @ 2019-08-14  8:03 UTC (permalink / raw)
  To: Himanshu Jha
  Cc: linux-kernel, maco, kstewart, linux-m68k, oneukum,
	Mauro Carvalho Chehab, usb-storage, hpa, joel, sam, cocci,
	linux-arch, linux-scsi, x86, lucas.de.marchi, mingo, geert,
	stern, kernel-team, sspatil, arnd, linux-kbuild, Nicolas Palix,
	jeyu, Jonathan Cameron, tglx, michal.lkml, gregkh,
	linux-usb@vger.kernel.orgNicolas Ferre

On Wed, Aug 14, 2019 at 12:06:11PM +0530, Himanshu Jha wrote:
>On Tue, Aug 13, 2019 at 01:17:05PM +0100, Matthias Maennich wrote:
>> A script that uses the '<module>.ns_deps' file generated by modpost to
>> automatically add the required symbol namespace dependencies to each
>> module.
>>
>> Usage:
>> 1) Move some symbols to a namespace with EXPORT_SYMBOL_NS() or define
>>    DEFAULT_SYMBOL_NAMESPACE
>> 2) Run 'make' (or 'make modules') and get warnings about modules not
>>    importing that namespace.
>> 3) Run 'make nsdeps' to automatically add required import statements
>>    to said modules.
>>
>> This makes it easer for subsystem maintainers to introduce and maintain
>> symbol namespaces into their codebase.
>>
>> Co-developed-by: Martijn Coenen <maco@android.com>
>> Signed-off-by: Martijn Coenen <maco@android.com>
>> Signed-off-by: Matthias Maennich <maennich@google.com>
>> ---
>
>[]
>
>>  MAINTAINERS                                 |  5 ++
>>  Makefile                                    | 12 +++++
>>  scripts/Makefile.modpost                    |  4 +-
>>  scripts/coccinelle/misc/add_namespace.cocci | 23 +++++++++
>>  scripts/nsdeps                              | 54 +++++++++++++++++++++
>>  5 files changed, 97 insertions(+), 1 deletion(-)
>>  create mode 100644 scripts/coccinelle/misc/add_namespace.cocci
>>  create mode 100644 scripts/nsdeps
>
>[]
>
>> +if [ "$SPATCH_VERSION_NUM" -lt "$SPATCH_REQ_VERSION_NUM" ] ; then
>> +    echo 'spatch needs to be version 1.06 or higher'
>
>Nitpick: 1.0.6
>

Good catch! Thanks!
Actually it needs to be even 1.0.4, so I will just use
$SPATCH_REQ_VERSION from above.

>> +    exit 1
>> +fi
>
>
>-- 
>Himanshu Jha
>Undergraduate Student
>Department of Electronics & Communication
>Guru Tegh Bahadur Institute of Technology

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [v2 08/10] scripts: Coccinelle script for namespace dependencies
       [not found]   ` <20190813121733.52480-9-maennich@google.com>
  2019-08-13 12:31     ` [PATCH v2 08/10] scripts: Coccinelle script for namespace dependencies Julia Lawall
  2019-08-14  6:36     ` [Cocci] " Himanshu Jha
@ 2019-08-14 12:00     ` " Markus Elfring
  2019-08-14 12:20       ` Matthias Maennich
  2 siblings, 1 reply; 5+ messages in thread
From: Markus Elfring @ 2019-08-14 12:00 UTC (permalink / raw)
  To: Matthias Maennich, Greg Kroah-Hartman, Julia Lawall,
	Martijn Coenen, Himanshu Jha, cocci, kernel-janitors
  Cc: Kate Stewart, linux-m68k, Oliver Neukum, Mauro Carvalho Chehab,
	usb-storage, H. Peter Anvin, Joel Fernandes, Sam Ravnborg,
	linux-arch, linux-scsi, x86, Lucas De Marchi, Ingo Molnar,
	Alan Stern, Geert Uytterhoeven, kernel-team, ,
	linux-kernel, Sandeep Patil, Arnd Bergmann, linux-kbuild,
	Philippe Ombredanne, Nicolas Palix, Jonatha

+# This script requires at least spatch
+# version 1.0.4.

How do you think about to avoid the duplicate specification of this identification?

Regards,
Markus

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [v2 08/10] scripts: Coccinelle script for namespace dependencies
  2019-08-14 12:00     ` [v2 " Markus Elfring
@ 2019-08-14 12:20       ` Matthias Maennich
  0 siblings, 0 replies; 5+ messages in thread
From: Matthias Maennich @ 2019-08-14 12:20 UTC (permalink / raw)
  To: Markus Elfring
  Cc: Kate Stewart, linux-m68k, Oliver Neukum, Mauro Carvalho Chehab,
	usb-storage, kernel-janitors, H. Peter Anvin, Joel Fernandes,
	Sam Ravnborg, cocci, linux-arch, linux-scsi, x86,
	Lucas De Marchi, Ingo Molnar, Alan Stern, Geert Uytterhoeven,
	kernel-team, Sandeep Patil, Arnd Bergmann, linux-kbuild,
	Philippe Ombredanne, Nicolas Palix

On Wed, Aug 14, 2019 at 02:00:23PM +0200, Markus Elfring wrote:
>+# This script requires at least spatch
>+# version 1.0.4.
>
>How do you think about to avoid the duplicate specification of this identification?
>

That is a good idea. I will reduce the patch to

+# This script requires a minimum spatch version.
+SPATCH_REQ_VERSION="1.0.4"

and use $SPATCH_REQ_VERSION when diagnosing this issue further down.

Cheers,
Matthias

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, back to index

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20180716122125.175792-1-maco@android.com>
     [not found] ` <20190813121733.52480-1-maennich@google.com>
     [not found]   ` <20190813121733.52480-9-maennich@google.com>
2019-08-13 12:31     ` [PATCH v2 08/10] scripts: Coccinelle script for namespace dependencies Julia Lawall
2019-08-14  6:36     ` [Cocci] " Himanshu Jha
2019-08-14  8:03       ` Matthias Maennich
2019-08-14 12:00     ` [v2 " Markus Elfring
2019-08-14 12:20       ` Matthias Maennich

($INBOX_DIR/description missing)

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-m68k/0 linux-m68k/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-m68k linux-m68k/ https://lore.kernel.org/linux-m68k \
		linux-m68k@vger.kernel.org
	public-inbox-index linux-m68k

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-m68k


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git