Re: [RFC PATCH] kbuild: check uniqueness of basename of modules

From: Masahiro Yamada
Date: Wed May 15 2019 - 14:10:36 EST


On Wed, May 15, 2019 at 4:40 PM Masahiro Yamada
<yamada.masahiro@xxxxxxxxxxxxx> wrote:

> $(Q)$(AWK) '!x[$$0]++' $^ > $(objtree)/modules.builtin
> diff --git a/scripts/modules-check.sh b/scripts/modules-check.sh
> new file mode 100755
> index 000000000000..944e68bd22b0
> --- /dev/null
> +++ b/scripts/modules-check.sh
> @@ -0,0 +1,18 @@
> +#!/bin/sh
> +# SPDX-License-Identifier: GPL-2.0
> +
> +# Warn if two or more modules have the same basename
> +check_same_name_modules()
> +{
> + same_name_modules=$(cat modules.order modules.builtin | \
> + xargs basename -a | sort | uniq -d)


I noticed a bug here.


allnoconfig + CONFIG_MODULES=y
will create empty modules.order and modules.builtin.

Then, 'basename -a' will emit the error messages
since it receives zero arguments.


basename: missing operand
Try 'basename --help' for more information.



I can fix it by checking the size of them.


# If both modules.order and modules.builtin are empty,
# "basename -a" emits error messages.
if [ ! -s modules.order -a ! -s modules.builtin ]; then
return
fi

same_name_modules=$(cat modules.order modules.builtin | \
xargs basename -a | sort | uniq -d)




I wonder if there is a more elegant way...




> + for m in $same_name_modules
> + do
> + echo "warning: same basename '$m' if the following are built as modules:"
> + grep --no-filename -e /$m modules.order modules.builtin | \
> + sed 's:^kernel/: :'
> + done
> +}
> +
> +check_same_name_modules
> --
> 2.17.1
>


--
Best Regards
Masahiro Yamada