def prep(self, package):
        self.script.append('echo "==> %prep:"')
        _prep = package.prep()
        if _prep:
            for l in _prep:
                args = l.split()
                if len(args):

                    def err(msg):
                        raise error.general('%s: %s' % (package, msg))

                    if args[0] == '%setup':
                        if len(args) == 1:
                            raise error.general('invalid %%setup directive: %s' % \
                                                (' '.join(args)))
                        if args[1] == 'source':
                            self.source_setup(package, args[1:])
                        elif args[1] == 'patch':
                            self.patch_setup(package, args[1:])
                    elif args[0] in ['%patch', '%source']:
                        sources.process(args[0][1:], args[1:], self.macros,
                                        err)
                    elif args[0] == '%hash':
                        sources.hash(args[1:], self.macros, err)
                        self.hash(package, args)
                    else:
                        self.script.append(' '.join(args))
Ejemplo n.º 2
0
def load_release_hashes(macros):
    def hash_error(msg):
        raise error.general(msg)

    if released():
        v = _load_released_version_config()
        if v is not None:
            try:
                hashes = v.items('hashes')
            except:
                hashes = []
            for hash in hashes:
                hs = hash[1].split()
                if len(hs) != 2:
                    raise error.general('invalid release hash in VERSION')
                sources.hash((hs[0], hash[0], hs[1]), macros, hash_error)
Ejemplo n.º 3
0
def load_release_hashes(macros):
    def hash_error(msg):
        raise error.general(msg)

    if released():
        v = _load_released_version_config()
        if v is not None:
            try:
                hashes = v.items('hashes')
            except:
                hashes = []
            for hash in hashes:
                hs = hash[1].split()
                if len(hs) != 2:
                    raise error.general('invalid release hash in VERSION')
                sources.hash((hs[0], hash[0], hs[1]), macros, hash_error)
Ejemplo n.º 4
0
def load_release_settings(macros):
    def setting_error(msg):
        raise error.general(msg)

    if released():
        v = _load_released_version_config()
        if v is not None:
            try:
                hashes = v.items('hashes')
            except:
                hashes = []
            try:
                release_path = v.get('version', 'release_path', raw=True)
            except:
                release_path = None
            for hash in hashes:
                hs = hash[1].split()
                if len(hs) != 2:
                    raise error.general('invalid release hash in VERSION')
                sources.hash((hs[0], hash[0], hs[1]), macros, setting_error)
            download.set_release_path(release_path, macros)
Ejemplo n.º 5
0
def load_release_settings(macros):
    def setting_error(msg):
        raise error.general(msg)

    if released():
        v = _load_released_version_config()
        if v is not None:
            try:
                hashes = v.items('hashes')
            except:
                hashes = []
            try:
                release_path = v.get('version', 'release_path', raw = True)
            except:
                release_path = None
            for hash in hashes:
                hs = hash[1].split()
                if len(hs) != 2:
                    raise error.general('invalid release hash in VERSION')
                sources.hash((hs[0], hash[0], hs[1]), macros, setting_error)
            download.set_release_path(release_path, macros)
Ejemplo n.º 6
0
 def prep(self, package):
     self.script.append('echo "==> %prep:"')
     _prep = package.prep()
     if _prep:
         for l in _prep:
             args = l.split()
             if len(args):
                 def err(msg):
                     raise error.general('%s: %s' % (package, msg))
                 if args[0] == '%setup':
                     if len(args) == 1:
                         raise error.general('invalid %%setup directive: %s' % (' '.join(args)))
                     if args[1] == 'source':
                         self.source_setup(package, args[1:])
                     elif args[1] == 'patch':
                         self.patch_setup(package, args[1:])
                 elif args[0] in ['%patch', '%source']:
                     sources.process(args[0][1:], args[1:], self.macros, err)
                 elif args[0] == '%hash':
                     sources.hash(args[1:], self.macros, err)
                     self.hash(package, args)
                 else:
                     self.script.append(' '.join(args))
Ejemplo n.º 7
0
    def parse(self, bset):

        #
        # Ouch, this is a copy of the setbuilder.py code.
        #

        def _clean(line):
            line = line[0:-1]
            b = line.find('#')
            if b >= 0:
                line = line[1:b]
            return line.strip()

        bsetname = bset

        if not path.exists(bsetname):
            for cp in self.macros.expand('%{_configdir}').split(':'):
                configdir = path.abspath(cp)
                bsetname = path.join(configdir, bset)
                if path.exists(bsetname):
                    break
                bsetname = None
            if bsetname is None:
                raise error.general('no build set file found: %s' % (bset))
        try:
            log.trace('_bset: %s: open: %s' % (self.bset, bsetname))
            bset = open(path.host(bsetname), 'r')
        except IOError as err:
            raise error.general('error opening bset file: %s' % (bsetname))

        configs = []

        try:
            lc = 0
            for l in bset:
                lc += 1
                l = _clean(l)
                if len(l) == 0:
                    continue
                log.trace('_bset: %s: %03d: %s' % (self.bset, lc, l))
                ls = l.split()
                if ls[0][-1] == ':' and ls[0][:-1] == 'package':
                    self.bset_pkg = ls[1].strip()
                    self.macros['package'] = self.bset_pkg
                elif ls[0][0] == '%':
                    def err(msg):
                        raise error.general('%s:%d: %s' % (self.bset, lc, msg))
                    if ls[0] == '%define':
                        if len(ls) > 2:
                            self.macros.define(ls[1].strip(),
                                               ' '.join([f.strip() for f in ls[2:]]))
                        else:
                            self.macros.define(ls[1].strip())
                    elif ls[0] == '%undefine':
                        if len(ls) > 2:
                            raise error.general('%s:%d: %undefine requires just the name' % \
                                                    (self.bset, lc))
                        self.macros.undefine(ls[1].strip())
                    elif ls[0] == '%include':
                        configs += self.parse(ls[1].strip())
                    elif ls[0] in ['%patch', '%source']:
                        sources.process(ls[0][1:], ls[1:], self.macros, err)
                    elif ls[0] == '%hash':
                        sources.hash(ls[1:], self.macros, err)
                else:
                    l = l.strip()
                    c = build.find_config(l, self.configs)
                    if c is None:
                        raise error.general('%s:%d: cannot find file: %s' % (self.bset, lc, l))
                    configs += [c]
        except:
            bset.close()
            raise

        bset.close()

        return configs
Ejemplo n.º 8
0
 def _hash(self, ls):
     return sources.hash(ls[1:], self.macros, self._error)
Ejemplo n.º 9
0
    def parse(self, bset):
        def _clean(line):
            line = line[0:-1]
            b = line.find('#')
            if b >= 0:
                line = line[1:b]
            return line.strip()

        bsetname = bset

        if not path.exists(bsetname):
            for cp in self.macros.expand('%{_configdir}').split(':'):
                configdir = path.abspath(cp)
                bsetname = path.join(configdir, bset)
                if path.exists(bsetname):
                    break
                bsetname = None
            if bsetname is None:
                raise error.general('no build set file found: %s' % (bset))
        try:
            log.trace('_bset: %s: open: %s' % (self.bset, bsetname))
            bset = open(path.host(bsetname), 'r')
        except IOError as err:
            raise error.general('error opening bset file: %s' % (bsetname))

        configs = []

        try:
            lc = 0
            for l in bset:
                lc += 1
                l = _clean(l)
                if len(l) == 0:
                    continue
                log.trace('_bset: %s: %03d: %s' % (self.bset, lc, l))
                ls = l.split()
                if ls[0][-1] == ':' and ls[0][:-1] == 'package':
                    self.bset_pkg = ls[1].strip()
                    self.macros['package'] = self.bset_pkg
                elif ls[0][0] == '%':

                    def err(msg):
                        raise error.general('%s:%d: %s' % (self.bset, lc, msg))

                    if ls[0] == '%define':
                        if len(ls) > 2:
                            self.macros.define(
                                ls[1].strip(),
                                ' '.join([f.strip() for f in ls[2:]]))
                        else:
                            self.macros.define(ls[1].strip())
                    elif ls[0] == '%undefine':
                        if len(ls) > 2:
                            raise error.general('%s:%d: %undefine requires just the name' % \
                                                    (self.bset, lc))
                        self.macros.undefine(ls[1].strip())
                    elif ls[0] == '%include':
                        configs += self.parse(ls[1].strip())
                    elif ls[0] in ['%patch', '%source']:
                        sources.process(ls[0][1:], ls[1:], self.macros, err)
                    elif ls[0] == '%hash':
                        sources.hash(ls[1:], self.macros, err)
                else:
                    l = l.strip()
                    c = build.find_config(l, self.configs)
                    if c is None:
                        raise error.general('%s:%d: cannot find file: %s' %
                                            (self.bset, lc, l))
                    configs += [c]
        except:
            bset.close()
            raise

        bset.close()

        return configs
Ejemplo n.º 10
0
 def _hash(self, ls):
     return sources.hash(ls[1:], self.macros, self._error)
Ejemplo n.º 11
0
class buildset:
    """Build a set builds a set of packages."""
    def __init__(self, bset, _configs, opts, macros=None):
        log.trace('_bset: %s: init' % (bset))
        self.configs = _configs
        self.opts = opts
        if macros is None:
            self.macros = copy.copy(opts.defaults)
        else:
            self.macros = copy.copy(macros)
        self.bset = bset
        _target = self.macros.expand('%{_target}')
        if len(_target):
            pkg_prefix = _target
        else:
            pkg_prefix = self.macros.expand('%{_host}')
        self.bset_pkg = '%s-%s-set' % (pkg_prefix, self.bset)
        self.mail_header = ''
        self.mail_report = ''
        self.build_failure = None

    def write_mail_header(self, text, prepend=False):
        if len(text) == 0 or text[-1] != '\n' or text[-1] != '\r':
            text += os.linesep
        if prepend:
            self.mail_header = text + self.mail_header
        else:
            self.mail_header += text

    def write_mail_report(self, text, prepend=False):
        if len(text) == 0 or text[-1] != '\n' or text[-1] != '\r':
            text += os.linesep
        if prepend:
            self.mail_report = text + self.mail_report
        else:
            self.mail_report += text

    def copy(self, src, dst):
        log.output('copy: %s => %s' % (path.host(src), path.host(dst)))
        if not self.opts.dry_run():
            path.copy_tree(src, dst)

    def report(self, _config, _build, opts, macros, format=None):
        if len(_build.main_package().name()) > 0 \
           and not _build.macros.get('%{_disable_reporting}') \
           and (not _build.opts.get_arg('--no-report') \
                or _build.opts.get_arg('--mail')):
            if format is None:
                format = _build.opts.get_arg('--report-format')
                if format is not None:
                    if len(format) != 2:
                        raise error.general(
                            'invalid report format option: %s' %
                            ('='.join(format)))
                    format = format[1]
            if format is None:
                format = 'text'
            if format == 'text':
                ext = '.txt'
            elif format == 'asciidoc':
                ext = '.txt'
            elif format == 'html':
                ext = '.html'
            elif format == 'xml':
                ext = '.xml'
            elif format == 'ini':
                ext = '.ini'
            else:
                raise error.general('invalid report format: %s' % (format))
            buildroot = _build.config.abspath('%{buildroot}')
            prefix = _build.macros.expand('%{_prefix}')
            name = _build.main_package().name() + ext
            log.notice('reporting: %s -> %s' % (_config, name))
            if not _build.opts.get_arg('--no-report'):
                outpath = path.host(
                    path.join(buildroot, prefix, 'share', 'rtems', 'rsb'))
                if not _build.opts.dry_run():
                    outname = path.host(path.join(outpath, name))
                else:
                    outname = None
                r = reports.report(format, self.configs, copy.copy(opts),
                                   copy.copy(macros))
                r.introduction(_build.config.file_name())
                r.generate(_build.config.file_name())
                r.epilogue(_build.config.file_name())
                if not _build.opts.dry_run():
                    _build.mkdir(outpath)
                    r.write(outname)
                del r
            if _build.opts.get_arg('--mail'):
                r = reports.report('text', self.configs, copy.copy(opts),
                                   copy.copy(macros))
                r.introduction(_build.config.file_name())
                r.generate(_build.config.file_name())
                r.epilogue(_build.config.file_name())
                self.write_mail_report(r.out)
                del r

    def root_copy(self, src, dst):
        what = '%s -> %s' % \
            (os.path.relpath(path.host(src)), os.path.relpath(path.host(dst)))
        log.trace('_bset: %s: collecting: %s' % (self.bset, what))
        self.copy(src, dst)

    def install(self, name, buildroot, prefix):
        dst = prefix
        src = path.join(buildroot, prefix)
        log.notice('installing: %s -> %s' % (name, path.host(dst)))
        self.copy(src, dst)

    def canadian_cross(self, _build):
        # @fixme Switch to using a private macros map.
        macros_to_save = [
            '%{_prefix}', '%{_tmproot}', '%{buildroot}', '%{_builddir}',
            '%{_host}'
        ]
        macros_to_copy = [('%{_host}', '%{_build}'),
                          ('%{_tmproot}', '%{_tmpcxcroot}'),
                          ('%{buildroot}', '%{buildcxcroot}'),
                          ('%{_builddir}', '%{_buildcxcdir}')]
        orig_macros = {}
        for m in macros_to_save:
            orig_macros[m] = _build.config.macro(m)
        for m in macros_to_copy:
            _build.config.set_define(m[0], _build.config.macro(m[1]))
        _build.make()
        for m in macros_to_save:
            _build.config.set_define(m, orig_macros[m])
        if not _build.macros.get('%{_disable_collecting}'):
            self.root_copy(_build.config.expand('%{buildcxcroot}'),
                           _build.config.expand('%{_tmpcxcroot}'))

    def build_package(self, _config, _build):
        if not _build.disabled():
            if _build.canadian_cross():
                self.canadian_cross(_build)
            _build.make()
            if not _build.macros.get('%{_disable_collecting}'):
                self.root_copy(_build.config.expand('%{buildroot}'),
                               _build.config.expand('%{_tmproot}'))

    def bset_tar(self, _build):
        tardir = _build.config.expand('%{_tardir}')
        if self.opts.get_arg('--bset-tar-file') \
           and not _build.macros.get('%{_disable_packaging}'):
            path.mkdir(tardir)
            tar = path.join(
                tardir, _build.config.expand('%s.tar.bz2' % (self.bset_pkg)))
            log.notice('tarball: %s' % (os.path.relpath(path.host(tar))))
            if not self.opts.dry_run():
                tmproot = _build.config.expand('%{_tmproot}')
                cmd = _build.config.expand("'cd " + tmproot + \
                                               " && %{__tar} -cf - . | %{__bzip2} > " + tar + "'")
                _build.run(cmd, shell_opts='-c', cwd=tmproot)

    def parse(self, bset):
        def _clean(line):
            line = line[0:-1]
            b = line.find('#')
            if b >= 0:
                line = line[1:b]
            return line.strip()

        bsetname = bset

        if not path.exists(bsetname):
            for cp in self.macros.expand('%{_configdir}').split(':'):
                configdir = path.abspath(cp)
                bsetname = path.join(configdir, bset)
                if path.exists(bsetname):
                    break
                bsetname = None
            if bsetname is None:
                raise error.general('no build set file found: %s' % (bset))
        try:
            log.trace('_bset: %s: open: %s' % (self.bset, bsetname))
            bset = open(path.host(bsetname), 'r')
        except IOError, err:
            raise error.general('error opening bset file: %s' % (bsetname))

        configs = []

        try:
            lc = 0
            for l in bset:
                lc += 1
                l = _clean(l)
                if len(l) == 0:
                    continue
                log.trace('_bset: %s: %03d: %s' % (self.bset, lc, l))
                ls = l.split()
                if ls[0][-1] == ':' and ls[0][:-1] == 'package':
                    self.bset_pkg = self.macros.expand(ls[1].strip())
                    self.macros['package'] = self.bset_pkg
                elif ls[0][0] == '%':

                    def err(msg):
                        raise error.general('%s:%d: %s' % (self.bset, lc, msg))

                    if ls[0] == '%define':
                        if len(ls) > 2:
                            self.macros.define(
                                ls[1].strip(),
                                ' '.join([f.strip() for f in ls[2:]]))
                        else:
                            self.macros.define(ls[1].strip())
                    elif ls[0] == '%undefine':
                        if len(ls) > 2:
                            raise error.general('%s:%d: %undefine requires just the name' % \
                                                    (self.bset, lc))
                        self.macros.undefine(ls[1].strip())
                    elif ls[0] == '%include':
                        configs += self.parse(ls[1].strip())
                    elif ls[0] in ['%patch', '%source']:
                        sources.process(ls[0][1:], ls[1:], self.macros, err)
                    elif ls[0] == '%hash':
                        sources.hash(ls[1:], self.macros, err)
                else:
                    l = l.strip()
                    c = build.find_config(l, self.configs)
                    if c is None:
                        raise error.general('%s:%d: cannot find file: %s' %
                                            (self.bset, lc, l))
                    configs += [c]
        except:
            bset.close()
            raise

        bset.close()

        return configs
def load(args, optargs=None, defaults='%{_sbdir}/defaults.mc', logfile=True):
    """
    Copy the defaults, get the host specific values and merge them overriding
    any matching defaults, then create an options object to handle the command
    line merging in any command line overrides. Finally post process the
    command line.
    """

    global host_windows
    global host_posix

    #
    # Adjust the args to remove the wrapper.
    #
    args = args[1:]

    #
    # The path to this command.
    #
    command_path = path.dirname(path.abspath(args[0]))
    if len(command_path) == 0:
        command_path = '.'

    #
    # The command line contains the base defaults object all build objects copy
    # and modify by loading a configuration.
    #
    o = command_line(args, optargs,
                     macros.macros(name=defaults, sbdir=command_path),
                     command_path)

    overrides = None
    if os.name == 'nt':
        try:
            import windows
            overrides = windows.load()
            host_windows = True
            host_posix = False
        except:
            raise error.general('failed to load Windows host support')
    elif os.name == 'posix':
        uname = os.uname()
        try:
            if uname[0].startswith('MINGW64_NT'):
                import windows
                overrides = windows.load()
                host_windows = True
            elif uname[0].startswith('CYGWIN_NT'):
                import windows
                overrides = windows.load()
            elif uname[0] == 'Darwin':
                import darwin
                overrides = darwin.load()
            elif uname[0] == 'FreeBSD':
                import freebsd
                overrides = freebsd.load()
            elif uname[0] == 'NetBSD':
                import netbsd
                overrides = netbsd.load()
            elif uname[0] == 'Linux':
                import linux
                overrides = linux.load()
            elif uname[0] == 'SunOS':
                import solaris
                overrides = solaris.load()
        except error.general as ge:
            raise error.general('failed to load %s host support: %s' %
                                (uname[0], ge))
        except:
            raise error.general('failed to load %s host support' % (uname[0]))
    else:
        raise error.general('unsupported host type; please add')
    if overrides is None:
        raise error.general('no hosts defaults found; please add')
    for k in overrides:
        o.defaults[k] = overrides[k]

    o.sb_released()
    o.sb_git()
    o.rtems_options()
    o.pre_process()
    o.process()
    o.post_process(logfile)

    #
    # Load the release settings
    #
    def setting_error(msg):
        raise error.general(msg)

    hashes = version.load_release_settings('hashes')
    for hash in hashes:
        hs = hash[1].split()
        if len(hs) != 2:
            raise error.general('invalid release hash in VERSION')
        sources.hash((hs[0], hash[0], hs[1]), o.defaults, setting_error)
    release_path = version.load_release_setting('version',
                                                'release_path',
                                                raw=True)
    if release_path is not None:
        try:
            release_path = ','.join(
                [rp.strip() for rp in release_path.split(',')])
        except:
            raise error.general('invalid release path in VERSION')
        download.set_release_path(release_path, o.defaults)
    return o