blob: 29123a483c733c5d3b6b3da0be51807a78a6a650 [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
54 def need_update(self, ud, d):
55 if (ud.date == "now"):
56 return True
57 if not os.path.exists(ud.localpath):
58 return True
59 return False
60
61 def download(self, ud, d):
62
63 method = ud.parm.get('method', 'pserver')
64 localdir = ud.parm.get('localdir', ud.module)
65 cvs_port = ud.parm.get('port', '')
66
67 cvs_rsh = None
68 if method == "ext":
69 if "rsh" in ud.parm:
70 cvs_rsh = ud.parm["rsh"]
71
72 if method == "dir":
73 cvsroot = ud.path
74 else:
75 cvsroot = ":" + method
Brad Bishop6e60e8b2018-02-01 10:27:11 -050076 cvsproxyhost = d.getVar('CVS_PROXY_HOST')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050077 if cvsproxyhost:
78 cvsroot += ";proxy=" + cvsproxyhost
Brad Bishop6e60e8b2018-02-01 10:27:11 -050079 cvsproxyport = d.getVar('CVS_PROXY_PORT')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050080 if cvsproxyport:
81 cvsroot += ";proxyport=" + cvsproxyport
82 cvsroot += ":" + ud.user
83 if ud.pswd:
84 cvsroot += ":" + ud.pswd
85 cvsroot += "@" + ud.host + ":" + cvs_port + ud.path
86
87 options = []
88 if 'norecurse' in ud.parm:
89 options.append("-l")
90 if ud.date:
91 # treat YYYYMMDDHHMM specially for CVS
92 if len(ud.date) == 12:
93 options.append("-D \"%s %s:%s UTC\"" % (ud.date[0:8], ud.date[8:10], ud.date[10:12]))
94 else:
95 options.append("-D \"%s UTC\"" % ud.date)
96 if ud.tag:
97 options.append("-r %s" % ud.tag)
98
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080099 cvsbasecmd = d.getVar("FETCHCMD_cvs") or "/usr/bin/env cvs"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500100 cvscmd = cvsbasecmd + " '-d" + cvsroot + "' co " + " ".join(options) + " " + ud.module
101 cvsupdatecmd = cvsbasecmd + " '-d" + cvsroot + "' update -d -P " + " ".join(options)
102
103 if cvs_rsh:
104 cvscmd = "CVS_RSH=\"%s\" %s" % (cvs_rsh, cvscmd)
105 cvsupdatecmd = "CVS_RSH=\"%s\" %s" % (cvs_rsh, cvsupdatecmd)
106
107 # create module directory
108 logger.debug(2, "Fetch: checking for module directory")
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500109 pkg = d.getVar('PN')
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800110 cvsdir = d.getVar("CVSDIR") or (d.getVar("DL_DIR") + "/cvs")
111 pkgdir = os.path.join(cvsdir, pkg)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500112 moddir = os.path.join(pkgdir, localdir)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600113 workdir = None
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500114 if os.access(os.path.join(moddir, 'CVS'), os.R_OK):
115 logger.info("Update " + ud.url)
116 bb.fetch2.check_network_access(d, cvsupdatecmd, ud.url)
117 # update sources there
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600118 workdir = moddir
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500119 cmd = cvsupdatecmd
120 else:
121 logger.info("Fetch " + ud.url)
122 # check out sources there
123 bb.utils.mkdirhier(pkgdir)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600124 workdir = pkgdir
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500125 logger.debug(1, "Running %s", cvscmd)
126 bb.fetch2.check_network_access(d, cvscmd, ud.url)
127 cmd = cvscmd
128
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600129 runfetchcmd(cmd, d, cleanup=[moddir], workdir=workdir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500130
131 if not os.access(moddir, os.R_OK):
132 raise FetchError("Directory %s was not readable despite sucessful fetch?!" % moddir, ud.url)
133
134 scmdata = ud.parm.get("scmdata", "")
135 if scmdata == "keep":
136 tar_flags = ""
137 else:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600138 tar_flags = "--exclude='CVS'"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500139
140 # tar them up to a defined filename
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600141 workdir = None
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500142 if 'fullpath' in ud.parm:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600143 workdir = pkgdir
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500144 cmd = "tar %s -czf %s %s" % (tar_flags, ud.localpath, localdir)
145 else:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600146 workdir = os.path.dirname(os.path.realpath(moddir))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500147 cmd = "tar %s -czf %s %s" % (tar_flags, ud.localpath, os.path.basename(moddir))
148
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600149 runfetchcmd(cmd, d, cleanup=[ud.localpath], workdir=workdir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500150
151 def clean(self, ud, d):
152 """ Clean CVS Files and tarballs """
153
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500154 pkg = d.getVar('PN')
155 pkgdir = os.path.join(d.getVar("CVSDIR"), pkg)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500156
157 bb.utils.remove(pkgdir, True)
158 bb.utils.remove(ud.localpath)
159