Skip to content
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

AP_Scripting: no warning if no ./scripts and no real filesystem #28012

Conversation

peterbarker
Copy link
Contributor

it is possible to build for boards without storage (so no Posix, no Fatafs), but still have scripts in ROMFS.

In this case we will use the backend AP_Filesystem_backend base class when doing file operations. This will alway fail to open directories, so when we try to load scripts from SCRIPTS_DIRECTORY it will always fail.

This leads to a warning being emitted:

Lua: State memory usage: 2796 + 5227
AP: Lua: open directory (./scripts) failed
AP: hello, world
Time has wrapped

Which isn't great.

Detect we are working on this filesystem and don't warn.

Alternative to https://github.com/ArduPilot/ardupilot/pull/27404/files

I've tested this on CubeOrange - warning is still emitted there (even if you're running scripts out of ROMFS already!)

STABILIZE> Got COMMAND_ACK: SCRIPTING: ACCEPTED
AP: Scripting: stopped
AP: Scripting: restarted
Lua: State memory usage: 2796 + 5431
AP: Lua: open directory (/APM/scripts) failed
AP: hello, world
AP: PreArm: RC not found

it is possible to build for boards without storage (so no Posix, no Fatafs), but still have scripts in ROMFS.

In this case we will use the backend AP_Filesystem_backend base class when doing file operations.  This will alway fail to open directories, so when we try to load scripts from SCRIPTS_DIRECTORY it will always fail.

This leads to a warning being emitted:

Lua: State memory usage: 2796 + 5227
AP: Lua: open directory (./scripts) failed
AP: hello, world
Time has wrapped

Which isn't great.

Detect we are working on this filesystem and don't warn.
@peterbarker peterbarker force-pushed the pr/no-warning-text-message-script-dir-open branch from 109676b to b686722 Compare September 4, 2024 14:47
@peterbarker
Copy link
Contributor Author

My testing was done on SDMODELH7v1 with this hwdef modification:

--- a/libraries/AP_HAL_ChibiOS/hwdef/SDMODELH7V1/hwdef.dat
+++ b/libraries/AP_HAL_ChibiOS/hwdef/SDMODELH7V1/hwdef.dat
@@ -2,3 +2,6 @@ include ../KakuteH7v2/hwdef.dat
 
 # board ID for firmware load
 APJ_BOARD_ID 1111
+
+undef AP_SCRIPTING_ENABLED
+define AP_SCRIPTING_ENABLED 1
pbarker@fx:~/rc/ardupilot(pr/no-warning-text-message-script-dir-open)$ 

@IamPete1
Copy link
Member

IamPete1 commented Sep 5, 2024

The advantage of the define approach is that we can error out at compile time if someone has scripting turned on and no way to load a script.

@peterbarker
Copy link
Contributor Author

The advantage of the define approach is that we can error out at compile time if someone has scripting turned on and no way to load a script.

That could/should be done as a separate check. I think it would be something like this:

#if AP_SCRIPTING_ENABLED
#if !AP_FILESYSTEM_POSIX_ENABLED && !AP_FILESYSTEM_FATFS_ENABLED && !AP_FILESYSTEM_ESP32_ENABLED && !AP_FILESYSTEM_ROMFS_ENABLED
#error "Scripting enabled but nowhere to read scripts from!"
#endif
#endif  // AP_SCRIPTING_ENABLED

I've no idea where that might live, however. Perhaps at the top of the file I'm modifying in here?

The reason I think these are separate things is that the user might be pointing SCRIPTING_DIRECTORY somewhere odd - like @ROMFS/extra_scripts, and that requires a runtime check.

@IamPete1
Copy link
Member

IamPete1 commented Sep 5, 2024

I've no idea where that might live, however. Perhaps at the top of the file I'm modifying in here?

We a check in config.h already, I think it would have to be updated as you sugest.

#error "Scripting requires a filesystem"

@peterbarker
Copy link
Contributor Author

I've no idea where that might live, however. Perhaps at the top of the file I'm modifying in here?

We a check in config.h already, I think it would have to be updated as you sugest.

#error "Scripting requires a filesystem"

#28027

@tridge tridge merged commit 777aab6 into ArduPilot:master Sep 9, 2024
93 checks passed
@peterbarker peterbarker deleted the pr/no-warning-text-message-script-dir-open branch September 10, 2024 02:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants