tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

generate_sources_mozbuild.py (6601B)


      1 # This Source Code Form is subject to the terms of the Mozilla Public
      2 # License, v. 2.0. If a copy of the MPL was not distributed with this
      3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
      4 
      5 import copy
      6 import datetime
      7 import os
      8 import re
      9 import subprocess
     10 import sys
     11 
     12 from mozcmakeparser import parse as cmake_parse
     13 
     14 
     15 AOM_DIR = '../../third_party/aom'
     16 
     17 def write_aom_config(system, arch, variables, cache_variables):
     18    # read template cmake file
     19    variables['year'] = datetime.datetime.now().year
     20    cmake_parse(variables, [], [AOM_DIR], os.path.join(AOM_DIR, 'build', 'cmake',
     21                'generate_aom_config_templates.cmake'), 'libaom')
     22 
     23    # filter variables
     24    cache_variables = [x for x in sorted(cache_variables)
     25                       if x and not x.startswith((' ', 'CMAKE', 'AOM_C', 'AOM_RTCD'))]
     26 
     27    # inherit this from the mozilla build config
     28    cache_variables.remove('HAVE_PTHREAD_H')
     29 
     30    outdir = os.path.join('config', system, arch, 'config')
     31    try:
     32        os.makedirs(outdir)
     33    except OSError:
     34        pass
     35 
     36    with open(os.path.join(outdir, 'aom_config.h'), 'w') as f:
     37        header = variables['h_file_header_block']
     38        f.write(header)
     39        f.write('\n')
     40        for var in cache_variables:
     41            f.write('#define %s %s\n' % (var, variables[var]))
     42        f.write('#endif /* AOM_CONFIG_H_ */\n')
     43 
     44    with open(os.path.join(outdir, 'aom_config.asm'), 'w') as f:
     45        header = variables['asm_file_header_block']
     46        f.write(header)
     47        f.write('\n')
     48        for var in cache_variables:
     49            if var in ['INCLUDE_INSTALL_DIR', 'INLINE',
     50                       'LIB_INSTALL_DIR', 'RESTRICT']:
     51                continue
     52            if arch == 'arm':
     53                f.write('.equ %s, %s\n' % (var, variables[var]))
     54            else:
     55                f.write('%s equ %s\n' % (var, variables[var]))
     56 
     57        if arch == 'arm':
     58            f.write('.section	.note.GNU-stack,"",%progbits')
     59 
     60 
     61 if __name__ == '__main__':
     62    import sys
     63 
     64    shared_variables = {
     65        'CMAKE_CURRENT_SOURCE_DIR': AOM_DIR,
     66        'CONFIG_AV1_DECODER': 1,
     67        'CONFIG_AV1_ENCODER': 1,
     68        'CONFIG_COLLECT_INTER_MODE_RD_STATS': 0,
     69        'CONFIG_INSPECTION': 0,
     70        'CONFIG_INTERNAL_STATS': 0,
     71        'CONFIG_LIBYUV': 0,
     72        'CONFIG_LOWBITDEPTH': 1,
     73        'CONFIG_MULTITHREAD': 1,
     74        'CONFIG_PIC': 0,
     75        'CONFIG_WEBM_IO': 0,
     76        'CMAKE_CURRENT_BINARY_DIR': 'OBJDIR',
     77        'CMAKE_INSTALL_PREFIX': 'INSTALLDIR',
     78        'CMAKE_SYSTEM_NAME': 'Linux',
     79        'CMAKE_SYSTEM_PROCESSOR': 'x86_64',
     80        'ENABLE_EXAMPLES': 0,
     81        'ENABLE_TESTS': 0,
     82        'ENABLE_TOOLS': 0,
     83        'ENABLE_DOCS': 0,
     84        'ENABLE_NEON': 1,
     85        'AOM_TEST_TEST_CMAKE_': 1, #prevent building tests
     86    }
     87 
     88    f = open('sources.mozbuild', 'w')
     89    f.write('# This file is generated. Do not edit.\n\n')
     90    f.write('files = {\n')
     91 
     92    platforms = [
     93        ('armv7', 'linux', 'arm', True),
     94        ('arm64', 'mac', 'arm64', True),
     95        ('generic', '', 'generic', True),
     96        ('x86', 'linux', 'ia32', True),
     97        ('x86', 'win', 'ia32', False),
     98        ('x86_64', 'linux', 'x64', True),
     99        ('x86_64', 'mac', 'x64', False),
    100        ('x86_64', 'win', 'x64', False),
    101    ]
    102    for cpu, system, arch, generate_sources in platforms:
    103        print('Running CMake for %s (%s)' % (cpu, system))
    104        variables = shared_variables.copy()
    105        variables['AOM_TARGET_CPU'] = cpu
    106 
    107        # We skip compiling test programs that detect these
    108        variables['HAVE_FEXCEPT'] = 1
    109        variables['INLINE'] = 'inline'
    110        if cpu == 'x86' and system == 'linux':
    111            variables['CONFIG_PIC'] = 1
    112        if cpu == 'armv7':
    113            variables['CONFIG_PIC'] = 1
    114        if system == 'win':
    115            variables['MSVC'] = 1
    116 
    117        cache_variables = []
    118        sources = cmake_parse(variables, cache_variables, [AOM_DIR],
    119                              os.path.join(AOM_DIR, 'CMakeLists.txt'), 'libaom')
    120 
    121        # Disable HAVE_UNISTD_H.
    122        cache_variables.remove('HAVE_UNISTD_H')
    123        write_aom_config(system, arch, variables, cache_variables)
    124 
    125        # Windows x86_64 needs this -- all other source files are shared
    126        # between OSes
    127        if cpu == 'x86_64' and system == 'win':
    128          f.write('  \'X64_WIN_SOURCES\': [\n')
    129          f.write('    \'%s\',\n' % variables['AOM_PORTS_ASM_X86'])
    130          f.write("  ],\n")
    131 
    132        # Currently, the sources are the same for each supported cpu
    133        # regardless of operating system / compiler. If that changes, we'll
    134        # have to generate sources for each combination.
    135        if generate_sources:
    136            # Remove spurious sources and perl files
    137            sources = list(filter(lambda x: x.startswith(AOM_DIR), sources))
    138            sources = list(filter(lambda x: not x.endswith('.pl'), sources))
    139 
    140            # Filter out exports
    141            exports = list(filter(lambda x: re.match(os.path.join(AOM_DIR, '(aom|aom_mem|aom_ports|aom_scale)/.*h$'), x), sources))
    142            exports = list(filter(lambda x: not re.search('(internal|src)', x), exports))
    143            exports = list(filter(lambda x: not re.search('(emmintrin_compat.h|mem_.*|msvc.h|aom_once.h)$', x), exports))
    144 
    145            sources = list(sources)
    146 
    147            for export in exports:
    148                if export in sources:
    149                    sources.remove(export)
    150 
    151            # Remove header and .inc files
    152            sources = sorted(filter(lambda x: not x.endswith('.h'), sources))
    153            sources = sorted(filter(lambda x: not x.endswith('.inc'), sources))
    154 
    155            # The build system is unhappy if two files have the same prefix
    156            # In libaom, sometimes .asm and .c files share the same prefix
    157            for i in range(len(sources) - 1):
    158                if sources[i].endswith('.asm'):
    159                    if os.path.splitext(sources[i])[0] == os.path.splitext(sources[i + 1])[0]:
    160                        old = sources[i]
    161                        sources[i] = sources[i].replace('.asm', '_asm.asm')
    162                        if not os.path.exists(sources[i]):
    163                            os.rename(old, sources[i])
    164 
    165            f.write('  \'%s_EXPORTS\': [\n' % arch.upper())
    166            for export in sorted(exports):
    167                f.write('    \'%s\',\n' % export)
    168            f.write("  ],\n")
    169 
    170            f.write('  \'%s_SOURCES\': [\n' % arch.upper())
    171            for source in sorted(sources):
    172                f.write('    \'%s\',\n' % source)
    173            f.write('  ],\n')
    174 
    175        print('\n')
    176 
    177    f.write('}\n')
    178    f.close()