spack/lib/spack
Todd Gamblin 54d741ba54 unparser: handle package-level loops, if statements, and with blocks
Many packages implement logic at the class level to handle complex dependencies and
conflicts. Others have started using `with when("@1.0"):` blocks since we added that
capability. The loops and other control logic can cause some pure directive logic not to
be removed by our package hashing logic -- and in many cases that's a lot of code that
will cause unnecessary rebuilds.

This commit changes the unparser so that it will descend into these blocks. Specifically:

  1. Descend into loops, if statements, and with blocks at the class level.
  2. Don't look inside function definitions (in or outside a class).
  3. Don't look at nested class definitions (they don't have directives)
  4. Add logic to *remove* empty loops/with blocks/if statements if all directives
     in them were removed.

This allows our package hash to ignore a lot of pure metadata that it was not ignoring
before, and makes it less sensitive.

In addition, we add `maintainers` and `tags` to the list of metadata attributes that
Spack should remove from packages when constructing canonoical source for a package
hash.

- [x] Make unparser handle if/for/while/with at class level.
- [x] Add tests for control logic removal.
- [x] Add a test to ensure that all packages are not only unparseable, but also
      that their canonical source is still compilable. This is a test for
      our control logic removal.
- [x] Add another unparse test package that has complex logic.
2022-01-12 06:14:18 -08:00
..
docs Fix table formatting (#28037) 2021-12-23 16:02:09 +01:00
env Support packages which need to explicitly refer to dpcpp by name (#27168) 2021-12-02 15:49:20 -08:00
external unparser: implement operator precedence algorithm for unparser 2022-01-12 06:14:18 -08:00
llnl Set backup=False by default in filter_file (#28036) 2021-12-23 16:02:09 +01:00
spack unparser: handle package-level loops, if statements, and with blocks 2022-01-12 06:14:18 -08:00