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

cfg: fix config-version incosistencies #312

Merged
merged 2 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/cfg-lexer.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "cfg-lexer-subst.h"
#include "cfg-block-generator.h"
#include "cfg-grammar.h"
#include "cfg.h"
#include "block-ref-parser.h"
#include "pragma-parser.h"
#include "messages.h"
Expand Down Expand Up @@ -1165,6 +1166,15 @@ cfg_lexer_preprocess(CfgLexer *self, gint tok, CFG_STYPE *yylval, CFG_LTYPE *yyl

return CLPR_LEX_AGAIN;
}
else if (cfg_lexer_get_context_type(self) != LL_CONTEXT_PRAGMA && !self->first_non_pragma_seen)
{
/* Config version must be set before the first non-pragma element to avoid
* version-specific inconsistencies (e.g. template functions). */
if (cfg_get_user_version(self->cfg) == 0)
cfg_set_current_version(self->cfg);

self->first_non_pragma_seen = TRUE;
}

return CLPR_OK;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/cfg-lexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ struct _CfgLexer
GString *token_pretext;
GString *token_text;
GlobalConfig *cfg;
guint ignore_pragma:1;
guint first_non_pragma_seen:1, ignore_pragma:1;
};

/* pattern buffer */
Expand Down
10 changes: 5 additions & 5 deletions lib/cfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,12 @@ cfg_set_version(GlobalConfig *self, gint version)
{
if (self->user_version != 0)
{
msg_warning("WARNING: you have multiple @version directives in your configuration, only the first one is considered",
msg_warning("WARNING: The @version directive must be placed at the top of the main configuration file "
"(preferably as the very first line), preceding any @include directives and other configuration "
"elements, otherwise, the current version will be used. If you specify multiple @version directives "
"in your configuration, only the first one will be considered",
cfg_format_config_version_tag(self),
cfg_format_version_tag("new-version", version));
cfg_format_version_tag("ignored-version", version));
return TRUE;
}
cfg_set_version_without_validation(self, version);
Expand Down Expand Up @@ -662,9 +665,6 @@ cfg_read_config(GlobalConfig *self, const gchar *fname, gchar *preprocess_into)
cfg_dump_processed_config(self->preprocess_config, preprocess_into);
}

if (self->user_version == 0)
cfg_set_current_version(self);

if (res)
{
/* successfully parsed */
Expand Down
2 changes: 2 additions & 0 deletions news/bugfix-312.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Config `@version`: fixed compat-mode inconsistencies when `@version` was not specified at the top of the configuration
file or was not specified at all
Loading