stefan-hoeck / idris2-pack

BSD 3-Clause "New" or "Revised" License
90 stars 23 forks source link

`pack install` doesn't run `postinstall` #248

Open joelberkeley opened 1 year ago

joelberkeley commented 1 year ago

If I pack install spidr, pack doesn't run postinstall. On the other hand, if I run pack build spidr.ipkg locally, it does run postbuild.

My script reads a file and prints some output, so it's obvious when it runs

joelberkeley commented 1 year ago

I've also checked and idris2 --install spidr.ipkg run the postinstall script

joelberkeley commented 1 year ago

since my postinstall mainly prints to stdout, it's possible that pack install is running postinstall but is supressing the output

stefan-hoeck commented 1 year ago

since my postinstall mainly prints to stdout, it's possible that pack install is running postinstall but is supressing the output

Can you try running with pack --log-level debug and see whether the expected output is printed? Also, as a default, pack runs idris2 --install-with-src internally instead of just idris2 --install. Could you please verify if with this command the postinstall hook is being run?

joelberkeley commented 1 year ago

pack --log-level debug does the trick. Haven't tried the others yet

joelberkeley commented 1 year ago

I also just verified that pack install without --log-level debug does run postinstall - I used it to create a file. So it's definitely just suppressing output

joelberkeley commented 1 year ago

and yes, idris2 --install-with-src spidr.ipkg does run postinstall

stefan-hoeck commented 1 year ago

I also just verified that pack install without --log-level debug does run postinstall - I used it to create a file. So it's definitely just suppressing output

Yes, this is the expected behavior. We want to suppress the output from idris2 --install (but not from idris2 --build), because it clutters the application log with lots of messages about what files get copied where. Hence, the output of postinstall-hooks will also be suppressed.

stefan-hoeck commented 1 year ago

I'm closing this, at it describes expected behavior. Feel free to reopen if you want to further discuss this issue.

joelberkeley commented 1 year ago

Can I ask why this is the intended behaviour? Why is it different from postbuild?

joelberkeley commented 1 year ago

btw I don't seem to have the option to reopen the issue

stefan-hoeck commented 1 year ago

Can I ask why this is the intended behaviour? Why is it different from postbuild?

The difference is not about the postbuild and postinstall hooks but that - as a default - we want the output of idris2 --build to be printed, because this shows us the progress of building a library, which typically takes several seconds. On the other hand, we don't want to print the output of idris2 --install, because it totally clutters stdout with the paths of what files get copied where during installation. This might be interesting for debugging, but the average user should not be bothered with this, especially since idris2 --install is more or less instantaneous.

So, internally, pack runs the two commands separately: First idris2 --build with the output being logged at log level build, and and then idris2 --install-with-src with the output being logged at log level debug. As a - possibly unfortunate - side effect, the output of postbuild hooks gets also logged at log level build while postinstall gets logged at log level install.

As an alternative we could try and filter the output of idris2 --install and logging the rest at log level build, but I'm not sure if this would make things even less predictable. Another alternative would be to adjust idris2 in such a way that it allows us the silence the file copying spam.

joelberkeley commented 1 year ago

OK, thanks for the detailed explanation. I don't want to take up your time over this detail, and am happy to just use postbuild for now. However, I'm also interested in working out the right way to do this. If you are too, here's what I'm doing:

My postinstall simply prints installation instructions appropriate for the specific commit. The instructions just download files and edit shared library links. I have a few reasons for printing the instructions rather than executing them, but eventually I may just execute them, so postinstall (or preinstall) definitely sounds like the right place for that.

joelberkeley commented 1 year ago

I like the idea of idris --install logging at different levels so it's possible to silence some parts but not others. I definitely think the output of postinstall and the list of which files were copied where could be at different logging levels. I guess it depends on how library authors use postinstall and postbuild, which could contain useful stuff, like my instructions, but it could also contain a whole load of noise.

buzden commented 1 year ago

As a workaround (if it is appropriate for you), you can print instructions to stderr in your postinstall. In this case, they won't be suppressed by pack.

joelberkeley commented 1 year ago

thanks. For now I've used postbuild

joelberkeley commented 1 year ago

I feel it's worth addressing this somehow but don't need it myself so don't need the issue to stay open