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

Side by Side Diff: scons-2.0.1/engine/SCons/Tool/mslink.py

Issue 6711079: Added an unmodified copy of SCons to third_party. (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/third_party/
Patch Set: '' Created 9 years, 9 months 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 | « scons-2.0.1/engine/SCons/Tool/mslib.py ('k') | scons-2.0.1/engine/SCons/Tool/mssdk.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 """SCons.Tool.mslink
2
3 Tool-specific initialization for the Microsoft linker.
4
5 There normally shouldn't be any need to import this module directly.
6 It will usually be imported through the generic SCons.Tool.Tool()
7 selection method.
8
9 """
10
11 #
12 # Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The S Cons Foundation
13 #
14 # Permission is hereby granted, free of charge, to any person obtaining
15 # a copy of this software and associated documentation files (the
16 # "Software"), to deal in the Software without restriction, including
17 # without limitation the rights to use, copy, modify, merge, publish,
18 # distribute, sublicense, and/or sell copies of the Software, and to
19 # permit persons to whom the Software is furnished to do so, subject to
20 # the following conditions:
21 #
22 # The above copyright notice and this permission notice shall be included
23 # in all copies or substantial portions of the Software.
24 #
25 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
26 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
27 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
29 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
30 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 #
33
34 __revision__ = "src/engine/SCons/Tool/mslink.py 5134 2010/08/16 23:02:40 bdeegan "
35
36 import os.path
37
38 import SCons.Action
39 import SCons.Defaults
40 import SCons.Errors
41 import SCons.Platform.win32
42 import SCons.Tool
43 import SCons.Tool.msvc
44 import SCons.Tool.msvs
45 import SCons.Util
46
47 from MSCommon import msvc_setup_env_once, msvc_exists
48
49 def pdbGenerator(env, target, source, for_signature):
50 try:
51 return ['/PDB:%s' % target[0].attributes.pdb, '/DEBUG']
52 except (AttributeError, IndexError):
53 return None
54
55 def _dllTargets(target, source, env, for_signature, paramtp):
56 listCmd = []
57 dll = env.FindIxes(target, '%sPREFIX' % paramtp, '%sSUFFIX' % paramtp)
58 if dll: listCmd.append("/out:%s"%dll.get_string(for_signature))
59
60 implib = env.FindIxes(target, 'LIBPREFIX', 'LIBSUFFIX')
61 if implib: listCmd.append("/implib:%s"%implib.get_string(for_signature))
62
63 return listCmd
64
65 def _dllSources(target, source, env, for_signature, paramtp):
66 listCmd = []
67
68 deffile = env.FindIxes(source, "WINDOWSDEFPREFIX", "WINDOWSDEFSUFFIX")
69 for src in source:
70 # Check explicitly for a non-None deffile so that the __cmp__
71 # method of the base SCons.Util.Proxy class used for some Node
72 # proxies doesn't try to use a non-existent __dict__ attribute.
73 if deffile and src == deffile:
74 # Treat this source as a .def file.
75 listCmd.append("/def:%s" % src.get_string(for_signature))
76 else:
77 # Just treat it as a generic source file.
78 listCmd.append(src)
79 return listCmd
80
81 def windowsShlinkTargets(target, source, env, for_signature):
82 return _dllTargets(target, source, env, for_signature, 'SHLIB')
83
84 def windowsShlinkSources(target, source, env, for_signature):
85 return _dllSources(target, source, env, for_signature, 'SHLIB')
86
87 def _windowsLdmodTargets(target, source, env, for_signature):
88 """Get targets for loadable modules."""
89 return _dllTargets(target, source, env, for_signature, 'LDMODULE')
90
91 def _windowsLdmodSources(target, source, env, for_signature):
92 """Get sources for loadable modules."""
93 return _dllSources(target, source, env, for_signature, 'LDMODULE')
94
95 def _dllEmitter(target, source, env, paramtp):
96 """Common implementation of dll emitter."""
97 SCons.Tool.msvc.validate_vars(env)
98
99 extratargets = []
100 extrasources = []
101
102 dll = env.FindIxes(target, '%sPREFIX' % paramtp, '%sSUFFIX' % paramtp)
103 no_import_lib = env.get('no_import_lib', 0)
104
105 if not dll:
106 raise SCons.Errors.UserError('A shared library should have exactly one t arget with the suffix: %s' % env.subst('$%sSUFFIX' % paramtp))
107
108 insert_def = env.subst("$WINDOWS_INSERT_DEF")
109 if not insert_def in ['', '0', 0] and \
110 not env.FindIxes(source, "WINDOWSDEFPREFIX", "WINDOWSDEFSUFFIX"):
111
112 # append a def file to the list of sources
113 extrasources.append(
114 env.ReplaceIxes(dll,
115 '%sPREFIX' % paramtp, '%sSUFFIX' % paramtp,
116 "WINDOWSDEFPREFIX", "WINDOWSDEFSUFFIX"))
117
118 version_num, suite = SCons.Tool.msvs.msvs_parse_version(env.get('MSVS_VERSIO N', '6.0'))
119 if version_num >= 8.0 and env.get('WINDOWS_INSERT_MANIFEST', 0):
120 # MSVC 8 automatically generates .manifest files that must be installed
121 extratargets.append(
122 env.ReplaceIxes(dll,
123 '%sPREFIX' % paramtp, '%sSUFFIX' % paramtp,
124 "WINDOWSSHLIBMANIFESTPREFIX", "WINDOWSSHLIBMANIFESTS UFFIX"))
125
126 if 'PDB' in env and env['PDB']:
127 pdb = env.arg2nodes('$PDB', target=target, source=source)[0]
128 extratargets.append(pdb)
129 target[0].attributes.pdb = pdb
130
131 if not no_import_lib and \
132 not env.FindIxes(target, "LIBPREFIX", "LIBSUFFIX"):
133 # Append an import library to the list of targets.
134 extratargets.append(
135 env.ReplaceIxes(dll,
136 '%sPREFIX' % paramtp, '%sSUFFIX' % paramtp,
137 "LIBPREFIX", "LIBSUFFIX"))
138 # and .exp file is created if there are exports from a DLL
139 extratargets.append(
140 env.ReplaceIxes(dll,
141 '%sPREFIX' % paramtp, '%sSUFFIX' % paramtp,
142 "WINDOWSEXPPREFIX", "WINDOWSEXPSUFFIX"))
143
144 return (target+extratargets, source+extrasources)
145
146 def windowsLibEmitter(target, source, env):
147 return _dllEmitter(target, source, env, 'SHLIB')
148
149 def ldmodEmitter(target, source, env):
150 """Emitter for loadable modules.
151
152 Loadable modules are identical to shared libraries on Windows, but building
153 them is subject to different parameters (LDMODULE*).
154 """
155 return _dllEmitter(target, source, env, 'LDMODULE')
156
157 def prog_emitter(target, source, env):
158 SCons.Tool.msvc.validate_vars(env)
159
160 extratargets = []
161
162 exe = env.FindIxes(target, "PROGPREFIX", "PROGSUFFIX")
163 if not exe:
164 raise SCons.Errors.UserError("An executable should have exactly one targ et with the suffix: %s" % env.subst("$PROGSUFFIX"))
165
166 version_num, suite = SCons.Tool.msvs.msvs_parse_version(env.get('MSVS_VERSIO N', '6.0'))
167 if version_num >= 8.0 and env.get('WINDOWS_INSERT_MANIFEST', 0):
168 # MSVC 8 automatically generates .manifest files that have to be install ed
169 extratargets.append(
170 env.ReplaceIxes(exe,
171 "PROGPREFIX", "PROGSUFFIX",
172 "WINDOWSPROGMANIFESTPREFIX", "WINDOWSPROGMANIFESTSUF FIX"))
173
174 if 'PDB' in env and env['PDB']:
175 pdb = env.arg2nodes('$PDB', target=target, source=source)[0]
176 extratargets.append(pdb)
177 target[0].attributes.pdb = pdb
178
179 return (target+extratargets,source)
180
181 def RegServerFunc(target, source, env):
182 if 'register' in env and env['register']:
183 ret = regServerAction([target[0]], [source[0]], env)
184 if ret:
185 raise SCons.Errors.UserError("Unable to register %s" % target[0])
186 else:
187 print "Registered %s sucessfully" % target[0]
188 return ret
189 return 0
190
191 regServerAction = SCons.Action.Action("$REGSVRCOM", "$REGSVRCOMSTR")
192 regServerCheck = SCons.Action.Action(RegServerFunc, None)
193 shlibLinkAction = SCons.Action.Action('${TEMPFILE("$SHLINK $SHLINKFLAGS $_SHLINK _TARGETS $_LIBDIRFLAGS $_LIBFLAGS $_PDB $_SHLINK_SOURCES")}')
194 compositeShLinkAction = shlibLinkAction + regServerCheck
195 ldmodLinkAction = SCons.Action.Action('${TEMPFILE("$LDMODULE $LDMODULEFLAGS $_LD MODULE_TARGETS $_LIBDIRFLAGS $_LIBFLAGS $_PDB $_LDMODULE_SOURCES")}')
196 compositeLdmodAction = ldmodLinkAction + regServerCheck
197
198 def generate(env):
199 """Add Builders and construction variables for ar to an Environment."""
200 SCons.Tool.createSharedLibBuilder(env)
201 SCons.Tool.createProgBuilder(env)
202
203 env['SHLINK'] = '$LINK'
204 env['SHLINKFLAGS'] = SCons.Util.CLVar('$LINKFLAGS /dll')
205 env['_SHLINK_TARGETS'] = windowsShlinkTargets
206 env['_SHLINK_SOURCES'] = windowsShlinkSources
207 env['SHLINKCOM'] = compositeShLinkAction
208 env.Append(SHLIBEMITTER = [windowsLibEmitter])
209 env['LINK'] = 'link'
210 env['LINKFLAGS'] = SCons.Util.CLVar('/nologo')
211 env['_PDB'] = pdbGenerator
212 env['LINKCOM'] = '${TEMPFILE("$LINK $LINKFLAGS /OUT:$TARGET.windows $_LIBDIR FLAGS $_LIBFLAGS $_PDB $SOURCES.windows")}'
213 env.Append(PROGEMITTER = [prog_emitter])
214 env['LIBDIRPREFIX']='/LIBPATH:'
215 env['LIBDIRSUFFIX']=''
216 env['LIBLINKPREFIX']=''
217 env['LIBLINKSUFFIX']='$LIBSUFFIX'
218
219 env['WIN32DEFPREFIX'] = ''
220 env['WIN32DEFSUFFIX'] = '.def'
221 env['WIN32_INSERT_DEF'] = 0
222 env['WINDOWSDEFPREFIX'] = '${WIN32DEFPREFIX}'
223 env['WINDOWSDEFSUFFIX'] = '${WIN32DEFSUFFIX}'
224 env['WINDOWS_INSERT_DEF'] = '${WIN32_INSERT_DEF}'
225
226 env['WIN32EXPPREFIX'] = ''
227 env['WIN32EXPSUFFIX'] = '.exp'
228 env['WINDOWSEXPPREFIX'] = '${WIN32EXPPREFIX}'
229 env['WINDOWSEXPSUFFIX'] = '${WIN32EXPSUFFIX}'
230
231 env['WINDOWSSHLIBMANIFESTPREFIX'] = ''
232 env['WINDOWSSHLIBMANIFESTSUFFIX'] = '${SHLIBSUFFIX}.manifest'
233 env['WINDOWSPROGMANIFESTPREFIX'] = ''
234 env['WINDOWSPROGMANIFESTSUFFIX'] = '${PROGSUFFIX}.manifest'
235
236 env['REGSVRACTION'] = regServerCheck
237 env['REGSVR'] = os.path.join(SCons.Platform.win32.get_system_root(),'System3 2','regsvr32')
238 env['REGSVRFLAGS'] = '/s '
239 env['REGSVRCOM'] = '$REGSVR $REGSVRFLAGS ${TARGET.windows}'
240
241 # Set-up ms tools paths
242 msvc_setup_env_once(env)
243
244
245 # Loadable modules are on Windows the same as shared libraries, but they
246 # are subject to different build parameters (LDMODULE* variables).
247 # Therefore LDMODULE* variables correspond as much as possible to
248 # SHLINK*/SHLIB* ones.
249 SCons.Tool.createLoadableModuleBuilder(env)
250 env['LDMODULE'] = '$SHLINK'
251 env['LDMODULEPREFIX'] = '$SHLIBPREFIX'
252 env['LDMODULESUFFIX'] = '$SHLIBSUFFIX'
253 env['LDMODULEFLAGS'] = '$SHLINKFLAGS'
254 env['_LDMODULE_TARGETS'] = _windowsLdmodTargets
255 env['_LDMODULE_SOURCES'] = _windowsLdmodSources
256 env['LDMODULEEMITTER'] = [ldmodEmitter]
257 env['LDMODULECOM'] = compositeLdmodAction
258
259 def exists(env):
260 return msvc_exists()
261
262 # Local Variables:
263 # tab-width:4
264 # indent-tabs-mode:nil
265 # End:
266 # vim: set expandtab tabstop=4 shiftwidth=4:
OLDNEW
« no previous file with comments | « scons-2.0.1/engine/SCons/Tool/mslib.py ('k') | scons-2.0.1/engine/SCons/Tool/mssdk.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698