예제 #1
0
def precompile_cache(formatter, source_path, gre_path, app_path):
    '''
    Create startup cache for the given application directory, using the
    given GRE path.
    - formatter is a Formatter instance where to add the startup cache.
    - source_path is the base path of the package.
    - gre_path is the GRE path, relative to source_path.
    - app_path is the application path, relative to source_path.
    Startup cache for all resources under resource://app/ are generated,
    except when gre_path == app_path, in which case it's under
    resource://gre/.
    '''
    from tempfile import mkstemp
    source_path = os.path.abspath(source_path)
    if app_path != gre_path:
        resource = 'app'
    else:
        resource = 'gre'
    app_path = os.path.join(source_path, app_path)
    gre_path = os.path.join(source_path, gre_path)

    fd, cache = mkstemp('.zip')
    os.close(fd)
    os.remove(cache)

    # For VC12, make sure we can find the right bitness of pgort120.dll
    env = os.environ.copy()
    if 'VS120COMNTOOLS' in env and not buildconfig.substs['HAVE_64BIT_OS']:
        vc12dir = os.path.abspath(
            os.path.join(env['VS120COMNTOOLS'], '../../VC/bin'))
        if os.path.exists(vc12dir):
            env['PATH'] = vc12dir + ';' + env['PATH']

    try:
        if launcher.launch([
                'xpcshell', '-g', gre_path, '-a', app_path, '-f',
                os.path.join(os.path.dirname(__file__), 'precompile_cache.js'),
                '-e',
                'precompile_startupcache("resource://%s/");' % resource
        ],
                           extra_linker_path=gre_path,
                           extra_env={
                               'MOZ_STARTUP_CACHE': cache,
                               'PATH': env['PATH']
                           }):
            errors.fatal('Error while running startup cache precompilation')
            return
        from mozpack.mozjar import JarReader
        jar = JarReader(cache)
        resource = '/resource/%s/' % resource
        for f in jar:
            if resource in f.filename:
                path = f.filename[f.filename.index(resource) + len(resource):]
                if formatter.contains(path):
                    formatter.add(f.filename, GeneratedFile(f.read()))
        jar.close()
    finally:
        if os.path.exists(cache):
            os.remove(cache)
예제 #2
0
def precompile_cache(formatter, source_path, gre_path, app_path):
    '''
    Create startup cache for the given application directory, using the
    given GRE path.
    - formatter is a Formatter instance where to add the startup cache.
    - source_path is the base path of the package.
    - gre_path is the GRE path, relative to source_path.
    - app_path is the application path, relative to source_path.
    Startup cache for all resources under resource://app/ are generated,
    except when gre_path == app_path, in which case it's under
    resource://gre/.
    '''
    from tempfile import mkstemp
    source_path = os.path.abspath(source_path)
    if app_path != gre_path:
        resource = 'app'
    else:
        resource = 'gre'
    app_path = os.path.join(source_path, app_path)
    gre_path = os.path.join(source_path, gre_path)

    fd, cache = mkstemp('.zip')
    os.close(fd)
    os.remove(cache)

    # For VC12, make sure we can find the right bitness of pgort120.dll
    env = os.environ.copy()
    if 'VS120COMNTOOLS' in env and not buildconfig.substs['HAVE_64BIT_OS']:
      vc12dir = os.path.abspath(os.path.join(env['VS120COMNTOOLS'],
                                             '../../VC/bin'))
      if os.path.exists(vc12dir):
        env['PATH'] = vc12dir + ';' + env['PATH']

    try:
        if launcher.launch(['xpcshell', '-g', gre_path, '-a', app_path,
                            '-f', os.path.join(os.path.dirname(__file__),
                            'precompile_cache.js'),
                            '-e', 'precompile_startupcache("resource://%s/");'
                                  % resource],
                           extra_linker_path=gre_path,
                           extra_env={'MOZ_STARTUP_CACHE': cache,
                                      'PATH': env['PATH']}):
            errors.fatal('Error while running startup cache precompilation')
            return
        from mozpack.mozjar import JarReader
        jar = JarReader(cache)
        resource = '/resource/%s/' % resource
        for f in jar:
            if resource in f.filename:
                path = f.filename[f.filename.index(resource) + len(resource):]
                if formatter.contains(path):
                    formatter.add(f.filename, GeneratedFile(f.read()))
        jar.close()
    finally:
        if os.path.exists(cache):
            os.remove(cache)
예제 #3
0
def precompile_cache(registry, source_path, gre_path, app_path):
    '''
    Create startup cache for the given application directory, using the
    given GRE path.
    - registry is a FileRegistry-like instance where to add the startup cache.
    - source_path is the base path of the package.
    - gre_path is the GRE path, relative to source_path.
    - app_path is the application path, relative to source_path.
    Startup cache for all resources under resource://app/ are generated,
    except when gre_path == app_path, in which case it's under
    resource://gre/.
    '''
    from tempfile import mkstemp
    source_path = os.path.abspath(source_path)
    if app_path != gre_path:
        resource = 'app'
    else:
        resource = 'gre'
    app_path = os.path.join(source_path, app_path)
    gre_path = os.path.join(source_path, gre_path)

    fd, cache = mkstemp('.zip')
    if os.name == 'os2':
        # NS_NewLocalFile is strict about slashes
        cache = cache.replace('/', '\\')
    os.close(fd)
    os.remove(cache)

    try:
        extra_env = {'MOZ_STARTUP_CACHE': cache}
        if buildconfig.substs.get('MOZ_TSAN'):
            extra_env['TSAN_OPTIONS'] = 'report_bugs=0'
        if buildconfig.substs.get('MOZ_ASAN'):
            extra_env['ASAN_OPTIONS'] = 'detect_leaks=0'
        if launcher.launch(['xpcshell', '-g', gre_path, '-a', app_path,
                            '-f', os.path.join(os.path.dirname(__file__),
                            'precompile_cache.js'),
                            '-e', 'precompile_startupcache("resource://%s/");'
                                  % resource],
                           extra_linker_path=gre_path,
                           extra_env=extra_env):
            errors.fatal('Error while running startup cache precompilation')
            return
        from mozpack.mozjar import JarReader
        jar = JarReader(cache)
        resource = '/resource/%s/' % resource
        for f in jar:
            if resource in f.filename:
                path = f.filename[f.filename.index(resource) + len(resource):]
                if registry.contains(path):
                    registry.add(f.filename, GeneratedFile(f.read()))
        jar.close()
    finally:
        if os.path.exists(cache):
            os.remove(cache)
예제 #4
0
def precompile_cache(registry, source_path, gre_path, app_path):
    '''
    Create startup cache for the given application directory, using the
    given GRE path.
    - registry is a FileRegistry-like instance where to add the startup cache.
    - source_path is the base path of the package.
    - gre_path is the GRE path, relative to source_path.
    - app_path is the application path, relative to source_path.
    Startup cache for all resources under resource://app/ are generated,
    except when gre_path == app_path, in which case it's under
    resource://gre/.
    '''
    from tempfile import mkstemp
    source_path = os.path.abspath(source_path)
    if app_path != gre_path:
        resource = 'app'
    else:
        resource = 'gre'
    app_path = os.path.join(source_path, app_path)
    gre_path = os.path.join(source_path, gre_path)

    fd, cache = mkstemp('.zip')
    os.close(fd)
    os.remove(cache)

    try:
        extra_env = {'MOZ_STARTUP_CACHE': cache}
        if buildconfig.substs.get('MOZ_TSAN'):
            extra_env['TSAN_OPTIONS'] = 'report_bugs=0'
        if buildconfig.substs.get('MOZ_ASAN'):
            extra_env['ASAN_OPTIONS'] = 'detect_leaks=0'
        if launcher.launch([
                'xpcshell', '-g', gre_path, '-a', app_path, '-f',
                os.path.join(os.path.dirname(__file__), 'precompile_cache.js'),
                '-e',
                'precompile_startupcache("resource://%s/");' % resource
        ],
                           extra_linker_path=gre_path,
                           extra_env=extra_env):
            errors.fatal('Error while running startup cache precompilation')
            return
        from mozpack.mozjar import JarReader
        jar = JarReader(cache)
        resource = '/resource/%s/' % resource
        for f in jar:
            if resource in f.filename:
                path = f.filename[f.filename.index(resource) + len(resource):]
                if registry.contains(path):
                    registry.add(f.filename, GeneratedFile(f.read()))
        jar.close()
    finally:
        if os.path.exists(cache):
            os.remove(cache)
예제 #5
0
def precompile_cache(formatter, source_path, gre_path, app_path):
    '''
    Create startup cache for the given application directory, using the
    given GRE path.
    - formatter is a Formatter instance where to add the startup cache.
    - source_path is the base path of the package.
    - gre_path is the GRE path, relative to source_path.
    - app_path is the application path, relative to source_path.
    Startup cache for all resources under resource://app/ are generated,
    except when gre_path == app_path, in which case it's under
    resource://gre/.
    '''
    from tempfile import mkstemp
    source_path = os.path.abspath(source_path)
    if app_path != gre_path:
        resource = 'app'
    else:
        resource = 'gre'
    app_path = os.path.join(source_path, app_path)
    gre_path = os.path.join(source_path, gre_path)

    fd, cache = mkstemp('.zip')
    if os.name == 'os2':
        # NS_NewLocalFile is strict about slashes
        cache = cache.replace('/', '\\')
    os.close(fd)
    os.remove(cache)

    try:
        if launcher.launch(['xpcshell', '-g', gre_path, '-a', app_path,
                            '-f', os.path.join(os.path.dirname(__file__),
                            'precompile_cache.js'),
                            '-e', 'precompile_startupcache("resource://%s/");'
                                  % resource],
                           extra_linker_path=gre_path,
                           extra_env={'MOZ_STARTUP_CACHE': cache}):
            errors.fatal('Error while running startup cache precompilation')
            return
        from mozpack.mozjar import JarReader
        jar = JarReader(cache)
        resource = '/resource/%s/' % resource
        for f in jar:
            if resource in f.filename:
                path = f.filename[f.filename.index(resource) + len(resource):]
                if formatter.contains(path):
                    formatter.add(f.filename, GeneratedFile(f.read()))
        jar.close()
    finally:
        if os.path.exists(cache):
            os.remove(cache)
예제 #6
0
def precompile_cache(formatter, source_path, gre_path, app_path):
    '''
    Create startup cache for the given application directory, using the
    given GRE path.
    - formatter is a Formatter instance where to add the startup cache.
    - source_path is the base path of the package.
    - gre_path is the GRE path, relative to source_path.
    - app_path is the application path, relative to source_path.
    Startup cache for all resources under resource://app/ are generated,
    except when gre_path == app_path, in which case it's under
    resource://gre/.
    '''
    from tempfile import mkstemp
    source_path = os.path.abspath(source_path)
    if app_path != gre_path:
        resource = 'app'
    else:
        resource = 'gre'
    app_path = os.path.join(source_path, app_path)
    gre_path = os.path.join(source_path, gre_path)

    fd, cache = mkstemp('.zip')
    os.close(fd)
    os.remove(cache)

    try:
        if launcher.launch(['xpcshell', '-g', gre_path, '-a', app_path,
                            '-f', os.path.join(os.path.dirname(__file__),
                            'precompile_cache.js'),
                            '-e', 'precompile_startupcache("resource://%s/");'
                                  % resource],
                           extra_linker_path=gre_path,
                           extra_env={'MOZ_STARTUP_CACHE': cache}):
            errors.fatal('Error while running startup cache precompilation')
            return
        from mozpack.mozjar import JarReader
        jar = JarReader(cache)
        resource = '/resource/%s/' % resource
        for f in jar:
            if resource in f.filename:
                path = f.filename[f.filename.index(resource) + len(resource):]
                if formatter.contains(path):
                    formatter.add(f.filename, GeneratedFile(f.read()))
        jar.close()
    finally:
        if os.path.exists(cache):
            os.remove(cache)
예제 #7
0
def precompile_cache(registry, source_path, gre_path, app_path):
    """
    Create startup cache for the given application directory, using the
    given GRE path.
    - registry is a FileRegistry-like instance where to add the startup cache.
    - source_path is the base path of the package.
    - gre_path is the GRE path, relative to source_path.
    - app_path is the application path, relative to source_path.
    Startup cache for all resources under resource://app/ are generated,
    except when gre_path == app_path, in which case it's under
    resource://gre/.
    """
    from tempfile import mkstemp

    source_path = os.path.abspath(source_path)
    if app_path != gre_path:
        resource = "app"
    else:
        resource = "gre"
    app_path = os.path.join(source_path, app_path)
    gre_path = os.path.join(source_path, gre_path)

    fd, cache = mkstemp(".zip")
    os.close(fd)
    os.remove(cache)

    try:
        extra_env = {"MOZ_STARTUP_CACHE": cache}
        if buildconfig.substs.get("MOZ_TSAN"):
            extra_env["TSAN_OPTIONS"] = "report_bugs=0"
        if buildconfig.substs.get("MOZ_ASAN"):
            extra_env["ASAN_OPTIONS"] = "detect_leaks=0"
        if launcher.launch(
            [
                "xpcshell",
                "-g",
                gre_path,
                "-a",
                app_path,
                "-f",
                os.path.join(os.path.dirname(__file__), "precompile_cache.js"),
                "-e",
                'precompile_startupcache("resource://%s/");' % resource,
            ],
            extra_linker_path=gre_path,
            extra_env=extra_env,
        ):
            errors.fatal("Error while running startup cache precompilation")
            return
        from mozpack.mozjar import JarReader

        jar = JarReader(cache)
        resource = "/resource/%s/" % resource
        for f in jar:
            if resource in f.filename:
                path = f.filename[f.filename.index(resource) + len(resource) :]
                if registry.contains(path):
                    registry.add(f.filename, GeneratedFile(f.read()))
        jar.close()
    finally:
        if os.path.exists(cache):
            os.remove(cache)