summaryrefslogtreecommitdiff
path: root/site_scons
diff options
context:
space:
mode:
authorMark Benvenuto <mark.benvenuto@mongodb.com>2017-03-29 11:32:59 -0400
committerMark Benvenuto <mark.benvenuto@mongodb.com>2017-03-29 11:37:08 -0400
commit29816153660280601d96289dc3ef0da2ee46d6ff (patch)
treed6e0865aed1acff2a652bf7bd729b60567910377 /site_scons
parent008a46edd04a5dca21f5aa61965b173bce109bbe (diff)
downloadmongo-29816153660280601d96289dc3ef0da2ee46d6ff.tar.gz
SERVER-28306 IDL Code Generator
Diffstat (limited to 'site_scons')
-rw-r--r--site_scons/site_tools/idl_tool.py58
1 files changed, 58 insertions, 0 deletions
diff --git a/site_scons/site_tools/idl_tool.py b/site_scons/site_tools/idl_tool.py
new file mode 100644
index 00000000000..22e75c4ac42
--- /dev/null
+++ b/site_scons/site_tools/idl_tool.py
@@ -0,0 +1,58 @@
+#!/usr/bin/env python2
+# Copyright (C) 2017 MongoDB Inc.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License, version 3,
+# as published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+"""IDL Compiler Scons Tool."""
+
+import os.path
+import sys
+
+import SCons
+
+def idlc_emitter(target, source, env):
+ """For each input IDL file, the tool produces a .cpp and .h file."""
+ first_source = str(source[0])
+
+ if not first_source.endswith(".idl"):
+ raise ValueError("Bad idl file name '%s', it must end with '.idl' " % (first_source))
+
+ base_file_name, _ = SCons.Util.splitext(str(target[0]))
+ target_source = base_file_name + "_gen.cpp"
+ target_header = base_file_name + "_gen.h"
+
+ return [target_source, target_header], source
+
+
+IDLCAction = SCons.Action.Action('$IDLCCOM', '$IDLCCOMSTR')
+
+# TODO: create a scanner for imports when imports are implemented
+IDLCBuilder = SCons.Builder.Builder(
+ action=IDLCAction,
+ emitter=idlc_emitter,
+ srcsuffx=".idl",
+ suffix=".cpp"
+ )
+
+def generate(env):
+ bld = IDLCBuilder
+ env['BUILDERS']['Idlc'] = bld
+
+ env['IDLC'] = sys.executable + " buildscripts/idl/idlc.py"
+ env['IDLCFLAGS'] = ''
+ base_dir = env.subst('$BUILD_ROOT/$VARIANT_DIR').replace("#", "")
+ env['IDLCCOM'] = '$IDLC --base_dir %s --header ${TARGETS[1]} --output ${TARGETS[0]} $SOURCES ' % (base_dir)
+ env['IDLCSUFFIX'] = '.idl'
+
+def exists(env):
+ return True \ No newline at end of file