BinaryAnalysisPlatform / bap

Binary Analysis Platform
MIT License
2.07k stars 273 forks source link

deduplicates dune plugins and ignores empty plugins #1569

Closed ivg closed 1 year ago

ivg commented 1 year ago

Removes duplicating packages, provided that they have the same implementation.

When dune executes a binary (either via dune exec or dune test) it sets an internal DUNE_DIR_LOCATIONS environment variable, which affects the selection of plugins in bap, even if bap is installed from an indepenent repository. I am still not sure if this is a bug or a feature of dune, but to prevent double-loading we have to deduplicate plugins. We silently remove duplicating names only if all implementations that match the name are the same. We compare implementation using the sum of md5 sums of files that comprise the plugin folder. The choice of md5 sum as the implementation witness instead of parsing the META files allows us to preserve the abstraction of dune plugins, as the contents of the folder is the implementation detail of dune. This increases the probability that this code will still work when they will change the implementation.

In addition, this change workarounds another subtle bug in the dune plugin system. When a plugin is removed with opam remove, opam leaves an empty folder in the plugin folder, which we should ignore, otherwise, dune plugin loader will fail on it.