2019-04-10 17:42:47 +02:00
|
|
|
#!/usr/bin/env python3
|
2017-03-29 17:32:59 +02:00
|
|
|
# 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
|
|
|
|
|
2019-12-04 16:00:54 +01:00
|
|
|
# We lazily import this at generate time.
|
|
|
|
idlc = None
|
|
|
|
|
|
|
|
IDL_GLOBAL_DEPS = []
|
|
|
|
|
2019-02-19 16:50:57 +01:00
|
|
|
|
2017-03-29 17:32:59 +02:00
|
|
|
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"
|
|
|
|
|
2017-05-16 21:14:27 +02:00
|
|
|
env.Alias('generated-sources', [target_source, target_header])
|
|
|
|
|
2017-03-29 17:32:59 +02:00
|
|
|
return [target_source, target_header], source
|
|
|
|
|
|
|
|
|
|
|
|
IDLCAction = SCons.Action.Action('$IDLCCOM', '$IDLCCOMSTR')
|
|
|
|
|
|
|
|
|
2017-04-20 15:48:31 +02:00
|
|
|
def idl_scanner(node, env, path):
|
2019-12-04 16:00:54 +01:00
|
|
|
nodes_deps_list = getattr(node.attributes, "IDL_NODE_DEPS", None)
|
|
|
|
if nodes_deps_list is not None:
|
|
|
|
return nodes_deps_list
|
2017-04-20 15:48:31 +02:00
|
|
|
|
2019-12-04 16:00:54 +01:00
|
|
|
nodes_deps_list = IDL_GLOBAL_DEPS[:]
|
2017-04-20 15:48:31 +02:00
|
|
|
|
2019-12-04 16:00:54 +01:00
|
|
|
with open(str(node), encoding='utf-8') as file_stream:
|
|
|
|
parsed_doc = idlc.parser.parse(file_stream, str(node),
|
|
|
|
idlc.CompilerImportResolver(['src']))
|
2017-04-20 15:48:31 +02:00
|
|
|
|
2019-12-04 16:00:54 +01:00
|
|
|
if not parsed_doc.errors and parsed_doc.spec.imports is not None:
|
|
|
|
nodes_deps_list.extend([
|
|
|
|
env.File(d) for d in sorted(parsed_doc.spec.imports.dependencies)
|
|
|
|
])
|
|
|
|
|
|
|
|
setattr(node.attributes, "IDL_NODE_DEPS", nodes_deps_list)
|
2017-04-20 15:48:31 +02:00
|
|
|
return nodes_deps_list
|
|
|
|
|
2017-05-12 16:34:39 +02:00
|
|
|
|
2017-04-20 15:48:31 +02:00
|
|
|
idl_scanner = SCons.Scanner.Scanner(function=idl_scanner, skeys=['.idl'])
|
|
|
|
|
2017-05-12 16:34:39 +02:00
|
|
|
# TODO: create a scanner for imports when imports are implemented
|
2019-02-19 16:50:57 +01:00
|
|
|
IDLCBuilder = SCons.Builder.Builder(action=IDLCAction, emitter=idlc_emitter, srcsuffx=".idl",
|
|
|
|
suffix=".cpp", source_scanner=idl_scanner)
|
2017-05-12 16:34:39 +02:00
|
|
|
|
|
|
|
|
2017-03-29 17:32:59 +02:00
|
|
|
def generate(env):
|
|
|
|
bld = IDLCBuilder
|
2017-04-20 15:48:31 +02:00
|
|
|
|
2019-02-19 16:50:57 +01:00
|
|
|
env.Append(SCANNERS=idl_scanner)
|
2017-04-20 15:48:31 +02:00
|
|
|
|
2017-03-29 17:32:59 +02:00
|
|
|
env['BUILDERS']['Idlc'] = bld
|
|
|
|
|
2019-12-04 16:00:54 +01:00
|
|
|
sys.path.append(env.Dir("#buildscripts").get_abspath())
|
|
|
|
import buildscripts.idl.idl.compiler as idlc_mod
|
|
|
|
global idlc
|
|
|
|
idlc = idlc_mod
|
|
|
|
|
2017-03-29 17:32:59 +02:00
|
|
|
env['IDLC'] = sys.executable + " buildscripts/idl/idlc.py"
|
|
|
|
env['IDLCFLAGS'] = ''
|
|
|
|
base_dir = env.subst('$BUILD_ROOT/$VARIANT_DIR').replace("#", "")
|
2019-02-19 16:50:57 +01:00
|
|
|
env['IDLCCOM'] = '$IDLC --include src --base_dir %s --target_arch $TARGET_ARCH --header ${TARGETS[1]} --output ${TARGETS[0]} $SOURCES ' % (
|
|
|
|
base_dir)
|
2017-03-29 17:32:59 +02:00
|
|
|
env['IDLCSUFFIX'] = '.idl'
|
|
|
|
|
2019-12-04 16:00:54 +01:00
|
|
|
IDL_GLOBAL_DEPS = env.Glob('#buildscripts/idl/*.py') + env.Glob('#buildscripts/idl/idl/*.py')
|
2019-03-08 01:38:01 +01:00
|
|
|
env['IDL_HAS_INLINE_DEPENDENCIES'] = True
|
2017-04-20 15:48:31 +02:00
|
|
|
|
2019-02-19 16:50:57 +01:00
|
|
|
|
2017-03-29 17:32:59 +02:00
|
|
|
def exists(env):
|
2017-05-02 04:33:35 +02:00
|
|
|
return True
|