2019-10-28 21:08:45

by Jessica Yu

[permalink] [raw]
Subject: [PATCH 2/4] scripts/nsdeps: don't prepend $srctree if *.mod already contains full paths

When building in-tree modules, the *.mod file contains relative paths.
When building external modules, the resulting *.mod file contains absolute
paths. Allow for the nsdeps script to account for both types of paths and
only prepend $srctree in the case of relative paths. Otherwise, the script
will append $srctree to the path regardless and it will error out with file
not found errors if the path was already absolute to begin with.

Signed-off-by: Jessica Yu <[email protected]>
---

The sed regex is getting more ugly. It's not my strong point :/ If anyone
has a better regex to prepend $srctree for every relative path encountered
while ignoring absolute paths, I'm all ears.

scripts/nsdeps | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/nsdeps b/scripts/nsdeps
index 54d2ab8f9e5c..9ddcd5cb96b1 100644
--- a/scripts/nsdeps
+++ b/scripts/nsdeps
@@ -33,7 +33,7 @@ generate_deps() {
if [ ! -f "$ns_deps_file" ]; then return; fi
local mod_source_files=`cat $mod_file | sed -n 1p \
| sed -e 's/\.o/\.c/g' \
- | sed "s|[^ ]* *|${srctree}/&|g"`
+ | sed -E "s%(^|\s)([^/][^ ]*)%\1$srctree/\2%g"`
for ns in `cat $ns_deps_file`; do
echo "Adding namespace $ns to module $mod_name (if needed)."
generate_deps_for_ns $ns $mod_source_files
--
2.16.4


2019-10-29 10:16:27

by Masahiro Yamada

[permalink] [raw]
Subject: Re: [PATCH 2/4] scripts/nsdeps: don't prepend $srctree if *.mod already contains full paths

On Tue, Oct 29, 2019 at 12:14 AM Jessica Yu <[email protected]> wrote:
>
> When building in-tree modules, the *.mod file contains relative paths.
> When building external modules, the resulting *.mod file contains absolute
> paths.

Not necessarily true.
Kbuild does not impose any restriction about absolute/relative path.
M= can be a relative path.


> Allow for the nsdeps script to account for both types of paths and
> only prepend $srctree in the case of relative paths. Otherwise, the script
> will append $srctree to the path regardless and it will error out with file
> not found errors if the path was already absolute to begin with.
>
> Signed-off-by: Jessica Yu <[email protected]>
> ---
>
> The sed regex is getting more ugly. It's not my strong point :/ If anyone
> has a better regex to prepend $srctree for every relative path encountered
> while ignoring absolute paths, I'm all ears.


It is not the problem of sed regex ugliness.


You can prefix $srctree/
unlesss building external modules.


if [ "$KBUILD_EXTMOD" ]; then
src_prefix=
else
src_prefix=$srctree/
fi


Then,

sed "s|[^ ]* *|${src_prefix}&|g"`


Caution: not tested at all





> scripts/nsdeps | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/scripts/nsdeps b/scripts/nsdeps
> index 54d2ab8f9e5c..9ddcd5cb96b1 100644
> --- a/scripts/nsdeps
> +++ b/scripts/nsdeps
> @@ -33,7 +33,7 @@ generate_deps() {
> if [ ! -f "$ns_deps_file" ]; then return; fi
> local mod_source_files=`cat $mod_file | sed -n 1p \
> | sed -e 's/\.o/\.c/g' \
> - | sed "s|[^ ]* *|${srctree}/&|g"`
> + | sed -E "s%(^|\s)([^/][^ ]*)%\1$srctree/\2%g"`
> for ns in `cat $ns_deps_file`; do
> echo "Adding namespace $ns to module $mod_name (if needed)."
> generate_deps_for_ns $ns $mod_source_files
> --
> 2.16.4
>


--
Best Regards
Masahiro Yamada