gfx/skia/generate_mozbuild.py

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/generate_mozbuild.py	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,366 @@
     1.4 +#!/usr/bin/env python
     1.5 +
     1.6 +import os
     1.7 +
     1.8 +import locale
     1.9 +locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
    1.10 +
    1.11 +header = """
    1.12 +# Please note this file is autogenerated from generate_mozbuild.py, so do not modify it directly
    1.13 +
    1.14 +"""
    1.15 +
    1.16 +footer = """
    1.17 +
    1.18 +# left out of UNIFIED_SOURCES for now; that's not C++ anyway, nothing else to unify it with
    1.19 +if not CONFIG['INTEL_ARCHITECTURE'] and CONFIG['CPU_ARCH'] == 'arm' and CONFIG['GNU_CC']:
    1.20 +    SOURCES += [
    1.21 +        'trunk/src/opts/memset.arm.S',
    1.22 +    ]
    1.23 +    if CONFIG['BUILD_ARM_NEON']:
    1.24 +        SOURCES += [
    1.25 +            'trunk/src/opts/memset16_neon.S',
    1.26 +            'trunk/src/opts/memset32_neon.S',
    1.27 +        ]
    1.28 +
    1.29 +MSVC_ENABLE_PGO = True
    1.30 +
    1.31 +FINAL_LIBRARY = 'gkmedias'
    1.32 +LOCAL_INCLUDES += [
    1.33 +    'trunk/include/config',
    1.34 +    'trunk/include/core',
    1.35 +    'trunk/include/effects',
    1.36 +    'trunk/include/gpu',
    1.37 +    'trunk/include/images',
    1.38 +    'trunk/include/lazy',
    1.39 +    'trunk/include/pathops',
    1.40 +    'trunk/include/pipe',
    1.41 +    'trunk/include/ports',
    1.42 +    'trunk/include/utils',
    1.43 +    'trunk/include/utils/mac',
    1.44 +    'trunk/include/utils/win',
    1.45 +    'trunk/include/views',
    1.46 +    'trunk/src/core',
    1.47 +    'trunk/src/gpu',
    1.48 +    'trunk/src/gpu/effects',
    1.49 +    'trunk/src/gpu/gl',
    1.50 +    'trunk/src/image',
    1.51 +    'trunk/src/lazy',
    1.52 +    'trunk/src/opts',
    1.53 +    'trunk/src/sfnt',
    1.54 +    'trunk/src/utils',
    1.55 +    'trunk/src/utils/android',
    1.56 +    'trunk/src/utils/mac',
    1.57 +    'trunk/src/utils/win',
    1.58 +]
    1.59 +
    1.60 +DEFINES['SK_A32_SHIFT'] = 24
    1.61 +DEFINES['SK_R32_SHIFT'] = 16
    1.62 +DEFINES['SK_G32_SHIFT'] = 8
    1.63 +DEFINES['SK_B32_SHIFT'] = 0
    1.64 +
    1.65 +if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('android', 'gtk2', 'gtk3', 'qt', 'gonk', 'cocoa'):
    1.66 +    DEFINES['SK_USE_POSIX_THREADS'] = 1
    1.67 +
    1.68 +if CONFIG['INTEL_ARCHITECTURE'] and CONFIG['HAVE_TOOLCHAIN_SUPPORT_MSSSE3']:
    1.69 +    DEFINES['SK_BUILD_SSSE3'] = 1
    1.70 +
    1.71 +if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('android', 'gonk'):
    1.72 +    DEFINES['SK_FONTHOST_CAIRO_STANDALONE'] = 0
    1.73 +
    1.74 +if (CONFIG['MOZ_WIDGET_TOOLKIT'] == 'android') or \
    1.75 +   (CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa') or \
    1.76 +   (CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk') or \
    1.77 +   (CONFIG['MOZ_WIDGET_TOOLKIT'] == 'qt') or \
    1.78 +   CONFIG['MOZ_WIDGET_GTK']:
    1.79 +    DEFINES['SK_FONTHOST_DOES_NOT_USE_FONTMGR'] = 1
    1.80 +
    1.81 +if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'windows':
    1.82 +    DEFINES['SKIA_DLL'] = 1
    1.83 +    DEFINES['GR_DLL'] = 1
    1.84 +
    1.85 +if CONFIG['INTEL_ARCHITECTURE'] and CONFIG['GNU_CC']:
    1.86 +    SOURCES['trunk/src/opts/SkBitmapFilter_opts_SSE2.cpp'].flags += CONFIG['SSE2_FLAGS']
    1.87 +    SOURCES['trunk/src/opts/SkBitmapProcState_opts_SSE2.cpp'].flags += CONFIG['SSE2_FLAGS']
    1.88 +    SOURCES['trunk/src/opts/SkBitmapProcState_opts_SSSE3.cpp'].flags += ['-mssse3']
    1.89 +    SOURCES['trunk/src/opts/SkBlitRect_opts_SSE2.cpp'].flags += CONFIG['SSE2_FLAGS']
    1.90 +    SOURCES['trunk/src/opts/SkBlitRow_opts_SSE2.cpp'].flags += CONFIG['SSE2_FLAGS']
    1.91 +    SOURCES['trunk/src/opts/SkBlurImage_opts_SSE2.cpp'].flags += CONFIG['SSE2_FLAGS']
    1.92 +    SOURCES['trunk/src/opts/SkMorphology_opts_SSE2.cpp'].flags += CONFIG['SSE2_FLAGS']
    1.93 +    SOURCES['trunk/src/opts/SkUtils_opts_SSE2.cpp'].flags += CONFIG['SSE2_FLAGS']
    1.94 +elif CONFIG['CPU_ARCH'] == 'arm' and CONFIG['GNU_CC'] and CONFIG['BUILD_ARM_NEON']:
    1.95 +    DEFINES['__ARM_HAVE_OPTIONAL_NEON_SUPPORT'] = 1
    1.96 +    DEFINES['USE_ANDROID_NDK_CPU_FEATURES'] = 0
    1.97 +
    1.98 +DEFINES['SKIA_IMPLEMENTATION'] = 1
    1.99 +DEFINES['GR_IMPLEMENTATION'] = 1
   1.100 +
   1.101 +if CONFIG['GNU_CXX']:
   1.102 +    CXXFLAGS += [
   1.103 +        '-Wno-overloaded-virtual',
   1.104 +        '-Wno-unused-function',
   1.105 +    ]
   1.106 +    if not CONFIG['CLANG_CXX']:
   1.107 +        CXXFLAGS += ['-Wno-logical-op']
   1.108 +"""
   1.109 +
   1.110 +import json
   1.111 +
   1.112 +platforms = ['linux', 'mac', 'android', 'win']
   1.113 +
   1.114 +custom_includes = {
   1.115 +  'trunk/src/ports/SkAtomics_android.h': True,
   1.116 +  'trunk/src/ports/SkAtomics_sync.h': True,
   1.117 +  'trunk/src/ports/SkAtomics_win.h': True,
   1.118 +  'trunk/src/ports/SkMutex_pthread.h': True,
   1.119 +  'trunk/src/ports/SkMutex_win.h': True
   1.120 +}
   1.121 +
   1.122 +def generate_includes():
   1.123 +  includes = {}
   1.124 +  for root, dirs, files in os.walk('trunk/include'):
   1.125 +    for name in files:
   1.126 +      if name.endswith('.h'):
   1.127 +        includes[os.path.join(root, name)] = True
   1.128 +
   1.129 +  return dict(includes.items() + custom_includes.items())
   1.130 +
   1.131 +def generate_opt_sources():
   1.132 +  opt_sources = {'opts': {''}}
   1.133 +  for root, dirs, files in os.walk('trunk/src/opts'):
   1.134 +    for name in files:
   1.135 +      if name.endswith('.cpp'):
   1.136 +        opt_sources['opts'].add(os.path.join(root, name))
   1.137 +
   1.138 +  return opt_sources
   1.139 +
   1.140 +def generate_platform_sources():
   1.141 +  sources = {}
   1.142 +
   1.143 +  for plat in platforms:
   1.144 +    if os.system("cd trunk && GYP_GENERATORS=dump_mozbuild ./gyp_skia -D OS=%s gyp/skia_lib.gyp" % plat) != 0:
   1.145 +      print 'Failed to generate sources for ' + plat
   1.146 +      continue
   1.147 +
   1.148 +
   1.149 +    f = open('trunk/sources.json');
   1.150 +    sources[plat] = set(json.load(f));
   1.151 +    f.close()
   1.152 +
   1.153 +  return dict(sources.items() + generate_opt_sources().items())
   1.154 +
   1.155 +
   1.156 +def generate_separated_sources(platform_sources):
   1.157 +  blacklist = [
   1.158 +    'ChromeUtils',
   1.159 +    'SkImageDecoder_',
   1.160 +    '_gif',
   1.161 +    'SkFontConfigParser_android',
   1.162 +    'SkJpeg',
   1.163 +    'SkXML',
   1.164 +    'SkCity',
   1.165 +    'GrGLCreateNativeInterface',
   1.166 +    'fontconfig',
   1.167 +    'SkThreadUtils_pthread_',
   1.168 +    'SkImage_Codec',
   1.169 +    'SkBitmapChecksummer',
   1.170 +    'SkNativeGLContext',
   1.171 +    'SkFontConfig',
   1.172 +    'SkFontHost_win_dw',
   1.173 +    'SkForceLinking',
   1.174 +    'SkMovie',
   1.175 +    'SkImageDecoder',
   1.176 +    'SkImageEncoder',
   1.177 +    'SkBitmapHasher',
   1.178 +    'SkWGL',
   1.179 +    'SkImages',
   1.180 +    'SkDiscardableMemory_ashmem',
   1.181 +    'SkMemory_malloc'
   1.182 +  ]
   1.183 +
   1.184 +  def isblacklisted(value):
   1.185 +    for item in blacklist:
   1.186 +      if value.find(item) >= 0:
   1.187 +        return True
   1.188 +
   1.189 +    return False
   1.190 +
   1.191 +  separated = {
   1.192 +    'common': {
   1.193 +      #'trunk/src/effects/gradients/SkGradientTileProc.cpp',
   1.194 +      'trunk/src/gpu/gl/GrGLCreateNativeInterface_none.cpp',
   1.195 +      'trunk/src/ports/SkDiscardableMemory_none.cpp',
   1.196 +      'trunk/src/ports/SkImageDecoder_empty.cpp',
   1.197 +      'trunk/src/ports/SkMemory_mozalloc.cpp',
   1.198 +      # 'trunk/src/images/SkImages.cpp',
   1.199 +      # 'trunk/src/images/SkImageRef.cpp',
   1.200 +      # 'trunk/src/images/SkImageRef_GlobalPool.cpp',
   1.201 +      # 'trunk/src/images/SkImageRefPool.cpp',
   1.202 +      # 'trunk/src/images/SkImageDecoder.cpp',
   1.203 +      # 'trunk/src/images/SkImageDecoder_Factory.cpp',
   1.204 +    },
   1.205 +    'android': {
   1.206 +      # 'trunk/src/ports/SkDebug_android.cpp',
   1.207 +      'trunk/src/ports/SkFontHost_android_old.cpp',
   1.208 +      'trunk/src/ports/SkFontHost_cairo.cpp',
   1.209 +      # 'trunk/src/ports/SkFontHost_FreeType.cpp',
   1.210 +      # 'trunk/src/ports/SkFontHost_FreeType_common.cpp',
   1.211 +      # 'trunk/src/ports/SkThread_pthread.cpp',
   1.212 +      # 'trunk/src/ports/SkPurgeableMemoryBlock_android.cpp',
   1.213 +      # 'trunk/src/ports/SkTime_Unix.cpp',
   1.214 +      # 'trunk/src/utils/SkThreadUtils_pthread.cpp',
   1.215 +      # 'trunk/src/images/SkImageRef_ashmem.cpp',
   1.216 +      # 'trunk/src/utils/android/ashmem.cpp',
   1.217 +    },
   1.218 +    'linux': {
   1.219 +      'trunk/src/ports/SkFontHost_cairo.cpp',
   1.220 +    },
   1.221 +    'intel': {
   1.222 +      'trunk/src/opts/SkXfermode_opts_none.cpp',
   1.223 +    },
   1.224 +    'arm': {
   1.225 +      'trunk/src/opts/SkUtils_opts_arm.cpp',
   1.226 +      'trunk/src/core/SkUtilsArm.cpp',
   1.227 +    },
   1.228 +    'neon': {
   1.229 +      'trunk/src/opts/SkBitmapProcState_arm_neon.cpp',
   1.230 +    },
   1.231 +    'none': {
   1.232 +      'trunk/src/opts/SkUtils_opts_none.cpp',
   1.233 +    }
   1.234 +  }
   1.235 +
   1.236 +  for plat in platform_sources.keys():
   1.237 +    if not separated.has_key(plat):
   1.238 +      separated[plat] = set()
   1.239 +
   1.240 +    for value in platform_sources[plat]:
   1.241 +      if isblacklisted(value):
   1.242 +        continue
   1.243 +
   1.244 +      if value.find('_SSE') > 0 or value.find('_SSSE') > 0: #lol
   1.245 +        separated['intel'].add(value)
   1.246 +        continue
   1.247 +
   1.248 +      if value.find('_neon') > 0:
   1.249 +        separated['neon'].add(value)
   1.250 +        continue
   1.251 +
   1.252 +      if value.find('_arm') > 0:
   1.253 +        separated['arm'].add(value)
   1.254 +        continue
   1.255 +
   1.256 +      if value.find('_none') > 0:
   1.257 +        separated['none'].add(value)
   1.258 +        continue
   1.259 +
   1.260 +      found = True
   1.261 +      for other in platforms:
   1.262 +        if other == plat or not platform_sources.has_key(other):
   1.263 +          continue
   1.264 +
   1.265 +        if not value in platform_sources[other]:
   1.266 +          found = False
   1.267 +          break;
   1.268 +
   1.269 +      if found:
   1.270 +        separated['common'].add(value)
   1.271 +      else:
   1.272 +        separated[plat].add(value)
   1.273 +
   1.274 +  return separated
   1.275 +
   1.276 +def uniq(seq):
   1.277 +  seen = set()
   1.278 +  seen_add = seen.add
   1.279 +  return [ x for x in seq if x not in seen and not seen_add(x)]
   1.280 +
   1.281 +def write_cflags(f, values, subsearch, cflag, indent):
   1.282 +  def write_indent(indent):
   1.283 +    for _ in range(indent):
   1.284 +        f.write(' ')
   1.285 +
   1.286 +  val_list = uniq(sorted(map(lambda val: val.replace('../', 'trunk/'), values), key=lambda x: x.lower()))
   1.287 +
   1.288 +  if len(val_list) == 0:
   1.289 +    return
   1.290 +
   1.291 +  for val in val_list:
   1.292 +    if val.find(subsearch) > 0:
   1.293 +      write_indent(indent)
   1.294 +      f.write("SOURCES[\'" + val + "\'].flags += [\'" + cflag + "\']\n")
   1.295 +
   1.296 +
   1.297 +def write_list(f, name, values, indent):
   1.298 +  def write_indent(indent):
   1.299 +    for _ in range(indent):
   1.300 +        f.write(' ')
   1.301 +
   1.302 +  val_list = uniq(sorted(map(lambda val: val.replace('../', 'trunk/'), values), key=lambda x: x.lower()))
   1.303 +
   1.304 +  if len(val_list) == 0:
   1.305 +    return
   1.306 +
   1.307 +  write_indent(indent)
   1.308 +  f.write(name + ' += [\n')
   1.309 +  for val in val_list:
   1.310 +    write_indent(indent + 4)
   1.311 +    f.write('\'' + val + '\',\n')
   1.312 +
   1.313 +  write_indent(indent)
   1.314 +  f.write(']\n')
   1.315 +
   1.316 +def write_mozbuild(includes, sources):
   1.317 +  filename = 'moz.build'
   1.318 +  f = open(filename, 'w')
   1.319 +
   1.320 +  f.write(header)
   1.321 +
   1.322 +  write_list(f, 'EXPORTS.skia', includes, 0)
   1.323 +
   1.324 +  write_list(f, 'SOURCES', sources['common'], 0)
   1.325 +
   1.326 +  f.write("if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('android', 'gonk'):\n")
   1.327 +  write_list(f, 'SOURCES', sources['android'], 4)
   1.328 +
   1.329 +  f.write("if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':\n")
   1.330 +  write_list(f, 'SOURCES', sources['mac'], 4)
   1.331 +
   1.332 +  f.write("if CONFIG['MOZ_WIDGET_GTK']:\n")
   1.333 +  write_list(f, 'SOURCES', sources['linux'], 4)
   1.334 +
   1.335 +  f.write("if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'qt':\n")
   1.336 +  write_list(f, 'SOURCES', sources['linux'], 4)
   1.337 +
   1.338 +  f.write("if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'windows':\n")
   1.339 +  write_list(f, 'SOURCES', sources['win'], 4)
   1.340 +
   1.341 +  f.write("\n\n")
   1.342 +  f.write("if CONFIG['INTEL_ARCHITECTURE']:\n")
   1.343 +  write_list(f, 'SOURCES', sources['intel'], 4)
   1.344 +
   1.345 +  f.write("elif CONFIG['CPU_ARCH'] == 'arm' and CONFIG['GNU_CC']:\n")
   1.346 +  write_list(f, 'SOURCES', sources['arm'], 4)
   1.347 +
   1.348 +  f.write("    if CONFIG['BUILD_ARM_NEON']:\n")
   1.349 +  write_list(f, 'SOURCES', sources['neon'], 8)
   1.350 +  write_cflags(f, sources['neon'], 'neon', '-mfpu=neon', 8)
   1.351 +
   1.352 +  f.write("else:\n")
   1.353 +  write_list(f, 'SOURCES', sources['none'], 4)
   1.354 +
   1.355 +  f.write(footer)
   1.356 +
   1.357 +  f.close()
   1.358 +
   1.359 +  print 'Wrote ' + filename
   1.360 +
   1.361 +def main():
   1.362 +  includes = generate_includes()
   1.363 +  platform_sources = generate_platform_sources()
   1.364 +  separated_sources = generate_separated_sources(platform_sources)
   1.365 +  write_mozbuild(includes, separated_sources)
   1.366 +
   1.367 +
   1.368 +if __name__ == '__main__':
   1.369 +  main()

mercurial