Author: Antonio Cuni <[email protected]>
Branch:
Changeset: r44143:e4bd974a1203
Date: 2011-05-13 15:43 +0000
http://bitbucket.org/pypy/pypy/changeset/e4bd974a1203/
Log: merge heads
diff --git a/pypy/config/support.py b/pypy/config/support.py
--- a/pypy/config/support.py
+++ b/pypy/config/support.py
@@ -2,13 +2,15 @@
""" Some support code
"""
-import re, sys, os
+import re, sys, os, subprocess
def detect_number_of_processors(filename_or_file='/proc/cpuinfo'):
- if sys.platform != 'linux2':
- return 1 # implement me
if os.environ.get('MAKEFLAGS'):
return 1 # don't override MAKEFLAGS. This will call 'make' without
any '-j' option
+ if sys.platform == 'darwin':
+ return darwin_get_cpu_count()
+ elif sys.platform != 'linux2':
+ return 1 # implement me
try:
if isinstance(filename_or_file, str):
f = open(filename_or_file, "r")
@@ -23,3 +25,12 @@
return count
except:
return 1 # we really don't want to explode here, at worst we have 1
+
+def darwin_get_cpu_count(cmd = "/usr/sbin/sysctl hw.ncpu"):
+ try:
+ proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
+ # 'hw.ncpu: 20'
+ count = proc.communicate()[0].rstrip()[8:]
+ return int(count)
+ except (OSError, ValueError):
+ return 1
diff --git a/pypy/config/test/test_support.py b/pypy/config/test/test_support.py
--- a/pypy/config/test/test_support.py
+++ b/pypy/config/test/test_support.py
@@ -1,6 +1,6 @@
from cStringIO import StringIO
-from pypy.config.support import detect_number_of_processors
+from pypy.config import support
import os, sys, py
cpuinfo = """
@@ -39,15 +39,38 @@
assert varname == 'MAKEFLAGS'
return self._value
-def test_cpuinfo():
+def test_cpuinfo_linux():
if sys.platform != 'linux2':
py.test.skip("linux only")
saved = os.environ
try:
os.environ = FakeEnviron(None)
- assert detect_number_of_processors(StringIO(cpuinfo)) == 3
- assert detect_number_of_processors('random crap that does not exist')
== 1
+ assert support.detect_number_of_processors(StringIO(cpuinfo)) == 3
+ assert support.detect_number_of_processors('random crap that does not
exist') == 1
os.environ = FakeEnviron('-j2')
- assert detect_number_of_processors(StringIO(cpuinfo)) == 1
+ assert support.detect_number_of_processors(StringIO(cpuinfo)) == 1
finally:
os.environ = saved
+
+def test_cpuinfo_darwin():
+ if sys.platform != 'darwin':
+ py.test.skip('mac only')
+ saved_func = support.darwin_get_cpu_count
+ saved = os.environ
+ def count():
+ return 42
+ try:
+ support.darwin_get_cpu_count = count
+ os.environ = FakeEnviron(None)
+ assert support.detect_number_of_processors() == 42
+ os.environ = FakeEnviron('-j2')
+ assert support.detect_number_of_processors() == 1
+ finally:
+ os.environ = saved
+ support.darwin_get_cpu_count = saved_func
+
+def test_darwin_get_cpu_count():
+ if sys.platform != 'darwin':
+ py.test.skip('mac only')
+ assert support.darwin_get_cpu_count() > 0 # hopefully
+ assert support.darwin_get_cpu_count("false") == 1
diff --git a/pypy/config/translationoption.py b/pypy/config/translationoption.py
--- a/pypy/config/translationoption.py
+++ b/pypy/config/translationoption.py
@@ -163,9 +163,6 @@
cmdline="--cflags"),
StrOption("linkerflags", "Specify flags for the linker (C backend only)",
cmdline="--ldflags"),
- BoolOption("force_make", "Force execution of makefile instead of"
- " calling platform", cmdline="--force-make",
- default=False, negation=False),
IntOption("make_jobs", "Specify -j argument to make for compilation"
" (C backend only)",
cmdline="--make-jobs", default=detect_number_of_processors()),
diff --git a/pypy/doc/config/translation.force_make.txt
b/pypy/doc/config/translation.force_make.txt
deleted file mode 100644
--- a/pypy/doc/config/translation.force_make.txt
+++ /dev/null
@@ -1,1 +0,0 @@
-Force executing makefile instead of using platform.
diff --git a/pypy/tool/runsubprocess.py b/pypy/tool/runsubprocess.py
--- a/pypy/tool/runsubprocess.py
+++ b/pypy/tool/runsubprocess.py
@@ -3,7 +3,7 @@
if the current process already grew very large.
"""
-import sys
+import sys, gc
import os
from subprocess import PIPE, Popen
@@ -21,6 +21,11 @@
else:
args = [str(executable)] + args
shell = False
+ # Just before spawning the subprocess, do a gc.collect(). This
+ # should help if we are running on top of PyPy, if the subprocess
+ # is going to need a lot of RAM and we are using a lot too.
+ gc.collect()
+ #
pipe = Popen(args, stdout=PIPE, stderr=PIPE, shell=shell, env=env, cwd=cwd)
stdout, stderr = pipe.communicate()
return pipe.returncode, stdout, stderr
diff --git a/pypy/translator/c/genc.py b/pypy/translator/c/genc.py
--- a/pypy/translator/c/genc.py
+++ b/pypy/translator/c/genc.py
@@ -508,27 +508,15 @@
shared = self.config.translation.shared
- if (self.config.translation.gcrootfinder == "asmgcc" or
- self.config.translation.force_make):
- extra_opts = []
- if self.config.translation.make_jobs != 1:
- extra_opts += ['-j', str(self.config.translation.make_jobs)]
- self.translator.platform.execute_makefile(self.targetdir,
- extra_opts)
- if shared:
- self.shared_library_name = self.executable_name.new(
- purebasename='lib' + self.executable_name.purebasename,
- ext=self.translator.platform.so_ext)
- else:
- compiler = CCompilerDriver(self.translator.platform,
- [self.c_source_filename] +
self.extrafiles,
- self.eci, profbased=self.getprofbased(),
- outputfilename=exe_name)
- self.executable_name = compiler.build(shared=shared)
- if shared:
- self.executable_name = self.build_main_for_shared(
- self.executable_name, "pypy_main_startup", exe_name)
- assert self.executable_name
+ extra_opts = []
+ if self.config.translation.make_jobs != 1:
+ extra_opts += ['-j', str(self.config.translation.make_jobs)]
+ self.translator.platform.execute_makefile(self.targetdir,
+ extra_opts)
+ if shared:
+ self.shared_library_name = self.executable_name.new(
+ purebasename='lib' + self.executable_name.purebasename,
+ ext=self.translator.platform.so_ext)
self._compiled = True
return self.executable_name
diff --git a/pypy/translator/goal/app_main.py b/pypy/translator/goal/app_main.py
--- a/pypy/translator/goal/app_main.py
+++ b/pypy/translator/goal/app_main.py
@@ -204,9 +204,11 @@
dirname = resolvedirof(search)
if dirname == search:
# not found! let's hope that the compiled-in path is ok
- print >> sys.stderr, ('debug: WARNING: library path not found, '
- 'using compiled-in sys.path '
- 'and sys.prefix will be unset')
+ print >> sys.stderr, """\
+debug: WARNING: Library path not found, using compiled-in sys.path.
+debug: WARNING: 'sys.prefix' will not be set.
+debug: WARNING: Make sure the pypy binary is kept inside its tree of files.
+debug: WARNING: It is ok to create a symlink to it from somewhere else."""
newpath = sys.path[:]
break
newpath = sys.pypy_initial_path(dirname)
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit