Fixup CppToolchain to be lazy and actually cache.

Review Request #1850 — Created March 2, 2015 and submitted

Previously the c++ compiler was resolved in the constructor.  Doing this
work in the constructor made every indirect user pay the price with the
concrete example being the unit tests which would
fail if run without CXX exported.

Also, only the compiler tool was cached, other tool lookups via
register_tool populated but did not use the cache.  Fixup register_tool
to fully self-contain its caching behavior.

Finally, fixup to be unit-friendly and run in the
absence of CXX being exported and also tighten up exception trapping.

 contrib/cpp/src/python/pants/contrib/cpp/toolchain/     | 41 +++++++++++++++++++++++------------------
 contrib/cpp/tests/python/pants_test/contrib/cpp/ |  6 +++---
 contrib/cpp/tests/python/pants_test/contrib/cpp/   | 40 +++++++++++++++++++++++-----------------
 3 files changed, 49 insertions(+), 38 deletions(-)
Previously this failed but now passes:
$ PANTS_DEV=1 ./pants test contrib/cpp/::

And this still works, with no skips:
$ CXX=g++ PANTS_DEV=1 ./pants test contrib/cpp/::

CI went green here:
  • 0
  • 0
  • 1
  • 1
  • 2
Description From Last Updated
  2. can this overwrite tools now? maybe it's worth erroring if we already have a tool with 'name' in the cache.

    1. It can't, since the caching is now fully contained to this method, the short circuit check against _validated_tools up above on lines 42-44 guards over-write.  Each tool(name) is populated only once lazily.
  3. pulling the basename out of the path is harder to reason about than just using 'good-tool' directly.

    1. Agreed - simplified.
  1. Ship It!
Review request changed

Status: Closed (submitted)

  1. Ship It!