DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (b6d82b1a6b02)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.


option(env='AUTOCONF', nargs=1, help='Path to autoconf 2.13')


@depends(mozconfig, 'AUTOCONF')
@checking('for autoconf')
@imports(_from='os.path', _import='exists')
@imports('re')
def autoconf(mozconfig, autoconf):
    mozconfig_autoconf = None
    if mozconfig['path']:
        make_extra = mozconfig['make_extra']
        if make_extra:
            for assignment in make_extra:
                m = re.match('(?:export\s+)?AUTOCONF\s*:?=\s*(.+)$',
                             assignment)
                if m:
                    mozconfig_autoconf = m.group(1)

    autoconf = autoconf[0] if autoconf else None

    for ac in (mozconfig_autoconf, autoconf, 'autoconf-2.13', 'autoconf2.13',
               'autoconf213'):
        if ac:
            autoconf = find_program(ac)
            if autoconf:
                break
    else:
        fink = find_program('fink')
        if fink:
            autoconf = os.path.normpath(os.path.join(
                fink, '..', '..', 'lib', 'autoconf2.13', 'bin', 'autoconf'))
        else:
            brew = find_program('brew')
            if brew:
                autoconf = os.path.normpath(os.path.join(
                    brew, '..', '..', 'Cellar', 'autoconf213', '2.13', 'bin',
                    'autoconf213'))

    if not autoconf:
        die('Could not find autoconf 2.13')

    if not exists(autoconf):
        die('Could not find autoconf 2.13 at %s', autoconf)

    return autoconf


set_config('AUTOCONF', autoconf)


@depends(mozconfig)
def prepare_mozconfig(mozconfig):
    if mozconfig['path']:
        items = {}
        for key, value in mozconfig['vars']['added'].items():
            items[key] = (value, 'added')
        for key, (old, value) in mozconfig['vars']['modified'].items():
            items[key] = (value, 'modified')
        for t in ('env', 'vars'):
            for key in mozconfig[t]['removed'].keys():
                items[key] = (None, 'removed ' + t)
        return items


@depends('OLD_CONFIGURE', prepare_mozconfig, autoconf, check_build_environment,
         shell, old_configure_assignments, build_project)
@imports(_from='__builtin__', _import='open')
@imports(_from='__builtin__', _import='print')
@imports(_from='__builtin__', _import='sorted')
@imports('glob')
@imports('itertools')
@imports('subprocess')
# Import getmtime without overwriting the sandbox os.path.
@imports(_from='os.path', _import='getmtime')
@imports(_from='os.path', _import='exists')
@imports(_from='mozbuild.shellutil', _import='quote')
@imports(_from='tempfile', _import='NamedTemporaryFile')
@imports(_from='os', _import='remove')
@imports(_from='os', _import='rename')
@imports(_from='__builtin__', _import='OSError')
def prepare_configure(old_configure, mozconfig, autoconf, build_env, shell,
                      old_configure_assignments, build_project):
    # os.path.abspath in the sandbox will ensure forward slashes on Windows,
    # which is actually necessary because this path actually ends up literally
    # as $0, and backslashes there breaks autoconf's detection of the source
    # directory.
    old_configure = os.path.abspath(old_configure[0])
    if build_project == 'js':
        old_configure_dir = os.path.dirname(old_configure)
        if not old_configure_dir.endswith('/js/src'):
            old_configure = os.path.join(old_configure_dir, 'js', 'src',
                                         os.path.basename(old_configure))

    refresh = True
    if exists(old_configure):
        mtime = getmtime(old_configure)
        aclocal = os.path.join(build_env.topsrcdir, 'build', 'autoconf',
                               '*.m4')
        for input in itertools.chain(
            (old_configure + '.in',
             os.path.join(os.path.dirname(old_configure), 'aclocal.m4')),
            glob.iglob(aclocal),
        ):
            if getmtime(input) > mtime:
                break
        else:
            refresh = False

    if refresh:
        log.info('Refreshing %s with %s', old_configure, autoconf)
        script = subprocess.check_output([
            shell, autoconf,
            '--localdir=%s' % os.path.dirname(old_configure),
            old_configure + '.in'])
        if not script:
            die('Generated old-configure is empty! Check that your autoconf 2.13 program works!')

        # Make old-configure append to config.log, where we put our own log.
        # This could be done with a m4 macro, but it's way easier this way
        script = script.replace('>./config.log', '>>${CONFIG_LOG=./config.log}')

        with NamedTemporaryFile(mode='wb', prefix=os.path.basename(old_configure),
                                dir=os.path.dirname(old_configure), delete=False) as fh:
            fh.write(script)

        try:
            rename(fh.name, old_configure)
        except OSError:
            try:
                # Likely the file already existed (on Windows). Retry after removing it.
                remove(old_configure)
                rename(fh.name, old_configure)
            except OSError as e:
                die('Failed re-creating old-configure: %s' % e.message)

    cmd = [shell, old_configure]
    with open('old-configure.vars', 'w') as out:
        log.debug('Injecting the following to old-configure:')

        def inject(command):
            print(command, file=out) # noqa Python 2vs3
            log.debug('| %s', command)

        if mozconfig:
            inject('# start of mozconfig values')
            for key, (value, action) in sorted(mozconfig.items()):
                if action.startswith('removed '):
                    inject("unset %s # from %s" % (
                        key, action[len('removed '):]))
                else:
                    inject("%s=%s # %s" % (key, quote(value), action))

            inject('# end of mozconfig values')

        # Autoconf is special, because it might be passed from
        # mozconfig['make_extra'], which we don't pass automatically above.
        inject('export AUTOCONF=%s' % quote(autoconf))

        for k, v in old_configure_assignments:
            inject('%s=%s' % (k, quote(v)))

    return cmd


@template
def old_configure_options(*options):
    for opt in options:
        option(opt, nargs='*', help='Help missing for old configure options')

    @dependable
    def all_options():
        return list(options)

    return depends(extra_old_configure_args, all_options, *options)


@old_configure_options(
    '--cache-file',
    '--datadir',
    '--enable-content-sandbox',
    '--enable-cookies',
    '--enable-cpp-rtti',
    '--enable-crashreporter',
    '--enable-dbus',
    '--enable-debug-js-modules',
    '--enable-directshow',
    '--enable-dtrace',
    '--enable-dump-painting',
    '--enable-extensions',
    '--enable-feeds',
    '--enable-gconf',
    '--enable-icf',
    '--enable-install-strip',
    '--enable-ios-target',
    '--enable-libjpeg-turbo',
    '--enable-libproxy',
    '--enable-llvm-hacks',
    '--enable-logrefcnt',
    '--enable-mobile-optimize',
    '--enable-necko-wifi',
    '--enable-negotiateauth',
    '--enable-nfc',
    '--enable-nspr-build',
    '--enable-official-branding',
    '--enable-parental-controls',
    '--enable-pref-extensions',
    '--enable-readline',
    '--enable-sandbox',
    '--enable-startup-notification',
    '--enable-startupcache',
    '--enable-strip',
    '--enable-synth-pico',
    '--enable-system-cairo',
    '--enable-system-extension-dirs',
    '--enable-system-pixman',
    '--enable-system-sqlite',
    '--enable-universalchardet',
    '--enable-updater',
    '--enable-xul',
    '--enable-zipwriter',
    '--includedir',
    '--libdir',
    '--prefix',
    '--with-android-distribution-directory',
    '--with-android-max-sdk',
    '--with-android-min-sdk',
    '--with-app-basename',
    '--with-app-name',
    '--with-branding',
    '--with-cross-lib',
    '--with-debug-label',
    '--with-distribution-id',
    '--with-doc-include-dirs',
    '--with-doc-input-dirs',
    '--with-doc-output-dir',
    '--with-intl-api',
    '--with-ios-sdk',
    '--with-jitreport-granularity',
    '--with-macbundlename-prefix',
    '--with-nspr-cflags',
    '--with-nspr-exec-prefix',
    '--with-nspr-libs',
    '--with-nspr-prefix',
    '--with-nss-exec-prefix',
    '--with-nss-prefix',
    '--with-qemu-exe',
    '--with-sixgill',
    '--with-system-bz2',
    '--with-system-icu',
    '--with-system-libevent',
    '--with-system-nspr',
    '--with-system-nss',
    '--with-system-png',
    '--with-system-zlib',
    '--with-unify-dist',
    '--with-user-appdir',
    '--x-includes',
    '--x-libraries',
)
def prepare_configure_options(extra_old_configure_args, all_options, *options):
    # old-configure only supports the options listed in @old_configure_options
    # so we don't need to pass it every single option we've been passed. Only
    # the ones that are not supported by python configure need to.
    options = [
        value.format(name)
        for name, value in zip(all_options, options)
        if value.origin != 'default'
    ]

    extra_env = {}

    # We also pass it the options from js/moz.configure so that it can pass
    # them down to js/src/configure. Note this list is empty when running
    # js/src/configure, in which case we don't need to pass those options
    # to old-configure since old-configure doesn't handle them anyways.
    if extra_old_configure_args:
        for arg in extra_old_configure_args:
            if arg.startswith('-'):
                options.append(arg)
            else:
                k, v = arg.split('=', 1)
                extra_env[k] = v

    return namespace(options=options, extra_env=extra_env, all_options=all_options)


@depends(prepare_configure, prepare_configure_options, altered_path)
@imports(_from='__builtin__', _import='compile')
@imports(_from='__builtin__', _import='open')
@imports('logging')
@imports('os')
@imports('subprocess')
@imports('sys')
@imports('types')
@imports(_from='mozbuild.shellutil', _import='quote')
@imports(_from='mozbuild.shellutil', _import='split')
def old_configure(prepare_configure, prepare_configure_options, altered_path):
    cmd = prepare_configure + prepare_configure_options.options
    extra_env = prepare_configure_options.extra_env

    env = dict(os.environ)
    if extra_env:
        env.update(extra_env)

    # For debugging purpose, in case it's not what we'd expect.
    log.debug('Running %s', quote(*cmd))
    if extra_env:
        log.debug('with extra environment: %s',
                  ' '.join('%s=%s' % pair for pair in extra_env.iteritems()))

    # Our logging goes to config.log, the same file old.configure uses.
    # We can't share the handle on the file, so close it.
    logger = logging.getLogger('moz.configure')
    config_log = None
    for handler in logger.handlers:
        if isinstance(handler, logging.FileHandler):
            config_log = handler
            config_log.close()
            logger.removeHandler(config_log)
            env['CONFIG_LOG'] = config_log.baseFilename
            log_size = os.path.getsize(config_log.baseFilename)
            break

    if altered_path:
        env['PATH'] = altered_path

    proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    while True:
        line = proc.stdout.readline()
        if not line:
            break
        log.info(line.rstrip())

    ret = proc.wait()
    if ret:
        with log.queue_debug():
            if config_log:
                with open(config_log.baseFilename, 'r') as fh:
                    fh.seek(log_size)
                    for line in fh:
                        log.debug(line.rstrip())
            log.error('old-configure failed')
        sys.exit(ret)

    if config_log:
        # Create a new handler in append mode
        handler = logging.FileHandler(config_log.baseFilename, mode='a', delay=True)
        handler.setFormatter(config_log.formatter)
        logger.addHandler(handler)

    raw_config = {
        'split': split,
        'unique_list': unique_list,
    }
    with open('config.data', 'r') as fh:
        code = compile(fh.read(), 'config.data', 'exec')
        # Every variation of the exec() function I tried led to:
        # SyntaxError: unqualified exec is not allowed in function 'main' it
        # contains a nested function with free variables
        exec code in raw_config # noqa

    # Ensure all the flags known to old-configure appear in the
    # @old_configure_options above.
    all_options = set(prepare_configure_options.all_options)
    for flag in raw_config['flags']:
        if flag not in all_options:
            die('Missing option in `@old_configure_options` in %s: %s',
                __file__, flag)

    # If the code execution above fails, we want to keep the file around for
    # debugging.
    os.remove('config.data')

    for c in ('substs', 'defines'):
        raw_config[c] = [
            (k[1:-1], v[1:-1] if isinstance(v, types.StringTypes) else v)
            for k, v in raw_config[c]
        ]

    return raw_config


# set_config is only available in the global namespace, not directly in
# @depends functions, but we do need to enumerate the result of
# old_configure, so we cheat.
@imports('__sandbox__')
def set_old_configure_config(name, value):
    __sandbox__.set_config_impl(name, value)

# Same as set_old_configure_config, but for set_define.


@imports('__sandbox__')
def set_old_configure_define(name, value):
    __sandbox__.set_define_impl(name, value)


@depends(old_configure)
def post_old_configure(raw_config):
    for k, v in raw_config['substs']:
        set_old_configure_config(k, v)

    for k, v in dict(raw_config['defines']).iteritems():
        set_old_configure_define(k, v)

    set_old_configure_config('non_global_defines',
                             raw_config['non_global_defines'])


# Assuming no other option is declared after this function, handle the
# env options that were injected by mozconfig_options by creating dummy
# Option instances and having the sandbox's CommandLineHelper handle
# them. We only do so for options that haven't been declared so far,
# which should be a proxy for the options that old-configure handles
# and that we don't know anything about.
@depends('--help')
@imports('__sandbox__')
@imports(_from='mozbuild.configure.options', _import='Option')
def remaining_mozconfig_options(_):
    helper = __sandbox__._helper
    for arg in helper:
        if helper._origins[arg] != 'mozconfig':
            continue
        name = arg.split('=', 1)[0]
        if name.isupper() and name not in __sandbox__._options:
            option = Option(env=name, nargs='*', help=name)
            helper.handle(option)

# Please do not add anything after remaining_mozconfig_options()