orchestrion icon indicating copy to clipboard operation
orchestrion copied to clipboard

fix: build fails when `-cover` and/or `-covermode` are passed

Open RomainMuller opened this issue 1 year ago • 0 comments

Overhaul the Injector API to stop using decorator.Load which internally relies on the use of packages.Load (similar to go list), which caused all dependencies to be built without instrumentation as part of the instrumentation build (i.e, wasted effort).

It turns out it is viable to instead use a combination of standard library APIs to construct just the required inputs:

  1. use go/parser.ParseFile to parse the original source code to a go/ast tree
  2. use go/types to type-check the source code
    • use a custom go/importer that looks up from the -importcfg file
    • extract the Uses map from produced types.Info
  3. Create a decorator.Decorator using gotypes.DecoratorResolver built from the Uses map
  4. From this point on, the previous mode of operation is fully supported

This actually simplifies the flow quite a bit, as fewer information is now necessary from the proxy.CompileCommand (we no longer need to infer a source tree root), and allows working with files that have been transformed by other tools (such as go tool cover) seamlessly.


This PR also introduces a new way to adjust line position information (generation of //line directives) to produce more accurate results. It does so by comparing line information of nodes between the newly restored AST & the original AST, and making sure adjusted line information matches; adding new directives as necessary.


This also updates the test runners' go runtimes to go1.22.6 and go1.21.13 releases, which include bug fixes that allow us to:

  1. forego using gotip to use the covdata tool, as it no longer keeps an excessive amount of file descriptors open;
  2. collect coverage of the integration tests themselves during ingteration test runs.

Fixes #214

RomainMuller avatar Aug 07 '24 13:08 RomainMuller