1""" 2BitBake 'Fetch' implementations 3 4Classes for obtaining upstream sources for the 5BitBake build tools. 6 7""" 8 9# Copyright (C) 2003, 2004 Chris Larson 10# 11# SPDX-License-Identifier: GPL-2.0-only 12# 13# Based on functions from the base bb module, Copyright 2003 Holger Schurig 14# 15 16import os 17import bb 18from bb.fetch2 import FetchMethod, FetchError, MissingParameterError, logger 19from bb.fetch2 import runfetchcmd 20 21class 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 52 ud.localfile = d.expand('%s_%s_%s_%s%s%s.tar.gz' % (ud.module.replace('/', '.'), ud.host, ud.tag, ud.date, norecurse, fullpath)) 53 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 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 80 cvsproxyhost = d.getVar('CVS_PROXY_HOST') 81 if cvsproxyhost: 82 cvsroot += ";proxy=" + cvsproxyhost 83 cvsproxyport = d.getVar('CVS_PROXY_PORT') 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 103 cvsbasecmd = d.getVar("FETCHCMD_cvs") or "/usr/bin/env cvs" 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 112 logger.debug2("Fetch: checking for module directory") 113 moddir = os.path.join(ud.pkgdir, localdir) 114 workdir = None 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 119 workdir = moddir 120 cmd = cvsupdatecmd 121 else: 122 logger.info("Fetch " + ud.url) 123 # check out sources there 124 bb.utils.mkdirhier(ud.pkgdir) 125 workdir = ud.pkgdir 126 logger.debug("Running %s", cvscmd) 127 bb.fetch2.check_network_access(d, cvscmd, ud.url) 128 cmd = cvscmd 129 130 runfetchcmd(cmd, d, cleanup=[moddir], workdir=workdir) 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: 139 tar_flags = "--exclude='CVS'" 140 141 # tar them up to a defined filename 142 workdir = None 143 if 'fullpath' in ud.parm: 144 workdir = ud.pkgdir 145 cmd = "tar %s -czf %s %s" % (tar_flags, ud.localpath, localdir) 146 else: 147 workdir = os.path.dirname(os.path.realpath(moddir)) 148 cmd = "tar %s -czf %s %s" % (tar_flags, ud.localpath, os.path.basename(moddir)) 149 150 runfetchcmd(cmd, d, cleanup=[ud.localpath], workdir=workdir) 151 152 def clean(self, ud, d): 153 """ Clean CVS Files and tarballs """ 154 155 bb.utils.remove(ud.pkgdir, True) 156 bb.utils.remove(ud.localpath) 157 158