summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Crosta <dcrosta@10gen.com>2012-07-05 11:54:01 -0400
committerDan Crosta <dcrosta@10gen.com>2012-07-06 16:08:39 -0400
commit09c5aff0fe4bfb0c9c3752df720e1cc3c10a23e4 (patch)
treeca683da21964a8574ea97e12af65c1e48cc37f60
parentb4c6a9a7c259e704093e275f2a5bb512835cb81b (diff)
downloadmongo-09c5aff0fe4bfb0c9c3752df720e1cc3c10a23e4.tar.gz
discover and configure modules in db/modules/
-rw-r--r--SConscript.buildinfo6
-rw-r--r--SConstruct9
-rw-r--r--buildscripts/moduleconfig.py90
-rw-r--r--src/mongo/SConscript14
4 files changed, 114 insertions, 5 deletions
diff --git a/SConscript.buildinfo b/SConscript.buildinfo
index 3853adf2ba5..e366e7bd5da 100644
--- a/SConscript.buildinfo
+++ b/SConscript.buildinfo
@@ -31,7 +31,11 @@ namespace mongo {
'''
def generate_buildinfo(env, target, source, **kw):
- contents = str(source[0]) % dict(git_version=buildscripts.utils.getGitVersion(),
+ git_version = buildscripts.utils.getGitVersion()
+ if env["MONGO_MODULES"]:
+ git_version += " modules: %s" % (", ".join(env["MONGO_MODULES"].keys()))
+
+ contents = str(source[0]) % dict(git_version=git_version,
sys_info=getSysInfo())
out = open(str(target[0]), 'wb')
try:
diff --git a/SConstruct b/SConstruct
index a2231faa2c5..ea92db6bae6 100644
--- a/SConstruct
+++ b/SConstruct
@@ -26,6 +26,7 @@ import types
import urllib
import urllib2
from buildscripts import utils
+from buildscripts import moduleconfig
import libdeps
@@ -835,6 +836,14 @@ def doConfigure(myenv):
myenv.Append( CPPDEFINES=[ "HEAP_CHECKING" ] )
myenv.Append( CCFLAGS=["-fno-omit-frame-pointer"] )
+ # discover modules (subdirectories of db/modules/), and
+ # load the (python) module for each module's build.py
+ modules = moduleconfig.discover_modules('.')
+
+ # ask each module to configure itself, and return a
+ # dictionary of name => list_of_sources for each module.
+ env["MONGO_MODULES"] = moduleconfig.configure_modules(modules, conf, env)
+
return conf.Finish()
env = doConfigure( env )
diff --git a/buildscripts/moduleconfig.py b/buildscripts/moduleconfig.py
new file mode 100644
index 00000000000..15062c57c9f
--- /dev/null
+++ b/buildscripts/moduleconfig.py
@@ -0,0 +1,90 @@
+"""Utility functions for SCons to discover and configure
+MongoDB modules (sub-trees of db/modules/). This file exports
+two functions:
+
+ discover_modules, which returns a dictionary of module name
+ to the imported python module object for the module's
+ build.py file
+
+ configure_modules, which runs per-module configuration, and
+ is given the SCons environment, its own path, etc
+
+Each module must have a "build.py" script, which is expected to
+have a "configure" function, and optionally a "test" function
+if the module exposes per-module tests.
+"""
+
+__all__ = ('discover_modules', 'configure_modules')
+
+import imp
+from os import listdir
+from os.path import abspath, dirname, join, isdir, isfile
+
+def discover_modules(mongo_root):
+ """Scan <mongo_root>/db/modules/ for directories that
+ look like MongoDB modules (i.e. they contain a "build.py"
+ file), and return a dictionary of module name (the directory
+ name) to build.py python modules.
+ """
+ found_modules = {}
+
+ module_root = abspath(join(mongo_root, 'db', 'modules'))
+ for name in listdir(module_root):
+ root = join(module_root, name)
+ if '.' in name or not isdir(root):
+ continue
+
+ build_py = join(root, 'build.py')
+ module = None
+
+ if isfile(build_py):
+ print "adding module: %s" % name
+ fp = open(build_py, "r")
+ module = imp.load_module("module_" + name, fp, build_py, (".py", "r", imp.PY_SOURCE))
+ found_modules[name] = module
+ fp.close()
+
+ return found_modules
+
+def configure_modules(modules, conf, env):
+ """
+ Run the configure() function in the build.py python modules
+ for each module listed in the modules dictionary (as created
+ by discover_modules). The configure() function should use the
+ prepare the Mongo build system for building the module.
+
+ build.py files may specify a "customIncludes" flag, which, if
+ True, causes configure() to be called with three arguments:
+ the SCons Configure() object, the SCons environment, and an
+ empty list which should be modified in-place by the configure()
+ function; if false, configure() is called with only the first
+ two arguments, and the source files are discovered with a
+ glob against the <module_root>/src/*.cpp.
+
+ Returns a dictionary mapping module name to a list of source
+ files to be compiled for the module.
+ """
+ source_map = {}
+
+ for name, module in modules.items():
+ print "configuring module: %s" % name
+
+ root = dirname(module.__file__)
+ module_sources = []
+
+ if getattr(module, "customIncludes", False):
+ # then the module configures itself and its
+ # configure() takes 3 args
+ module.configure(conf, env, module_sources)
+ else:
+ # else we glob the files in the module's src/
+ # subdirectory, and its configure() takes 2 args
+ module.configure(conf, env)
+ module_sources.extend(Glob(join(root, "src/*.cpp")))
+
+ if not module_sources:
+ print "WARNING: no source files for module %s, module will not be built." % name
+ else:
+ source_map[name] = module_sources
+
+ return source_map
diff --git a/src/mongo/SConscript b/src/mongo/SConscript
index 94795ea2140..6e9230d6912 100644
--- a/src/mongo/SConscript
+++ b/src/mongo/SConscript
@@ -366,11 +366,17 @@ everythingButMongodAndMongosFiles = [
]
env.StaticLibrary("notmongodormongos", everythingButMongodAndMongosFiles)
-modules = []
-moduleNames = []
-
mongodOnlyFiles = [ "db/db.cpp", "db/compact.cpp", "db/commands/touch.cpp" ]
+# create a library per module, and add it as a dependency
+# for the mongod target; as of now, modules are only included
+# in mongod, as though they were part of serverOnlyFiles
+modules = []
+for modName, modSources in env["MONGO_MODULES"].items():
+ libName = "mod%s" % modName
+ env.StaticLibrary(libName, modSources)
+ modules.append(libName)
+
# ----- TARGETS ------
env.StaticLibrary("gridfs", "client/gridfs.cpp")
@@ -385,7 +391,7 @@ env.StaticLibrary("coreserver", coreServerFiles, LIBDEPS=["mongocommon", "script
mongod = env.Install(
'#/', env.Program( "mongod", mongodOnlyFiles,
LIBDEPS=["coreserver", "serveronly", "coredb", "ntservice",
- "mongodandmongos"],
+ "mongodandmongos"] + modules,
_LIBDEPS='$_LIBDEPS_OBJS' ) )
Default( mongod )