Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | # ex:ts=4:sw=4:sts=4:et |
| 2 | # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- |
| 3 | """ |
| 4 | BitBake 'Fetch' implementations |
| 5 | |
| 6 | Classes for obtaining upstream sources for the |
| 7 | BitBake build tools. |
| 8 | |
| 9 | """ |
| 10 | |
| 11 | # Copyright (C) 2003, 2004 Chris Larson |
| 12 | # |
| 13 | # This program is free software; you can redistribute it and/or modify |
| 14 | # it under the terms of the GNU General Public License version 2 as |
| 15 | # published by the Free Software Foundation. |
| 16 | # |
| 17 | # This program is distributed in the hope that it will be useful, |
| 18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | # GNU General Public License for more details. |
| 21 | # |
| 22 | # You should have received a copy of the GNU General Public License along |
| 23 | # with this program; if not, write to the Free Software Foundation, Inc., |
| 24 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 25 | # |
| 26 | #Based on functions from the base bb module, Copyright 2003 Holger Schurig |
| 27 | # |
| 28 | |
| 29 | import os |
| 30 | import logging |
| 31 | import bb |
| 32 | from bb.fetch2 import FetchMethod, FetchError, MissingParameterError, logger |
| 33 | from bb.fetch2 import runfetchcmd |
| 34 | |
| 35 | class Cvs(FetchMethod): |
| 36 | """ |
| 37 | Class to fetch a module or modules from cvs repositories |
| 38 | """ |
| 39 | def supports(self, ud, d): |
| 40 | """ |
| 41 | Check to see if a given url can be fetched with cvs. |
| 42 | """ |
| 43 | return ud.type in ['cvs'] |
| 44 | |
| 45 | def urldata_init(self, ud, d): |
| 46 | if not "module" in ud.parm: |
| 47 | raise MissingParameterError("module", ud.url) |
| 48 | ud.module = ud.parm["module"] |
| 49 | |
| 50 | ud.tag = ud.parm.get('tag', "") |
| 51 | |
| 52 | # Override the default date in certain cases |
| 53 | if 'date' in ud.parm: |
| 54 | ud.date = ud.parm['date'] |
| 55 | elif ud.tag: |
| 56 | ud.date = "" |
| 57 | |
| 58 | norecurse = '' |
| 59 | if 'norecurse' in ud.parm: |
| 60 | norecurse = '_norecurse' |
| 61 | |
| 62 | fullpath = '' |
| 63 | if 'fullpath' in ud.parm: |
| 64 | fullpath = '_fullpath' |
| 65 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 66 | ud.localfile = d.expand('%s_%s_%s_%s%s%s.tar.gz' % (ud.module.replace('/', '.'), ud.host, ud.tag, ud.date, norecurse, fullpath)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 67 | |
| 68 | def need_update(self, ud, d): |
| 69 | if (ud.date == "now"): |
| 70 | return True |
| 71 | if not os.path.exists(ud.localpath): |
| 72 | return True |
| 73 | return False |
| 74 | |
| 75 | def download(self, ud, d): |
| 76 | |
| 77 | method = ud.parm.get('method', 'pserver') |
| 78 | localdir = ud.parm.get('localdir', ud.module) |
| 79 | cvs_port = ud.parm.get('port', '') |
| 80 | |
| 81 | cvs_rsh = None |
| 82 | if method == "ext": |
| 83 | if "rsh" in ud.parm: |
| 84 | cvs_rsh = ud.parm["rsh"] |
| 85 | |
| 86 | if method == "dir": |
| 87 | cvsroot = ud.path |
| 88 | else: |
| 89 | cvsroot = ":" + method |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 90 | cvsproxyhost = d.getVar('CVS_PROXY_HOST') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 91 | if cvsproxyhost: |
| 92 | cvsroot += ";proxy=" + cvsproxyhost |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 93 | cvsproxyport = d.getVar('CVS_PROXY_PORT') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 94 | if cvsproxyport: |
| 95 | cvsroot += ";proxyport=" + cvsproxyport |
| 96 | cvsroot += ":" + ud.user |
| 97 | if ud.pswd: |
| 98 | cvsroot += ":" + ud.pswd |
| 99 | cvsroot += "@" + ud.host + ":" + cvs_port + ud.path |
| 100 | |
| 101 | options = [] |
| 102 | if 'norecurse' in ud.parm: |
| 103 | options.append("-l") |
| 104 | if ud.date: |
| 105 | # treat YYYYMMDDHHMM specially for CVS |
| 106 | if len(ud.date) == 12: |
| 107 | options.append("-D \"%s %s:%s UTC\"" % (ud.date[0:8], ud.date[8:10], ud.date[10:12])) |
| 108 | else: |
| 109 | options.append("-D \"%s UTC\"" % ud.date) |
| 110 | if ud.tag: |
| 111 | options.append("-r %s" % ud.tag) |
| 112 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 113 | cvsbasecmd = d.getVar("FETCHCMD_cvs") or "/usr/bin/env cvs" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 114 | cvscmd = cvsbasecmd + " '-d" + cvsroot + "' co " + " ".join(options) + " " + ud.module |
| 115 | cvsupdatecmd = cvsbasecmd + " '-d" + cvsroot + "' update -d -P " + " ".join(options) |
| 116 | |
| 117 | if cvs_rsh: |
| 118 | cvscmd = "CVS_RSH=\"%s\" %s" % (cvs_rsh, cvscmd) |
| 119 | cvsupdatecmd = "CVS_RSH=\"%s\" %s" % (cvs_rsh, cvsupdatecmd) |
| 120 | |
| 121 | # create module directory |
| 122 | logger.debug(2, "Fetch: checking for module directory") |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 123 | pkg = d.getVar('PN') |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 124 | cvsdir = d.getVar("CVSDIR") or (d.getVar("DL_DIR") + "/cvs") |
| 125 | pkgdir = os.path.join(cvsdir, pkg) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 126 | moddir = os.path.join(pkgdir, localdir) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 127 | workdir = None |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 128 | if os.access(os.path.join(moddir, 'CVS'), os.R_OK): |
| 129 | logger.info("Update " + ud.url) |
| 130 | bb.fetch2.check_network_access(d, cvsupdatecmd, ud.url) |
| 131 | # update sources there |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 132 | workdir = moddir |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 133 | cmd = cvsupdatecmd |
| 134 | else: |
| 135 | logger.info("Fetch " + ud.url) |
| 136 | # check out sources there |
| 137 | bb.utils.mkdirhier(pkgdir) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 138 | workdir = pkgdir |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 139 | logger.debug(1, "Running %s", cvscmd) |
| 140 | bb.fetch2.check_network_access(d, cvscmd, ud.url) |
| 141 | cmd = cvscmd |
| 142 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 143 | runfetchcmd(cmd, d, cleanup=[moddir], workdir=workdir) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 144 | |
| 145 | if not os.access(moddir, os.R_OK): |
| 146 | raise FetchError("Directory %s was not readable despite sucessful fetch?!" % moddir, ud.url) |
| 147 | |
| 148 | scmdata = ud.parm.get("scmdata", "") |
| 149 | if scmdata == "keep": |
| 150 | tar_flags = "" |
| 151 | else: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 152 | tar_flags = "--exclude='CVS'" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 153 | |
| 154 | # tar them up to a defined filename |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 155 | workdir = None |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 156 | if 'fullpath' in ud.parm: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 157 | workdir = pkgdir |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 158 | cmd = "tar %s -czf %s %s" % (tar_flags, ud.localpath, localdir) |
| 159 | else: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 160 | workdir = os.path.dirname(os.path.realpath(moddir)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 161 | cmd = "tar %s -czf %s %s" % (tar_flags, ud.localpath, os.path.basename(moddir)) |
| 162 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 163 | runfetchcmd(cmd, d, cleanup=[ud.localpath], workdir=workdir) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 164 | |
| 165 | def clean(self, ud, d): |
| 166 | """ Clean CVS Files and tarballs """ |
| 167 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 168 | pkg = d.getVar('PN') |
| 169 | pkgdir = os.path.join(d.getVar("CVSDIR"), pkg) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 170 | |
| 171 | bb.utils.remove(pkgdir, True) |
| 172 | bb.utils.remove(ud.localpath) |
| 173 | |