Bug 1043144 - Don't write machc bytecode file; r=mshal
authorGregory Szorc <gps@mozilla.com>
Tue, 05 Aug 2014 10:39:24 -0700
changeset 221481 65bcc7b2a8a6f4e5475be2b8c7949f5bbae08369
parent 221480 c61532028ee4afd683963d7cd8a0628659c1b68e
child 221482 5e3c1c70e2eda75fe8db3721ffe9a0f3ca72ae36
push id583
push userbhearsum@mozilla.com
push dateMon, 24 Nov 2014 19:04:58 +0000
treeherdermozilla-release@c107e74250f4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmshal
bugs1043144
milestone34.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1043144 - Don't write machc bytecode file; r=mshal When writing bytecode, Python will append "c" to the loaded filename to produce a bytecode file. Since "mach" was being imported, this resulted in the creation of a "machc" file. The implementation of imp.load_module() in CPython's import.c checks sys.dont_write_bytecode. So, we wrap imp.load_module to set this flag when importing mach.
mach
--- a/mach
+++ b/mach
@@ -87,25 +87,42 @@ if __name__ == '__main__':
         # And: https://bugzilla.mozilla.org/show_bug.cgi?id=914563
         import inspect
         from multiprocessing import forking
         global orig_command_line
 
         def fork_interpose():
             import imp
             import os
+            import sys
             orig_find_module = imp.find_module
             def my_find_module(name, dirs):
                 if name == 'mach':
                     path = os.path.join(dirs[0], 'mach')
                     f = open(path)
                     return (f, path, ('', 'r', imp.PY_SOURCE))
                 return orig_find_module(name, dirs)
 
+            # Don't allow writing bytecode file for mach module.
+            orig_load_module = imp.load_module
+            def my_load_module(name, file, path, description):
+                # multiprocess.forking invokes imp.load_module manually and
+                # hard-codes the name __parents_main__ as the module name.
+                if name == '__parents_main__':
+                    old_bytecode = sys.dont_write_bytecode
+                    sys.dont_write_bytecode = True
+                    try:
+                        return orig_load_module(name, file, path, description)
+                    finally:
+                        sys.dont_write_bytecode = old_bytecode
+
+                return orig_load_module(name, file, path, description)
+
             imp.find_module = my_find_module
+            imp.load_module = my_load_module
             from multiprocessing.forking import main; main()
 
         def my_get_command_line():
             fork_code, lineno = inspect.getsourcelines(fork_interpose)
             # Remove the first line (for 'def fork_interpose():') and the three
             # levels of indentation (12 spaces).
             fork_string = ''.join(x[12:] for x in fork_code[1:])
             cmdline = orig_command_line()