From ecdd2b0b2930b5e94d9f55e006a39b2e452c20e0 Mon Sep 17 00:00:00 2001 From: Arne Welzel Date: Tue, 27 Feb 2024 10:49:03 +0100 Subject: [PATCH] spicy/zeekygen: Remove mtime from generated code Zeekygen implements its own make-style update logic to prevent re-creation of files that have not changed. To fulfill this, we currently encode the current time into spicyz generated .cc files. This degrades ccache efficiency for built-in analyzers and also for all .evt files compiled during testing. Switch SpicyModuleInfo to return current time instead. This results in the re-generation of documentation files unconditionally when running Zeekygen, but that seems more acceptable IMO. Generally wonder if Zeekygen should produce output unconditionally and if we need to clobber prevention, compare with the content of the existing file. Closes #3619 --- scripts/spicy/zeek_rt.hlt | 2 +- src/spicy/manager.cc | 5 ++--- src/spicy/manager.h | 4 +--- src/spicy/runtime-support.cc | 5 ++--- src/spicy/runtime-support.h | 2 +- src/spicy/spicyz/glue-compiler.cc | 8 ++++---- src/zeekygen/SpicyModuleInfo.h | 7 +++---- 7 files changed, 14 insertions(+), 19 deletions(-) diff --git a/scripts/spicy/zeek_rt.hlt b/scripts/spicy/zeek_rt.hlt index d90f9c5187..3f4dd28adc 100644 --- a/scripts/spicy/zeek_rt.hlt +++ b/scripts/spicy/zeek_rt.hlt @@ -17,7 +17,7 @@ type ZeekTypeTag = enum { Addr, Any, Bool, Count, Double, Enum, Error, File, Func, Int, Interval, List, Opaque, Pattern, Port, Record, String, Subnet, Table, Time, Type, Vector, Void } &cxxname="::zeek::spicy::rt::ZeekTypeTag"; -declare public void register_spicy_module_begin(string name, string description, time mtime) &cxxname="zeek::spicy::rt::register_spicy_module_begin"; +declare public void register_spicy_module_begin(string name, string description) &cxxname="zeek::spicy::rt::register_spicy_module_begin"; declare public void register_protocol_analyzer(string name, hilti::Protocol protocol, vector ports, string parser_orig, string parser_resp, string replaces, string linker_scope) &cxxname="zeek::spicy::rt::register_protocol_analyzer" &have_prototype; declare public void register_file_analyzer(string name, vector mime_types, string parser, string replaces, string linker_scope) &cxxname="zeek::spicy::rt::register_file_analyzer" &have_prototype; declare public void register_packet_analyzer(string name, string parser, string replaces, string linker_scope) &cxxname="zeek::spicy::rt::register_packet_analyzer" &have_prototype; diff --git a/src/spicy/manager.cc b/src/spicy/manager.cc index 063fa495ad..87543e33aa 100644 --- a/src/spicy/manager.cc +++ b/src/spicy/manager.cc @@ -47,10 +47,9 @@ static std::pair parseID(const std::string& s) { Manager::~Manager() {} -void Manager::registerSpicyModuleBegin(const std::string& name, const std::string& description, hilti::rt::Time mtime) { +void Manager::registerSpicyModuleBegin(const std::string& name, const std::string& description) { assert(! _module_info); - _module_info = - std::make_unique(name, description, static_cast(mtime.seconds())); + _module_info = std::make_unique(name, description); } void Manager::registerSpicyModuleEnd() { diff --git a/src/spicy/manager.h b/src/spicy/manager.h index 2c5fac9008..6f74176d50 100644 --- a/src/spicy/manager.h +++ b/src/spicy/manager.h @@ -75,10 +75,8 @@ public: * and to index it, inside the Zeekygen documentation. * @param description textual description in reST that will be shown for * this module inside the Zeekygen documentation - * @param mtime timestamp indicating last time of modification of any of - * the module's content; used by Zeekygen to trigger rebuilds as necessary */ - void registerSpicyModuleBegin(const std::string& name, const std::string& description, hilti::rt::Time mtime); + void registerSpicyModuleBegin(const std::string& name, const std::string& description); /** * Runtime method to register a protocol analyzer with its Zeek-side diff --git a/src/spicy/runtime-support.cc b/src/spicy/runtime-support.cc index cd812cf106..0319ba15ee 100644 --- a/src/spicy/runtime-support.cc +++ b/src/spicy/runtime-support.cc @@ -20,9 +20,8 @@ using namespace zeek; using namespace zeek::spicy; -void rt::register_spicy_module_begin(const std::string& name, const std::string& description, - const hilti::rt::Time& mtime) { - spicy_mgr->registerSpicyModuleBegin(name, description, mtime); +void rt::register_spicy_module_begin(const std::string& name, const std::string& description) { + spicy_mgr->registerSpicyModuleBegin(name, description); } void rt::register_spicy_module_end() { spicy_mgr->registerSpicyModuleEnd(); } diff --git a/src/spicy/runtime-support.h b/src/spicy/runtime-support.h index 60a4890ea2..d84d4258a5 100644 --- a/src/spicy/runtime-support.h +++ b/src/spicy/runtime-support.h @@ -94,7 +94,7 @@ public: * Begins registration of a Spicy EVT module. All subsequent, other `register_*()` * function call will be associated with this module for documentation purposes. */ -void register_spicy_module_begin(const std::string& name, const std::string& description, const hilti::rt::Time& mtime); +void register_spicy_module_begin(const std::string& name, const std::string& description); /** * Registers a Spicy protocol analyzer with its EVT meta information with the diff --git a/src/spicy/spicyz/glue-compiler.cc b/src/spicy/spicyz/glue-compiler.cc index 550813539f..f81478f2ad 100644 --- a/src/spicy/spicyz/glue-compiler.cc +++ b/src/spicy/spicyz/glue-compiler.cc @@ -987,10 +987,10 @@ bool GlueCompiler::compile() { return false; if ( ! _doc_id.empty() ) { - auto mtime = hilti::expression::Ctor(hilti::ctor::Time(hilti::rt::time::current_time())); - preinit_body.addCall("zeek_rt::register_spicy_module_begin", - {hilti::builder::string_mut(_doc_id), hilti::builder::string_mut(_doc_description), - mtime}); + preinit_body.addCall("zeek_rt::register_spicy_module_begin", { + hilti::builder::string_mut(_doc_id), + hilti::builder::string_mut(_doc_description), + }); } for ( auto& a : _protocol_analyzers ) { diff --git a/src/zeekygen/SpicyModuleInfo.h b/src/zeekygen/SpicyModuleInfo.h index 75da7eeedd..634d0c3228 100644 --- a/src/zeekygen/SpicyModuleInfo.h +++ b/src/zeekygen/SpicyModuleInfo.h @@ -22,8 +22,8 @@ public: * @param name name of the Spicy EVT module. * @param description text describing the module further */ - explicit SpicyModuleInfo(const std::string& name, const std::string& description, time_t mtime) - : name(name), description(description), mtime(mtime) {} + explicit SpicyModuleInfo(const std::string& name, const std::string& description) + : name(name), description(description) {} /** @return textual description of the module */ const auto& Description() const { return description; } @@ -45,13 +45,12 @@ public: void AddBifItem(const std::string& id, plugin::BifItem::Type type) { bif_items.emplace_back(id, type); } private: - time_t DoGetModificationTime() const override { return mtime; } + time_t DoGetModificationTime() const override { return time(nullptr); } std::string DoName() const override { return name; } std::string DoReStructuredText(bool roles_only) const override { return ""; } std::string name; std::string description; - time_t mtime; std::list components; std::list bif_items;