Changeset f179dc6 in rtems-source-builder


Ignore:
Timestamp:
Jun 8, 2017, 6:03:15 AM (3 years ago)
Author:
Chris Johns <chrisj@…>
Branches:
4.11
Children:
d3aced9
Parents:
d57380a
git-author:
Chris Johns <chrisj@…> (06/08/17 06:03:15)
git-committer:
Chris Johns <chrisj@…> (06/14/17 01:22:50)
Message:

sb: Backport from master the '--rsb-file=' option.

Upates #3033.

Location:
source-builder/sb
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • source-builder/sb/build.py

    rd57380a rf179dc6  
    210210                raise error.internal('source macro not found: %s in %s (%s)' % \
    211211                                         (s, name, _map))
    212             url = self.config.expand(sm[2])
    213             src = download.parse_url(url, '_sourcedir', self.config, self.opts)
     212            opts = []
     213            url = []
     214            for sp in sm[2].split():
     215                if len(url) == 0 and sp[0] == '-':
     216                    opts += [sp]
     217                else:
     218                    url += [sp]
     219            if len(url) == 0:
     220                raise error.general('source URL not found: %s' % (' '.join(args)))
     221            #
     222            # Look for --rsb-file as an option we use as a local file name.
     223            # This can be used if a URL has no reasonable file name the
     224            # download URL parser can figure out.
     225            #
     226            file_override = None
     227            if len(opts) > 0:
     228                for o in opts:
     229                    if o.startswith('--rsb-file'):
     230                       os_ = o.split('=')
     231                       if len(os_) != 2:
     232                           raise error.general('invalid --rsb-file option: %s' % (' '.join(args)))
     233                       if os_[0] != '--rsb-file':
     234                           raise error.general('invalid --rsb-file option: %s' % (' '.join(args)))
     235                       file_override = os_[1]
     236                opts = [o for o in opts if not o.startswith('--rsb-')]
     237            url = self.config.expand(' '.join(url))
     238            src = download.parse_url(url, '_sourcedir', self.config, self.opts, file_override)
    214239            download.get_file(src['url'], src['local'], self.opts, self.config)
    215240            if 'symlink' in src:
     
    304329            if len(url) == 0:
    305330                raise error.general('patch URL not found: %s' % (' '.join(args)))
     331            #
     332            # Look for --rsb-file as an option we use as a local file name.
     333            # This can be used if a URL has no reasonable file name the
     334            # download URL parser can figure out.
     335            #
     336            file_override = None
     337            if len(opts) > 0:
     338                for o in opts:
     339                    if o.startswith('--rsb-file'):
     340                       os_ = o.split('=')
     341                       if len(os_) != 2:
     342                           raise error.general('invalid --rsb-file option: %s' % (' '.join(args)))
     343                       if os_[0] != '--rsb-file':
     344                           raise error.general('invalid --rsb-file option: %s' % (' '.join(args)))
     345                       file_override = os_[1]
     346                opts = [o for o in opts if not o.startswith('--rsb-')]
    306347            if len(opts) == 0:
    307348                opts = default_opts
     
    313354            # Parse the URL first in the source builder's patch directory.
    314355            #
    315             patch = download.parse_url(url, '_patchdir', self.config, self.opts)
    316             #
    317             # If not in the source builder package check the source directory.
    318             #
    319             if not path.exists(patch['local']):
    320                 patch = download.parse_url(url, '_patchdir', self.config, self.opts)
     356            patch = download.parse_url(url, '_patchdir', self.config, self.opts, file_override)
     357            #
     358            # Download the patch
     359            #
    321360            download.get_file(patch['url'], patch['local'], self.opts, self.config)
    322361            if 'compressed' in patch:
  • source-builder/sb/download.py

    rd57380a rf179dc6  
    2727import hashlib
    2828import os
     29import re
    2930import stat
    3031import sys
     
    131132def _local_path(source, pathkey, config):
    132133    for p in config.define(pathkey).split(':'):
    133         local = path.join(path.abspath(p), source['file'])
     134        local_prefix = path.abspath(p)
     135        local = path.join(local_prefix, source['file'])
    134136        if source['local'] is None:
    135             source['local_prefix'] = path.abspath(p)
     137            source['local_prefix'] = local_prefix
    136138            source['local'] = local
    137139        if path.exists(local):
    138             source['local_prefix'] = path.abspath(p)
     140            source['local_prefix'] = local_prefix
    139141            source['local'] = local
    140142            _hash_check(source['file'], local, config.macros)
     
    143145def _http_parser(source, pathkey, config, opts):
    144146    #
    145     # Hack for gitweb.cgi patch downloads. We rewrite the various fields.
    146     #
    147     if 'gitweb.cgi' in source['url']:
    148         url = source['url']
    149         if '?' not in url:
    150             raise error.general('invalid gitweb.cgi request: %s' % (url))
    151         req = url.split('?')[1]
    152         if len(req) == 0:
    153             raise error.general('invalid gitweb.cgi request: %s' % (url))
    154         #
    155         # The gitweb.cgi request should have:
    156         #    p=<what>
    157         #    a=patch
    158         #    h=<hash>
    159         # so extract the p and h parts to make the local name.
    160         #
    161         p = None
    162         a = None
    163         h = None
    164         for r in req.split(';'):
    165             if '=' not in r:
    166                 raise error.general('invalid gitweb.cgi path: %s' % (url))
    167             rs = r.split('=')
    168             if rs[0] == 'p':
    169                 p = rs[1].replace('.', '-')
    170             elif rs[0] == 'a':
    171                 a = rs[1]
    172             elif rs[0] == 'h':
    173                 h = rs[1]
    174         if p is None or h is None:
    175             raise error.general('gitweb.cgi path missing p or h: %s' % (url))
    176         source['file'] = '%s-%s.patch' % (p, h)
    177     #
    178     # Check the source file name for any extra request query data and remove if
    179     # found. Some hosts do not like file names containing them.
    180     #
    181     if '?' in source['file']:
    182         qmark = source['file'].find('?')
    183         source['file'] = source['file'][:qmark]
     147    # If the file has not been overrided attempt to recover a possible file name.
     148    #
     149    if 'file-override' not in source['options']:
     150        #
     151        # Hack for gitweb.cgi patch downloads. We rewrite the various fields.
     152        #
     153        if 'gitweb.cgi' in source['url']:
     154            url = source['url']
     155            if '?' not in url:
     156                raise error.general('invalid gitweb.cgi request: %s' % (url))
     157            req = url.split('?')[1]
     158            if len(req) == 0:
     159                raise error.general('invalid gitweb.cgi request: %s' % (url))
     160            #
     161            # The gitweb.cgi request should have:
     162            #    p=<what>
     163            #    a=patch
     164            #    h=<hash>
     165            # so extract the p and h parts to make the local name.
     166            #
     167            p = None
     168            a = None
     169            h = None
     170            for r in req.split(';'):
     171                if '=' not in r:
     172                    raise error.general('invalid gitweb.cgi path: %s' % (url))
     173                rs = r.split('=')
     174                if rs[0] == 'p':
     175                    p = rs[1].replace('.', '-')
     176                elif rs[0] == 'a':
     177                    a = rs[1]
     178                elif rs[0] == 'h':
     179                    h = rs[1]
     180            if p is None or h is None:
     181                raise error.general('gitweb.cgi path missing p or h: %s' % (url))
     182            source['file'] = '%s-%s.patch' % (p, h)
     183        #
     184        # Check the source file name for any extra request query data and remove if
     185        # found. Some hosts do not like file names containing them.
     186        #
     187        if '?' in source['file']:
     188            qmark = source['file'].find('?')
     189            source['file'] = source['file'][:qmark]
    184190    #
    185191    # Check local path
     
    302308    macros.define('release_path', release_path)
    303309
    304 def parse_url(url, pathkey, config, opts):
     310def parse_url(url, pathkey, config, opts, file_override = None):
    305311    #
    306312    # Split the source up into the parts we need.
     
    308314    source = {}
    309315    source['url'] = url
     316    source['options'] = []
    310317    colon = url.find(':')
    311318    if url[colon + 1:colon + 3] != '//':
    312319        raise error.general('malforned URL (no protocol prefix): %s' % (url))
    313320    source['path'] = url[:colon + 3] + path.dirname(url[colon + 3:])
    314     source['file'] = path.basename(url)
     321    if file_override is None:
     322        source['file'] = path.basename(url)
     323    else:
     324        bad_chars = [c for c in ['/', '\\', '?', '*'] if c in file_override]
     325        if len(bad_chars) > 0:
     326            raise error.general('bad characters in file name: %s' % (file_override))
     327
     328        log.output('download: file-override: %s' % (file_override))
     329        source['file'] = file_override
     330        source['options'] += ['file-override']
    315331    source['name'], source['ext'] = path.splitext(source['file'])
    316332    if source['name'].endswith('.tar'):
     
    338354        url = urllib_parse.urljoin(url, config.expand('tarball/%{version}'))
    339355    dst = os.path.relpath(path.host(local))
    340     log.output('download: %s -> %s' % (url, dst))
     356    log.output('download: (full) %s -> %s' % (url, dst))
    341357    log.notice('download: %s -> %s' % (_sensible_url(url, len(dst)), dst))
    342358    failed = False
     
    364380                    _in = urllib_request.urlopen(_req, context = _ssl_context)
    365381                except:
     382                    log.output('download: no ssl context')
    366383                    _ssl_context = None
    367384                if _ssl_context is None:
Note: See TracChangeset for help on using the changeset viewer.