Changeset 649a64c in rtems-source-builder for source-builder/sb/build.py


Ignore:
Timestamp:
Apr 16, 2013, 4:25:34 AM (8 years ago)
Author:
Chris Johns <chrisj@…>
Branches:
4.10, 4.11, 4.9, 5, master
Children:
82e9f91
Parents:
b022691
git-author:
Chris Johns <chrisj@…> (04/16/13 04:25:34)
git-committer:
Chris Johns <chrisj@…> (04/16/13 04:28:34)
Message:

Add download git support.

Add support to use a git cloned repo as the source. Move the download
code out of the build module and into a separate module. Add to this
module support for git.

Update the GCC common configuration to support using a symlinked
git repo.

Add checks for all languages.

File:
1 edited

Legend:

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

    rb022691 r649a64c  
    11#
    22# RTEMS Tools Project (http://www.rtems.org/)
    3 # Copyright 2010-2012 Chris Johns (chrisj@rtems.org)
     3# Copyright 2010-2013 Chris Johns (chrisj@rtems.org)
    44# All rights reserved.
    55#
     
    3535    import check
    3636    import config
     37    import download
    3738    import error
    3839    import execute
     
    126127            path.mkdir(mkpath)
    127128
    128     def get_file(self, url, local):
    129         if local is None:
    130             raise error.general('source/patch path invalid')
    131         if not path.isdir(path.dirname(local)) and not self.opts.download_disabled():
    132             _notice(self.opts,
    133                     'Creating source directory: %s' % (os.path.relpath(path.host(path.dirname(local)))))
    134             self.mkdir(path.host(path.dirname(local)))
    135         if not path.exists(local):
    136             if self.opts.download_disabled():
    137                 raise error.general('source not found: %s' % (path.host(local)))
    138             #
    139             # Not localy found so we need to download it. Check if a URL has
    140             # been provided on the command line.
    141             #
    142             url_bases = self.opts.urls()
    143             urls = []
    144             if url_bases is not None:
    145                 for base in url_bases:
    146                     if base[-1:] != '/':
    147                         base += '/'
    148                     url_path = urlparse.urlsplit(url)[2]
    149                     slash = url_path.rfind('/')
    150                     if slash < 0:
    151                         url_file = url_path
    152                     else:
    153                         url_file = url_path[slash + 1:]
    154                     urls.append(urlparse.urljoin(base, url_file))
    155             urls.append(url)
    156             if self.opts.trace():
    157                 print '_url:', ','.join(urls), '->', local
    158             for url in urls:
    159                 #
    160                 # Hack for GitHub.
    161                 #
    162                 if url.startswith('https://api.github.com'):
    163                     url = urlparse.urljoin(url, self.config.expand('tarball/%{version}'))
    164                 _notice(self.opts, 'download: %s -> %s' % (url, os.path.relpath(path.host(local))))
    165                 if not self.opts.dry_run():
    166                     failed = False
    167                     _in = None
    168                     _out = None
    169                     try:
    170                         _in = urllib2.urlopen(url)
    171                         _out = open(path.host(local), 'wb')
    172                         _out.write(_in.read())
    173                     except IOError, err:
    174                         msg = 'download: %s: error: %s' % (url, str(err))
    175                         _notice(self.opts, msg)
    176                         if path.exists(local):
    177                             os.remove(path.host(local))
    178                         failed = True
    179                     except ValueError, err:
    180                         msg = 'download: %s: error: %s' % (url, str(err))
    181                         _notice(self.opts, msg)
    182                         if path.exists(local):
    183                             os.remove(path.host(local))
    184                         failed = True
    185                     except:
    186                         msg = 'download: %s: error' % (url)
    187                         print >> sys.stderr, msg
    188                         if _out is not None:
    189                             _out.close()
    190                         raise
    191                     if _out is not None:
    192                         _out.close()
    193                     if _in is not None:
    194                         del _in
    195                     if not failed:
    196                         if not path.isfile(local):
    197                             raise error.general('source is not a file: %s' % (path.host(local)))
    198                         return
    199             if not self.opts.dry_run():
    200                 raise error.general('downloading %s: all paths have failed, giving up' % (url))
    201 
    202     def parse_url(self, url, pathkey):
    203         #
    204         # Split the source up into the parts we need.
    205         #
    206         source = {}
    207         source['url'] = url
    208         source['path'] = path.dirname(url)
    209         source['file'] = path.basename(url)
    210         source['name'], source['ext'] = path.splitext(source['file'])
    211         #
    212         # Get the file. Checks the local source directory first.
    213         #
    214         source['local'] = None
    215         for p in self.config.define(pathkey).split(':'):
    216             local = path.join(path.abspath(p), source['file'])
    217             if source['local'] is None:
    218                 source['local'] = local
    219             if path.exists(local):
    220                 source['local'] = local
    221                 break
    222         #
    223         # Is the file compressed ?
    224         #
    225         esl = source['ext'].split('.')
    226         if esl[-1:][0] == 'gz':
    227             source['compressed'] = '%{__gzip} -dc'
    228         elif esl[-1:][0] == 'bz2':
    229             source['compressed'] = '%{__bzip2} -dc'
    230         elif esl[-1:][0] == 'bz2':
    231             source['compressed'] = '%{__zip} -u'
    232         elif esl[-1:][0] == 'xz':
    233             source['compressed'] = '%{__xz} -dc'
    234         source['script'] = ''
    235         return source
    236 
    237129    def source(self, package, source_tag):
    238130        #
     
    251143        if url is None:
    252144            raise error.general('source tag not found: source%d' % (source_tag))
    253         source = self.parse_url(url, '_sourcedir')
    254         self.get_file(source['url'], source['local'])
    255         if 'compressed' in source:
     145        source = download.parse_url(url, '_sourcedir', self.config, self.opts)
     146        download.get_file(source['url'], source['local'], self.opts, self.config)
     147        if 'symlink' in source:
     148            source['script'] = '%%{__ln_s} %s ${source_dir_%d}' % (source['local'], source_tag)
     149        elif 'compressed' in source:
    256150            source['script'] = source['compressed'] + ' ' + \
    257151                source['local'] + ' | %{__tar_extract} -'
     
    276170        # Parse the URL first in the source builder's patch directory.
    277171        #
    278         patch = self.parse_url(url, '_patchdir')
     172        patch = download.parse_url(url, '_patchdir', self.config, self.opts)
    279173        #
    280174        # If not in the source builder package check the source directory.
    281175        #
    282176        if not path.exists(patch['local']):
    283             patch = self.parse_url(url, '_patchdir')
    284         self.get_file(patch['url'], patch['local'])
     177            patch = download.parse_url(url, '_patchdir', self.config, self.opts)
     178        download.get_file(patch['url'], patch['local'], self.opts, self.config)
    285179        if 'compressed' in patch:
    286180            patch['script'] = patch['compressed'] + ' ' +  patch['local']
Note: See TracChangeset for help on using the changeset viewer.