1# -*- mode: python; -*- 2 3# This SConscript describes construction of buildinfo.cpp, which is independent of the 4# build variant's target. 5 6import os 7import sys 8 9import buildscripts.utils 10 11Import('env windows usev8') 12 13def getSysInfo(): 14 if windows: 15 return "windows " + str( sys.getwindowsversion() ) 16 else: 17 return " ".join( os.uname() ) 18 19buildinfo_filename = '$BUILD_DIR/buildinfo.cpp' 20env.NoCache(buildinfo_filename) 21 22buildinfo_template = ''' 23#include <string> 24#include <boost/version.hpp> 25 26#include "mongo/util/version.h" 27 28namespace mongo { 29 const char * gitVersion() { return "%(git_version)s"; } 30 const char * compiledJSEngine() { return "%(js_engine)s"; } 31 const char * allocator() { return "%(allocator)s"; } 32 const char * loaderFlags() { return "%(loader_flags)s"; } 33 const char * compilerFlags() { return "%(compiler_flags)s"; } 34 std::string sysInfo() { return "%(sys_info)s BOOST_LIB_VERSION=" BOOST_LIB_VERSION ; } 35} // namespace mongo 36''' 37 38def generate_buildinfo(env, target, source, **kw): 39 git_version = buildscripts.utils.getGitVersion() 40 if len(env["MONGO_MODULES"]): 41 git_version += " modules: " + ", ".join(env["MONGO_MODULES"]) 42 43 if usev8: 44 js_engine = "V8" 45 else: 46 js_engine = "Unknown" 47 48 contents = str(source[0]) % dict(git_version=git_version, 49 js_engine=js_engine, 50 sys_info=getSysInfo(), 51 allocator=GetOption('allocator'), 52 loader_flags=env.subst('$LINKFLAGS $LDFLAGS', 53 source=source, target=target), 54 compiler_flags=env.subst('$CXXFLAGS $CCFLAGS $CFLAGS', 55 source=source, target=target)) 56 out = open(str(target[0]), 'wb') 57 try: 58 out.write(contents) 59 finally: 60 out.close() 61 62env.Command(buildinfo_filename, 63 Value(buildinfo_template), 64 Action(generate_buildinfo, "Generating $TARGET")) 65env.AlwaysBuild(buildinfo_filename) 66env.Install('$BUILD_DIR/mongo', buildinfo_filename) 67 68