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.

--HG--
extra : rebase_source : 248a2349663affee3920a0726e10818d57c6ff17
extra : amend_source : 221280da9963cf91975658144ff3011353852fee
This commit is contained in:
Gregory Szorc 2014-08-05 10:39:24 -07:00
parent fabadffc20
commit 1a4ee759b7

17
mach
View File

@ -92,6 +92,7 @@ if __name__ == '__main__':
def fork_interpose():
import imp
import os
import sys
orig_find_module = imp.find_module
def my_find_module(name, dirs):
if name == 'mach':
@ -100,7 +101,23 @@ if __name__ == '__main__':
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():