| 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 """XML output of component targets for SCons.""" |
| 32 |
| 33 |
| 34 import xml.dom |
| 35 import SCons.Script |
| 36 |
| 37 |
| 38 def TargetXMLHelp(target, source, env): |
| 39 """Generates target information in XML format. |
| 40 |
| 41 Args: |
| 42 target: Destination file. |
| 43 source: List of sources. Should be empty, otherwise this will actually |
| 44 require the sources to be built first. |
| 45 env: Environment context. |
| 46 """ |
| 47 env = env |
| 48 source = source # Silence gpylint |
| 49 |
| 50 target_path = target[0].abspath |
| 51 |
| 52 xml_impl = xml.dom.getDOMImplementation() |
| 53 doc = xml_impl.createDocument(None, 'help', None) |
| 54 |
| 55 mode_list = doc.createElement('mode_list') |
| 56 doc.documentElement.appendChild(mode_list) |
| 57 for mode in GetTargetModes().values(): |
| 58 n = doc.createElement('build_mode') |
| 59 n.setAttribute('name', mode.name) |
| 60 n.setAttribute('description', mode.description) |
| 61 mode_list.appendChild(n) |
| 62 |
| 63 group_list = doc.createElement('target_groups') |
| 64 doc.documentElement.appendChild(group_list) |
| 65 for group in GetTargetGroups().values(): |
| 66 items = group.GetTargetNames() |
| 67 if not items: |
| 68 continue |
| 69 |
| 70 ngroup = doc.createElement('target_group') |
| 71 ngroup.setAttribute('name', group.name) |
| 72 group_list.appendChild(ngroup) |
| 73 |
| 74 for i in items: |
| 75 ntarget = doc.createElement('build_target') |
| 76 ntarget.setAttribute('name', i) |
| 77 ngroup.appendChild(ntarget) |
| 78 |
| 79 # Get properties for target, if any |
| 80 target = GetTargets().get(i) |
| 81 if target: |
| 82 # All modes |
| 83 for k, v in target.properties.items(): |
| 84 n = doc.createElement('target_property') |
| 85 n.setAttribute('name', k) |
| 86 n.setAttribute('value', v) |
| 87 ntarget.appendChild(n) |
| 88 |
| 89 # Mode-specific |
| 90 for mode, mode_properties in target.mode_properties.items(): |
| 91 nmode = doc.createElement('target_mode') |
| 92 nmode.setAttribute('name', mode) |
| 93 ntarget.appendChild(nmode) |
| 94 |
| 95 for k, v in mode_properties.items(): |
| 96 n = doc.createElement('target_property') |
| 97 n.setAttribute('name', k) |
| 98 n.setAttribute('value', v) |
| 99 nmode.appendChild(n) |
| 100 |
| 101 f = open(target_path, 'wt') |
| 102 doc.writexml(f, encoding='UTF-8', addindent=' ', newl='\n') |
| 103 f.close() |
| 104 |
| 105 #------------------------------------------------------------------------------ |
| 106 |
| 107 |
| 108 def generate(env): |
| 109 # NOTE: SCons requires the use of this name, which fails gpylint. |
| 110 """SCons entry point for this tool.""" |
| 111 env = env # Silence gpylint |
| 112 |
| 113 SCons.Script.Help('''\ |
| 114 targets_xml Write information on the build mode's targets to |
| 115 targets.xml. Most useful with --mode=all. |
| 116 ''') |
| 117 |
| 118 # Add build target to generate help |
| 119 p = env.Command('$DESTINATION_ROOT/targets.xml', [], |
| 120 env.Action(TargetXMLHelp)) |
| 121 |
| 122 # Always build xml info if requested. |
| 123 # TODO(rspangler): Is there a better way to determine the xml info is up to |
| 124 # date? |
| 125 env.AlwaysBuild(p) |
| 126 env.Alias('targets_xml', p) |
| OLD | NEW |