05-20-2021 01:40 PM
The Linker.Read Info From File method is a helpful utility for identifying the dependencies of a given VI/class/library, and especially useful for identifying and remedying cyclic dependencies (since these appear to significantly impact the editor environment and executable build times).
But the problem is: it doesn't work. Or, rather, it doesn't seem to work consistently. I was just running a little script I hacked together to try to identify cyclic dependencies, and it reported a few instances where a pair of classes were mutually dependent. Great news; that's exactly the sort of thing I was looking for. But when I started digging in, I couldn't find anything that would be linking those classes to one another.
After a lot of digging and headscratching, I found that the Linker method would return different results if I had the classes in memory. One of the main reasons why I like that method is that I was under the impression that it did not need to load (and compile) VIs, and was just looking at static linker information encoded directly in the files. But based on my recent findings, that does not appear to be the case.
Here's my hacky script (was planning to clean up and eventually roll it into our CI process, so we could fail a pipeline if cyclic dependencies were introduced):
I was specifically excluding stuff from vi.lib (technically, everything in C:\Program Files (x86)), and building a map of the class dependencies of each class in my project directory. Then, iterating over the map elements to look for cross-linking.
When I noticed the inconsistent behavior, I added that Write Text File operation to dump the results as JSON to disk. Then I ran this utility once by itself and once after opening the main project file that contained the classes I was analyzing, and compared the resulting JSON files using a diff viewer. Sure enough, there were significant differences in the two files.
I did a save-all, and even a mass compile (although nothing in the analyzed directory is set to "separate compiled code"), but I still always get different results when I scan the files with and without loading them into memory first. Oh, and I should note this is all using LV2019.
Does anyone have an explanation for this? Even if not, I figured it was worth pointing out here, in case someone else runs into a similar problem and starts googling for answers. And it might dissuade others from trusting this Linker method for anything critical (like my original plan for incorporating it into CI tests).