Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate the stubprocess.py wrapper from Parts #3703

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER

From Dirk Baechle:
- Added Docker images for building and testing SCons. (issue #3585)
- Integrated stubprocess.py wrapper from the Parts project in order
to speed up large builds. It's available as an experimental option
'--stubprocess-wrapper' for now.

From James Benton:
- Improve Visual Studio solution/project generation code to add support
Expand Down
6 changes: 6 additions & 0 deletions RELEASE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
- Add CompilationDatabase() builder in compilation_db tool. Contributed by MongoDB.
Setting COMPILATIONDB_USE_ABSPATH to True|False controls whether the files are absolute or relative
paths. Address Issue #3693 and #3694 found during development.
- Added a new command-line option "--stubprocess-wrapper", which will try to wrap the
subprocess.Popen() call when activated. Enabling this option can give a significant speedup
for the build of large projects that consume a lot of memory and create many files.
Small builds however may experience a slow-down, which is why we declared this option
an "experimental feature" for the moment. Please also refer to the corresponding entry
in the MAN page for more information.
Comment on lines +23 to +28
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mention that it is specific to Mac and Linux.



DEPRECATED FUNCTIONALITY
Expand Down
3 changes: 3 additions & 0 deletions SCons/Platform/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@
import SCons.Subst
import SCons.Tool

# Gets set to True in Main._main() when the '--stubprocess-wrapper'
# option was given on the command-line for speeding up large builds.
stubprocess_wrapper = False

def platform_default():
r"""Return the platform string for our execution environment.
Expand Down
27 changes: 24 additions & 3 deletions SCons/Platform/posix.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,31 @@
import select

import SCons.Util
from SCons.Platform import TempFileMunge
from SCons.Platform import TempFileMunge, stubprocess_wrapper
from SCons.Platform.virtualenv import ImportVirtualenv
from SCons.Platform.virtualenv import ignore_virtualenv, enable_virtualenv

if stubprocess_wrapper:
# Create a copy of the subprocess.Popen by subclassing
class PopenWrapped(subprocess.Popen):
pass

# We sneak our new 'wrapped' Popen into the subprocess module,
# such that the original subprocess.Popen() is guaranteed to stay
# unchanged. Otherwise, wrapping the Popen() directly might interfere
# with user SConstructs where subprocess is imported directly.
# Here we try to ensure that only SCons' spawn calls are redirected
# through the PopenWrapped().
subprocess.PopenWrapped = PopenWrapped

# Now try to import and activate Parts' stubprocess wrapper for
# speeding up process forks...if this isn't possible for some reason,
# our subprocess.PopenWrapped() will still behave exactly the same as the
# builtin subprocess.Popen().
import SCons.Platform.stubprocess
else:
subprocess.PopenWrapped = subprocess.Popen

exitvalmap = {
2 : 127,
13 : 126,
Expand All @@ -63,14 +84,14 @@ def escape(arg):


def exec_subprocess(l, env):
proc = subprocess.Popen(l, env = env, close_fds = True)
proc = subprocess.PopenWrapped(l, env = env, close_fds = True)
return proc.wait()

def subprocess_spawn(sh, escape, cmd, args, env):
return exec_subprocess([sh, '-c', ' '.join(args)], env)

def exec_popen3(l, env, stdout, stderr):
proc = subprocess.Popen(l, env = env, close_fds = True,
proc = subprocess.PopenWrapped(l, env = env, close_fds = True,
stdout = stdout,
stderr = stderr)
return proc.wait()
Expand Down
Loading