Skip to content

sys/shell: Fix missing dependency #19485

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 22, 2023
Merged

Conversation

maribu
Copy link
Member

@maribu maribu commented Apr 19, 2023

Contribution description

The shell commands depend on the shell module being use. This was already the case in KConfig, but was overlooked in the shell's Makefile.dep.

In addition, this uncovered that tests/memarray had a bogus dependency on shell commands without every using the shell.

Testing procedure

Ideally binaries should not differ (except for debug section).

Issues/PRs references

Split out of #19483

maribu added 2 commits April 19, 2023 12:24
There is no need for shell commands if there is no shell.
The shell_cmds module depends on the shell module. This was correctly
added to KConfig, but the Makefile dependencies missed this one. This
commit adds the missing dep.
@maribu maribu added Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) Impact: minor The PR is small in size and might only require a quick look of a knowledgeable reviewer CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Apr 19, 2023
@github-actions github-actions bot added Area: sys Area: System Area: tests Area: tests and testing framework labels Apr 19, 2023
@riot-ci
Copy link

riot-ci commented Apr 19, 2023

Murdock results

✔️ PASSED

69b3e05 sys/shell: restructure deps

Success Failures Total Runtime
6882 0 6882 10m:28s

Artifacts

@aabadie
Copy link
Contributor

aabadie commented Apr 19, 2023

This could go even further by removing all USEMODULE += shell from applications where there is:

USEMODULE += shell
USEMODULE += shell_cmds_default

And there's a lot of these :)

@aabadie
Copy link
Contributor

aabadie commented Apr 19, 2023

There's something weird with the way shell dependencies are managed.

I think

ifneq (,$(filter shell_cmds,$(USEMODULE)))
  USEMODULE += shell
endif

should go in sys/Makefile.dep instead of sys/shell/Makefile.dep. In the second case, it means when both shell and shell_cmds are included, include shell again...

The following code in sys/Makefile.dep should rather be rewritten:

RIOT/sys/Makefile.dep

Lines 337 to 340 in 812c216

ifneq (,$(filter shell%,$(USEMODULE)))
USEMODULE += stdin
include $(RIOTBASE)/sys/shell/Makefile.dep
endif

with something like:

ifneq (,$(filter shell_commands,$(USEMODULE)))
  # shell_commands has been renamed to shell_cmds_default, but let's keep this
  # for backward compatibility
  USEMODULE += shell_cmds_default
endif

ifneq (,$(filter shell_cmd_%,$(USEMODULE)))
  # each and every command is a submodule of shell_cmds
  USEMODULE += shell_cmds
endif

ifneq (,$(filter shell_cmds,$(USEMODULE)))
  USEMODULE += shell
endif

And let the shell module manage its own dependencies (so in sys/shell/Makefile.dep):

USEMODULE += stdin

ifneq (,$(filter shell_cmds_default,$(USEMODULE)))
  USEMODULE += shell_cmd_sys

  ...

@aabadie
Copy link
Contributor

aabadie commented Apr 19, 2023

Also isn't the benefit of this PR to allow to just include shell_command_default instead of both shell and shell_command_default. So why not apply this new pattern everywhere for consistency, from the start ?

@aabadie
Copy link
Contributor

aabadie commented Apr 19, 2023

One last thing: should Kconfig be also updated ?

@maribu
Copy link
Member Author

maribu commented Apr 19, 2023

One last thing: should Kconfig be also updated ?

No, in KConfig the dependency is there already. It was just missing in the Makefile bases dependency modeling.

@maribu
Copy link
Member Author

maribu commented Apr 19, 2023

There's something weird with the way shell dependencies are managed.

I think

ifneq (,$(filter shell_cmds,$(USEMODULE)))
  USEMODULE += shell
endif

should go in sys/Makefile.dep instead of sys/shell/Makefile.dep.

But why? sys/Makefile.dep is already pretty crowded and a hot spot for merge conflicts. Having all shell related dependencies in sys/shell/Makefile.dep is much better structured.

Also isn't the benefit of this PR to allow to just include shell_command_default instead of both shell and shell_command_default. So why not apply this new pattern everywhere for consistency, from the start ?

I can do that, one sec.

When depending on one or more shell commands, the shell is pulled in
as dependency anyway.
@maribu maribu requested a review from jeandudey as a code owner April 19, 2023 14:59
@github-actions github-actions bot added Area: build system Area: Build system Area: examples Area: Example Applications labels Apr 19, 2023
@aabadie
Copy link
Contributor

aabadie commented Apr 20, 2023

But why?

Because it's more correct ?

Having all shell related dependencies in sys/shell/Makefile.dep is much better structured.

Except that shell_cmds and shell_cmd_default (both are pseudomodules) are not dependencies of shell but the other way around. If you look at how drivers dependencies are managed, my proposal goes into that direction. Each driver has a Makefile.dep to manage its own dependencies but the drivers/Makefile.dep contains some dependency resolution logic when pseudomodules are pulled in (for example "sx126x" is the concrete module but sx126% dependencies are handled in drivers/Makefile.dep.

My proposal above does exactly the same for shell.

@aabadie
Copy link
Contributor

aabadie commented Apr 20, 2023

Actually to get the same behavior as for driver modules, there's something missing in the top level Makefile.dep file:

# pull Makefile.dep of each sys modules if they exist
-include $(sort $(USEMODULE:%=$(RIOTBASE)/sys/%/Makefile.dep))

And that should do the trick (and we could have a Makefile.dep per sys module that contain their own dependencies)

@aabadie
Copy link
Contributor

aabadie commented Apr 21, 2023

Using the following patch works for me and I find it cleaner than the current master version:

git format-patch -1 --stdout 
From 4221a118d48c4c3d4930d03df1e2bb5a5ba8162c Mon Sep 17 00:00:00 2001
From: Alexandre Abadie <alexandre.abadie@inria.fr>
Date: Fri, 21 Apr 2023 09:23:52 +0200
Subject: [PATCH] sys/shell: cleanup shell dependency resolution

---
 Makefile.dep           |  3 +++
 sys/Makefile.dep       | 16 +++++++++++++---
 sys/shell/Makefile.dep | 11 +----------
 3 files changed, 17 insertions(+), 13 deletions(-)

diff --git a/Makefile.dep b/Makefile.dep
index db56c9c1f0..d8a1074c6d 100644
--- a/Makefile.dep
+++ b/Makefile.dep
@@ -19,6 +19,9 @@ include $(RIOTBASE)/drivers/Makefile.dep
 # pull Makefile.dep of each driver modules if they exist
 -include $(sort $(USEMODULE:%=$(RIOTBASE)/drivers/%/Makefile.dep))
 
+# pull Makefile.dep of each sys modules if they exist
+-include $(sort $(USEMODULE:%=$(RIOTBASE)/sys/%/Makefile.dep))
+
 # pull dependencies from packages
 -include $(PKG_PATHS:%=%Makefile.dep)
 
diff --git a/sys/Makefile.dep b/sys/Makefile.dep
index 5cb8f39945..2849fc029f 100644
--- a/sys/Makefile.dep
+++ b/sys/Makefile.dep
@@ -334,9 +334,19 @@ ifneq (,$(filter random_cmd,$(USEMODULE)))
   USEMODULE += shell_cmd_random
 endif
 
-ifneq (,$(filter shell%,$(USEMODULE)))
-  USEMODULE += stdin
-  include $(RIOTBASE)/sys/shell/Makefile.dep
+ifneq (,$(filter shell_commands,$(USEMODULE)))
+  # shell_commands has been renamed to shell_cmds_default, but let's keep this
+  # for backward compatibility
+  USEMODULE += shell_cmds_default
+endif
+
+ifneq (,$(filter shell_cmd%,$(USEMODULE)))
+  # each and every command is a submodule of shell_cmds
+  USEMODULE += shell_cmds
+endif
+
+ifneq (,$(filter shell_cmds,$(USEMODULE)))
+  USEMODULE += shell
 endif
 
 # Include all stdio_% dependencies after all USEMODULE += stdio_%
diff --git a/sys/shell/Makefile.dep b/sys/shell/Makefile.dep
index eb2360479c..da3616e0e5 100644
--- a/sys/shell/Makefile.dep
+++ b/sys/shell/Makefile.dep
@@ -1,13 +1,4 @@
-ifneq (,$(filter shell_cmd_%,$(USEMODULE)))
-  # each and every command is a submodule of shell_cmds
-  USEMODULE += shell_cmds
-endif
-
-ifneq (,$(filter shell_commands,$(USEMODULE)))
-  # shell_commands has been renamed to shell_cmds_default, but let's keep this
-  # for backward compatibility
-  USEMODULE += shell_cmds_default
-endif
+USEMODULE += stdin
 
 ifneq (,$(filter shell_cmds_default,$(USEMODULE)))
   USEMODULE += shell_cmd_sys
-- 
2.37.2

Move deps on sys/shell to sys/Makefile.dep and only keep deps of
sys/shell in sys/shell/Makefile.dep
@maribu
Copy link
Member Author

maribu commented Apr 21, 2023

Since you insist, I move the dependencies on sys/shell to sys/Makefile.dep

diff --git a/Makefile.dep b/Makefile.dep
index db56c9c1f0..d8a1074c6d 100644
--- a/Makefile.dep
+++ b/Makefile.dep
@@ -19,6 +19,9 @@ include $(RIOTBASE)/drivers/Makefile.dep
 # pull Makefile.dep of each driver modules if they exist
 -include $(sort $(USEMODULE:%=$(RIOTBASE)/drivers/%/Makefile.dep))
 
+# pull Makefile.dep of each sys modules if they exist
+-include $(sort $(USEMODULE:%=$(RIOTBASE)/sys/%/Makefile.dep))
+
 # pull dependencies from packages
 -include $(PKG_PATHS:%=%Makefile.dep)
 
diff --git a/sys/Makefile.dep b/sys/Makefile.dep
index 5cb8f39945..2849fc029f 100644

Let's not get overboard with this PR. This PR is intended to just fix a simple bug.

@aabadie
Copy link
Contributor

aabadie commented Apr 21, 2023

Let's not get overboard with this PR. This PR is intended to just fix a simple bug.

I agree. If unsure we can still do in a follow up PR. I tried to apply that change (the -include $(sort $(USEMODULE:%=$(RIOTBASE)/sys/%/Makefile.dep)) trick) and I think it might have some impact in the dependency resolution of xtimer/ztimer where it seems inclusion order matters a lot. I opened a draft in #19492 (doesn't contain the shell changes though)

@aabadie
Copy link
Contributor

aabadie commented Apr 21, 2023

Since you insist, I move the dependencies on sys/shell to sys/Makefile.dep

Thanks! I don't see the diff from #19485 (comment) in the PR changes. But let's keep it like this as I think it can have a high impact and requires special care.

Copy link
Contributor

@aabadie aabadie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK

@aabadie
Copy link
Contributor

aabadie commented Apr 22, 2023

bors merge

@bors
Copy link
Contributor

bors bot commented Apr 22, 2023

Build succeeded:

@bors bors bot merged commit 0101663 into RIOT-OS:master Apr 22, 2023
@maribu maribu deleted the sys/shell/fix_dep branch April 25, 2023 11:50
@benpicco benpicco added this to the Release 2023.07 milestone Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: build system Area: Build system Area: examples Area: Example Applications Area: sys Area: System Area: tests Area: tests and testing framework CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Impact: minor The PR is small in size and might only require a quick look of a knowledgeable reviewer Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants