summaryrefslogtreecommitdiff
path: root/site_scons/site_tools/idl_tool.py
blob: 22e75c4ac42203d80229d7774ca51cc6c8130401 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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