Changeset 383f7e6 in rtems-source-builder


Ignore:
Timestamp:
Apr 15, 2016, 1:44:27 AM (4 years ago)
Author:
Chris Johns <chrisj@…>
Branches:
4.10, 4.9, master
Children:
c139715
Parents:
c98555c
git-author:
Chris Johns <chrisj@…> (04/15/16 01:44:27)
git-committer:
Chris Johns <chrisj@…> (04/15/16 01:59:30)
Message:

sb: Add --rsb-file options to %source and %patch to set a file name.

Override the automatic file name of a downloaded file and use the file
name provided by the option. This is useful if the URL has no meanful
file that can be automatically extracted from the URL.

Location:
source-builder/sb
Files:
2 edited

Legend:

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

    rc98555c r383f7e6  
    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

    rc98555c r383f7e6  
    131131def _local_path(source, pathkey, config):
    132132    for p in config.define(pathkey).split(':'):
    133         local = path.join(path.abspath(p), source['file'])
     133        local_prefix = path.abspath(p)
     134        local = path.join(local_prefix, source['file'])
    134135        if source['local'] is None:
    135             source['local_prefix'] = path.abspath(p)
     136            source['local_prefix'] = local_prefix
    136137            source['local'] = local
    137138        if path.exists(local):
    138             source['local_prefix'] = path.abspath(p)
     139            source['local_prefix'] = local_prefix
    139140            source['local'] = local
    140141            _hash_check(source['file'], local, config.macros)
     
    143144def _http_parser(source, pathkey, config, opts):
    144145    #
    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]
     146    # If the file has not been overrided attempt to recover a possible file name.
     147    #
     148    if 'file-override' not in source['options']:
     149        #
     150        # Hack for gitweb.cgi patch downloads. We rewrite the various fields.
     151        #
     152        if 'gitweb.cgi' in source['url']:
     153            url = source['url']
     154            if '?' not in url:
     155                raise error.general('invalid gitweb.cgi request: %s' % (url))
     156            req = url.split('?')[1]
     157            if len(req) == 0:
     158                raise error.general('invalid gitweb.cgi request: %s' % (url))
     159            #
     160            # The gitweb.cgi request should have:
     161            #    p=<what>
     162            #    a=patch
     163            #    h=<hash>
     164            # so extract the p and h parts to make the local name.
     165            #
     166            p = None
     167            a = None
     168            h = None
     169            for r in req.split(';'):
     170                if '=' not in r:
     171                    raise error.general('invalid gitweb.cgi path: %s' % (url))
     172                rs = r.split('=')
     173                if rs[0] == 'p':
     174                    p = rs[1].replace('.', '-')
     175                elif rs[0] == 'a':
     176                    a = rs[1]
     177                elif rs[0] == 'h':
     178                    h = rs[1]
     179            if p is None or h is None:
     180                raise error.general('gitweb.cgi path missing p or h: %s' % (url))
     181            source['file'] = '%s-%s.patch' % (p, h)
     182        #
     183        # Check the source file name for any extra request query data and remove if
     184        # found. Some hosts do not like file names containing them.
     185        #
     186        if '?' in source['file']:
     187            qmark = source['file'].find('?')
     188            source['file'] = source['file'][:qmark]
    184189    #
    185190    # Check local path
     
    297302            'file': _file_parser }
    298303
    299 def parse_url(url, pathkey, config, opts):
     304def parse_url(url, pathkey, config, opts, file_override = None):
    300305    #
    301306    # Split the source up into the parts we need.
     
    303308    source = {}
    304309    source['url'] = url
     310    source['options'] = []
    305311    colon = url.find(':')
    306312    if url[colon + 1:colon + 3] != '//':
    307313        raise error.general('malforned URL (no protocol prefix): %s' % (url))
    308314    source['path'] = url[:colon + 3] + path.dirname(url[colon + 3:])
    309     source['file'] = path.basename(url)
     315    if file_override is None:
     316        source['file'] = path.basename(url)
     317    else:
     318        bad_chars = [c for c in ['/', '\\', '?', '*'] if c in file_override]
     319        if len(bad_chars) > 0:
     320            raise error.general('bad characters in file name: %s' % (file_override))
     321
     322        log.output('download: file-override: %s' % (file_override))
     323        source['file'] = file_override
     324        source['options'] += ['file-override']
    310325    source['name'], source['ext'] = path.splitext(source['file'])
    311326    if source['name'].endswith('.tar'):
     
    333348        url = urllib_parse.urljoin(url, config.expand('tarball/%{version}'))
    334349    dst = os.path.relpath(path.host(local))
    335     log.output('download: %s -> %s' % (url, dst))
     350    log.output('download: (full) %s -> %s' % (url, dst))
    336351    log.notice('download: %s -> %s' % (_sensible_url(url, len(dst)), dst))
    337352    failed = False
     
    359374                    _in = urllib_request.urlopen(_req, context = _ssl_context)
    360375                except:
     376                    log.output('download: no ssl context')
    361377                    _ssl_context = None
    362378                if _ssl_context is None:
Note: See TracChangeset for help on using the changeset viewer.