Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(192)

Side by Side Diff: site_scons/site_tools/component_setup.py

Issue 9094: Adding in new software construction toolkit version. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 12 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « site_scons/site_tools/component_builders.py ('k') | site_scons/site_tools/component_targets.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python2.4 1 #!/usr/bin/python2.4
2 # Copyright 2008, Google Inc. 2 # Copyright 2008, Google Inc.
3 # All rights reserved. 3 # All rights reserved.
4 # 4 #
5 # Redistribution and use in source and binary forms, with or without 5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are 6 # modification, are permitted provided that the following conditions are
7 # met: 7 # met:
8 # 8 #
9 # * Redistributions of source code must retain the above copyright 9 # * Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer. 10 # notice, this list of conditions and the following disclaimer.
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 Return code from SCons Node link function. 56 Return code from SCons Node link function.
57 """ 57 """
58 58
59 # Use link function for Install() and InstallAs(), since it's much much 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 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 61 # installing to a build output directory and not to a permanent location such
62 # as /usr/bin. 62 # as /usr/bin.
63 # Need to force the target and source to be lists of nodes 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) 64 return SCons.Node.FS.LinkFunc([env.Entry(target)], [env.Entry(source)], env)
65 65
66
67 def PreEvaluateVariables(env):
68 """Deferred function to pre-evaluate SCons varables for each build mode.
69
70 Args:
71 env: Environment for the current build mode.
72 """
73 # Convert directory variables to strings
74 for var in env.SubstList2('PRE_EVALUATE_DIRS'):
75 env[var] = str(env.Dir('$' + var))
76
77
66 #------------------------------------------------------------------------------ 78 #------------------------------------------------------------------------------
67 79
68 80
69 def generate(env): 81 def generate(env):
70 # NOTE: SCons requires the use of this name, which fails gpylint. 82 # NOTE: SCons requires the use of this name, which fails gpylint.
71 """SCons entry point for this tool.""" 83 """SCons entry point for this tool."""
72 84
73 # Use MD5 to tell when files differ, if the timestamps differ. This is 85 # 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 86 # 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 87 # to rescan the file), and also better than pure timestamp (since if a file
(...skipping 25 matching lines...) Expand all
101 # alias as the program name itself. This conflict manifests itself as a 113 # 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, 114 # python exception if you try to build a program in multiple modes on linux,
103 # for example: 115 # for example:
104 # hammer --mode=dbg,opt port_test 116 # hammer --mode=dbg,opt port_test
105 new_lookup_list = [] 117 new_lookup_list = []
106 for func in env.lookup_list: 118 for func in env.lookup_list:
107 if func.im_class != SCons.Node.Alias.AliasNameSpace: 119 if func.im_class != SCons.Node.Alias.AliasNameSpace:
108 new_lookup_list.append(func) 120 new_lookup_list.append(func)
109 env.lookup_list = new_lookup_list 121 env.lookup_list = new_lookup_list
110 122
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 123 # Cover part of the environment
116 env.Replace( 124 env.Replace(
117 # Add a reference to our python executable, so subprocesses can find and 125 # Add a reference to our python executable, so subprocesses can find and
118 # invoke python. 126 # invoke python.
119 PYTHON = env.File(sys.executable), 127 PYTHON = env.File(sys.executable),
120 128
121 # Get the absolute path to the directory containing main.scons (or 129 # Get the absolute path to the directory containing main.scons (or
122 # SConstruct). This should be used in place of the SCons variable '#', 130 # SConstruct). This should be used in place of the SCons variable '#',
123 # since '#' is not always replaced (for example, when being used to set 131 # since '#' is not always replaced (for example, when being used to set
124 # an environment variable). 132 # an environment variable).
125 MAIN_DIR = env.Dir('#').abspath, 133 MAIN_DIR = env.Dir('#').abspath,
126 # Supply deprecated SCONSTRUCT_DIR for legacy suport 134 # Supply deprecated SCONSTRUCT_DIR for legacy suport
127 # TODO(rspangler): remove legacy support once everyone has switched over. 135 # TODO(rspangler): remove legacy support once everyone has switched over.
128 SCONSTRUCT_DIR = env.Dir('#').abspath, 136 SCONSTRUCT_DIR = env.Dir('#').abspath,
129 137
130 # Use install function above, which uses links in preference to copying. 138 # Use install function above, which uses links in preference to copying.
131 INSTALL = InstallUsingLink, 139 INSTALL = InstallUsingLink,
140 )
132 141
142 # Specify defaults for variables where we don't need to force replacement
143 env.SetDefault(
133 # Environments are in the 'all' group by default 144 # Environments are in the 'all' group by default
134 BUILD_GROUPS=['all'], 145 BUILD_GROUPS=['all'],
135 146
147 # Directories
136 DESTINATION_ROOT='$MAIN_DIR/scons-out$HOST_PLATFORM_SUFFIX', 148 DESTINATION_ROOT='$MAIN_DIR/scons-out$HOST_PLATFORM_SUFFIX',
137 TARGET_ROOT='$DESTINATION_ROOT/$BUILD_TYPE', 149 TARGET_ROOT='$DESTINATION_ROOT/$BUILD_TYPE',
138 OBJ_ROOT='$TARGET_ROOT/obj', 150 OBJ_ROOT='$TARGET_ROOT/obj',
139 ARTIFACTS_DIR='$TARGET_ROOT/artifacts', 151 ARTIFACTS_DIR='$TARGET_ROOT/artifacts',
140 CPPDEFINES=[],
141 ) 152 )
142 153
154 # Add default list of variables we should pre-evaluate for each build mode
155 env.Append(PRE_EVALUATE_DIRS = [
156 'ARTIFACTS_DIR',
157 'DESTINATION_ROOT',
158 'OBJ_ROOT',
159 'SOURCE_ROOT',
160 'TARGET_ROOT',
161 'TOOL_ROOT',
162 ])
163
143 # If a host platform was specified, need to put the SCons output in its own 164 # 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 165 # destination directory. Different host platforms compile the same files
145 # different ways, so need their own .sconsign files. 166 # different ways, so need their own .sconsign files.
146 force_host_platform = SCons.Script.GetOption('host_platform') 167 force_host_platform = SCons.Script.GetOption('host_platform')
147 if force_host_platform: 168 if force_host_platform:
148 env['HOST_PLATFORM_SUFFIX'] = '-' + force_host_platform 169 env['HOST_PLATFORM_SUFFIX'] = '-' + force_host_platform
149 170
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 # 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 # 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 # 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 # case where the --host_platform option is not used (for instance when the
174 # project has platform suffixes on all the build types). 175 # project has platform suffixes on all the build types).
175 # This will prevent host platforms from mistakenly using each others .sconsign 176 # 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 # databases and will allow two host platform builds to occur in the same
177 # shared tree simulataneously. 178 # shared tree simulataneously.
178 sconsign_dir = env.Dir('$DESTINATION_ROOT').abspath 179 sconsign_dir = env.Dir('$DESTINATION_ROOT').abspath
179 sconsign_filename = '$DESTINATION_ROOT/.sconsign_%s' % sys.platform 180 sconsign_filename = '$DESTINATION_ROOT/.sconsign_%s' % sys.platform
180 sconsign_file = env.File(sconsign_filename).abspath 181 sconsign_file = env.File(sconsign_filename).abspath
181 # TODO(sgk): SConsignFile() doesn't seem to like it if the destination 182 # TODO(sgk): SConsignFile() doesn't seem to like it if the destination
182 # directory doesn't already exists, so make sure it exists. 183 # directory doesn't already exists, so make sure it exists.
183 if not os.path.isdir(sconsign_dir): 184 if not os.path.isdir(sconsign_dir):
184 os.makedirs(sconsign_dir) 185 os.makedirs(sconsign_dir)
185 SCons.Script.SConsignFile(sconsign_file) 186 SCons.Script.SConsignFile(sconsign_file)
186 187
187 # Build all by default 188 # Build all by default
188 # TODO(rspangler): This would be more nicely done by creating an 'all' 189 # 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 # 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 # $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 # 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 # 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 # Note that this currently forces projects which want to override the
194 # default to do so after including the component_setup tool. 195 # default to do so after including the component_setup tool.
195 env.Default('$DESTINATION_ROOT') 196 env.Default('$DESTINATION_ROOT')
197
198 # Add other default tools from our toolkit
199 # TODO(rspangler): Currently this needs to be before SOURCE_ROOT in case a
200 # tool needs to redefine it. Need a better way to handle order-dependency
201 # in tool setup.
202 for t in component_setup_tools:
203 env.Tool(t)
204
205 # The following environment replacements use env.Dir() to force immediate
206 # evaluation/substitution of SCons variables. They can't be part of the
207 # preceding env.Replace() since they they may rely indirectly on variables
208 # defined there, and the env.Dir() calls would be evaluated before the
209 # env.Replace().
210
211 # Set default SOURCE_ROOT if there is none, assuming we're in a local
212 # site_scons directory for the project.
213 source_root_relative = os.path.normpath(
214 os.path.join(os.path.dirname(__file__), '../..'))
215 source_root = env.get('SOURCE_ROOT', source_root_relative)
216 env['SOURCE_ROOT'] = env.Dir(source_root).abspath
217
218 # Make tool root separate from source root so it can be overridden when we
219 # have a common location for tools outside of the current clientspec. Need
220 # to check if it's defined already, so it can be set prior to this tool
221 # being included.
222 tool_root = env.get('TOOL_ROOT', '$SOURCE_ROOT')
223 env['TOOL_ROOT'] = env.Dir(tool_root).abspath
224
225 # Defer pre-evaluating some environment variables, but do before building
226 # SConscripts.
227 env.Defer(PreEvaluateVariables)
228 env.Defer('BuildEnvironmentSConscripts', after=PreEvaluateVariables)
OLDNEW
« no previous file with comments | « site_scons/site_tools/component_builders.py ('k') | site_scons/site_tools/component_targets.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698