sapling/build/fbcode_builder/CMake
Alexander Mols 0229ed4506 Fix bug in optimizing module loader for coverage collection
Summary:
In coverage collection mode a special module loader is prepended to
`sys.meta_path`. In very specific conditions this module loader can end up
returning a loader pointing to a _completely wrong module_. When importing
symbols from the wrong module errors occur.

The conditions to trigger the bug are:

- running in coverage collection mode, enabling the custom loader
- the test binary is a zip (e.g. par_style=fastzip)
- having a module name where the end part matches the name of a builtin Python
  module

When these conditions were met, the special loader would return the builtin
Python module instead of the expected module. E.g. when loading a module like
`myapp.somemod.platform` in a zip style binary.

The custom loader first calls `imp.find_module()` to find the module it wants
to return a wrapped loader for. This fails for modules included in the test
binary, because the builtin `imp` module can not load from zips. This was the
trigger leading to the call to the buggy code.

When the initial call to `imp.find_module()` failed, the custom loader would
try a second call, asking the internal loader to this time try any path on
`sys.path`. For most module names this call would also fail, making the custom
loader return `None`, after which Python tries other loaders on `sys.path`.
However, when the final part of the module that was asked to load matches the
name of a Python builtin module, then the second call to the `imp` module would
succeed, returning a loader for the builtin module. E.g. `platform` when asking
for `myapp.somemod.platform`.

This diff fixes the issue by removing the broken second call to the internal
loader. This will never have worked, we just have not triggered or noticed
triggering the wrong loading before.

Differential Revision: D20798119

fbshipit-source-id: dffb54e308106a81af21b63c5ee64c6ca2041920
2020-04-02 02:42:33 -07:00
..
fb_py_test_main.py Fix bug in optimizing module loader for coverage collection 2020-04-02 02:42:33 -07:00
fb_py_win_main.c getdeps: update FBPythonBinary.cmake to generate executable files on Windows 2019-11-18 18:41:00 -08:00
FBBuildOptions.cmake fbcode_builder: add a license header to FBBuildOptions.cmake 2019-09-16 15:41:57 -07:00
FBCMakeParseArgs.cmake fbcode_builder: CMake functions for building standalone python programs 2019-08-19 11:08:34 -07:00
FBPythonBinary.cmake getdeps: add an install_fb_python_executable() function to the CMake utilities 2019-12-03 21:42:27 -08:00
FBPythonTestAddTests.cmake getdeps: add an add_fb_python_unittest() function 2019-09-30 10:46:18 -07:00
FBThriftCppLibrary.cmake Make thrift metadata available across fbcode oss builds. 2020-02-14 14:53:47 -08:00
FBThriftLibrary.cmake fbcode_builder: add a FBThriftLibrary.cmake file 2019-08-29 22:05:44 -07:00
FBThriftPyLibrary.cmake fix the thrift CMake rules to add dependencies on the thrift compiler 2019-09-16 21:10:01 -07:00
FindGflags.cmake add fbcode_builder sources 2019-04-26 11:31:58 -07:00
FindGlog.cmake add fbcode_builder sources 2019-04-26 11:31:58 -07:00
FindGMock.cmake add fbcode_builder sources 2019-04-26 11:31:58 -07:00
FindLibEvent.cmake add fbcode_builder sources 2019-04-26 11:31:58 -07:00
FindPCRE.cmake add fbcode_builder sources 2019-04-26 11:31:58 -07:00
make_fbpy_archive.py update make_fbpy_archive.py to replace the output on Windows 2019-09-18 20:05:01 -07:00