While working on packaging Flang in Gentoo, I’ve noticed that the fir-opt has some #ifdef FLANG_INCLUDE_TESTS that means that the tool’s behavior is slightly different depending on the value of this option. It was pointed out to me that MLIR suffers from the same problem, and indeed, I see that multiple MLIR tools have #ifdef MLIR_INCLUDE_TESTS conditions.
In my opinion, this goes against the principle of least surprise. It means that an option that’s described as responsible for “generating build targets for MLIR unit tests” actually changes how installed tools are built. This means that if you have two pipelines:
- that is intended to build MLIR, run tests, then install it.
- that is intended to build MLIR and install it, without running tests.
Then, if you set -DMLIR_INCLUDE_TESTS=OFF for the latter pipeline, you’re surprisingly going to get slightly different tools.
We’ve already discussed the same problem in Flang, but I think it would make sense to agree on the same solution for both MLIR and Flang, so I’d like to open a discussion here.
My “best” idea so far was to build a separate variant of the tools for tests. For example, mlir-opt would be always built without test-specific code, and if tests are enabled, an additional mlir-test-opt would be built with test-specific the code. Only the regular mlir-opt tool would be installed, and mlir-test-opt would be a build tree-only executable.
Throughout the discussion, it was also suggested that fir-opt isn’t really needed for end users, and that we may instead make it a test executable only, i.e. stop building and installing it otherwise. However, I don’t know if the same applies to MLIR tools involved, and given how long they have been installed, if there aren’t people actually using them.
What are your thoughts about the problem?