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

Installing scripts is broken for Spicy analyzers. #97

Open
J-Gras opened this issue Oct 11, 2023 · 9 comments
Open

Installing scripts is broken for Spicy analyzers. #97

J-Gras opened this issue Oct 11, 2023 · 9 comments

Comments

@J-Gras
Copy link

J-Gras commented Oct 11, 2023

Looks like SPICY_SCRIPTS_OUTPUT_DIR_INSTALL is never set.

@bbannier
Copy link
Member

bbannier commented Oct 11, 2023

This reproduces with the default template.

To expand on this, we install SCRIPTS registered with spicy_add_analyzer iff SPICY_SCRIPTS_OUTPUT_DIR_INSTALL is set,

if (SPICY_SCRIPTS_OUTPUT_DIR_INSTALL AND DEFINED SPICY_ANALYZER_SCRIPTS)
if (NOT DEFINED SPICY_ANALYZER_PACKAGE_NAME)
message(FATAL_ERROR "SCRIPTS argument requires PACKAGE_NAME")
endif ()
install(
FILES ${SPICY_ANALYZER_SCRIPTS}
DESTINATION
"${SPICY_SCRIPTS_OUTPUT_DIR_INSTALL}/${SPICY_ANALYZER_PACKAGE_NAME}/${NAME_LOWER}")
endif ()

The original code in zeek/spicy-plugin populated this from spicyz --print-plugin-path, https://github.com/zeek/spicy-plugin/blob/a3e38215e7eb3ee733132c43cc3942379b038fc4/cmake/ZeekSpicyAnalyzerSupport.cmake#L161-L163

That flag now returns nothing for the version on the Zeek master branch, https://github.com/zeek/spicy-plugin/blob/a3e38215e7eb3ee733132c43cc3942379b038fc4/cmake/ZeekSpicyAnalyzerSupport.cmake#L161-L163

I am not really sure where the right location would be. Any ideas @rsmmr?

@bbannier bbannier self-assigned this Oct 24, 2023
@bbannier
Copy link
Member

The default package template for Spicy analyzers should set a script_dir in zkg.meta which makes analyzer Zeek scripts accessible at runtime, so this does not seem to be an issue. That being said, if one installs a Spicy analyzer directly from a manual CMake build, they will not be installed; this is similar to how manual installs of other Zeek plugin behave (also require manual copy).

I looked and the Spicy analyzers have behaved this way since the 5.x timeframe so the CMake code under that conditional has been dead code for some time.

@J-Gras
Copy link
Author

J-Gras commented Oct 26, 2023

this is similar to how manual installs of other Zeek plugin behave (also require manual copy).

I'm not following here. Doing a make install of a classic plugin copies its scripts to lib/zeek/plugins/<plugin_name> (tested using latest package template). Zeek 4.2 even introduced zeek_plugin_scripts() to trigger rebuilds on script changes.

Long story short: make install not resulting in a working installation is an issue that should be fixed. In case fiddling with scripts is out of scope, the install target should be removed altogether.

@J-Gras J-Gras reopened this Oct 26, 2023
@bbannier bbannier removed their assignment Oct 26, 2023
@awelzel
Copy link
Contributor

awelzel commented Oct 26, 2023

I'm not following here. Doing a make install of a classic plugin copies its scripts to lib/zeek/plugins/<plugin_name>

Sorry, that was me adding to the confusion because I thought that didn't quite work with normal plugins either. But that was about a non-default scripts_dir in zkg.meta. The ./scripts dir is always installed - with some quirks around zkg interaction.

https://zeekorg.slack.com/archives/CSZBXF6TH/p1687910485598759?thread_ts=1687887010.223089&cid=CSZBXF6TH
amzn/zeek-plugin-s7comm@1737987

Long story short: make install not resulting in a working installation is an issue that should be fixed. In case fiddling with scripts is out of scope, the install target should be removed altogether.

Re-opening is the right call. Pinging @rsmmr again, if he had a preferred solution.

@rsmmr
Copy link
Member

rsmmr commented Oct 30, 2023

Iirc these used to go into a scripts directory associated with the plugin, which the plugin would automatically add to ZEEK_PATH so that they would be found. With the the plugin now part of Zeek, I''m thinking these should probably now just install into Zeek's site directory under the analyzer's name.

@bbannier bbannier moved this to Todo in Zeek 6.2 Nov 7, 2023
@ckreibich
Copy link
Member

I'm circling back here since I just ended up in a support thread where this issue came up again and it still makes my head spin, plus I labeled this Zeek 7 above. :-)

I'm not sure I understand the use-case for the files specified in spicy_add_analyzer(SCRIPTS ...) — if in the past they were installed into the plugin's scripts folder, then they were subject to the plugin's load stage, so things like __preload__.zeek would work, which won't be the case if we start treating them like regular ZEEKPATH scripts. Also, if we now drop these into a folder below site named after the analyzer, then this risks collision (or at least confusion) with the directory zkg already creates for that purpose via symlinks into packages/<name>.

So I'm wondering — is there really a need for these scripts, or does the usual scripts_dir via zkg.meta cover the need? I am noticing that for built-in plugins spicy_add_analyzer() does not actually support SCRIPTS. So perhaps we just need to deprecate the use of SCRIPTS in the spicy_add_analyzer() version from ZeekSpicyAnalyzerSupport.cmake?

Fwiw, there are packages in the standard source (like spicy-http) that both use spicy_add_analyzer(SCRIPTS ...) in an analyzer directory while also pointing script_dir at this directory. This has the effect that unrelated files also get installed into what's supposed to be a tree of just Zeek scripts — things like CMakeLists.txt etc...

awelzel added a commit to zeek/package-template that referenced this issue Jun 18, 2024
The SCRIPTS parameter for spicy_add_analyzer() is not functional, so rendering
it into CMakeLists.txt is confusing [1]. Remove it.

These scripts are installed via zkg.meta's script_dir here in the template.

[1] zeek/cmake#97
@awelzel
Copy link
Contributor

awelzel commented Jun 19, 2024

So perhaps we just need to deprecate the use of SCRIPTS in the spicy_add_analyzer() version from ZeekSpicyAnalyzerSupport.cmake?

As discussed yesterday, to me this actually seems a valid approach, too. I've opened a PR to remove the rendering from the package-template as that seems confusing/misleading today given it's not working anyhow.

Emitting a deprecation warning if SCRIPTS are used (as it hasn't been functional) and advise users to leverage zkg and/or manually copying their scripts to the "right" place seems pragmatic.

For the latter, maybe a separate cmake function to install scripts into site/ could be interesting, leaving more decisions up to the user, but keeping it separate from spicy_add_analyzer() - I suspect that would most often collide with zkg logic if not used properly, but then that's not necessarily on us to fix.

@rsmmr
Copy link
Member

rsmmr commented Jun 19, 2024

As discussed yesterday, to me this actually seems a valid approach, too. I've opened a PR to remove the rendering from the package-template as that seems confusing/misleading today given it's not working anyhow.

Makes sense.

Emitting a deprecation warning if SCRIPTS are used (as it hasn't been functional) and advise users to leverage zkg and/or manually copying their scripts to the "right" place seems pragmatic.

Likewise agree.

For the latter, maybe a separate cmake function to install scripts into site/ could be interesting, leaving more decisions up to the user, but keeping it separate from spicy_add_analyzer() - I suspect that would most often collide with zkg logic if not used properly, but then that's not necessarily on us to fix.

Yeah, in principle people could just use normal CMake installation tools, but the trick is finding the destination path. Providing help with that would be good. Though the next question then is if the template should include such installation logic as well ...

@awelzel
Copy link
Contributor

awelzel commented Jun 19, 2024

Yeah, in principle people could just use normal CMake installation tools, but the trick is finding the destination path. Providing help with that would be good. Though the next question then is if the template should include such installation logic as well ...

Yep, install(FILES ...) might just do, but I realize its then the decision of individual plugin/analyzer authors how scripts are installed within Zeek's tree - seems better to make this hard and mention zkg here.

evantypanski added a commit to evantypanski/spicy-redis that referenced this issue Nov 1, 2024
I'm still confused about how scripts are supposed to be loaded in a
spicy plugin, a la zeek/cmake#97

It's just weird and unintuitive.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Status: Todo
Development

No branches or pull requests

5 participants