| OLD | NEW |
| (Empty) | |
| 1 #!/usr/bin/python2.4 |
| 2 # Copyright 2008, Google Inc. |
| 3 # All rights reserved. |
| 4 # |
| 5 # Redistribution and use in source and binary forms, with or without |
| 6 # modification, are permitted provided that the following conditions are |
| 7 # met: |
| 8 # |
| 9 # * Redistributions of source code must retain the above copyright |
| 10 # notice, this list of conditions and the following disclaimer. |
| 11 # * Redistributions in binary form must reproduce the above |
| 12 # copyright notice, this list of conditions and the following disclaimer |
| 13 # in the documentation and/or other materials provided with the |
| 14 # distribution. |
| 15 # * Neither the name of Google Inc. nor the names of its |
| 16 # contributors may be used to endorse or promote products derived from |
| 17 # this software without specific prior written permission. |
| 18 # |
| 19 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 20 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 21 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 22 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 23 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 24 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 25 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 26 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 27 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 28 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 29 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 |
| 31 """Main setup for software construction toolkit. |
| 32 |
| 33 This module is a SCons tool which should be include in all environments. |
| 34 It is used as follows: |
| 35 env = Environment(tools = ['component_setup']) |
| 36 and should be the first tool from this toolkit referenced by any environment. |
| 37 """ |
| 38 |
| 39 import os |
| 40 import sys |
| 41 import SCons |
| 42 |
| 43 |
| 44 #------------------------------------------------------------------------------ |
| 45 |
| 46 |
| 47 def InstallUsingLink(target, source, env): |
| 48 """Install function for environment which uses link in preference to copy. |
| 49 |
| 50 Args: |
| 51 target: Destintion filename |
| 52 source: Source filename |
| 53 env: Environment |
| 54 |
| 55 Returns: |
| 56 Return code from SCons Node link function. |
| 57 """ |
| 58 |
| 59 # Use link function for Install() and InstallAs(), since it's much much |
| 60 # faster than copying. This is ok for the way we build clients, where we're |
| 61 # installing to a build output directory and not to a permanent location such |
| 62 # as /usr/bin. |
| 63 # Need to force the target and source to be lists of nodes |
| 64 return SCons.Node.FS.LinkFunc([env.Entry(target)], [env.Entry(source)], env) |
| 65 |
| 66 #------------------------------------------------------------------------------ |
| 67 |
| 68 |
| 69 def generate(env): |
| 70 # NOTE: SCons requires the use of this name, which fails gpylint. |
| 71 """SCons entry point for this tool.""" |
| 72 |
| 73 # Use MD5 to tell when files differ, if the timestamps differ. This is |
| 74 # better than pure MD5 (since if the timestamps are the same, we don't need |
| 75 # to rescan the file), and also better than pure timestamp (since if a file |
| 76 # is rebuilt to the same contents, we don't need to trigger the build steps |
| 77 # which depend on it). |
| 78 env.Decider('MD5-timestamp') |
| 79 |
| 80 # Use implicit-cache by default. This means that SCons doesn't scan all the |
| 81 # directories looking for include files found in an earlier directory in the |
| 82 # include path. For continuous builds, this is not an issue because they're |
| 83 # usually clean builds (so there wouldn't be a cache to load anyway). |
| 84 # |
| 85 # If you're doing a continuous incremental build, just use the |
| 86 # --implicit-deps-changed option to force SCons to ignore its implicit cache. |
| 87 # |
| 88 # Use SCons.Script.SetOption() rather than env.SetOption() to make it clear |
| 89 # this is a global setting, not just a setting for the current environment. |
| 90 SCons.Script.SetOption('implicit_cache', 1) |
| 91 |
| 92 # For duplication order, use hard links then fall back to copying. Don't use |
| 93 # soft links, since those won't do the right thing if the output directory |
| 94 # is tar'd up and moved elsewhere. |
| 95 SCons.Script.SetOption('duplicate', 'hard-copy') |
| 96 |
| 97 # Remove the alias namespace lookup function from the list which SCons uses |
| 98 # when coercing strings into nodes. This prevents SCons from looking up |
| 99 # aliases in input/output lists if they're not explicitly coerced via |
| 100 # Alias(), and removes a conflict where a program has the same shorthand |
| 101 # alias as the program name itself. This conflict manifests itself as a |
| 102 # python exception if you try to build a program in multiple modes on linux, |
| 103 # for example: |
| 104 # hammer --mode=dbg,opt port_test |
| 105 new_lookup_list = [] |
| 106 for func in env.lookup_list: |
| 107 if func.im_class != SCons.Node.Alias.AliasNameSpace: |
| 108 new_lookup_list.append(func) |
| 109 env.lookup_list = new_lookup_list |
| 110 |
| 111 # Add other default tools from our toolkit |
| 112 for t in component_setup_tools: |
| 113 env.Tool(t) |
| 114 |
| 115 # Cover part of the environment |
| 116 env.Replace( |
| 117 # Add a reference to our python executable, so subprocesses can find and |
| 118 # invoke python. |
| 119 PYTHON = env.File(sys.executable), |
| 120 |
| 121 # Get the absolute path to the directory containing main.scons (or |
| 122 # SConstruct). This should be used in place of the SCons variable '#', |
| 123 # since '#' is not always replaced (for example, when being used to set |
| 124 # an environment variable). |
| 125 MAIN_DIR = env.Dir('#').abspath, |
| 126 # Supply deprecated SCONSTRUCT_DIR for legacy suport |
| 127 # TODO(rspangler): remove legacy support once everyone has switched over. |
| 128 SCONSTRUCT_DIR = env.Dir('#').abspath, |
| 129 |
| 130 # Use install function above, which uses links in preference to copying. |
| 131 INSTALL = InstallUsingLink, |
| 132 |
| 133 # Environments are in the 'all' group by default |
| 134 BUILD_GROUPS=['all'], |
| 135 |
| 136 DESTINATION_ROOT='$MAIN_DIR/scons-out$HOST_PLATFORM_SUFFIX', |
| 137 TARGET_ROOT='$DESTINATION_ROOT/$BUILD_TYPE', |
| 138 OBJ_ROOT='$TARGET_ROOT/obj', |
| 139 ARTIFACTS_DIR='$TARGET_ROOT/artifacts', |
| 140 CPPDEFINES=[], |
| 141 ) |
| 142 |
| 143 # If a host platform was specified, need to put the SCons output in its own |
| 144 # destination directory. Different host platforms compile the same files |
| 145 # different ways, so need their own .sconsign files. |
| 146 force_host_platform = SCons.Script.GetOption('host_platform') |
| 147 if force_host_platform: |
| 148 env['HOST_PLATFORM_SUFFIX'] = '-' + force_host_platform |
| 149 |
| 150 # The following environment replacements use env.Dir() to force immediate |
| 151 # evaluation/substitution of SCons variables. They can't be part of the |
| 152 # preceding env.Replace() since they they may rely indirectly on variables |
| 153 # defined there, and the env.Dir() calls would be evaluated before the |
| 154 # env.Replace(). |
| 155 |
| 156 # Set default SOURCE_ROOT if there is none, assuming we're in a local |
| 157 # site_scons directory for the project. |
| 158 source_root_relative = os.path.normpath( |
| 159 os.path.join(os.path.dirname(__file__), '../..')) |
| 160 source_root = env.get('SOURCE_ROOT', source_root_relative) |
| 161 env['SOURCE_ROOT'] = env.Dir(source_root) |
| 162 |
| 163 # Make tool root separate from source root so it can be overridden when we |
| 164 # have a common location for tools outside of the current clientspec. Need |
| 165 # to check if it's defined already, so it can be set prior to this tool |
| 166 # being included. |
| 167 tool_root = env.get('TOOL_ROOT', '$SOURCE_ROOT') |
| 168 env['TOOL_ROOT'] = env.Dir(tool_root) |
| 169 |
| 170 # Put the .sconsign.dblite file in our destination root directory, so that we |
| 171 # don't pollute the source tree. Use the '_' + sys.platform suffix to prevent |
| 172 # the .sconsign.dblite from being shared between host platforms, even in the |
| 173 # case where the --host_platform option is not used (for instance when the |
| 174 # project has platform suffixes on all the build types). |
| 175 # This will prevent host platforms from mistakenly using each others .sconsign |
| 176 # databases and will allow two host platform builds to occur in the same |
| 177 # shared tree simulataneously. |
| 178 sconsign_dir = env.Dir('$DESTINATION_ROOT').abspath |
| 179 sconsign_filename = '$DESTINATION_ROOT/.sconsign_%s' % sys.platform |
| 180 sconsign_file = env.File(sconsign_filename).abspath |
| 181 # TODO(sgk): SConsignFile() doesn't seem to like it if the destination |
| 182 # directory doesn't already exists, so make sure it exists. |
| 183 if not os.path.isdir(sconsign_dir): |
| 184 os.makedirs(sconsign_dir) |
| 185 SCons.Script.SConsignFile(sconsign_file) |
| 186 |
| 187 # Build all by default |
| 188 # TODO(rspangler): This would be more nicely done by creating an 'all' |
| 189 # alias and mapping that to $DESTINATION_ROOT (or the accumulation of all |
| 190 # $TARGET_ROOT's for the environments which apply to the current host |
| 191 # platform). Ideally, that would be done in site_init.py and not here. But |
| 192 # since we can't do that, just set the default to be DESTINATION_ROOT here. |
| 193 # Note that this currently forces projects which want to override the |
| 194 # default to do so after including the component_setup tool. |
| 195 env.Default('$DESTINATION_ROOT') |
| OLD | NEW |