Fix build error with scons-4.4.0 version which is based on python3
[platform/upstream/iotivity.git] / tools / scons / BoostBootstrap.py
1 # -*- coding: utf-8 -*-
2
3 # *********************************************************************
4 #
5 # Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
6 #
7 # *********************************************************************
8 #
9 # Licensed under the Apache License, Version 2.0 (the "License");
10 # you may not use this file except in compliance with the License.
11 # You may obtain a copy of the License at
12 #
13 #      http:#www.apache.org/licenses/LICENSE-2.0
14 #
15 # Unless required by applicable law or agreed to in writing, software
16 # distributed under the License is distributed on an "AS IS" BASIS,
17 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 # See the License for the specific language governing permissions and
19 # limitations under the License.
20 #
21 # *********************************************************************
22
23 # This SCONS builder executes the boost bootstrap function which
24 # is needed to create their build utility called 'b2'
25
26 import os, subprocess
27 import SCons.Builder, SCons.Node, SCons.Errors
28
29 # creates the downloading output message
30 # @param s original message
31 # @param target target name
32 # @param source source name
33 # @param env environment object
34 def __message( s, target, source, env ) :
35     print('bootstrapping using [%s] ...' % (source[0]))
36
37
38 # Create the builder action which executes the bootstrap script
39 #
40 # @param target target file on the local drive
41 # @param source URL for download
42 # @param env environment object
43 def __action( target, source, env ) :
44     cmd = None
45
46     # Windows...
47     if env['PLATFORM'] in ['win32'] :
48         if env.WhereIs('cmd') :
49             # TODO: Add Windows Support
50             cmd = None
51
52     # read the tools on *nix systems and sets the default parameters
53     elif env['PLATFORM'] in ['darwin', 'linux', 'posix'] :
54         if env.WhereIs('sh') :
55             cmd = './bootstrap.sh'
56
57     if not cmd :
58         raise SCons.Errors.StopError('Bootstrapping shell on this platform [%s] unkown' % (env['PLATFORM']))
59
60     # We need to be in the target's directory
61     cwd = os.path.dirname(os.path.realpath(target[0].path))
62
63     # build it now (we need the shell, because some programs need it)
64     devnull = open(os.devnull, 'wb')
65     handle  = subprocess.Popen( cmd, shell=True, cwd=cwd, stdout=devnull )
66
67     if handle.wait() != 0 :
68         raise SCons.Errors.BuildError( 'Bootstrapping script [%s] on the source [%s]' % (cmd, source[0])  )
69
70 # Define the emitter of the builder
71 #
72 # @param target target file on the local drive
73 # @param source
74 # @param env environment object
75 def __emitter( target, source, env ) :
76     return target, source
77
78 # Generate function which adds the builder to the environment,
79 #
80 # @param env environment object
81 def generate( env ) :
82     env['BUILDERS']['BoostBootstrap'] = SCons.Builder.Builder( action = __action,  emitter = __emitter,  target_factory = SCons.Node.FS.File,  source_factory = SCons.Node.FS.File,  single_source = True,  PRINT_CMD_LINE_FUNC = __message )
83
84 # Exist function of the builder
85 # @param env environment object
86 # @return true
87 def exists( env ) :
88     return 1
89