Example #1
0
 def include(self, filename):
     '''Read configuration variables from a file.'''
     try:
         execfile(filename, self._config)
     except Exception:
         traceback.print_exc()
         raise FatalError(
             _('Could not include config file (%s)') % filename)
Example #2
0
    def load(self, filename=None):
        config = self._config
        if filename:
            try:
                execfile(filename, config)
            except Exception as e:
                if isinstance(e, FatalError):
                    # raise FatalErrors back, as it means an error in include()
                    # and it will print a traceback, and provide a meaningful
                    # message.
                    raise e
                traceback.print_exc()
                raise FatalError(_('could not load config file'))

        if not config.get('quiet_mode'):
            unknown_keys = []
            for k in config.keys():
                if k in _known_keys + ['cvsroots', 'svnroots', 'cflags']:
                    continue
                if k[0] == '_':
                    continue
                if type(config[k]) in (types.ModuleType, types.FunctionType,
                                       types.MethodType):
                    continue
                unknown_keys.append(k)
            if unknown_keys:
                logging.info(
                        _('unknown keys defined in configuration file: %s') % \
                        ', '.join(unknown_keys))

        # backward compatibility, from the days when jhbuild only
        # supported Gnome.org CVS.
        if config.get('cvsroot'):
            logging.warning(
                _('the "%s" configuration variable is deprecated, '
                  'you should use "repos[\'gnome.org\']".') % 'cvsroot')
            config['repos'].update({'gnome.org': config['cvsroot']})
        if config.get('cvsroots'):
            logging.warning(
                _('the "%s" configuration variable is deprecated, '
                  'you should use "repos".') % 'cvsroots')
            config['repos'].update(config['cvsroots'])
        if config.get('svnroots'):
            logging.warning(
                _('the "%s" configuration variable is deprecated, '
                  'you should use "repos".') % 'svnroots')
            config['repos'].update(config['svnroots'])

        # environment variables
        if 'cflags' in config and config['cflags']:
            os.environ['CFLAGS'] = config['cflags']
        if config.get('installprog') and os.path.exists(config['installprog']):
            os.environ['INSTALL'] = config['installprog']

        for path_key in ('checkoutroot', 'buildroot', 'top_builddir',
                         'tinderbox_outputdir', 'tarballdir', 'copy_dir',
                         'modulesets_dir', 'dvcs_mirror_dir',
                         'static_analyzer_outputdir', 'prefix'):
            if config.get(path_key):
                config[path_key] = os.path.expanduser(config[path_key])

        # copy known config keys to attributes on the instance
        for name in _known_keys:
            setattr(self, name, config[name])

        # default tarballdir to checkoutroot
        if not self.tarballdir:
            self.tarballdir = self.checkoutroot

        # Ensure top_builddir is absolute
        if not os.path.isabs(self.top_builddir):
            self.top_builddir = os.path.join(self.prefix, self.top_builddir)

        # check possible checkout_mode values
        seen_copy_mode = (self.checkout_mode == 'copy')
        possible_checkout_modes = ('update', 'clobber', 'export', 'copy')
        if self.checkout_mode not in possible_checkout_modes:
            raise FatalError(_('invalid checkout mode'))
        for module, checkout_mode in self.module_checkout_mode.items():
            seen_copy_mode = seen_copy_mode or (checkout_mode == 'copy')
            if checkout_mode not in possible_checkout_modes:
                raise FatalError(
                    _('invalid checkout mode (module: %s)') % module)
        if seen_copy_mode and not self.copy_dir:
            raise FatalError(_('copy mode requires copy_dir to be set'))

        if not os.path.exists(self.modulesets_dir):
            if self.use_local_modulesets:
                logging.warning(
                    _('modulesets directory (%s) not found, '
                      'disabling use_local_modulesets') % self.modulesets_dir)
                self.use_local_modulesets = False
            self.modulesets_dir = None

        if self.buildroot and not os.path.isabs(self.buildroot):
            raise FatalError(_('%s must be an absolute path') % 'buildroot')
        if not os.path.isabs(self.checkoutroot):
            raise FatalError(_('%s must be an absolute path') % 'checkoutroot')
        if not os.path.isabs(self.prefix):
            raise FatalError(_('%s must be an absolute path') % 'prefix')
        if not os.path.isabs(self.tarballdir):
            raise FatalError(_('%s must be an absolute path') % 'tarballdir')
        if (self.tinderbox_outputdir
                and not os.path.isabs(self.tinderbox_outputdir)):
            raise FatalError(
                _('%s must be an absolute path') % 'tinderbox_outputdir')
Example #3
0
    def __init__(self, filename, conditions_modifiers):
        self._config = {
            '__file__': _defaults_file,
            'addpath': addpath,
            'prependpath': prependpath,
            'include': self.include,
        }

        if not self._orig_environ:
            self.__dict__['_orig_environ'] = os.environ.copy()
        os.environ['UNMANGLED_LD_LIBRARY_PATH'] = os.environ.get(
            'LD_LIBRARY_PATH', '')
        os.environ['UNMANGLED_PATH'] = os.environ.get('PATH', '')

        env_prepends.clear()
        try:
            execfile(_defaults_file, self._config)
        except Exception:
            traceback.print_exc()
            raise FatalError(_('could not load config defaults'))

        old_config = os.path.join(os.path.expanduser('~'), '.jhbuildrc')
        new_config = os.path.join(
            os.environ.get('XDG_CONFIG_HOME',
                           os.path.join(os.path.expanduser('~'), '.config')),
            'jhbuildrc')

        if filename:
            if not os.path.exists(filename):
                raise FatalError(
                    _('could not load config file, %s is missing') % filename)
        else:
            if os.path.isfile(old_config) \
                    and not os.path.islink(old_config) \
                    and os.path.isfile(new_config) \
                    and not os.path.islink(new_config):
                raise FatalError(_('The default location of the configuration '
                                   'file has changed. Please move %(old_path)s'
                                   ' to %(new_path)s.' \
                                   % {'old_path': old_config,
                                      'new_path': new_config}))
            if os.path.exists(new_config):
                filename = new_config
            elif os.path.exists(old_config):
                filename = old_config

        if filename:
            self._config['__file__'] = filename
            self.filename = filename
        else:
            self._config['__file__'] = new_config
            self.filename = new_config

        # we might need to redo this process on config reloads, so save these
        self.saved_conditions_modifiers = conditions_modifiers

        # We handle the conditions flags like so:
        #   - get the default set of conditions (determined by the OS)
        #   - modify it with the commandline arguments
        #   - load the config file so that it can make further modifications
        #   - modify it with the commandline arguments again
        #
        # We apply the commandline argument condition modifiers both before
        # and after parsing the configuration so that the jhbuildrc has a
        # chance to inspect the modified set of flags (and conditionally act
        # on it to set new autogenargs, for example) but also so that the
        # condition flags given on the commandline will ultimately override
        # those in jhbuildrc.
        self._config['conditions'] = sysid.get_default_conditions()
        modify_conditions(self._config['conditions'], conditions_modifiers)
        self.load(filename)
        modify_conditions(self.conditions, conditions_modifiers)
        self.ignore_conditions = False

        self.create_directories()

        setup_env_defaults(self.system_libdirs)

        for prefix in reversed(self.extra_prefixes):
            setup_env(prefix)
        setup_env(self.prefix)

        self.apply_env_prepends()
        self.update_build_targets()