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 |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 17 | import bb |
| 18 | from bb.fetch2 import FetchMethod, FetchError, MissingParameterError, logger |
| 19 | from bb.fetch2 import runfetchcmd |
| 20 | |
| 21 | class Cvs(FetchMethod): |
| 22 | """ |
| 23 | Class to fetch a module or modules from cvs repositories |
| 24 | """ |
| 25 | def supports(self, ud, d): |
| 26 | """ |
| 27 | Check to see if a given url can be fetched with cvs. |
| 28 | """ |
| 29 | return ud.type in ['cvs'] |
| 30 | |
| 31 | def urldata_init(self, ud, d): |
| 32 | if not "module" in ud.parm: |
| 33 | raise MissingParameterError("module", ud.url) |
| 34 | ud.module = ud.parm["module"] |
| 35 | |
| 36 | ud.tag = ud.parm.get('tag', "") |
| 37 | |
| 38 | # Override the default date in certain cases |
| 39 | if 'date' in ud.parm: |
| 40 | ud.date = ud.parm['date'] |
| 41 | elif ud.tag: |
| 42 | ud.date = "" |
| 43 | |
| 44 | norecurse = '' |
| 45 | if 'norecurse' in ud.parm: |
| 46 | norecurse = '_norecurse' |
| 47 | |
| 48 | fullpath = '' |
| 49 | if 'fullpath' in ud.parm: |
| 50 | fullpath = '_fullpath' |
| 51 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 52 | 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] | 53 | |
Andrew Geissler | 1e34c2d | 2020-05-29 16:02:59 -0500 | [diff] [blame] | 54 | pkg = d.getVar('PN') |
| 55 | cvsdir = d.getVar("CVSDIR") or (d.getVar("DL_DIR") + "/cvs") |
| 56 | ud.pkgdir = os.path.join(cvsdir, pkg) |
| 57 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 58 | def need_update(self, ud, d): |
| 59 | if (ud.date == "now"): |
| 60 | return True |
| 61 | if not os.path.exists(ud.localpath): |
| 62 | return True |
| 63 | return False |
| 64 | |
| 65 | def download(self, ud, d): |
| 66 | |
| 67 | method = ud.parm.get('method', 'pserver') |
| 68 | localdir = ud.parm.get('localdir', ud.module) |
| 69 | cvs_port = ud.parm.get('port', '') |
| 70 | |
| 71 | cvs_rsh = None |
| 72 | if method == "ext": |
| 73 | if "rsh" in ud.parm: |
| 74 | cvs_rsh = ud.parm["rsh"] |
| 75 | |
| 76 | if method == "dir": |
| 77 | cvsroot = ud.path |
| 78 | else: |
| 79 | cvsroot = ":" + method |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 80 | cvsproxyhost = d.getVar('CVS_PROXY_HOST') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 81 | if cvsproxyhost: |
| 82 | cvsroot += ";proxy=" + cvsproxyhost |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 83 | cvsproxyport = d.getVar('CVS_PROXY_PORT') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 84 | if cvsproxyport: |
| 85 | cvsroot += ";proxyport=" + cvsproxyport |
| 86 | cvsroot += ":" + ud.user |
| 87 | if ud.pswd: |
| 88 | cvsroot += ":" + ud.pswd |
| 89 | cvsroot += "@" + ud.host + ":" + cvs_port + ud.path |
| 90 | |
| 91 | options = [] |
| 92 | if 'norecurse' in ud.parm: |
| 93 | options.append("-l") |
| 94 | if ud.date: |
| 95 | # treat YYYYMMDDHHMM specially for CVS |
| 96 | if len(ud.date) == 12: |
| 97 | options.append("-D \"%s %s:%s UTC\"" % (ud.date[0:8], ud.date[8:10], ud.date[10:12])) |
| 98 | else: |
| 99 | options.append("-D \"%s UTC\"" % ud.date) |
| 100 | if ud.tag: |
| 101 | options.append("-r %s" % ud.tag) |
| 102 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 103 | cvsbasecmd = d.getVar("FETCHCMD_cvs") or "/usr/bin/env cvs" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 104 | cvscmd = cvsbasecmd + " '-d" + cvsroot + "' co " + " ".join(options) + " " + ud.module |
| 105 | cvsupdatecmd = cvsbasecmd + " '-d" + cvsroot + "' update -d -P " + " ".join(options) |
| 106 | |
| 107 | if cvs_rsh: |
| 108 | cvscmd = "CVS_RSH=\"%s\" %s" % (cvs_rsh, cvscmd) |
| 109 | cvsupdatecmd = "CVS_RSH=\"%s\" %s" % (cvs_rsh, cvsupdatecmd) |
| 110 | |
| 111 | # create module directory |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 112 | logger.debug2("Fetch: checking for module directory") |
Andrew Geissler | 1e34c2d | 2020-05-29 16:02:59 -0500 | [diff] [blame] | 113 | moddir = os.path.join(ud.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 |
Andrew Geissler | 1e34c2d | 2020-05-29 16:02:59 -0500 | [diff] [blame] | 124 | bb.utils.mkdirhier(ud.pkgdir) |
| 125 | workdir = ud.pkgdir |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 126 | logger.debug("Running %s", cvscmd) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 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: |
Andrew Geissler | 1e34c2d | 2020-05-29 16:02:59 -0500 | [diff] [blame] | 144 | workdir = ud.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 | |
Andrew Geissler | 1e34c2d | 2020-05-29 16:02:59 -0500 | [diff] [blame] | 155 | bb.utils.remove(ud.pkgdir, True) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 156 | bb.utils.remove(ud.localpath) |
| 157 | |