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

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

Issue 6329: Dropping in software construction toolkit. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 12 years, 2 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 | « site_scons/site_tools/component_setup.py ('k') | site_scons/site_tools/defer.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 """Source concatenation builder for SCons."""
32
33
34 import SCons.Script
35
36
37 def ConcatSourceBuilder(target, source, env):
38 """ConcatSource builder.
39
40 Args:
41 target: List of target nodes
42 source: List of source nodes
43 env: Environment in which to build
44
45 Returns:
46 None if successful; 1 if error.
47 """
48 if len(target) != 1:
49 print 'ERROR: multiple ConcatSource targets when 1 expected'
50 return 1
51
52 output_lines = [
53 '// This file is auto-generated by the ConcatSource builder.']
54
55 for source_file in source:
56 # Skip source files which are not CPP files. These will be passed through
57 # to the output list by the pseudo-builder.
58 if source_file.suffix not in env['CONCAT_SOURCE_SUFFIXES']:
59 continue
60
61 source_path = str(source_file)
62
63 if 'msvc' in env['TOOLS']:
64 # Add message pragma for nicer progress indication when building with
65 # MSVC.
66 output_lines.append('#pragma message("--%s")' % (
67 source_path.replace("\\", "/")))
68
69 output_lines.append('#include "%s"' % source_path)
70
71 # Need an EOL at the end of the file for more finicky build tools
72 output_lines.append('\n')
73
74 output_file = open(str(target[0]), 'w')
75 output_file.write('\n'.join(output_lines))
76 output_file.close()
77
78
79 def ConcatSourcePseudoBuilder(self, target, source):
80 """ConcatSource pseudo-builder; calls builder or passes through source nodes.
81
82 Args:
83 self: Environment in which to build
84 target: List of target nodes
85 source: List of source nodes
86
87 Returns:
88 If self['CONCAT_SOURCE_ENABLE'], calls self.ConcatSource and returns
89 the list of target nodes. Otherwise, returns the list of source nodes.
90 Source nodes which are not CPP files are passed through unchanged to the
91 list of output nodes.
92 """
93 if self.get('CONCAT_SOURCE_ENABLE', True):
94 # Scan down source list and separate CPP sources (which we concatenate)
95 # from other files (which we pass through).
96 cppsource = []
97 outputs = []
98 for source_file in SCons.Script.Flatten(source):
99 if self.File(source_file).suffix in self['CONCAT_SOURCE_SUFFIXES']:
100 cppsource.append(source_file)
101 else:
102 outputs.append(source_file)
103
104 if len(cppsource) > 1:
105 # More than one file, so concatenate them together
106 outputs += self.ConcatSourceBuilder(target, cppsource)
107 else:
108 # <2 files, so pass them through; no need for a ConcatSource target
109 outputs += cppsource
110 return outputs
111 else:
112 # ConcatSource is disabled, so pass through the list of source nodes.
113 return source
114
115
116 def generate(env):
117 # NOTE: SCons requires the use of this name, which fails gpylint.
118 """SCons entry point for this tool."""
119
120 # Add the builder
121 action = SCons.Script.Action(ConcatSourceBuilder,
122 varlist = ['CONCAT_SOURCE_SUFFIXES'])
123 builder = SCons.Script.Builder(action = action, suffix = '$CXXFILESUFFIX')
124 env.Append(BUILDERS={'ConcatSourceBuilder': builder})
125
126 # Suffixes of sources we can concatenate. Files not in this list will be
127 # passed through untouched. (Note that on Mac, Objective C/C++ files
128 # cannot be concatenated with regular C/C++ files.)
129 # TODO(rspangler): Probably shouldn't mix C, C++ either...
130 env['CONCAT_SOURCE_SUFFIXES'] = ['.c', '.C', '.cxx', '.cpp', '.c++', '.cc',
131 '.h', '.H', '.hxx', '.hpp', '.hh']
132
133 # Add a psuedo-builder method which can look at the environment to determine
134 # whether to call the ConcatSource builder or not
135 env.AddMethod(ConcatSourcePseudoBuilder, 'ConcatSource')
OLDNEW
« no previous file with comments | « site_scons/site_tools/component_setup.py ('k') | site_scons/site_tools/defer.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698