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