-
Notifications
You must be signed in to change notification settings - Fork 123
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
Basic implementation of "gopts" hook #4471
Basic implementation of "gopts" hook #4471
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The general idea looks great (it's pretty much what I had in mind when I started the new-backend
branch). However, the way you changed struct _KDB
requires quite a lot of allocations. I'm pretty sure we can avoid those. There are also some other minor issues.
Co-authored-by: Klemens Böswirth <23529132+kodebach@users.noreply.github.com>
Co-authored-by: Klemens Böswirth <23529132+kodebach@users.noreply.github.com>
Co-authored-by: Klemens Böswirth <23529132+kodebach@users.noreply.github.com>
Co-authored-by: Klemens Böswirth <23529132+kodebach@users.noreply.github.com>
Co-authored-by: Klemens Böswirth <23529132+kodebach@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Beautiful coding style!
doc/dev/hooks.md
Outdated
## Selecting which Plugin will be used for a specific hook | ||
|
||
Currently, the names of the plugins are hard-coded. | ||
This decision was made, because these plugins are meant to fulfil very specific purposes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Link to the decision.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a decision file specifically for the hardcoding part?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, we only have doc/decisions/global_plugins.md
And you need to adapt the decision with what we are actually doing now, e.g. calling it hooks. So the file also needs to be renamed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have modified and renamed it now.
src/libs/elektra/kdb.c
Outdated
@@ -999,6 +999,29 @@ KDB * kdbOpen (const KeySet * contract, Key * errorKey) | |||
goto error; | |||
} | |||
|
|||
// TODO (atmaxinger): improve | |||
bool existingError = keyGetMeta (errorKey, "error") != NULL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use new API, keyMeta and meta:/ (keyGetMeta will probably stay as alias but will not accept keys without meta:/ prefix)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO that's more of a nice-to-know. It's good if @atmaxinger knows that in future the recommended way to access meta keys is ksLookupByName (keyMeta (errorKey), "meta:/error", 0)
(or possibly keyGetMeta (errorKey, "meta:/error")
), but in the end it really doesn't matter if my tree-surgeon
scripts have to replace one more call.
So maybe always use meta:/
in future, but IMO there is really no need to change this now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kodebach if your tool can do these changes automatically it is of course also fine for now. But at some point we need to learn writing correct code (not relying on legacy code being in place), otherwise we will introduce wrong code again...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we keep it for now and let the tool of @kodebach handle it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you can keep this. But for future PRs it's probably better to always use meta:/
for meta keys. Just to get into the habbit and because there are already cases, where you need to meta:/
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have documentation for keyMeta
? Because the API Doc still tells me that I should use keySetMeta
and keyGetMeta
. Or is it just that I have to use the meta:/
prefix for all keys I use with those functions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Beyond the API docs, I don't think keyMeta
is documented yet. The docs are definitely outdated. keyGetMeta
/keySetMeta
might be removed (uncertain), but keyMeta
definitely will be the main API for metadata in future, since you can already do everything necessary with it.
Or is it just that I have to use the
meta:/
prefix for all keys I use with those functions?
When you use keyMeta
then you definitely have to provide the meta:/
namespace yourself. The fact that keyGetMeta
and keySetMeta
work without the meta:/
prefix is a backwards compatibility thing. Nobody has yet wanted to update all uses, and my semi-automatic tool isn't ready yet.
The actual meta keys always use the meta:/
prefix, because otherwise it wouldn't be a valid keyname. For example:
printf ("%s\n", keyName (keyGetMeta (keyNew ("/foo", KEY_META, "type", "string", KEY_END), "type")));
// prints meta:/type
What you should do to get in the habit of things is write code with meta:/
instead of without:
Key * k = keyNew ("/foo", KEY_META, "meta:/type", "string", KEY_END);
keyGetMeta (k, "meta:/type");
keySetMeta (k, "meta:/type", "long");
This also makes it far less likely that you run into problems with one of the cases, where the meta:/
is actually needed, e.g. things like:
Key * k = keyNew ("/foo", KEY_META, "type", "string", KEY_END);
if (strcmp ("type", keyName (keyGetMeta (k, "type"))) == 0) {
// doesn't work
}
if (strcmp ("meta:/type", keyName (keyGetMeta (k, "type"))) == 0) {
// works
}
…ebugging purposes
Co-authored-by: Markus Raab <markus2330@users.noreply.github.com>
Co-authored-by: Klemens Böswirth <23529132+kodebach@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work, LGTM. I really like the way you wrote the tests. Very clean. I have a few other comments, but IMO the PR could be merged as-is.
I also noticed that there are 10 new tests that fail compared to new-backend
(see also):
testshell_markdown_blacklist
testshell_markdown_conditionals
testshell_markdown_email
testshell_markdown_ipaddr
testshell_markdown_length
testshell_markdown_tutorial_validation
testkdb_error
testkdb_nested
testkdb_simple
Please have a quick look, if you find any obvious problems that are easy to fix. If you don't find anything or it's too much work, just leave it for another PR. I think the issue might be that you disable all "global plugins" including spec
.
*/ | ||
int initHooks (KDB * kdb, const KeySet * config, KeySet * modules, const KeySet * contract, Key * errorKey) | ||
{ | ||
bool existingError = ksLookupByName (keyMeta (errorKey), "meta:/error", 0) != NULL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, you can probably just return -1
, if there is an existing error and avoid the if (!existingError)
checks. If there was already an error, kdbOpen
should never have called this function.
Co-authored-by: Klemens Böswirth <23529132+kodebach@users.noreply.github.com>
Co-authored-by: Klemens Böswirth <23529132+kodebach@users.noreply.github.com>
Co-authored-by: Klemens Böswirth <23529132+kodebach@users.noreply.github.com>
Those seem to expect
I can't run these for whatever reason (probably missing dependency), but if I interpret it correctly, these tests just execute the shell commands included in the README of those plugins? |
I think some of these plugins don't have dependencies. You probably haven't enabled them in CMake. When you run
Yes, all the
In some way it must be your changes, since the test worked in the latest run on |
Yes, the problem lies in bool goptsActive = handle->globalPlugins[PROCGETSTORAGE][MAXONCE] != NULL; Which doesn't really tell you if libelektra/src/libs/elektra/kdb.c Lines 1780 to 1794 in 3e9f5ed
So this is more or less a bug/works-by-accident behaviour of the |
Hm yeah you're right. Let's leave it the way it is. We'll fix it in another PR at some point. Although something needs to change, because the failing tests haven't changed for a long time. For example this one hasn't changed for at least 7 years. That's a lot older than |
@markus2330 can we merge this so I can continue with spec and the other hooks? |
@atmaxinger Thank you, great job! Is there already something to test for @eiskasten? |
This PR aims to provide a basic implementation for the "gopts" hook. In theory it works, but there is still one assert in the test cases that does not, as mentioned in #4412.
This PR should also provide an opportunity to discuss the architecture of hooks in general.
Basics
(added as entry in
doc/news/_preparation_next_release.md
whichcontains
_(my name)_
)Please always add something to the release notes.
(first line should have
module: short statement
syntax)close #X
, are in the commit messages.doc/news/_preparation_next_release.md
scripts/dev/reformat-all
Checklist
(not in the PR description)
Review
Labels