blob: 1b35ba4cf012720383ca80aecba8e2d0c7f7c03a [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
17import logging
18import bb
19from bb.fetch2 import FetchMethod, FetchError, MissingParameterError, logger
20from bb.fetch2 import runfetchcmd
21
22class 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 Bishop6e60e8b2018-02-01 10:27:11 -050053 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 -050054
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 Bishop6e60e8b2018-02-01 10:27:11 -050077 cvsproxyhost = d.getVar('CVS_PROXY_HOST')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050078 if cvsproxyhost:
79 cvsroot += ";proxy=" + cvsproxyhost
Brad Bishop6e60e8b2018-02-01 10:27:11 -050080 cvsproxyport = d.getVar('CVS_PROXY_PORT')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050081 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 Bishop1a4b7ee2018-12-16 17:11:34 -0800100 cvsbasecmd = d.getVar("FETCHCMD_cvs") or "/usr/bin/env cvs"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500101 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 Bishop6e60e8b2018-02-01 10:27:11 -0500110 pkg = d.getVar('PN')
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800111 cvsdir = d.getVar("CVSDIR") or (d.getVar("DL_DIR") + "/cvs")
112 pkgdir = os.path.join(cvsdir, pkg)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500113 moddir = os.path.join(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
124 bb.utils.mkdirhier(pkgdir)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600125 workdir = pkgdir
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500126 logger.debug(1, "Running %s", cvscmd)
127 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:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600144 workdir = 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
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500155 pkg = d.getVar('PN')
156 pkgdir = os.path.join(d.getVar("CVSDIR"), pkg)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500157
158 bb.utils.remove(pkgdir, True)
159 bb.utils.remove(ud.localpath)
160