Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | """ |
| 2 | BitBake 'Fetch' implementations |
| 3 | |
| 4 | Classes for obtaining upstream sources for the |
| 5 | BitBake build tools. |
| 6 | |
| 7 | """ |
| 8 | |
| 9 | # Copyright (C) 2003, 2004 Chris Larson |
| 10 | # |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 11 | # SPDX-License-Identifier: GPL-2.0-only |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 12 | # |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 13 | # Based on functions from the base bb module, Copyright 2003 Holger Schurig |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 14 | # |
| 15 | |
| 16 | import os |
| 17 | import logging |
| 18 | import bb |
| 19 | from bb.fetch2 import FetchMethod, FetchError, MissingParameterError, logger |
| 20 | from bb.fetch2 import runfetchcmd |
| 21 | |
| 22 | class Cvs(FetchMethod): |
| 23 | """ |
| 24 | Class to fetch a module or modules from cvs repositories |
| 25 | """ |
| 26 | def supports(self, ud, d): |
| 27 | """ |
| 28 | Check to see if a given url can be fetched with cvs. |
| 29 | """ |
| 30 | return ud.type in ['cvs'] |
| 31 | |
| 32 | def urldata_init(self, ud, d): |
| 33 | if not "module" in ud.parm: |
| 34 | raise MissingParameterError("module", ud.url) |
| 35 | ud.module = ud.parm["module"] |
| 36 | |
| 37 | ud.tag = ud.parm.get('tag', "") |
| 38 | |
| 39 | # Override the default date in certain cases |
| 40 | if 'date' in ud.parm: |
| 41 | ud.date = ud.parm['date'] |
| 42 | elif ud.tag: |
| 43 | ud.date = "" |
| 44 | |
| 45 | norecurse = '' |
| 46 | if 'norecurse' in ud.parm: |
| 47 | norecurse = '_norecurse' |
| 48 | |
| 49 | fullpath = '' |
| 50 | if 'fullpath' in ud.parm: |
| 51 | fullpath = '_fullpath' |
| 52 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 53 | 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] | 54 | |
| 55 | def need_update(self, ud, d): |
| 56 | if (ud.date == "now"): |
| 57 | return True |
| 58 | if not os.path.exists(ud.localpath): |
| 59 | return True |
| 60 | return False |
| 61 | |
| 62 | def download(self, ud, d): |
| 63 | |
| 64 | method = ud.parm.get('method', 'pserver') |
| 65 | localdir = ud.parm.get('localdir', ud.module) |
| 66 | cvs_port = ud.parm.get('port', '') |
| 67 | |
| 68 | cvs_rsh = None |
| 69 | if method == "ext": |
| 70 | if "rsh" in ud.parm: |
| 71 | cvs_rsh = ud.parm["rsh"] |
| 72 | |
| 73 | if method == "dir": |
| 74 | cvsroot = ud.path |
| 75 | else: |
| 76 | cvsroot = ":" + method |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 77 | cvsproxyhost = d.getVar('CVS_PROXY_HOST') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 78 | if cvsproxyhost: |
| 79 | cvsroot += ";proxy=" + cvsproxyhost |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 80 | cvsproxyport = d.getVar('CVS_PROXY_PORT') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 81 | if cvsproxyport: |
| 82 | cvsroot += ";proxyport=" + cvsproxyport |
| 83 | cvsroot += ":" + ud.user |
| 84 | if ud.pswd: |
| 85 | cvsroot += ":" + ud.pswd |
| 86 | cvsroot += "@" + ud.host + ":" + cvs_port + ud.path |
| 87 | |
| 88 | options = [] |
| 89 | if 'norecurse' in ud.parm: |
| 90 | options.append("-l") |
| 91 | if ud.date: |
| 92 | # treat YYYYMMDDHHMM specially for CVS |
| 93 | if len(ud.date) == 12: |
| 94 | options.append("-D \"%s %s:%s UTC\"" % (ud.date[0:8], ud.date[8:10], ud.date[10:12])) |
| 95 | else: |
| 96 | options.append("-D \"%s UTC\"" % ud.date) |
| 97 | if ud.tag: |
| 98 | options.append("-r %s" % ud.tag) |
| 99 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 100 | cvsbasecmd = d.getVar("FETCHCMD_cvs") or "/usr/bin/env cvs" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 101 | cvscmd = cvsbasecmd + " '-d" + cvsroot + "' co " + " ".join(options) + " " + ud.module |
| 102 | cvsupdatecmd = cvsbasecmd + " '-d" + cvsroot + "' update -d -P " + " ".join(options) |
| 103 | |
| 104 | if cvs_rsh: |
| 105 | cvscmd = "CVS_RSH=\"%s\" %s" % (cvs_rsh, cvscmd) |
| 106 | cvsupdatecmd = "CVS_RSH=\"%s\" %s" % (cvs_rsh, cvsupdatecmd) |
| 107 | |
| 108 | # create module directory |
| 109 | logger.debug(2, "Fetch: checking for module directory") |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 110 | pkg = d.getVar('PN') |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 111 | cvsdir = d.getVar("CVSDIR") or (d.getVar("DL_DIR") + "/cvs") |
| 112 | pkgdir = os.path.join(cvsdir, pkg) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 113 | moddir = os.path.join(pkgdir, localdir) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 114 | workdir = None |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 115 | if os.access(os.path.join(moddir, 'CVS'), os.R_OK): |
| 116 | logger.info("Update " + ud.url) |
| 117 | bb.fetch2.check_network_access(d, cvsupdatecmd, ud.url) |
| 118 | # update sources there |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 119 | workdir = moddir |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 120 | cmd = cvsupdatecmd |
| 121 | else: |
| 122 | logger.info("Fetch " + ud.url) |
| 123 | # check out sources there |
| 124 | bb.utils.mkdirhier(pkgdir) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 125 | workdir = pkgdir |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 126 | logger.debug(1, "Running %s", cvscmd) |
| 127 | bb.fetch2.check_network_access(d, cvscmd, ud.url) |
| 128 | cmd = cvscmd |
| 129 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 130 | runfetchcmd(cmd, d, cleanup=[moddir], workdir=workdir) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 131 | |
| 132 | if not os.access(moddir, os.R_OK): |
| 133 | raise FetchError("Directory %s was not readable despite sucessful fetch?!" % moddir, ud.url) |
| 134 | |
| 135 | scmdata = ud.parm.get("scmdata", "") |
| 136 | if scmdata == "keep": |
| 137 | tar_flags = "" |
| 138 | else: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 139 | tar_flags = "--exclude='CVS'" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 140 | |
| 141 | # tar them up to a defined filename |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 142 | workdir = None |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 143 | if 'fullpath' in ud.parm: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 144 | workdir = pkgdir |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 145 | cmd = "tar %s -czf %s %s" % (tar_flags, ud.localpath, localdir) |
| 146 | else: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 147 | workdir = os.path.dirname(os.path.realpath(moddir)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 148 | cmd = "tar %s -czf %s %s" % (tar_flags, ud.localpath, os.path.basename(moddir)) |
| 149 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 150 | runfetchcmd(cmd, d, cleanup=[ud.localpath], workdir=workdir) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 151 | |
| 152 | def clean(self, ud, d): |
| 153 | """ Clean CVS Files and tarballs """ |
| 154 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 155 | pkg = d.getVar('PN') |
| 156 | pkgdir = os.path.join(d.getVar("CVSDIR"), pkg) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 157 | |
| 158 | bb.utils.remove(pkgdir, True) |
| 159 | bb.utils.remove(ud.localpath) |
| 160 | |