blob: 01de5ff4caf3cd35fb9246ad7bc2467068339804 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001"""
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#
Brad Bishopc342db32019-05-15 21:57:59 -040011# SPDX-License-Identifier: GPL-2.0-only
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012#
Brad Bishopc342db32019-05-15 21:57:59 -040013# Based on functions from the base bb module, Copyright 2003 Holger Schurig
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014#
15
16import os
Patrick Williamsc124f4f2015-09-15 14:41:29 -050017import 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
Brad Bishop6e60e8b2018-02-01 10:27:11 -050052 ud.localfile = d.expand('%s_%s_%s_%s%s%s.tar.gz' % (ud.module.replace('/', '.'), ud.host, ud.tag, ud.date, norecurse, fullpath))
Patrick Williamsc124f4f2015-09-15 14:41:29 -050053
Andrew Geissler1e34c2d2020-05-29 16:02:59 -050054 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 Williamsc124f4f2015-09-15 14:41:29 -050058 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 Bishop6e60e8b2018-02-01 10:27:11 -050080 cvsproxyhost = d.getVar('CVS_PROXY_HOST')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050081 if cvsproxyhost:
82 cvsroot += ";proxy=" + cvsproxyhost
Brad Bishop6e60e8b2018-02-01 10:27:11 -050083 cvsproxyport = d.getVar('CVS_PROXY_PORT')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050084 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 Bishop1a4b7ee2018-12-16 17:11:34 -0800103 cvsbasecmd = d.getVar("FETCHCMD_cvs") or "/usr/bin/env cvs"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500104 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 Geisslerd1e89492021-02-12 15:35:20 -0600112 logger.debug2("Fetch: checking for module directory")
Andrew Geissler1e34c2d2020-05-29 16:02:59 -0500113 moddir = os.path.join(ud.pkgdir, localdir)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600114 workdir = None
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500115 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 Williamsc0f7c042017-02-23 20:41:17 -0600119 workdir = moddir
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500120 cmd = cvsupdatecmd
121 else:
122 logger.info("Fetch " + ud.url)
123 # check out sources there
Andrew Geissler1e34c2d2020-05-29 16:02:59 -0500124 bb.utils.mkdirhier(ud.pkgdir)
125 workdir = ud.pkgdir
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600126 logger.debug("Running %s", cvscmd)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500127 bb.fetch2.check_network_access(d, cvscmd, ud.url)
128 cmd = cvscmd
129
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600130 runfetchcmd(cmd, d, cleanup=[moddir], workdir=workdir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500131
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 Williamsc0f7c042017-02-23 20:41:17 -0600139 tar_flags = "--exclude='CVS'"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500140
141 # tar them up to a defined filename
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600142 workdir = None
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500143 if 'fullpath' in ud.parm:
Andrew Geissler1e34c2d2020-05-29 16:02:59 -0500144 workdir = ud.pkgdir
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500145 cmd = "tar %s -czf %s %s" % (tar_flags, ud.localpath, localdir)
146 else:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600147 workdir = os.path.dirname(os.path.realpath(moddir))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500148 cmd = "tar %s -czf %s %s" % (tar_flags, ud.localpath, os.path.basename(moddir))
149
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600150 runfetchcmd(cmd, d, cleanup=[ud.localpath], workdir=workdir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500151
152 def clean(self, ud, d):
153 """ Clean CVS Files and tarballs """
154
Andrew Geissler1e34c2d2020-05-29 16:02:59 -0500155 bb.utils.remove(ud.pkgdir, True)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500156 bb.utils.remove(ud.localpath)
157