0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-11-30 00:56:44 +01:00
mongodb/site_scons/site_tools/idl_tool.py

79 lines
2.5 KiB
Python
Raw Normal View History

2017-03-29 17:32:59 +02:00
#!/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
2017-04-20 15:48:31 +02:00
import subprocess
2017-03-29 17:32:59 +02:00
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"
)
2017-04-20 15:48:31 +02:00
def idl_scanner(node, env, path):
# Use the import scanner mode of the IDL compiler to file imported files
cmd = [sys.executable, "buildscripts/idl/idlc.py", '--include','src', str(node), '--write-dependencies']
deps_str = subprocess.check_output(cmd)
deps_list = deps_str.splitlines()
nodes_deps_list = [ env.File(d) for d in deps_list]
nodes_deps_list.extend(env.Glob('#buildscripts/idl/*.py'))
nodes_deps_list.extend(env.Glob('#buildscripts/idl/idl/*.py'))
2017-04-20 15:48:31 +02:00
return nodes_deps_list
idl_scanner = SCons.Scanner.Scanner(function=idl_scanner, skeys=['.idl'])
2017-03-29 17:32:59 +02:00
def generate(env):
bld = IDLCBuilder
2017-04-20 15:48:31 +02:00
env.Append(SCANNERS = idl_scanner)
2017-03-29 17:32:59 +02:00
env['BUILDERS']['Idlc'] = bld
env['IDLC'] = sys.executable + " buildscripts/idl/idlc.py"
env['IDLCFLAGS'] = ''
base_dir = env.subst('$BUILD_ROOT/$VARIANT_DIR').replace("#", "")
2017-04-20 15:48:31 +02:00
env['IDLCCOM'] = '$IDLC --include src --base_dir %s --header ${TARGETS[1]} --output ${TARGETS[0]} $SOURCES ' % (base_dir)
2017-03-29 17:32:59 +02:00
env['IDLCSUFFIX'] = '.idl'
2017-04-20 15:48:31 +02:00
2017-03-29 17:32:59 +02:00
def exists(env):
return True