From a467d0c92dcc6107eacfdf36d541a71b7c2ffe7b Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Fri, 31 Aug 2018 09:24:03 -0500 Subject: [PATCH] Add @deprecated directive It emits a warning stating that the script is deprecated. --- doc/script-reference/directives.rst | 10 ++++++++++ src/scan.l | 17 +++++++++++++++++ .../Baseline/language.at-deprecated/.stderr | 3 +++ testing/btest/language/at-deprecated.bro | 16 ++++++++++++++++ 4 files changed, 46 insertions(+) create mode 100644 testing/btest/Baseline/language.at-deprecated/.stderr create mode 100644 testing/btest/language/at-deprecated.bro diff --git a/doc/script-reference/directives.rst b/doc/script-reference/directives.rst index b56967ff3d..e515cf8bdb 100644 --- a/doc/script-reference/directives.rst +++ b/doc/script-reference/directives.rst @@ -27,6 +27,16 @@ executed. Directives are evaluated before script execution begins. 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 Loads the specified Bro script, specified as the relative pathname diff --git a/src/scan.l b/src/scan.l index ffdec4d640..9e0e5f75fc 100644 --- a/src/scan.l +++ b/src/scan.l @@ -315,6 +315,23 @@ when return TOK_WHEN; 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 diff --git a/testing/btest/Baseline/language.at-deprecated/.stderr b/testing/btest/Baseline/language.at-deprecated/.stderr new file mode 100644 index 0000000000..4668f2d7bf --- /dev/null +++ b/testing/btest/Baseline/language.at-deprecated/.stderr @@ -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 diff --git a/testing/btest/language/at-deprecated.bro b/testing/btest/language/at-deprecated.bro new file mode 100644 index 0000000000..dd0f746658 --- /dev/null +++ b/testing/btest/language/at-deprecated.bro @@ -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