summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Morrow <acm@mongodb.com>2017-04-01 12:08:15 -0400
committerAndrew Morrow <acm@mongodb.com>2017-04-06 14:31:32 -0400
commit865b400e4a74c3acb529d7bbba9d782e9db9fb11 (patch)
tree6715a8caac61e3b81d8f7f7ddd5c0b7f9335f806
parentaddc9971f7f1bb155992711ac9b655137334b25c (diff)
downloadmongo-865b400e4a74c3acb529d7bbba9d782e9db9fb11.tar.gz
SERVER-28583 Move some functions down into site_scons modules
-rw-r--r--SConstruct90
-rw-r--r--site_scons/mongo/__init__.py8
-rw-r--r--site_scons/mongo/platform.py66
3 files changed, 89 insertions, 75 deletions
diff --git a/SConstruct b/SConstruct
index d71a68393f0..ba567a001ca 100644
--- a/SConstruct
+++ b/SConstruct
@@ -20,6 +20,11 @@ import SCons
# we are to avoid bulk loading all tools in the DefaultEnvironment.
DefaultEnvironment(tools=[])
+# These come from site_scons/mongo. Import these things
+# after calling DefaultEnvironment, for the sake of paranoia.
+import mongo
+import mongo.platform as mongo_platform
+
EnsurePythonVersion(2, 7)
EnsureSConsVersion(2, 5)
@@ -34,72 +39,7 @@ from mongo_scons_utils import (
import libdeps
-def print_build_failures():
- from SCons.Script import GetBuildFailures
- for bf in GetBuildFailures():
- print "%s failed: %s" % (bf.node, bf.errstr)
-atexit.register(print_build_failures)
-
-def versiontuple(v):
- return tuple(map(int, (v.split("."))))
-
-# --- OS identification ---
-#
-# This needs to precede the options section so that we can only offer some options on certain
-# operating systems.
-
-# This function gets the running OS as identified by Python
-# It should only be used to set up defaults for options/variables, because
-# its value could potentially be overridden by setting TARGET_OS on the
-# command-line. Treat this output as the value of HOST_OS
-def get_running_os_name():
- running_os = os.sys.platform
- if running_os.startswith('linux'):
- running_os = 'linux'
- elif running_os.startswith('freebsd'):
- running_os = 'freebsd'
- elif running_os.startswith('openbsd'):
- running_os = 'openbsd'
- elif running_os == 'sunos5':
- running_os = 'solaris'
- elif running_os == 'win32':
- running_os = 'windows'
- elif running_os == 'darwin':
- running_os = 'macOS'
- else:
- running_os = 'unknown'
- return running_os
-
-def env_get_os_name_wrapper(self):
- return env['TARGET_OS']
-
-def is_os_raw(target_os, os_list_to_check):
- okay = False
-
- darwin_os_list = [ 'macOS', 'tvOS', 'tvOS-sim', 'iOS', 'iOS-sim' ]
- posix_os_list = [ 'linux', 'openbsd', 'freebsd', 'solaris' ] + darwin_os_list
-
- for p in os_list_to_check:
- if p == 'posix' and target_os in posix_os_list:
- okay = True
- break
- if p == 'darwin' and target_os in darwin_os_list:
- okay = True
- break
- elif p == target_os:
- okay = True
- break
- return okay
-
-# This function tests the running OS as identified by Python
-# It should only be used to set up defaults for options/variables, because
-# its value could potentially be overridden by setting TARGET_OS on the
-# command-line. Treat this output as the value of HOST_OS
-def is_running_os(*os_list):
- return is_os_raw(get_running_os_name(), os_list)
-
-def env_os_is_wrapper(self, *os_list):
- return is_os_raw(self['TARGET_OS'], os_list)
+atexit.register(mongo.print_build_failures)
def add_option(name, **kwargs):
@@ -555,7 +495,7 @@ def variable_shlex_converter(val):
return val
parse_mode = get_option('variable-parse-mode')
if parse_mode == 'auto':
- parse_mode = 'other' if is_running_os('windows') else 'posix'
+ parse_mode = 'other' if mongo_platform.is_running_os('windows') else 'posix'
return shlex.split(val, posix=(parse_mode == 'posix'))
def variable_arch_converter(val):
@@ -585,12 +525,12 @@ def variable_arch_converter(val):
# If we aren't on a platform where we know the minimal set of tools, we fall back to loading
# the 'default' tool.
def decide_platform_tools():
- if is_running_os('windows'):
+ if mongo_platform.is_running_os('windows'):
# we only support MS toolchain on windows
return ['msvc', 'mslink', 'mslib', 'masm']
- elif is_running_os('linux', 'solaris'):
+ elif mongo_platform.is_running_os('linux', 'solaris'):
return ['gcc', 'g++', 'gnulink', 'ar', 'gas']
- elif is_running_os('darwin'):
+ elif mongo_platform.is_running_os('darwin'):
return ['gcc', 'g++', 'applelink', 'ar', 'as']
else:
return ["default"]
@@ -778,7 +718,7 @@ env_vars.Add('TARGET_ARCH',
env_vars.Add('TARGET_OS',
help='Sets the target OS to build for',
- default=get_running_os_name())
+ default=mongo_platform.get_running_os_name())
env_vars.Add('TOOLS',
help='Sets the list of SCons tools to add to the environment',
@@ -933,8 +873,8 @@ envDict = dict(BUILD_ROOT=buildDir,
env = Environment(variables=env_vars, **envDict)
del envDict
-env.AddMethod(env_os_is_wrapper, 'TargetOSIs')
-env.AddMethod(env_get_os_name_wrapper, 'GetTargetOSName')
+env.AddMethod(mongo_platform.env_os_is_wrapper, 'TargetOSIs')
+env.AddMethod(mongo_platform.env_get_os_name_wrapper, 'GetTargetOSName')
def fatal_error(env, msg, *args):
print msg.format(*args)
@@ -1131,7 +1071,7 @@ if not detectConf.CheckForCXXLink():
detectEnv['CXX'])
toolchain_search_sequence = [ "GCC", "clang" ]
-if is_running_os('windows'):
+if mongo_platform.is_running_os('windows'):
toolchain_search_sequence = [ 'MSVC', 'clang', 'GCC' ]
for candidate_toolchain in toolchain_search_sequence:
if detectConf.CheckForToolchain(candidate_toolchain, "C++", "CXX", ".cpp"):
@@ -3011,7 +2951,7 @@ env.Tool("compilation_db")
# If we can, load the dagger tool for build dependency graph introspection.
# Dagger is only supported on Linux and OSX (not Windows or Solaris).
-should_dagger = ( is_running_os('osx') or is_running_os('linux') ) and "dagger" in COMMAND_LINE_TARGETS
+should_dagger = ( mongo_platform.is_running_os('osx') or mongo_platform.is_running_os('linux') ) and "dagger" in COMMAND_LINE_TARGETS
if should_dagger:
env.Tool("dagger")
diff --git a/site_scons/mongo/__init__.py b/site_scons/mongo/__init__.py
new file mode 100644
index 00000000000..510bd7bcc2f
--- /dev/null
+++ b/site_scons/mongo/__init__.py
@@ -0,0 +1,8 @@
+# -*- mode: python; -*-
+
+# General utility functions live in this file.
+
+def print_build_failures():
+ from SCons.Script import GetBuildFailures
+ for bf in GetBuildFailures():
+ print "%s failed: %s" % (bf.node, bf.errstr)
diff --git a/site_scons/mongo/platform.py b/site_scons/mongo/platform.py
new file mode 100644
index 00000000000..c60ef0f9298
--- /dev/null
+++ b/site_scons/mongo/platform.py
@@ -0,0 +1,66 @@
+# -*- mode: python; -*-
+
+"""
+Support code related to OS detection in general. System specific facilities or customization
+hooks live in mongo_platform_<PLATFORM>.py files.
+"""
+
+import os
+
+# --- OS identification ---
+#
+# This needs to precede the options section so that we can only offer some options on certain
+# operating systems.
+
+# This function gets the running OS as identified by Python
+# It should only be used to set up defaults for options/variables, because
+# its value could potentially be overridden by setting TARGET_OS on the
+# command-line. Treat this output as the value of HOST_OS
+def get_running_os_name():
+ running_os = os.sys.platform
+ if running_os.startswith('linux'):
+ running_os = 'linux'
+ elif running_os.startswith('freebsd'):
+ running_os = 'freebsd'
+ elif running_os.startswith('openbsd'):
+ running_os = 'openbsd'
+ elif running_os == 'sunos5':
+ running_os = 'solaris'
+ elif running_os == 'win32':
+ running_os = 'windows'
+ elif running_os == 'darwin':
+ running_os = 'macOS'
+ else:
+ running_os = 'unknown'
+ return running_os
+
+def env_get_os_name_wrapper(self):
+ return self['TARGET_OS']
+
+def is_os_raw(target_os, os_list_to_check):
+ okay = False
+
+ darwin_os_list = [ 'macOS', 'tvOS', 'tvOS-sim', 'iOS', 'iOS-sim' ]
+ posix_os_list = [ 'linux', 'openbsd', 'freebsd', 'solaris' ] + darwin_os_list
+
+ for p in os_list_to_check:
+ if p == 'posix' and target_os in posix_os_list:
+ okay = True
+ break
+ if p == 'darwin' and target_os in darwin_os_list:
+ okay = True
+ break
+ elif p == target_os:
+ okay = True
+ break
+ return okay
+
+# This function tests the running OS as identified by Python
+# It should only be used to set up defaults for options/variables, because
+# its value could potentially be overridden by setting TARGET_OS on the
+# command-line. Treat this output as the value of HOST_OS
+def is_running_os(*os_list):
+ return is_os_raw(get_running_os_name(), os_list)
+
+def env_os_is_wrapper(self, *os_list):
+ return is_os_raw(self['TARGET_OS'], os_list)