| 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 """Build tool setup for MacOS. |
| 32 |
| 33 This module is a SCons tool which should be include in the topmost mac |
| 34 environment. |
| 35 It is used as follows: |
| 36 env = base_env.Clone(tools = ['component_setup']) |
| 37 mac_env = base_env.Clone(tools = ['target_platform_mac']) |
| 38 """ |
| 39 |
| 40 |
| 41 import SCons.Script |
| 42 |
| 43 |
| 44 def ComponentPlatformSetup(env, builder_name): |
| 45 """Hook to allow platform to modify environment inside a component builder. |
| 46 |
| 47 Args: |
| 48 env: Environment to modify |
| 49 builder_name: Name of the builder |
| 50 """ |
| 51 if env.get('ENABLE_EXCEPTIONS'): |
| 52 env.FilterOut(CCFLAGS=['-fno-exceptions']) |
| 53 env.Append(CCFLAGS=['-fexceptions']) |
| 54 |
| 55 #------------------------------------------------------------------------------ |
| 56 |
| 57 |
| 58 def BundlePseudoBuilder(env, target, **kwargs): |
| 59 """MacOS Bundle PseudoBuilder. |
| 60 |
| 61 Args: |
| 62 env: Environment in which to build |
| 63 target: Name of the bundle to build |
| 64 kwargs: Additional parameters to set in the environment |
| 65 |
| 66 Returns: |
| 67 The target is returned. |
| 68 """ |
| 69 # Don't change the environment passed into the pseudo-builder |
| 70 env = env.Clone() |
| 71 |
| 72 # Bring keywords args into the environment. |
| 73 for k, v in kwargs.items(): |
| 74 env[k] = v |
| 75 # Make sure BUNDLE_RESOURCES is set and not empty; force it to be a list |
| 76 bundle_resources = env.Flatten(env.get('BUNDLE_RESOURCES', [])) |
| 77 if not bundle_resources: |
| 78 raise ValueError('BUNDLE_RESOURCES must be set and non-empty') |
| 79 |
| 80 # Make each resource into a directory node. |
| 81 # TODO(jrg): this seems a little too restrictive. |
| 82 # bundle_resources = [env.Dir(i) for i in bundle_resources] |
| 83 bundle_resources = [i for i in bundle_resources] |
| 84 |
| 85 # Create a PkgInfo file only if BUNDLE_PKGINFO_FILENAME is useful. |
| 86 # (NPAPI bundles are unhappy with PkgInfo files.) |
| 87 # TODO(jrg): discuss method with Bradley |
| 88 if env.get('BUNDLE_PKGINFO_FILENAME'): |
| 89 pkginfo_create_command = ('$BUNDLE_GENERATE_PKGINFO ' |
| 90 '>$TARGET/$BUNDLE_PKGINFO_FILENAME') |
| 91 else: |
| 92 pkginfo_create_command = '/bin/echo no PkgInfo will be created' # noop |
| 93 |
| 94 # Add the build step for the bundle. |
| 95 p = env.Command(env.Dir(target), |
| 96 [env.File('$BUNDLE_EXE'), |
| 97 env.File('$BUNDLE_INFO_PLIST')] + |
| 98 bundle_resources, |
| 99 [SCons.Script.Delete('$TARGET'), |
| 100 SCons.Script.Mkdir('$TARGET/Contents'), |
| 101 SCons.Script.Mkdir('$TARGET/Contents/MacOS'), |
| 102 SCons.Script.Mkdir('$TARGET/Contents/Resources'), |
| 103 'cp -f $SOURCE $TARGET/Contents/MacOS', |
| 104 'cp -f ${SOURCES[1]} $TARGET/Contents', |
| 105 pkginfo_create_command, |
| 106 'cp -rf ${SOURCES[2:]} $TARGET/Contents/Resources']) |
| 107 |
| 108 # Add an alias for this target. |
| 109 # This also allows the 'all_bundles' target to build me. |
| 110 a = env.Alias(target, p) |
| 111 for group in env['COMPONENT_BUNDLE_GROUPS']: |
| 112 SCons.Script.Alias(group, a) |
| 113 |
| 114 return env.Dir(target) |
| 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 # Use g++ |
| 121 env.Tool('g++') |
| 122 env.Tool('gcc') |
| 123 env.Tool('gnulink') |
| 124 env.Tool('ar') |
| 125 env.Tool('as') |
| 126 env.Tool('applelink') |
| 127 |
| 128 # Declare bits |
| 129 DeclareBit('mac', 'Target platform is mac.', |
| 130 exclusive_groups=('target_platform')) |
| 131 DeclareBit('posix', 'Target platform is posix.') |
| 132 env.SetBits('mac', 'posix') |
| 133 |
| 134 env.Replace( |
| 135 TARGET_PLATFORM='MAC', |
| 136 COMPONENT_PLATFORM_SETUP=ComponentPlatformSetup, |
| 137 ) |
| 138 |
| 139 env.Append( |
| 140 HOST_PLATFORMS=['MAC'], |
| 141 CPPDEFINES=['OS_MACOSX=OS_MACOSX'], |
| 142 BITS=['mac', 'posix'], |
| 143 |
| 144 # Settings for debug |
| 145 CCFLAGS_DEBUG=['-g'], |
| 146 LINKFLAGS_DEBUG=['-g'], |
| 147 |
| 148 # Settings for optimized |
| 149 CCFLAGS_OPTIMIZED=['-O2'], |
| 150 |
| 151 # Settings for component_builders |
| 152 COMPONENT_LIBRARY_LINK_SUFFIXES=['.dylib', '.a'], |
| 153 COMPONENT_LIBRARY_DEBUG_SUFFIXES=[], |
| 154 |
| 155 # New 'all' target. Helpful: "hammer -h" now lists it! |
| 156 COMPONENT_BUNDLE_GROUPS=['all_bundles'], |
| 157 ) |
| 158 |
| 159 |
| 160 # Set default values used by the Bundle pseudobuilder. |
| 161 env.Replace( |
| 162 BUNDLE_TYPE='APPL', |
| 163 BUNDLE_STRING='${BUNDLE_TYPE}????', |
| 164 BUNDLE_GENERATE_PKGINFO='echo "${BUNDLE_STRING}"', |
| 165 BUNDLE_PKGINFO_FILENAME='PkgInfo', |
| 166 BUNDLE_INFO_PLIST='Info.plist', |
| 167 ) |
| 168 |
| 169 # Add the Bundle pseudobuilder. |
| 170 env.AddMethod(BundlePseudoBuilder, 'Bundle') |
| 171 |
| 172 # Add our target groups |
| 173 AddTargetGroup('all_bundles', 'bundles can be built') |
| OLD | NEW |