Please sign in to comment.
try defining algebraic Executables in the native backend to compose m…
…ore readable toolchains (pantsbuild#6855) ### Problem As can be seen in `native_toolchain.py` in e.g. pantsbuild#6800, it is often difficult to follow changes to the native backend, especially changes which modify the order of resources such as library and include directories for our linkers and compilers. This is because we have been patching together collections of these resources "by hand", without applying any higher-level structure (explicitly constructing each `path_entries` and `library_dirs` field for every executable, every time, for example). This was done to avoid creating abstractions that might break down due to the rapidly evolving code. We can now take the step of more clearly defining the relationships between the toolchains we construct hierarchically. ### Solution - Add an `ExtensibleAlgebraic` mixin which allows declaring list fields which can be immutably modified one at a time with `prepend_field` and `append_field`, or all at once with `sequence`. - Add a `for_compiler` method to `BaseLinker` to wrap the specific process required to prep our linker for a specific compiler. - Apply all of the above in `native_toolchain.py`. ### Result The compilers and linkers provided by `@rule`s in `native_toolchain.py` are composed with consistent verbs from `ExtensibleAlgebraic`, leading to increased readability.
- Loading branch information...
Showing with 241 additions and 175 deletions.
- +141 −36 src/python/pants/backend/native/config/environment.py
- +3 −2 src/python/pants/backend/native/subsystems/binaries/binutils.py
- +2 −2 src/python/pants/backend/native/subsystems/binaries/gcc.py
- +2 −2 src/python/pants/backend/native/subsystems/binaries/llvm.py
- +76 −116 src/python/pants/backend/native/subsystems/native_toolchain.py
- +5 −4 src/python/pants/backend/native/subsystems/xcode_cli_tools.py
- +1 −1 src/python/pants/backend/native/tasks/link_shared_libraries.py
- +5 −6 src/python/pants/backend/native/tasks/native_compile.py
- +6 −6 tests/python/pants_test/backend/native/subsystems/test_native_toolchain.py
Oops, something went wrong.