Example #1
0
    def test_get_binary_path(self):
        base = self.get_base()

        platform = sys.platform

        # We should ideally use the config.status from the build. Let's install
        # a fake one.
        substs = []
        if sys.platform.startswith('darwin'):
            substs.append(('OS_ARCH', 'Darwin'))
            substs.append(('MOZ_MACBUNDLE_NAME', 'Nightly.app'))
        elif sys.platform.startswith(('win32', 'cygwin')):
            substs.append(('BIN_SUFFIX', '.exe'))

        base._config_environment = ConfigEnvironment(base.topsrcdir,
                                                     base.topobjdir,
                                                     substs=substs)

        p = base.get_binary_path('xpcshell', False)
        if platform.startswith('darwin'):
            self.assertTrue(p.endswith('Contents/MacOS/xpcshell'))
        elif platform.startswith(('win32', 'cygwin')):
            self.assertTrue(p.endswith('xpcshell.exe'))
        else:
            self.assertTrue(p.endswith('dist/bin/xpcshell'))
Example #2
0
    def test_get_binary_path(self):
        base = self.get_base(topobjdir=topobjdir)

        platform = sys.platform

        # We should ideally use the config.status from the build. Let's install
        # a fake one.
        substs = [
            ("MOZ_APP_NAME", "awesomeapp"),
            ("MOZ_BUILD_APP", "awesomeapp"),
        ]
        if sys.platform.startswith("darwin"):
            substs.append(("OS_ARCH", "Darwin"))
            substs.append(("BIN_SUFFIX", ""))
            substs.append(("MOZ_MACBUNDLE_NAME", "Nightly.app"))
        elif sys.platform.startswith(("win32", "cygwin")):
            substs.append(("OS_ARCH", "WINNT"))
            substs.append(("BIN_SUFFIX", ".exe"))
        else:
            substs.append(("OS_ARCH", "something"))
            substs.append(("BIN_SUFFIX", ""))

        base._config_environment = ConfigEnvironment(
            base.topsrcdir, base.topobjdir, substs=substs
        )

        p = base.get_binary_path("xpcshell", False)
        if platform.startswith("darwin"):
            self.assertTrue(p.endswith("Contents/MacOS/xpcshell"))
        elif platform.startswith(("win32", "cygwin")):
            self.assertTrue(p.endswith("xpcshell.exe"))
        else:
            self.assertTrue(p.endswith("dist/bin/xpcshell"))

        p = base.get_binary_path(validate_exists=False)
        if platform.startswith("darwin"):
            self.assertTrue(p.endswith("Contents/MacOS/awesomeapp"))
        elif platform.startswith(("win32", "cygwin")):
            self.assertTrue(p.endswith("awesomeapp.exe"))
        else:
            self.assertTrue(p.endswith("dist/bin/awesomeapp"))

        p = base.get_binary_path(validate_exists=False, where="staged-package")
        if platform.startswith("darwin"):
            self.assertTrue(
                p.endswith("awesomeapp/Nightly.app/Contents/MacOS/awesomeapp")
            )
        elif platform.startswith(("win32", "cygwin")):
            self.assertTrue(p.endswith("awesomeapp\\awesomeapp.exe"))
        else:
            self.assertTrue(p.endswith("awesomeapp/awesomeapp"))

        self.assertRaises(Exception, base.get_binary_path, where="somewhere")

        p = base.get_binary_path("foobar", validate_exists=False)
        if platform.startswith("win32"):
            self.assertTrue(p.endswith("foobar.exe"))
        else:
            self.assertTrue(p.endswith("foobar"))
Example #3
0
    def test_get_binary_path(self):
        base = self.get_base(topobjdir=topobjdir)

        platform = sys.platform

        # We should ideally use the config.status from the build. Let's install
        # a fake one.
        substs = [
            ('MOZ_APP_NAME', 'awesomeapp'),
            ('MOZ_BUILD_APP', 'awesomeapp'),
        ]
        if sys.platform.startswith('darwin'):
            substs.append(('OS_ARCH', 'Darwin'))
            substs.append(('BIN_SUFFIX', ''))
            substs.append(('MOZ_MACBUNDLE_NAME', 'Nightly.app'))
        elif sys.platform.startswith(('win32', 'cygwin')):
            substs.append(('OS_ARCH', 'WINNT'))
            substs.append(('BIN_SUFFIX', '.exe'))
        else:
            substs.append(('OS_ARCH', 'something'))
            substs.append(('BIN_SUFFIX', ''))

        base._config_environment = ConfigEnvironment(base.topsrcdir,
                                                     base.topobjdir,
                                                     substs=substs)

        p = base.get_binary_path('xpcshell', False)
        if platform.startswith('darwin'):
            self.assertTrue(p.endswith('Contents/MacOS/xpcshell'))
        elif platform.startswith(('win32', 'cygwin')):
            self.assertTrue(p.endswith('xpcshell.exe'))
        else:
            self.assertTrue(p.endswith('dist/bin/xpcshell'))

        p = base.get_binary_path(validate_exists=False)
        if platform.startswith('darwin'):
            self.assertTrue(p.endswith('Contents/MacOS/awesomeapp'))
        elif platform.startswith(('win32', 'cygwin')):
            self.assertTrue(p.endswith('awesomeapp.exe'))
        else:
            self.assertTrue(p.endswith('dist/bin/awesomeapp'))

        p = base.get_binary_path(validate_exists=False, where="staged-package")
        if platform.startswith('darwin'):
            self.assertTrue(
                p.endswith('awesomeapp/Nightly.app/Contents/MacOS/awesomeapp'))
        elif platform.startswith(('win32', 'cygwin')):
            self.assertTrue(p.endswith('awesomeapp\\awesomeapp.exe'))
        else:
            self.assertTrue(p.endswith('awesomeapp/awesomeapp'))

        self.assertRaises(Exception, base.get_binary_path, where="somewhere")

        p = base.get_binary_path('foobar', validate_exists=False)
        if platform.startswith('win32'):
            self.assertTrue(p.endswith('foobar.exe'))
        else:
            self.assertTrue(p.endswith('foobar'))
Example #4
0
    def _get_environment(self, name):
        """Obtain a new instance of a ConfigEnvironment for a known profile.

        A new temporary object directory is created for the environment. The
        environment is cleaned up automatically when the test finishes.
        """
        config = CONFIGS[name]

        objdir = mkdtemp()
        self.addCleanup(rmtree, objdir)

        srcdir = mozpath.join(test_data_path, name)
        config['substs']['top_srcdir'] = srcdir
        return ConfigEnvironment(srcdir, objdir, **config)
Example #5
0
    def _get_environment(self, name):
        """Obtain a new instance of a ConfigEnvironment for a known profile.

        A new temporary object directory is created for the environment. The
        environment is cleaned up automatically when the test finishes.
        """
        config = CONFIGS[name]
        config['substs']['MOZ_UI_LOCALE'] = 'en-US'

        srcdir = mozpath.join(test_data_path, name)
        config['substs']['top_srcdir'] = srcdir

        # Create the objdir in the srcdir to ensure that they share the
        # same drive on Windows.
        objdir = mkdtemp(dir=srcdir)
        self.addCleanup(rmtree, objdir)

        return ConfigEnvironment(srcdir, objdir, **config)
Example #6
0
    def do_test_backend(self, *backends, **kwargs):
        topobjdir = mkdtemp()
        try:
            config = ConfigEnvironment(buildconfig.topsrcdir, topobjdir,
                                       **kwargs)
            reader = BuildReader(config)
            emitter = TreeMetadataEmitter(config)
            moz_build = mozpath.join(config.topsrcdir, 'test.mozbuild')
            definitions = list(emitter.emit(
                reader.read_mozbuild(moz_build, config)))
            for backend in backends:
                backend(config).consume(definitions)

            yield config
        except:
            raise
        finally:
            if not os.environ.get('MOZ_NO_CLEANUP'):
                shutil.rmtree(topobjdir)
Example #7
0
    def do_test_backend(self, *backends, **kwargs):
        # Create the objdir in the srcdir to ensure that they share
        # the same drive on Windows.
        topobjdir = mkdtemp(dir=buildconfig.topsrcdir)
        try:
            config = ConfigEnvironment(buildconfig.topsrcdir, topobjdir,
                                       **kwargs)
            reader = BuildReader(config)
            emitter = TreeMetadataEmitter(config)
            moz_build = mozpath.join(config.topsrcdir, "test.mozbuild")
            definitions = list(
                emitter.emit(reader.read_mozbuild(moz_build, config)))
            for backend in backends:
                backend(config).consume(definitions)

            yield config
        except Exception:
            raise
        finally:
            if not os.environ.get("MOZ_NO_CLEANUP"):
                shutil.rmtree(topobjdir)
Example #8
0
 def _config(self, substs={}):
     d = os.path.dirname(__file__)
     return ConfigEnvironment(d, d, substs=substs)
Example #9
0
    def __init__(self, config, path, metadata={}):
        """Create an empty mozbuild Sandbox.

        config is a ConfigStatus instance (the output of configure). path is
        the path of the main mozbuild file that is being executed. It is used
        to compute encountered relative paths.
        """
        Sandbox.__init__(self, allowed_variables=VARIABLES)

        self._log = logging.getLogger(__name__)

        self.config = config
        self.metadata = dict(metadata)

        topobjdir = mozpath.abspath(config.topobjdir)
        topsrcdir = config.topsrcdir
        norm_topsrcdir = mozpath.normpath(topsrcdir)

        self.external_source_dirs = []
        external_dirs = config.substs.get('EXTERNAL_SOURCE_DIR', '').split()
        for external in external_dirs:
            external = mozpath.normpath(external)

            if not os.path.isabs(external):
                external = mozpath.join(config.topsrcdir, external)

            external = mozpath.normpath(external)
            self.external_source_dirs.append(external)


        if not path.startswith(norm_topsrcdir):
            for external in self.external_source_dirs:
                if not path.startswith(external):
                    continue

                topsrcdir = external

                break

        self.topsrcdir = topsrcdir

        relpath = mozpath.relpath(path, topsrcdir)
        reldir = mozpath.dirname(relpath)

        if mozpath.dirname(relpath) == 'js/src' and \
                not config.substs.get('JS_STANDALONE'):
            config = ConfigEnvironment.from_config_status(
                mozpath.join(topobjdir, reldir, 'config.status'))
            config.topobjdir = topobjdir
            self.config = config

        with self._globals.allow_all_writes() as d:
            d['TOPSRCDIR'] = topsrcdir
            d['TOPOBJDIR'] = topobjdir
            d['RELATIVEDIR'] = reldir
            d['SRCDIR'] = mozpath.join(topsrcdir, reldir).rstrip('/')
            d['OBJDIR'] = mozpath.join(topobjdir, reldir).rstrip('/')

            d['CONFIG'] = ReadOnlyDefaultDict(lambda: None,
                self.config.substs_unicode)

            # Register functions.
            for name, func in FUNCTIONS.items():
                d[name] = getattr(self, func[0])

            # Initialize the exports that we need in the global.
            extra_vars = self.metadata.get('exports', dict())
            self._globals.update(extra_vars)
Example #10
0
def config_status(topobjdir='.',
                  topsrcdir='.',
                  defines=[],
                  non_global_defines=[],
                  substs=[],
                  source=None):
    '''Main function, providing config.status functionality.

    Contrary to config.status, it doesn't use CONFIG_FILES or CONFIG_HEADERS
    variables.

    Without the -n option, this program acts as config.status and considers
    the current directory as the top object directory, even when config.status
    is in a different directory. It will, however, treat the directory
    containing config.status as the top object directory with the -n option.

    The --recheck option, like with the original config.status, runs configure
    again, with the options given in the "ac_configure_args" subst.

    The options to this function are passed when creating the
    ConfigEnvironment. These lists, as well as the actual wrapper script
    around this function, are meant to be generated by configure.
    See build/autoconf/config.status.m4.
    '''

    if 'CONFIG_FILES' in os.environ:
        raise Exception('Using the CONFIG_FILES environment variable is not '
                        'supported.')
    if 'CONFIG_HEADERS' in os.environ:
        raise Exception('Using the CONFIG_HEADERS environment variable is not '
                        'supported.')

    if not os.path.isabs(topsrcdir):
        raise Exception('topsrcdir must be defined as an absolute directory: '
                        '%s' % topsrcdir)

    default_backends = ['RecursiveMake']
    # We have a chicken/egg problem, where we only have a dict for substs after
    # creating the ConfigEnvironment, which requires argument parsing to have
    # occurred.
    for name, value in substs:
        if name == 'BUILD_BACKENDS':
            default_backends = value
            break

    parser = ArgumentParser()
    parser.add_argument(
        '--recheck',
        dest='recheck',
        action='store_true',
        help='update config.status by reconfiguring in the same conditions')
    parser.add_argument('-v',
                        '--verbose',
                        dest='verbose',
                        action='store_true',
                        help='display verbose output')
    parser.add_argument(
        '-n',
        dest='not_topobjdir',
        action='store_true',
        help='do not consider current directory as top object directory')
    parser.add_argument('-d',
                        '--diff',
                        action='store_true',
                        help='print diffs of changed files.')
    parser.add_argument('-b',
                        '--backend',
                        nargs='+',
                        choices=[
                            'RecursiveMake', 'AndroidEclipse', 'CppEclipse',
                            'VisualStudio', 'FasterMake', 'CompileDB'
                        ],
                        default=default_backends,
                        help='what backend to build (default: %s).' %
                        ' '.join(default_backends))
    options = parser.parse_args()

    # Without -n, the current directory is meant to be the top object directory
    if not options.not_topobjdir:
        topobjdir = os.path.abspath('.')

    env = ConfigEnvironment(topsrcdir,
                            topobjdir,
                            defines=defines,
                            non_global_defines=non_global_defines,
                            substs=substs,
                            source=source)

    # mozinfo.json only needs written if configure changes and configure always
    # passes this environment variable.
    if 'WRITE_MOZINFO' in os.environ:
        write_mozinfo(os.path.join(topobjdir, 'mozinfo.json'), env, os.environ)

    # Make an appropriate backend instance, defaulting to RecursiveMakeBackend.
    backends_cls = []
    for backend in options.backend:
        if backend == 'AndroidEclipse':
            from mozbuild.backend.android_eclipse import AndroidEclipseBackend
            if not MachCommandConditions.is_android(env):
                raise Exception(
                    'The Android Eclipse backend is not available with this configuration.'
                )
            backends_cls.append(AndroidEclipseBackend)
        elif backend == 'CppEclipse':
            from mozbuild.backend.cpp_eclipse import CppEclipseBackend
            backends_cls.append(CppEclipseBackend)
            if os.name == 'nt':
                raise Exception(
                    'Eclipse is not supported on Windows. Consider using Visual Studio instead.'
                )
        elif backend == 'VisualStudio':
            from mozbuild.backend.visualstudio import VisualStudioBackend
            backends_cls.append(VisualStudioBackend)
        elif backend == 'FasterMake':
            from mozbuild.backend.fastermake import FasterMakeBackend
            backends_cls.append(FasterMakeBackend)
        elif backend == 'CompileDB':
            from mozbuild.compilation.database import CompileDBBackend
            backends_cls.append(CompileDBBackend)
        else:
            backends_cls.append(RecursiveMakeBackend)

    cpu_start = time.clock()
    time_start = time.time()

    backends = [cls(env) for cls in backends_cls]

    reader = BuildReader(env)
    emitter = TreeMetadataEmitter(env)
    # This won't actually do anything because of the magic of generators.
    definitions = emitter.emit(reader.read_topsrcdir())

    if options.recheck:
        # Execute configure from the top object directory
        os.chdir(topobjdir)
        os.execlp(
            'sh', 'sh', '-c', ' '.join([
                os.path.join(topsrcdir,
                             'configure'), env.substs['ac_configure_args'],
                '--no-create', '--no-recursion'
            ]))

    log_level = logging.DEBUG if options.verbose else logging.INFO
    log_manager.add_terminal_logging(level=log_level)
    log_manager.enable_unstructured()

    print('Reticulating splines...', file=sys.stderr)
    if len(backends) > 1:
        definitions = list(definitions)

    for the_backend in backends:
        the_backend.consume(definitions)

    execution_time = 0.0
    for obj in chain((reader, emitter), backends):
        summary = obj.summary()
        print(summary, file=sys.stderr)
        execution_time += summary.execution_time

    cpu_time = time.clock() - cpu_start
    wall_time = time.time() - time_start
    efficiency = cpu_time / wall_time if wall_time else 100
    untracked = wall_time - execution_time

    print('Total wall time: {:.2f}s; CPU time: {:.2f}s; Efficiency: '
          '{:.0%}; Untracked: {:.2f}s'.format(wall_time, cpu_time, efficiency,
                                              untracked),
          file=sys.stderr)

    if options.diff:
        for the_backend in backends:
            for path, diff in sorted(the_backend.file_diffs.items()):
                print('\n'.join(diff))

    # Advertise Visual Studio if appropriate.
    if os.name == 'nt' and 'VisualStudio' not in options.backend:
        print(VISUAL_STUDIO_ADVERTISEMENT)

    # Advertise Eclipse if it is appropriate.
    if MachCommandConditions.is_android(env):
        if 'AndroidEclipse' not in options.backend:
            print(ANDROID_IDE_ADVERTISEMENT)
Example #11
0
def config_status(
    topobjdir=".",
    topsrcdir=".",
    defines=None,
    substs=None,
    source=None,
    mozconfig=None,
    args=sys.argv[1:],
):
    """Main function, providing config.status functionality.

    Contrary to config.status, it doesn't use CONFIG_FILES or CONFIG_HEADERS
    variables.

    Without the -n option, this program acts as config.status and considers
    the current directory as the top object directory, even when config.status
    is in a different directory. It will, however, treat the directory
    containing config.status as the top object directory with the -n option.

    The options to this function are passed when creating the
    ConfigEnvironment. These lists, as well as the actual wrapper script
    around this function, are meant to be generated by configure.
    See build/autoconf/config.status.m4.
    """

    if "CONFIG_FILES" in os.environ:
        raise Exception("Using the CONFIG_FILES environment variable is not "
                        "supported.")
    if "CONFIG_HEADERS" in os.environ:
        raise Exception("Using the CONFIG_HEADERS environment variable is not "
                        "supported.")

    if not os.path.isabs(topsrcdir):
        raise Exception("topsrcdir must be defined as an absolute directory: "
                        "%s" % topsrcdir)

    default_backends = ["RecursiveMake"]
    default_backends = (substs or {}).get("BUILD_BACKENDS", ["RecursiveMake"])

    parser = ArgumentParser()
    parser.add_argument(
        "-v",
        "--verbose",
        dest="verbose",
        action="store_true",
        help="display verbose output",
    )
    parser.add_argument(
        "-n",
        dest="not_topobjdir",
        action="store_true",
        help="do not consider current directory as top object directory",
    )
    parser.add_argument("-d",
                        "--diff",
                        action="store_true",
                        help="print diffs of changed files.")
    parser.add_argument(
        "-b",
        "--backend",
        nargs="+",
        choices=sorted(backends),
        default=default_backends,
        help="what backend to build (default: %s)." %
        " ".join(default_backends),
    )
    parser.add_argument("--dry-run",
                        action="store_true",
                        help="do everything except writing files out.")
    options = parser.parse_args(args)

    # Without -n, the current directory is meant to be the top object directory
    if not options.not_topobjdir:
        topobjdir = os.path.realpath(".")

    env = ConfigEnvironment(
        topsrcdir,
        topobjdir,
        defines=defines,
        substs=substs,
        source=source,
        mozconfig=mozconfig,
    )

    with FileAvoidWrite(os.path.join(topobjdir, "mozinfo.json")) as f:
        write_mozinfo(f, env, os.environ)

    cpu_start = process_time()
    time_start = time.time()

    # Make appropriate backend instances, defaulting to RecursiveMakeBackend,
    # or what is in BUILD_BACKENDS.
    selected_backends = [get_backend_class(b)(env) for b in options.backend]

    if options.dry_run:
        for b in selected_backends:
            b.dry_run = True

    reader = BuildReader(env)
    emitter = TreeMetadataEmitter(env)
    # This won't actually do anything because of the magic of generators.
    definitions = emitter.emit(reader.read_topsrcdir())

    log_level = logging.DEBUG if options.verbose else logging.INFO
    log_manager.add_terminal_logging(level=log_level)
    log_manager.enable_unstructured()

    print("Reticulating splines...", file=sys.stderr)
    if len(selected_backends) > 1:
        definitions = list(definitions)

    for the_backend in selected_backends:
        the_backend.consume(definitions)

    execution_time = 0.0
    for obj in chain((reader, emitter), selected_backends):
        summary = obj.summary()
        print(summary, file=sys.stderr)
        execution_time += summary.execution_time
        if hasattr(obj, "gyp_summary"):
            summary = obj.gyp_summary()
            print(summary, file=sys.stderr)

    cpu_time = process_time() - cpu_start
    wall_time = time.time() - time_start
    efficiency = cpu_time / wall_time if wall_time else 100
    untracked = wall_time - execution_time

    print(
        "Total wall time: {:.2f}s; CPU time: {:.2f}s; Efficiency: "
        "{:.0%}; Untracked: {:.2f}s".format(wall_time, cpu_time, efficiency,
                                            untracked),
        file=sys.stderr,
    )

    if options.diff:
        for the_backend in selected_backends:
            for path, diff in sorted(the_backend.file_diffs.items()):
                print("\n".join(diff))

    # Advertise Visual Studio if appropriate.
    if os.name == "nt" and "VisualStudio" not in options.backend:
        print(VISUAL_STUDIO_ADVERTISEMENT)

    # Advertise Android Studio if it is appropriate.
    if MachCommandConditions.is_android(env):
        print(ANDROID_IDE_ADVERTISEMENT)
Example #12
0
def config_status(topobjdir='.',
                  topsrcdir='.',
                  defines=[],
                  non_global_defines=[],
                  substs=[],
                  source=None):
    '''Main function, providing config.status functionality.

    Contrary to config.status, it doesn't use CONFIG_FILES or CONFIG_HEADERS
    variables.

    Without the -n option, this program acts as config.status and considers
    the current directory as the top object directory, even when config.status
    is in a different directory. It will, however, treat the directory
    containing config.status as the top object directory with the -n option.

    The --recheck option, like with the original config.status, runs configure
    again, with the options given in the "ac_configure_args" subst.

    The options to this function are passed when creating the
    ConfigEnvironment. These lists, as well as the actual wrapper script
    around this function, are meant to be generated by configure.
    See build/autoconf/config.status.m4.
    '''

    if 'CONFIG_FILES' in os.environ:
        raise Exception('Using the CONFIG_FILES environment variable is not '
                        'supported.')
    if 'CONFIG_HEADERS' in os.environ:
        raise Exception('Using the CONFIG_HEADERS environment variable is not '
                        'supported.')

    if not os.path.isabs(topsrcdir):
        raise Exception('topsrcdir must be defined as an absolute directory: '
                        '%s' % topsrcdir)

    parser = OptionParser()
    parser.add_option(
        '--recheck',
        dest='recheck',
        action='store_true',
        help='update config.status by reconfiguring in the same conditions')
    parser.add_option('-v',
                      '--verbose',
                      dest='verbose',
                      action='store_true',
                      help='display verbose output')
    parser.add_option(
        '-n',
        dest='not_topobjdir',
        action='store_true',
        help='do not consider current directory as top object directory')
    parser.add_option('-d',
                      '--diff',
                      action='store_true',
                      help='print diffs of changed files.')
    parser.add_option('-b',
                      '--backend',
                      choices=[
                          'RecursiveMake', 'AndroidEclipse', 'CppEclipse',
                          'VisualStudio'
                      ],
                      default='RecursiveMake',
                      help='what backend to build (default: RecursiveMake).')
    options, args = parser.parse_args()

    # Without -n, the current directory is meant to be the top object directory
    if not options.not_topobjdir:
        topobjdir = os.path.abspath('.')

    env = ConfigEnvironment(topsrcdir,
                            topobjdir,
                            defines=defines,
                            non_global_defines=non_global_defines,
                            substs=substs,
                            source=source)

    # mozinfo.json only needs written if configure changes and configure always
    # passes this environment variable.
    if 'WRITE_MOZINFO' in os.environ:
        write_mozinfo(os.path.join(topobjdir, 'mozinfo.json'), env, os.environ)

    # Make an appropriate backend instance, defaulting to RecursiveMakeBackend.
    backend_cls = RecursiveMakeBackend
    if options.backend == 'AndroidEclipse':
        from mozbuild.backend.android_eclipse import AndroidEclipseBackend
        if not MachCommandConditions.is_android(env):
            raise Exception(
                'The Android Eclipse backend is not available with this configuration.'
            )
        backend_cls = AndroidEclipseBackend
    elif options.backend == 'CppEclipse':
        from mozbuild.backend.cpp_eclipse import CppEclipseBackend
        backend_cls = CppEclipseBackend
        if os.name == 'nt':
            raise Exception(
                'Eclipse is not supported on Windows. Consider using Visual Studio instead.'
            )
    elif options.backend == 'VisualStudio':
        from mozbuild.backend.visualstudio import VisualStudioBackend
        backend_cls = VisualStudioBackend

    the_backend = backend_cls(env)

    reader = BuildReader(env)
    emitter = TreeMetadataEmitter(env)
    # This won't actually do anything because of the magic of generators.
    definitions = emitter.emit(reader.read_topsrcdir())

    if options.recheck:
        # Execute configure from the top object directory
        os.chdir(topobjdir)
        os.execlp(
            'sh', 'sh', '-c', ' '.join([
                os.path.join(topsrcdir,
                             'configure'), env.substs['ac_configure_args'],
                '--no-create', '--no-recursion'
            ]))

    log_level = logging.DEBUG if options.verbose else logging.INFO
    log_manager.add_terminal_logging(level=log_level)
    log_manager.enable_unstructured()

    print('Walking the dog...', file=sys.stderr)
    summary = the_backend.consume(definitions)

    for line in summary.summaries():
        print(line, file=sys.stderr)

    if options.diff:
        for path, diff in sorted(summary.file_diffs.items()):
            print('\n'.join(diff))

    # Advertise Visual Studio if appropriate.
    if os.name == 'nt' and options.backend == 'RecursiveMake':
        print(VISUAL_STUDIO_ADVERTISEMENT)

    # Advertise Eclipse if it is appropriate.
    if MachCommandConditions.is_android(env):
        if options.backend == 'RecursiveMake':
            print(ANDROID_IDE_ADVERTISEMENT)
Example #13
0
def config_status(topobjdir = '.', topsrcdir = '.',
                  defines = [], non_global_defines = [], substs = [],
                  files = [], headers = []):
    '''Main function, providing config.status functionality.

    Contrary to config.status, it doesn't use CONFIG_FILES or CONFIG_HEADERS
    variables, but like config.status from autoconf 2.6, single files may be
    generated with the --file and --header options. Several such options can
    be given to generate several files at the same time.

    Without the -n option, this program acts as config.status and considers
    the current directory as the top object directory, even when config.status
    is in a different directory. It will, however, treat the directory
    containing config.status as the top object directory with the -n option,
    while files given to the --file and --header arguments are considered
    relative to the current directory.

    The --recheck option, like with the original config.status, runs configure
    again, with the options given in the "ac_configure_args" subst.

    The options to this function are passed when creating the
    ConfigEnvironment, except for files and headers, which contain the list
    of files and headers to be generated by default. These lists, as well as
    the actual wrapper script around this function, are meant to be generated
    by configure. See build/autoconf/config.status.m4.

    Unlike config.status behaviour with CONFIG_FILES and CONFIG_HEADERS,
    but like config.status behaviour with --file and --header, providing
    files or headers on the command line inhibits the default generation of
    files when given headers and headers when given files.

    Unlike config.status, the FILE:TEMPLATE syntax is not supported for
    files and headers. The template is always the filename suffixed with
    '.in', in the corresponding directory under the top source directory.
    '''

    if 'CONFIG_FILES' in os.environ:
        raise Exception, 'Using the CONFIG_FILES environment variable is not supported. Use --file instead.'
    if 'CONFIG_HEADERS' in os.environ:
        raise Exception, 'Using the CONFIG_HEADERS environment variable is not supported. Use --header instead.'

    parser = OptionParser()
    parser.add_option('--recheck', dest='recheck', action='store_true',
                      help='update config.status by reconfiguring in the same conditions')
    parser.add_option('--file', dest='files', metavar='FILE', action='append',
                      help='instantiate the configuration file FILE')
    parser.add_option('--header', dest='headers', metavar='FILE', action='append',
                      help='instantiate the configuration header FILE')
    parser.add_option('-v', '--verbose', dest='verbose', action='store_true',
                      help='display verbose output')
    parser.add_option('-n', dest='not_topobjdir', action='store_true',
                      help='do not consider current directory as top object directory')
    (options, args) = parser.parse_args()

    # Without -n, the current directory is meant to be the top object directory
    if not options.not_topobjdir:
        topobjdir = '.'

    env = ConfigEnvironment(topsrcdir, topobjdir, defines=defines,
            non_global_defines=non_global_defines, substs=substs)

    reader = BuildReader(env)
    emitter = TreeMetadataEmitter(env)
    backend = RecursiveMakeBackend(env)
    # This won't actually do anything because of the magic of generators.
    definitions = emitter.emit(reader.read_topsrcdir())

    if options.recheck:
        # Execute configure from the top object directory
        if not os.path.isabs(topsrcdir):
            topsrcdir = relpath(topsrcdir, topobjdir)
        os.chdir(topobjdir)
        os.execlp('sh', 'sh', '-c', ' '.join([os.path.join(topsrcdir, 'configure'), env.substs['ac_configure_args'], '--no-create', '--no-recursion']))

    if options.files:
        files = options.files
        headers = []
    if options.headers:
        headers = options.headers
        if not options.files:
            files = []
    # Default to display messages when giving --file or --headers on the
    # command line.
    log_level = logging.INFO

    if options.files or options.headers or options.verbose:
        log_level = logging.DEBUG

    log_manager.add_terminal_logging(level=log_level)
    log_manager.enable_unstructured()

    if not options.files and not options.headers:
        print('Reticulating splines...', file=sys.stderr)
        summary = backend.consume(definitions)

        for line in summary.summaries():
            print(line, file=sys.stderr)

        files = [os.path.join(topobjdir, f) for f in files]
        headers = [os.path.join(topobjdir, f) for f in headers]

    for file in files:
        env.create_config_file(file)
    for header in headers:
        env.create_config_header(header)
Example #14
0
def process_define_file(output, input):
    '''Creates the given config header. A config header is generated by
    taking the corresponding source file and replacing some #define/#undef
    occurences:
        "#undef NAME" is turned into "#define NAME VALUE"
        "#define NAME" is unchanged
        "#define NAME ORIGINAL_VALUE" is turned into "#define NAME VALUE"
        "#undef UNKNOWN_NAME" is turned into "/* #undef UNKNOWN_NAME */"
        Whitespaces are preserved.

    As a special rule, "#undef ALLDEFINES" is turned into "#define NAME
    VALUE" for all the defined variables.
    '''

    path = os.path.abspath(input)

    config = ConfigEnvironment.from_config_status(
        mozpath.join(topobjdir, 'config.status'))

    if mozpath.basedir(path,
                       [mozpath.join(config.topsrcdir, 'js/src')]) and \
            not config.substs.get('JS_STANDALONE'):
        config = ConfigEnvironment.from_config_status(
            mozpath.join(topobjdir, 'js', 'src', 'config.status'))

    with open(path, 'rU') as input:
        r = re.compile('^\s*#\s*(?P<cmd>[a-z]+)(?:\s+(?P<name>\S+)(?:\s+(?P<value>\S+))?)?', re.U)
        for l in input:
            m = r.match(l)
            if m:
                cmd = m.group('cmd')
                name = m.group('name')
                value = m.group('value')
                if name:
                    if name == 'ALLDEFINES':
                        if cmd == 'define':
                            raise Exception(
                                '`#define ALLDEFINES` is not allowed in a '
                                'CONFIGURE_DEFINE_FILE')
                        defines = '\n'.join(sorted(
                            '#define %s %s' % (name, val)
                            for name, val in config.defines.iteritems()
                            if name not in config.non_global_defines))
                        l = l[:m.start('cmd') - 1] \
                            + defines + l[m.end('name'):]
                    elif name in config.defines:
                        if cmd == 'define' and value:
                            l = l[:m.start('value')] \
                                + str(config.defines[name]) \
                                + l[m.end('value'):]
                        elif cmd == 'undef':
                            l = l[:m.start('cmd')] \
                                + 'define' \
                                + l[m.end('cmd'):m.end('name')] \
                                + ' ' \
                                + str(config.defines[name]) \
                                + l[m.end('name'):]
                    elif cmd == 'undef':
                       l = '/* ' + l[:m.end('name')] + ' */' + l[m.end('name'):]

            output.write(l)

    return {config.source}
Example #15
0
    def _read_mozbuild(self, path, config, descend, metadata):
        path = mozpath.normpath(path)
        log(self._log, logging.DEBUG, 'read_mozbuild', {'path': path},
            'Reading file: {path}')

        if path in self._read_files:
            log(self._log, logging.WARNING, 'read_already', {'path': path},
                'File already read. Skipping: {path}')
            return

        self._read_files.add(path)

        time_start = time.time()

        topobjdir = config.topobjdir

        if not mozpath.basedir(path, [config.topsrcdir]):
            external = config.external_source_dir
            if external and mozpath.basedir(path, [external]):
                config = ConfigEnvironment.from_config_status(
                    mozpath.join(topobjdir, 'config.status'))
                config.topsrcdir = external
                config.external_source_dir = None

        relpath = mozpath.relpath(path, config.topsrcdir)
        reldir = mozpath.dirname(relpath)

        if mozpath.dirname(relpath) == 'js/src' and \
                not config.substs.get('JS_STANDALONE'):
            config = ConfigEnvironment.from_config_status(
                mozpath.join(topobjdir, reldir, 'config.status'))
            config.topobjdir = topobjdir
            config.external_source_dir = None

        context = Context(VARIABLES, config)
        sandbox = MozbuildSandbox(context, metadata=metadata)
        sandbox.exec_file(path)
        context.execution_time = time.time() - time_start

        # Yield main context before doing any processing. This gives immediate
        # consumers an opportunity to change state before our remaining
        # processing is performed.
        yield context

        # We first collect directories populated in variables.
        dir_vars = ['DIRS']

        if context.config.substs.get('ENABLE_TESTS', False) == '1':
            dir_vars.append('TEST_DIRS')

        dirs = [(v, context[v]) for v in dir_vars if v in context]

        curdir = mozpath.dirname(path)

        gyp_contexts = []
        for target_dir in context.get('GYP_DIRS', []):
            gyp_dir = context['GYP_DIRS'][target_dir]
            for v in ('input', 'variables'):
                if not getattr(gyp_dir, v):
                    raise SandboxValidationError(
                        'Missing value for '
                        'GYP_DIRS["%s"].%s' % (target_dir, v), context)

            # The make backend assumes contexts for sub-directories are
            # emitted after their parent, so accumulate the gyp contexts.
            # We could emit the parent context before processing gyp
            # configuration, but we need to add the gyp objdirs to that context
            # first.
            from .gyp_reader import read_from_gyp
            non_unified_sources = set()
            for s in gyp_dir.non_unified_sources:
                source = SourcePath(context, s)
                if not os.path.exists(source.full_path):
                    raise SandboxValidationError('Cannot find %s.' % source,
                                                 context)
                non_unified_sources.add(source)
            for gyp_context in read_from_gyp(
                    context.config,
                    mozpath.join(curdir, gyp_dir.input),
                    mozpath.join(context.objdir, target_dir),
                    gyp_dir.variables,
                    non_unified_sources=non_unified_sources):
                gyp_context.update(gyp_dir.sandbox_vars)
                gyp_contexts.append(gyp_context)

        for gyp_context in gyp_contexts:
            context['DIRS'].append(
                mozpath.relpath(gyp_context.objdir, context.objdir))
            sandbox.subcontexts.append(gyp_context)

        for subcontext in sandbox.subcontexts:
            yield subcontext

        # Traverse into referenced files.

        # It's very tempting to use a set here. Unfortunately, the recursive
        # make backend needs order preserved. Once we autogenerate all backend
        # files, we should be able to convert this to a set.
        recurse_info = OrderedDict()
        for var, var_dirs in dirs:
            for d in var_dirs:
                if d in recurse_info:
                    raise SandboxValidationError(
                        'Directory (%s) registered multiple times in %s' %
                        (mozpath.relpath(d.full_path, context.srcdir), var),
                        context)

                recurse_info[d] = {}
                for key in sandbox.metadata:
                    if key == 'exports':
                        sandbox.recompute_exports()

                    recurse_info[d][key] = dict(sandbox.metadata[key])

        for path, child_metadata in recurse_info.items():
            child_path = path.join('moz.build').full_path

            # Ensure we don't break out of the topsrcdir. We don't do realpath
            # because it isn't necessary. If there are symlinks in the srcdir,
            # that's not our problem. We're not a hosted application: we don't
            # need to worry about security too much.
            if not is_read_allowed(child_path, context.config):
                raise SandboxValidationError(
                    'Attempting to process file outside of allowed paths: %s' %
                    child_path, context)

            if not descend:
                continue

            for res in self.read_mozbuild(child_path,
                                          context.config,
                                          metadata=child_metadata):
                yield res

        self._execution_stack.pop()
Example #16
0
    def _read_mozbuild(self, path, config, descend, metadata):
        path = mozpath.normpath(path)
        log(self._log, logging.DEBUG, 'read_mozbuild', {'path': path},
            'Reading file: {path}')

        if path in self._read_files:
            log(self._log, logging.WARNING, 'read_already', {'path': path},
                'File already read. Skipping: {path}')
            return

        self._read_files.add(path)

        time_start = time.time()

        topobjdir = config.topobjdir

        if not mozpath.basedir(path, [config.topsrcdir]):
            external = config.external_source_dir
            if external and mozpath.basedir(path, [external]):
                config = ConfigEnvironment.from_config_status(
                    mozpath.join(topobjdir, 'config.status'))
                config.topsrcdir = external
                config.external_source_dir = None

        relpath = mozpath.relpath(path, config.topsrcdir)
        reldir = mozpath.dirname(relpath)

        if mozpath.dirname(relpath) == 'js/src' and \
                not config.substs.get('JS_STANDALONE'):
            config = ConfigEnvironment.from_config_status(
                mozpath.join(topobjdir, reldir, 'config.status'))
            config.topobjdir = topobjdir
            config.external_source_dir = None

        context = Context(VARIABLES, config)
        sandbox = MozbuildSandbox(context, metadata=metadata)
        sandbox.exec_file(path)
        context.execution_time = time.time() - time_start

        # Yield main context before doing any processing. This gives immediate
        # consumers an opportunity to change state before our remaining
        # processing is performed.
        yield context

        # We first collect directories populated in variables.
        dir_vars = ['DIRS']

        if context.config.substs.get('ENABLE_TESTS', False) == '1':
            dir_vars.append('TEST_DIRS')

        dirs = [(v, context[v]) for v in dir_vars if v in context]

        curdir = mozpath.dirname(path)

        gyp_contexts = []
        for target_dir in context.get('GYP_DIRS', []):
            gyp_dir = context['GYP_DIRS'][target_dir]
            for v in ('input', 'variables'):
                if not getattr(gyp_dir, v):
                    raise SandboxValidationError('Missing value for '
                        'GYP_DIRS["%s"].%s' % (target_dir, v), context)

            # The make backend assumes contexts for sub-directories are
            # emitted after their parent, so accumulate the gyp contexts.
            # We could emit the parent context before processing gyp
            # configuration, but we need to add the gyp objdirs to that context
            # first.
            from .gyp_reader import read_from_gyp
            non_unified_sources = set()
            for s in gyp_dir.non_unified_sources:
                source = mozpath.normpath(mozpath.join(curdir, s))
                if not os.path.exists(source):
                    raise SandboxValidationError('Cannot find %s.' % source,
                        context)
                non_unified_sources.add(source)
            for gyp_context in read_from_gyp(context.config,
                                             mozpath.join(curdir, gyp_dir.input),
                                             mozpath.join(context.objdir,
                                                          target_dir),
                                             gyp_dir.variables,
                                             non_unified_sources = non_unified_sources):
                gyp_context.update(gyp_dir.sandbox_vars)
                gyp_contexts.append(gyp_context)

        for gyp_context in gyp_contexts:
            context['DIRS'].append(mozpath.relpath(gyp_context.objdir, context.objdir))
            sandbox.subcontexts.append(gyp_context)

        for subcontext in sandbox.subcontexts:
            yield subcontext

        # Traverse into referenced files.

        # It's very tempting to use a set here. Unfortunately, the recursive
        # make backend needs order preserved. Once we autogenerate all backend
        # files, we should be able to convert this to a set.
        recurse_info = OrderedDict()
        for var, var_dirs in dirs:
            for d in var_dirs:
                if d in recurse_info:
                    raise SandboxValidationError(
                        'Directory (%s) registered multiple times in %s' % (
                            mozpath.relpath(d, context.srcdir), var), context)

                recurse_info[d] = {}
                for key in sandbox.metadata:
                    if key == 'exports':
                        sandbox.recompute_exports()

                    recurse_info[d][key] = dict(sandbox.metadata[key])

        for path, child_metadata in recurse_info.items():
            child_path = path.join('moz.build')

            # Ensure we don't break out of the topsrcdir. We don't do realpath
            # because it isn't necessary. If there are symlinks in the srcdir,
            # that's not our problem. We're not a hosted application: we don't
            # need to worry about security too much.
            if not is_read_allowed(child_path, context.config):
                raise SandboxValidationError(
                    'Attempting to process file outside of allowed paths: %s' %
                        child_path, context)

            if not descend:
                continue

            for res in self.read_mozbuild(child_path, context.config,
                                          metadata=child_metadata):
                yield res

        self._execution_stack.pop()
Example #17
0
    def _read_mozbuild(self, path, config, read_tiers, filesystem_absolute,
                       descend, metadata):
        path = mozpath.normpath(path)
        log(self._log, logging.DEBUG, 'read_mozbuild', {'path': path},
            'Reading file: {path}')

        if path in self._read_files:
            log(self._log, logging.WARNING, 'read_already', {'path': path},
                'File already read. Skipping: {path}')
            return

        self._read_files.add(path)

        time_start = time.time()

        topobjdir = config.topobjdir

        if not mozpath.basedir(path, [config.topsrcdir]):
            external = config.external_source_dir
            if external and mozpath.basedir(path, [external]):
                config = ConfigEnvironment.from_config_status(
                    mozpath.join(topobjdir, 'config.status'))
                config.topsrcdir = external
                config.external_source_dir = None

        relpath = mozpath.relpath(path, config.topsrcdir)
        reldir = mozpath.dirname(relpath)

        if mozpath.dirname(relpath) == 'js/src' and \
                not config.substs.get('JS_STANDALONE'):
            config = ConfigEnvironment.from_config_status(
                mozpath.join(topobjdir, reldir, 'config.status'))
            config.topobjdir = topobjdir
            config.external_source_dir = None

        context = Context(VARIABLES, config)
        sandbox = MozbuildSandbox(context, metadata=metadata)
        sandbox.exec_file(path, filesystem_absolute=filesystem_absolute)
        context.execution_time = time.time() - time_start

        if self._sandbox_post_eval_cb:
            self._sandbox_post_eval_cb(context)

        # We first collect directories populated in variables.
        dir_vars = ['DIRS']

        if context.config.substs.get('ENABLE_TESTS', False) == '1':
            dir_vars.append('TEST_DIRS')

        dirs = [(v, context[v]) for v in dir_vars if v in context]

        curdir = mozpath.dirname(path)

        gyp_contexts = []
        for target_dir in context['GYP_DIRS']:
            gyp_dir = context['GYP_DIRS'][target_dir]
            for v in ('input', 'variables'):
                if not getattr(gyp_dir, v):
                    raise SandboxValidationError(
                        'Missing value for '
                        'GYP_DIRS["%s"].%s' % (target_dir, v), context)

            # The make backend assumes contexts for sub-directories are
            # emitted after their parent, so accumulate the gyp contexts.
            # We could emit the parent context before processing gyp
            # configuration, but we need to add the gyp objdirs to that context
            # first.
            from .gyp_reader import read_from_gyp
            non_unified_sources = set()
            for s in gyp_dir.non_unified_sources:
                source = mozpath.normpath(mozpath.join(curdir, s))
                if not os.path.exists(source):
                    raise SandboxValidationError('Cannot find %s.' % source,
                                                 context)
                non_unified_sources.add(source)
            for gyp_context in read_from_gyp(
                    context.config,
                    mozpath.join(curdir, gyp_dir.input),
                    mozpath.join(context.objdir, target_dir),
                    gyp_dir.variables,
                    non_unified_sources=non_unified_sources):
                gyp_context.update(gyp_dir.sandbox_vars)
                gyp_contexts.append(gyp_context)

        for gyp_context in gyp_contexts:
            if self._sandbox_post_eval_cb:
                self._sandbox_post_eval_cb(gyp_context)

            context['DIRS'].append(
                mozpath.relpath(gyp_context.objdir, context.objdir))

        yield context

        for gyp_context in gyp_contexts:
            yield gyp_context

        # Traverse into referenced files.

        # It's very tempting to use a set here. Unfortunately, the recursive
        # make backend needs order preserved. Once we autogenerate all backend
        # files, we should be able to convert this to a set.
        recurse_info = OrderedDict()
        for var, var_dirs in dirs:
            for d in var_dirs:
                if d in recurse_info:
                    raise SandboxValidationError(
                        'Directory (%s) registered multiple times in %s' %
                        (d, var), context)

                recurse_info[d] = {}
                if 'templates' in sandbox.metadata:
                    recurse_info[d]['templates'] = dict(
                        sandbox.metadata['templates'])
                if 'exports' in sandbox.metadata:
                    sandbox.recompute_exports()
                    recurse_info[d]['exports'] = dict(
                        sandbox.metadata['exports'])

        # We also have tiers whose members are directories.
        if 'TIERS' in context:
            if not read_tiers:
                raise SandboxValidationError(
                    'TIERS defined but it should not be', context)

            for tier, values in context['TIERS'].items():
                # We don't descend into external directories because external by
                # definition is external to the build system.
                for d in values['regular']:
                    if d in recurse_info:
                        raise SandboxValidationError(
                            'Tier directory (%s) registered multiple '
                            'times in %s' % (d, tier), context)
                    recurse_info[d] = {'check_external': True}
                    if 'templates' in sandbox.metadata:
                        recurse_info[d]['templates'] = dict(
                            sandbox.metadata['templates'])

        for relpath, child_metadata in recurse_info.items():
            if 'check_external' in child_metadata:
                relpath = '/' + relpath
            child_path = sandbox.normalize_path(mozpath.join(
                relpath, 'moz.build'),
                                                srcdir=curdir)

            # Ensure we don't break out of the topsrcdir. We don't do realpath
            # because it isn't necessary. If there are symlinks in the srcdir,
            # that's not our problem. We're not a hosted application: we don't
            # need to worry about security too much.
            if not is_read_allowed(child_path, context.config):
                raise SandboxValidationError(
                    'Attempting to process file outside of allowed paths: %s' %
                    child_path, context)

            if not descend:
                continue

            for res in self.read_mozbuild(child_path,
                                          context.config,
                                          read_tiers=False,
                                          filesystem_absolute=True,
                                          metadata=child_metadata):
                yield res

        self._execution_stack.pop()
Example #18
0
def config_status(topobjdir='.', topsrcdir='.',
        defines=[], non_global_defines=[], substs=[]):
    '''Main function, providing config.status functionality.

    Contrary to config.status, it doesn't use CONFIG_FILES or CONFIG_HEADERS
    variables.

    Without the -n option, this program acts as config.status and considers
    the current directory as the top object directory, even when config.status
    is in a different directory. It will, however, treat the directory
    containing config.status as the top object directory with the -n option.

    The --recheck option, like with the original config.status, runs configure
    again, with the options given in the "ac_configure_args" subst.

    The options to this function are passed when creating the
    ConfigEnvironment. These lists, as well as the actual wrapper script
    around this function, are meant to be generated by configure.
    See build/autoconf/config.status.m4.
    '''

    if 'CONFIG_FILES' in os.environ:
        raise Exception('Using the CONFIG_FILES environment variable is not '
            'supported.')
    if 'CONFIG_HEADERS' in os.environ:
        raise Exception('Using the CONFIG_HEADERS environment variable is not '
            'supported.')

    if not os.path.isabs(topsrcdir):
        raise Exception('topsrcdir must be defined as an absolute directory: '
            '%s' % topsrcdir)

    parser = OptionParser()
    parser.add_option('--recheck', dest='recheck', action='store_true',
                      help='update config.status by reconfiguring in the same conditions')
    parser.add_option('-v', '--verbose', dest='verbose', action='store_true',
                      help='display verbose output')
    parser.add_option('-n', dest='not_topobjdir', action='store_true',
                      help='do not consider current directory as top object directory')
    parser.add_option('-d', '--diff', action='store_true',
                      help='print diffs of changed files.')
    options, args = parser.parse_args()

    # Without -n, the current directory is meant to be the top object directory
    if not options.not_topobjdir:
        topobjdir = os.path.abspath('.')

    env = ConfigEnvironment(topsrcdir, topobjdir, defines=defines,
            non_global_defines=non_global_defines, substs=substs)

    # mozinfo.json only needs written if configure changes and configure always
    # passes this environment variable.
    if 'WRITE_MOZINFO' in os.environ:
        write_mozinfo(os.path.join(topobjdir, 'mozinfo.json'), env, os.environ)

    reader = BuildReader(env)
    emitter = TreeMetadataEmitter(env)
    backend = RecursiveMakeBackend(env)
    # This won't actually do anything because of the magic of generators.
    definitions = emitter.emit(reader.read_topsrcdir())

    if options.recheck:
        # Execute configure from the top object directory
        os.chdir(topobjdir)
        os.execlp('sh', 'sh', '-c', ' '.join([os.path.join(topsrcdir, 'configure'), env.substs['ac_configure_args'], '--no-create', '--no-recursion']))

    log_level = logging.DEBUG if options.verbose else logging.INFO
    log_manager.add_terminal_logging(level=log_level)
    log_manager.enable_unstructured()

    print('Reticulating splines...', file=sys.stderr)
    summary = backend.consume(definitions)

    for line in summary.summaries():
        print(line, file=sys.stderr)

    if options.diff:
        for path, diff in sorted(summary.file_diffs.items()):
            print(diff)
Example #19
0
    def __init__(self, config, path, metadata={}):
        """Create an empty mozbuild Sandbox.

        config is a ConfigStatus instance (the output of configure). path is
        the path of the main mozbuild file that is being executed. It is used
        to compute encountered relative paths.
        """
        Sandbox.__init__(self, allowed_variables=VARIABLES)

        self._log = logging.getLogger(__name__)

        self.config = config
        self.metadata = dict(metadata)

        topobjdir = mozpath.abspath(config.topobjdir)
        topsrcdir = config.topsrcdir
        norm_topsrcdir = mozpath.normpath(topsrcdir)

        if not path.startswith(norm_topsrcdir):
            external_dirs = config.substs.get('EXTERNAL_SOURCE_DIR', '').split()
            for external in external_dirs:
                external = mozpath.normpath(external)

                if not os.path.isabs(external):
                    external = mozpath.join(config.topsrcdir, external)

                external = mozpath.normpath(external)

                if not path.startswith(external):
                    continue

                topsrcdir = external

                # This is really hacky and should be replaced with something
                # more robust. We assume that if an external source directory
                # is in play that the main build system is built in a
                # subdirectory of its topobjdir. Therefore, the topobjdir of
                # the external source directory is the parent of our topobjdir.
                topobjdir = mozpath.dirname(topobjdir)

                # This is suboptimal because we load the config.status multiple
                # times. We should consider caching it, possibly by moving this
                # code up to the reader.
                config = ConfigEnvironment.from_config_status(
                    mozpath.join(topobjdir, 'config.status'))
                self.config = config
                break

        self.topsrcdir = topsrcdir

        relpath = mozpath.relpath(path, topsrcdir)
        reldir = mozpath.dirname(relpath)

        if mozpath.dirname(relpath) == 'js/src' and \
                not config.substs.get('JS_STANDALONE'):
            config = ConfigEnvironment.from_config_status(
                mozpath.join(topobjdir, reldir, 'config.status'))
            config.topobjdir = topobjdir
            self.config = config

        with self._globals.allow_all_writes() as d:
            d['TOPSRCDIR'] = topsrcdir
            d['TOPOBJDIR'] = topobjdir
            d['RELATIVEDIR'] = reldir
            d['SRCDIR'] = mozpath.join(topsrcdir, reldir).rstrip('/')
            d['OBJDIR'] = mozpath.join(topobjdir, reldir).rstrip('/')

            d['CONFIG'] = ReadOnlyDefaultDict(lambda: None,
                self.config.substs_unicode)

            # Register functions.
            for name, func in FUNCTIONS.items():
                d[name] = getattr(self, func[0])

            # Initialize the exports that we need in the global.
            extra_vars = self.metadata.get('exports', dict())
            self._globals.update(extra_vars)
Example #20
0
    def __init__(self, config, path, metadata={}):
        """Create an empty mozbuild Sandbox.

        config is a ConfigStatus instance (the output of configure). path is
        the path of the main mozbuild file that is being executed. It is used
        to compute encountered relative paths.
        """
        Sandbox.__init__(self, allowed_variables=VARIABLES)

        self._log = logging.getLogger(__name__)

        self.config = config
        self.metadata = dict(metadata)

        topobjdir = mozpath.abspath(config.topobjdir)
        topsrcdir = config.topsrcdir
        norm_topsrcdir = mozpath.normpath(topsrcdir)

        if not path.startswith(norm_topsrcdir):
            external_dirs = config.substs.get('EXTERNAL_SOURCE_DIR', '').split()
            for external in external_dirs:
                external = mozpath.normpath(external)

                if not os.path.isabs(external):
                    external = mozpath.join(config.topsrcdir, external)

                external = mozpath.normpath(external)

                if not path.startswith(external):
                    continue

                topsrcdir = external

                # This is really hacky and should be replaced with something
                # more robust. We assume that if an external source directory
                # is in play that the main build system is built in a
                # subdirectory of its topobjdir. Therefore, the topobjdir of
                # the external source directory is the parent of our topobjdir.
                topobjdir = mozpath.dirname(topobjdir)

                # This is suboptimal because we load the config.status multiple
                # times. We should consider caching it, possibly by moving this
                # code up to the reader.
                config = ConfigEnvironment.from_config_status(
                    mozpath.join(topobjdir, 'config.status'))
                self.config = config
                break

        self.topsrcdir = topsrcdir

        relpath = mozpath.relpath(path, topsrcdir)
        reldir = mozpath.dirname(relpath)

        with self._globals.allow_all_writes() as d:
            d['TOPSRCDIR'] = topsrcdir
            d['TOPOBJDIR'] = topobjdir
            d['RELATIVEDIR'] = reldir
            d['SRCDIR'] = mozpath.join(topsrcdir, reldir).rstrip('/')
            d['OBJDIR'] = mozpath.join(topobjdir, reldir).rstrip('/')

            d['CONFIG'] = ReadOnlyDefaultDict(self.config.substs_unicode,
                global_default=None)

            var = metadata.get('var', None)
            if var and var in ['TOOL_DIRS', 'TEST_TOOL_DIRS']:
                d['IS_TOOL_DIR'] = True

            # Register functions.
            for name, func in FUNCTIONS.items():
                d[name] = getattr(self, func[0])

            # Initialize the exports that we need in the global.
            extra_vars = self.metadata.get('exports', dict())
            self._globals.update(extra_vars)
Example #21
0
def config_status(topobjdir='.',
                  topsrcdir='.',
                  defines=None,
                  non_global_defines=None,
                  substs=None,
                  source=None,
                  mozconfig=None,
                  args=sys.argv[1:]):
    '''Main function, providing config.status functionality.

    Contrary to config.status, it doesn't use CONFIG_FILES or CONFIG_HEADERS
    variables.

    Without the -n option, this program acts as config.status and considers
    the current directory as the top object directory, even when config.status
    is in a different directory. It will, however, treat the directory
    containing config.status as the top object directory with the -n option.

    The options to this function are passed when creating the
    ConfigEnvironment. These lists, as well as the actual wrapper script
    around this function, are meant to be generated by configure.
    See build/autoconf/config.status.m4.
    '''

    if 'CONFIG_FILES' in os.environ:
        raise Exception('Using the CONFIG_FILES environment variable is not '
                        'supported.')
    if 'CONFIG_HEADERS' in os.environ:
        raise Exception('Using the CONFIG_HEADERS environment variable is not '
                        'supported.')

    if not os.path.isabs(topsrcdir):
        raise Exception('topsrcdir must be defined as an absolute directory: '
                        '%s' % topsrcdir)

    default_backends = ['RecursiveMake']
    default_backends = (substs or {}).get('BUILD_BACKENDS', ['RecursiveMake'])

    parser = ArgumentParser()
    parser.add_argument('-v',
                        '--verbose',
                        dest='verbose',
                        action='store_true',
                        help='display verbose output')
    parser.add_argument(
        '-n',
        dest='not_topobjdir',
        action='store_true',
        help='do not consider current directory as top object directory')
    parser.add_argument('-d',
                        '--diff',
                        action='store_true',
                        help='print diffs of changed files.')
    parser.add_argument('-b',
                        '--backend',
                        nargs='+',
                        choices=sorted(backends),
                        default=default_backends,
                        help='what backend to build (default: %s).' %
                        ' '.join(default_backends))
    parser.add_argument('--dry-run',
                        action='store_true',
                        help='do everything except writing files out.')
    options = parser.parse_args(args)

    # Without -n, the current directory is meant to be the top object directory
    if not options.not_topobjdir:
        topobjdir = os.path.abspath('.')

    env = ConfigEnvironment(topsrcdir,
                            topobjdir,
                            defines=defines,
                            non_global_defines=non_global_defines,
                            substs=substs,
                            source=source,
                            mozconfig=mozconfig)

    # mozinfo.json only needs written if configure changes and configure always
    # passes this environment variable.
    if 'WRITE_MOZINFO' in os.environ:
        write_mozinfo(os.path.join(topobjdir, 'mozinfo.json'), env, os.environ)

    cpu_start = time.clock()
    time_start = time.time()

    # Make appropriate backend instances, defaulting to RecursiveMakeBackend,
    # or what is in BUILD_BACKENDS.
    selected_backends = [get_backend_class(b)(env) for b in options.backend]

    if options.dry_run:
        for b in selected_backends:
            b.dry_run = True

    reader = BuildReader(env)
    emitter = TreeMetadataEmitter(env)
    # This won't actually do anything because of the magic of generators.
    definitions = emitter.emit(reader.read_topsrcdir())

    log_level = logging.DEBUG if options.verbose else logging.INFO
    log_manager.add_terminal_logging(level=log_level)
    log_manager.enable_unstructured()

    print('Reticulating splines...', file=sys.stderr)
    if len(selected_backends) > 1:
        definitions = list(definitions)

    for the_backend in selected_backends:
        the_backend.consume(definitions)

    execution_time = 0.0
    for obj in chain((reader, emitter), selected_backends):
        summary = obj.summary()
        print(summary, file=sys.stderr)
        execution_time += summary.execution_time
        if hasattr(obj, 'gyp_summary'):
            summary = obj.gyp_summary()
            print(summary, file=sys.stderr)

    cpu_time = time.clock() - cpu_start
    wall_time = time.time() - time_start
    efficiency = cpu_time / wall_time if wall_time else 100
    untracked = wall_time - execution_time

    print('Total wall time: {:.2f}s; CPU time: {:.2f}s; Efficiency: '
          '{:.0%}; Untracked: {:.2f}s'.format(wall_time, cpu_time, efficiency,
                                              untracked),
          file=sys.stderr)

    if options.diff:
        for the_backend in selected_backends:
            for path, diff in sorted(the_backend.file_diffs.items()):
                print('\n'.join(diff))

    # Advertise Visual Studio if appropriate.
    if os.name == 'nt' and 'VisualStudio' not in options.backend:
        print(VISUAL_STUDIO_ADVERTISEMENT)

    # Advertise Eclipse if it is appropriate.
    if MachCommandConditions.is_android(env):
        if 'AndroidEclipse' not in options.backend:
            print(ANDROID_IDE_ADVERTISEMENT)
Example #22
0
    def __init__(self, config, path):
        """Create an empty mozbuild Sandbox.

        config is a ConfigStatus instance (the output of configure). path is
        the path of the main mozbuild file that is being executed. It is used
        to compute encountered relative paths.
        """
        Sandbox.__init__(self, allowed_variables=VARIABLES)

        self._log = logging.getLogger(__name__)

        self.config = config

        topobjdir = os.path.abspath(config.topobjdir)
        topsrcdir = config.topsrcdir
        norm_topsrcdir = os.path.normpath(topsrcdir)

        if not path.startswith(norm_topsrcdir):
            external_dirs = config.substs.get('EXTERNAL_SOURCE_DIR',
                                              '').split()
            for external in external_dirs:
                external = os.path.normpath(external)

                if not os.path.isabs(external):
                    external = os.path.join(config.topsrcdir, external)

                external = os.path.normpath(external)

                if not path.startswith(external):
                    continue

                topsrcdir = external

                # This is really hacky and should be replaced with something
                # more robust. We assume that if an external source directory
                # is in play that the main build system is built in a
                # subdirectory of its topobjdir. Therefore, the topobjdir of
                # the external source directory is the parent of our topobjdir.
                topobjdir = os.path.dirname(topobjdir)

                # This is suboptimal because we load the config.status multiple
                # times. We should consider caching it, possibly by moving this
                # code up to the reader.
                config = ConfigEnvironment.from_config_status(
                    os.path.join(topobjdir, 'config.status'))
                self.config = config
                break

        self.topsrcdir = topsrcdir

        relpath = os.path.relpath(path, topsrcdir).replace(os.sep, '/')
        reldir = os.path.dirname(relpath)

        with self._globals.allow_all_writes() as d:
            d['TOPSRCDIR'] = topsrcdir
            d['TOPOBJDIR'] = topobjdir
            d['RELATIVEDIR'] = reldir
            d['SRCDIR'] = os.path.join(topsrcdir,
                                       reldir).replace(os.sep, '/').rstrip('/')
            d['OBJDIR'] = os.path.join(topobjdir,
                                       reldir).replace(os.sep, '/').rstrip('/')

            # config.status does not yet use unicode. However, mozbuild expects
            # unicode everywhere. So, decode binary into unicode as necessary.
            # Bug 844509 tracks a better way to do this.
            substs = {}
            for k, v in config.substs.items():
                if not isinstance(v, text_type):
                    try:
                        v = v.decode('utf-8')
                    except UnicodeDecodeError:
                        log(
                            self._log, logging.INFO, 'lossy_encoding',
                            {'variable': k},
                            'Lossy Unicode encoding for {variable}. See bug 844509.'
                        )

                        v = v.decode('utf-8', 'replace')

                substs[k] = v

            d['CONFIG'] = ReadOnlyDefaultDict(substs, global_default=None)

            # Register functions.
            for name, func in FUNCTIONS.items():
                d[name] = getattr(self, func[0])