| 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 #------------------------------------------------------------------------------ | |
| 117 | |
| 118 | |
| 119 def generate(env): | |
| 120 # NOTE: SCons requires the use of this name, which fails gpylint. | |
| 121 """SCons entry point for this tool.""" | |
| 122 | |
| 123 # Use g++ | |
| 124 env.Tool('g++') | |
| 125 env.Tool('gcc') | |
| 126 env.Tool('gnulink') | |
| 127 env.Tool('ar') | |
| 128 env.Tool('as') | |
| 129 env.Tool('applelink') | |
| 130 | |
| 131 # Declare bits | |
| 132 DeclareBit('mac', 'Target platform is mac.', | |
| 133 exclusive_groups=('target_platform')) | |
| 134 DeclareBit('posix', 'Target platform is posix.') | |
| 135 env.SetBits('mac', 'posix') | |
| 136 | |
| 137 env.Replace( | |
| 138 TARGET_PLATFORM='MAC', | |
| 139 COMPONENT_PLATFORM_SETUP=ComponentPlatformSetup, | |
| 140 CCFLAG_INCLUDE='-include', # Command line option to include a header | |
| 141 | |
| 142 # Code coverage related. | |
| 143 COVERAGE_CCFLAGS=['-ftest-coverage', '-fprofile-arcs'], | |
| 144 COVERAGE_LIBS='gcov', | |
| 145 COVERAGE_STOP_CMD=[ | |
| 146 '$COVERAGE_MCOV --directory "$TARGET_ROOT" --output "$TARGET"', | |
| 147 ('$COVERAGE_GENHTML --output-directory $COVERAGE_HTML_DIR ' | |
| 148 '$COVERAGE_OUTPUT_FILE'), | |
| 149 ], | |
| 150 ) | |
| 151 | |
| 152 env.Append( | |
| 153 HOST_PLATFORMS=['MAC'], | |
| 154 CPPDEFINES=['OS_MACOSX=OS_MACOSX'], | |
| 155 | |
| 156 # Settings for debug | |
| 157 CCFLAGS_DEBUG=['-g'], | |
| 158 LINKFLAGS_DEBUG=['-g'], | |
| 159 | |
| 160 # Settings for optimized | |
| 161 CCFLAGS_OPTIMIZED=['-O2'], | |
| 162 | |
| 163 # Settings for component_builders | |
| 164 COMPONENT_LIBRARY_LINK_SUFFIXES=['.dylib', '.a'], | |
| 165 COMPONENT_LIBRARY_DEBUG_SUFFIXES=[], | |
| 166 | |
| 167 # New 'all' target. Helpful: "hammer -h" now lists it! | |
| 168 COMPONENT_BUNDLE_GROUPS=['all_bundles'], | |
| 169 ) | |
| 170 | |
| 171 | |
| 172 # Set default values used by the Bundle pseudobuilder. | |
| 173 env.Replace( | |
| 174 BUNDLE_TYPE='APPL', | |
| 175 BUNDLE_STRING='${BUNDLE_TYPE}????', | |
| 176 BUNDLE_GENERATE_PKGINFO='echo "${BUNDLE_STRING}"', | |
| 177 BUNDLE_PKGINFO_FILENAME='PkgInfo', | |
| 178 BUNDLE_INFO_PLIST='Info.plist', | |
| 179 ) | |
| 180 | |
| 181 # Add the Bundle pseudobuilder. | |
| 182 env.AddMethod(BundlePseudoBuilder, 'Bundle') | |
| 183 | |
| 184 # Add our target groups | |
| 185 AddTargetGroup('all_bundles', 'bundles can be built') | |
| OLD | NEW |