| OLD | NEW | 
|---|
| 1 #!/usr/bin/python2.4 | 1 #!/usr/bin/python2.4 | 
| 2 # Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be | 
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. | 
| 5 | 5 | 
| 6 '''SCons integration for GRIT. | 6 '''SCons integration for GRIT. | 
| 7 ''' | 7 ''' | 
| 8 | 8 | 
| 9 # NOTE:  DO NOT IMPORT ANY GRIT STUFF HERE - we import lazily so that grit and | 9 # NOTE:  DO NOT IMPORT ANY GRIT STUFF HERE - we import lazily so that grit and | 
| 10 # its dependencies aren't imported until actually needed. | 10 # its dependencies aren't imported until actually needed. | 
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 77   # TODO(gspencer):  Had to use .abspath, not str(target[0]), to get | 77   # TODO(gspencer):  Had to use .abspath, not str(target[0]), to get | 
| 78   # this to work with Repository() directories. | 78   # this to work with Repository() directories. | 
| 79   # Get this functionality folded back into the upstream grit tool. | 79   # Get this functionality folded back into the upstream grit tool. | 
| 80   #base_dir = util.dirname(str(target[0])) | 80   #base_dir = util.dirname(str(target[0])) | 
| 81   base_dir = util.dirname(target[0].abspath) | 81   base_dir = util.dirname(target[0].abspath) | 
| 82 | 82 | 
| 83   grd = grd_reader.Parse(_SourceToFile(source), debug=_IsDebugEnabled()) | 83   grd = grd_reader.Parse(_SourceToFile(source), debug=_IsDebugEnabled()) | 
| 84 | 84 | 
| 85   target = [] | 85   target = [] | 
| 86   lang_folders = {} | 86   lang_folders = {} | 
|  | 87   # TODO(tc): new_header_output is a hack while we migrate to | 
|  | 88   # grit_derived_sources/grit/ as the new output dir for headers. | 
|  | 89   new_header_output = None | 
| 87   # Add all explicitly-specified output files | 90   # Add all explicitly-specified output files | 
| 88   for output in grd.GetOutputFiles(): | 91   for output in grd.GetOutputFiles(): | 
| 89     path = os.path.join(base_dir, output.GetFilename()) | 92     path = os.path.join(base_dir, output.GetFilename()) | 
| 90     target.append(path) | 93     target.append(path) | 
|  | 94 | 
|  | 95     if path.endswith('.h'): | 
|  | 96       path, filename = os.path.split(path) | 
|  | 97       new_header_output = os.path.join(path, 'grit', filename) | 
| 91     if _IsDebugEnabled(): | 98     if _IsDebugEnabled(): | 
| 92       print "GRIT: Added target %s" % path | 99       print "GRIT: Added target %s" % path | 
| 93     if output.attrs['lang'] != '': | 100     if output.attrs['lang'] != '': | 
| 94       lang_folders[output.attrs['lang']] = os.path.dirname(path) | 101       lang_folders[output.attrs['lang']] = os.path.dirname(path) | 
| 95 | 102 | 
| 96   # Add all generated files, once for each output language. | 103   # Add all generated files, once for each output language. | 
| 97   for node in grd: | 104   for node in grd: | 
| 98     if node.name == 'structure': | 105     if node.name == 'structure': | 
| 99       # TODO(joi) Should remove the "if sconsdep is true" thing as it is a | 106       # TODO(joi) Should remove the "if sconsdep is true" thing as it is a | 
| 100       # hack - see grit/node/structure.py | 107       # hack - see grit/node/structure.py | 
| 101       if node.HasFileForLanguage() and node.attrs['sconsdep'] == 'true': | 108       if node.HasFileForLanguage() and node.attrs['sconsdep'] == 'true': | 
| 102         for lang in lang_folders: | 109         for lang in lang_folders: | 
| 103           path = node.FileForLanguage(lang, lang_folders[lang], | 110           path = node.FileForLanguage(lang, lang_folders[lang], | 
| 104                                       create_file=False, | 111                                       create_file=False, | 
| 105                                       return_if_not_generated=False) | 112                                       return_if_not_generated=False) | 
| 106           if path: | 113           if path: | 
| 107             target.append(path) | 114             target.append(path) | 
| 108             if _IsDebugEnabled(): | 115             if _IsDebugEnabled(): | 
| 109               print "GRIT: Added target %s" % path | 116               print "GRIT: Added target %s" % path | 
| 110 | 117 | 
|  | 118   if new_header_output: | 
|  | 119     target.append(new_header_output) | 
|  | 120 | 
| 111   # GRIT is not thread safe so we should only build one grit target at a time. | 121   # GRIT is not thread safe so we should only build one grit target at a time. | 
| 112   # We tell scons about this by making a fake side effect target. | 122   # We tell scons about this by making a fake side effect target. | 
| 113   env.SideEffect('grit_lock', target) | 123   env.SideEffect('grit_lock', target) | 
| 114 | 124 | 
| 115   # return target and source lists | 125   # return target and source lists | 
| 116   return (target, source) | 126   return (target, source) | 
| 117 | 127 | 
| 118 | 128 | 
| 119 def _Scanner(file_node, env, path): | 129 def _Scanner(file_node, env, path): | 
| 120   '''A SCons scanner function for .grd files, which outputs the list of files | 130   '''A SCons scanner function for .grd files, which outputs the list of files | 
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 170   builder = env.Builder(action=action, emitter=_Emitter, | 180   builder = env.Builder(action=action, emitter=_Emitter, | 
| 171                         source_scanner=scanner, | 181                         source_scanner=scanner, | 
| 172                         src_suffix='.grd') | 182                         src_suffix='.grd') | 
| 173 | 183 | 
| 174   # add our builder and scanner to the environment | 184   # add our builder and scanner to the environment | 
| 175   env.Append(BUILDERS = {'GRIT': builder}) | 185   env.Append(BUILDERS = {'GRIT': builder}) | 
| 176 | 186 | 
| 177 # Function name is mandated by newer versions of SCons. | 187 # Function name is mandated by newer versions of SCons. | 
| 178 def exists(env): | 188 def exists(env): | 
| 179   return 1 | 189   return 1 | 
| OLD | NEW | 
|---|