blob: 0e0a3196f8690705f25d8d68e796bdb0044cf0aa [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001# ex:ts=4:sw=4:sts=4:et
2# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
3"""
4BitBake 'Fetch' implementations
5
6Classes for obtaining upstream sources for the
7BitBake build tools.
8
9"""
10
11# Copyright (C) 2003, 2004 Chris Larson
12#
13# This program is free software; you can redistribute it and/or modify
14# it under the terms of the GNU General Public License version 2 as
15# published by the Free Software Foundation.
16#
17# This program is distributed in the hope that it will be useful,
18# but WITHOUT ANY WARRANTY; without even the implied warranty of
19# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20# GNU General Public License for more details.
21#
22# You should have received a copy of the GNU General Public License along
23# with this program; if not, write to the Free Software Foundation, Inc.,
24# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25#
26#Based on functions from the base bb module, Copyright 2003 Holger Schurig
27#
28
29import os
30import logging
31import bb
32from bb.fetch2 import FetchMethod, FetchError, MissingParameterError, logger
33from bb.fetch2 import runfetchcmd
34
35class Cvs(FetchMethod):
36 """
37 Class to fetch a module or modules from cvs repositories
38 """
39 def supports(self, ud, d):
40 """
41 Check to see if a given url can be fetched with cvs.
42 """
43 return ud.type in ['cvs']
44
45 def urldata_init(self, ud, d):
46 if not "module" in ud.parm:
47 raise MissingParameterError("module", ud.url)
48 ud.module = ud.parm["module"]
49
50 ud.tag = ud.parm.get('tag', "")
51
52 # Override the default date in certain cases
53 if 'date' in ud.parm:
54 ud.date = ud.parm['date']
55 elif ud.tag:
56 ud.date = ""
57
58 norecurse = ''
59 if 'norecurse' in ud.parm:
60 norecurse = '_norecurse'
61
62 fullpath = ''
63 if 'fullpath' in ud.parm:
64 fullpath = '_fullpath'
65
Brad Bishop6e60e8b2018-02-01 10:27:11 -050066 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 -050067
68 def need_update(self, ud, d):
69 if (ud.date == "now"):
70 return True
71 if not os.path.exists(ud.localpath):
72 return True
73 return False
74
75 def download(self, ud, d):
76
77 method = ud.parm.get('method', 'pserver')
78 localdir = ud.parm.get('localdir', ud.module)
79 cvs_port = ud.parm.get('port', '')
80
81 cvs_rsh = None
82 if method == "ext":
83 if "rsh" in ud.parm:
84 cvs_rsh = ud.parm["rsh"]
85
86 if method == "dir":
87 cvsroot = ud.path
88 else:
89 cvsroot = ":" + method
Brad Bishop6e60e8b2018-02-01 10:27:11 -050090 cvsproxyhost = d.getVar('CVS_PROXY_HOST')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050091 if cvsproxyhost:
92 cvsroot += ";proxy=" + cvsproxyhost
Brad Bishop6e60e8b2018-02-01 10:27:11 -050093 cvsproxyport = d.getVar('CVS_PROXY_PORT')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050094 if cvsproxyport:
95 cvsroot += ";proxyport=" + cvsproxyport
96 cvsroot += ":" + ud.user
97 if ud.pswd:
98 cvsroot += ":" + ud.pswd
99 cvsroot += "@" + ud.host + ":" + cvs_port + ud.path
100
101 options = []
102 if 'norecurse' in ud.parm:
103 options.append("-l")
104 if ud.date:
105 # treat YYYYMMDDHHMM specially for CVS
106 if len(ud.date) == 12:
107 options.append("-D \"%s %s:%s UTC\"" % (ud.date[0:8], ud.date[8:10], ud.date[10:12]))
108 else:
109 options.append("-D \"%s UTC\"" % ud.date)
110 if ud.tag:
111 options.append("-r %s" % ud.tag)
112
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800113 cvsbasecmd = d.getVar("FETCHCMD_cvs") or "/usr/bin/env cvs"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500114 cvscmd = cvsbasecmd + " '-d" + cvsroot + "' co " + " ".join(options) + " " + ud.module
115 cvsupdatecmd = cvsbasecmd + " '-d" + cvsroot + "' update -d -P " + " ".join(options)
116
117 if cvs_rsh:
118 cvscmd = "CVS_RSH=\"%s\" %s" % (cvs_rsh, cvscmd)
119 cvsupdatecmd = "CVS_RSH=\"%s\" %s" % (cvs_rsh, cvsupdatecmd)
120
121 # create module directory
122 logger.debug(2, "Fetch: checking for module directory")
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500123 pkg = d.getVar('PN')
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800124 cvsdir = d.getVar("CVSDIR") or (d.getVar("DL_DIR") + "/cvs")
125 pkgdir = os.path.join(cvsdir, pkg)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500126 moddir = os.path.join(pkgdir, localdir)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600127 workdir = None
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500128 if os.access(os.path.join(moddir, 'CVS'), os.R_OK):
129 logger.info("Update " + ud.url)
130 bb.fetch2.check_network_access(d, cvsupdatecmd, ud.url)
131 # update sources there
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600132 workdir = moddir
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500133 cmd = cvsupdatecmd
134 else:
135 logger.info("Fetch " + ud.url)
136 # check out sources there
137 bb.utils.mkdirhier(pkgdir)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600138 workdir = pkgdir
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500139 logger.debug(1, "Running %s", cvscmd)
140 bb.fetch2.check_network_access(d, cvscmd, ud.url)
141 cmd = cvscmd
142
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600143 runfetchcmd(cmd, d, cleanup=[moddir], workdir=workdir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500144
145 if not os.access(moddir, os.R_OK):
146 raise FetchError("Directory %s was not readable despite sucessful fetch?!" % moddir, ud.url)
147
148 scmdata = ud.parm.get("scmdata", "")
149 if scmdata == "keep":
150 tar_flags = ""
151 else:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600152 tar_flags = "--exclude='CVS'"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500153
154 # tar them up to a defined filename
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600155 workdir = None
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500156 if 'fullpath' in ud.parm:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600157 workdir = pkgdir
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500158 cmd = "tar %s -czf %s %s" % (tar_flags, ud.localpath, localdir)
159 else:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600160 workdir = os.path.dirname(os.path.realpath(moddir))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500161 cmd = "tar %s -czf %s %s" % (tar_flags, ud.localpath, os.path.basename(moddir))
162
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600163 runfetchcmd(cmd, d, cleanup=[ud.localpath], workdir=workdir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500164
165 def clean(self, ud, d):
166 """ Clean CVS Files and tarballs """
167
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500168 pkg = d.getVar('PN')
169 pkgdir = os.path.join(d.getVar("CVSDIR"), pkg)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500170
171 bb.utils.remove(pkgdir, True)
172 bb.utils.remove(ud.localpath)
173