Add @deprecated directive

It emits a warning stating that the script is deprecated.
This commit is contained in:
Jon Siwek 2018-08-31 09:24:03 -05:00
parent 57a505b0e4
commit a467d0c92d
4 changed files with 46 additions and 0 deletions

View file

@ -27,6 +27,16 @@ executed. Directives are evaluated before script execution begins.
print "File:", @FILENAME; print "File:", @FILENAME;
.. bro:keyword:: @deprecated
Marks the current script as deprecated. This can be placed anywhere in
the script, but a good convention is to put it as the first line.
You can also supply additional comments.
Example::
@deprecated "Use '@load foo' instead"
.. bro:keyword:: @load .. bro:keyword:: @load
Loads the specified Bro script, specified as the relative pathname Loads the specified Bro script, specified as the relative pathname

View file

@ -315,6 +315,23 @@ when return TOK_WHEN;
return TOK_ATTR_SYNCHRONIZED; return TOK_ATTR_SYNCHRONIZED;
} }
@deprecated.* {
auto num_files = file_stack.length();
auto comment = skip_whitespace(yytext + 11);
if ( num_files > 0 )
{
auto lf = file_stack[num_files - 1];
if ( lf->name )
reporter->Warning("deprecated script loaded from %s:%d %s",
lf->name, lf->line, comment);
else
reporter->Warning("deprecated script loaded from command line arguments %s", comment);
}
else
reporter->Warning("deprecated script loaded %s", comment);
}
@DEBUG return TOK_DEBUG; // marks input for debugger @DEBUG return TOK_DEBUG; // marks input for debugger

View file

@ -0,0 +1,3 @@
warning in ./foo.bro, line 1: deprecated script loaded from command line arguments
warning in ./bar.bro, line 1: deprecated script loaded from ./foo.bro:2 "Use '@load qux.bro' instead"
warning in ./baz.bro, line 1: deprecated script loaded from ./foo.bro:3

View file

@ -0,0 +1,16 @@
# @TEST-EXEC: bro -b foo
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff .stderr
@TEST-START-FILE foo.bro
@deprecated
@load bar
@load baz
@TEST-END-FILE
@TEST-START-FILE bar.bro
@deprecated "Use '@load qux.bro' instead"
@TEST-END-FILE
@TEST-START-FILE baz.bro
@deprecated
@TEST-END-FILE