2020-04-22 17:38:25 +02:00
|
|
|
# Copyright 2020 MongoDB Inc.
|
2017-03-29 17:32:59 +02:00
|
|
|
#
|
2020-04-22 17:38:25 +02:00
|
|
|
# Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
# a copy of this software and associated documentation files (the
|
|
|
|
# "Software"), to deal in the Software without restriction, including
|
|
|
|
# without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
# distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
# permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
# the following conditions:
|
2017-03-29 17:32:59 +02:00
|
|
|
#
|
2020-04-22 17:38:25 +02:00
|
|
|
# The above copyright notice and this permission notice shall be included
|
|
|
|
# in all copies or substantial portions of the Software.
|
2017-03-29 17:32:59 +02:00
|
|
|
#
|
2020-04-22 17:38:25 +02:00
|
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
|
|
|
|
# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
|
|
|
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
|
|
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
|
|
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
|
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
2017-03-29 17:32:59 +02:00
|
|
|
#
|
2020-04-22 17:38:25 +02:00
|
|
|
|
2017-03-29 17:32:59 +02:00
|
|
|
"""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"):
|
2020-01-07 19:48:42 +01:00
|
|
|
raise ValueError(
|
|
|
|
"Bad idl file name '%s', it must end with '.idl' " % (first_source)
|
|
|
|
)
|
2017-03-29 17:32:59 +02:00
|
|
|
|
|
|
|
base_file_name, _ = SCons.Util.splitext(str(target[0]))
|
2020-01-24 17:08:37 +01:00
|
|
|
target_source = env.File(base_file_name + "_gen.cpp")
|
|
|
|
target_header = env.File(base_file_name + "_gen.h")
|
|
|
|
|
2020-01-07 19:48:42 +01:00
|
|
|
env.Alias("generated-sources", [target_source, target_header])
|
2017-05-16 21:14:27 +02:00
|
|
|
|
2017-03-29 17:32:59 +02:00
|
|
|
return [target_source, target_header], source
|
|
|
|
|
|
|
|
|
2020-01-07 19:48:42 +01:00
|
|
|
IDLCAction = SCons.Action.Action("$IDLCCOM", "$IDLCCOMSTR")
|
2017-03-29 17:32:59 +02:00
|
|
|
|
|
|
|
|
2017-04-20 15:48:31 +02:00
|
|
|
def idl_scanner(node, env, path):
|
2020-01-24 17:08:37 +01:00
|
|
|
|
|
|
|
# When generating ninja we only need to add the IDL_GLOBAL_DEPS
|
|
|
|
# because the implicit dependencies will be picked up using the
|
|
|
|
# deps=msvc method.
|
|
|
|
if env.get("GENERATING_NINJA", False):
|
|
|
|
return IDL_GLOBAL_DEPS
|
|
|
|
|
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
|
|
|
|
2020-11-20 19:24:19 +01:00
|
|
|
# Compute the include paths to use based on the include flags in IDLCFLAGS
|
|
|
|
flags = env["IDLCFLAGS"]
|
|
|
|
include_paths = []
|
|
|
|
for i in range(len(flags)):
|
|
|
|
if flags[i] == "--include":
|
|
|
|
include_paths.append(flags[i + 1])
|
|
|
|
|
2020-01-07 19:48:42 +01:00
|
|
|
with open(str(node), encoding="utf-8") as file_stream:
|
|
|
|
parsed_doc = idlc.parser.parse(
|
2020-11-20 19:24:19 +01:00
|
|
|
file_stream, str(node), idlc.CompilerImportResolver(include_paths)
|
2020-01-07 19:48:42 +01:00
|
|
|
)
|
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:
|
2020-01-07 19:48:42 +01:00
|
|
|
nodes_deps_list.extend(
|
|
|
|
[env.File(d) for d in sorted(parsed_doc.spec.imports.dependencies)]
|
|
|
|
)
|
2019-12-04 16:00:54 +01:00
|
|
|
|
|
|
|
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
|
|
|
|
2020-01-07 19:48:42 +01:00
|
|
|
idl_scanner = SCons.Scanner.Scanner(function=idl_scanner, skeys=[".idl"])
|
2017-04-20 15:48:31 +02:00
|
|
|
|
2017-05-12 16:34:39 +02:00
|
|
|
# TODO: create a scanner for imports when imports are implemented
|
2020-01-07 19:48:42 +01:00
|
|
|
IDLCBuilder = SCons.Builder.Builder(
|
|
|
|
action=IDLCAction,
|
|
|
|
emitter=idlc_emitter,
|
2020-10-21 20:03:41 +02:00
|
|
|
src_suffix=".idl",
|
2020-01-07 19:48:42 +01:00
|
|
|
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
|
|
|
|
2020-01-07 19:48:42 +01:00
|
|
|
env["BUILDERS"]["Idlc"] = bld
|
2017-03-29 17:32:59 +02:00
|
|
|
|
2019-12-04 16:00:54 +01:00
|
|
|
sys.path.append(env.Dir("#buildscripts").get_abspath())
|
|
|
|
import buildscripts.idl.idl.compiler as idlc_mod
|
2020-01-07 19:48:42 +01:00
|
|
|
|
2019-12-04 16:00:54 +01:00
|
|
|
global idlc
|
|
|
|
idlc = idlc_mod
|
|
|
|
|
2020-01-17 00:04:43 +01:00
|
|
|
env["IDLC"] = "$PYTHON buildscripts/idl/idlc.py"
|
2020-10-21 06:21:42 +02:00
|
|
|
base_dir = env.Dir("$BUILD_DIR").path
|
2020-01-24 17:08:37 +01:00
|
|
|
env["IDLCFLAGS"] = [
|
|
|
|
"--include", "src",
|
|
|
|
"--base_dir", base_dir,
|
|
|
|
"--target_arch", "$TARGET_ARCH",
|
|
|
|
]
|
|
|
|
env["IDLCCOM"] = "$IDLC $IDLCFLAGS --header ${TARGETS[1]} --output ${TARGETS[0]} $SOURCES"
|
2020-10-21 06:21:42 +02:00
|
|
|
env["IDLCCOMSTR"] = ("Generating ${TARGETS[0]}"
|
|
|
|
if not env.get("VERBOSE", "").lower() in ['true', '1']
|
|
|
|
else None)
|
2020-01-07 19:48:42 +01:00
|
|
|
env["IDLCSUFFIX"] = ".idl"
|
|
|
|
|
2020-11-03 06:48:25 +01:00
|
|
|
global IDL_GLOBAL_DEPS
|
2020-01-07 19:48:42 +01:00
|
|
|
IDL_GLOBAL_DEPS = env.Glob("#buildscripts/idl/*.py") + env.Glob(
|
|
|
|
"#buildscripts/idl/idl/*.py"
|
|
|
|
)
|
|
|
|
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
|