blob: 490c9547187033636b36b3d13434fb1ee7cde8a4 [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 Bishop6e60e8b2018-02-01 10:27:11 -0500113 cvsbasecmd = d.getVar("FETCHCMD_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')
124 pkgdir = os.path.join(d.getVar('CVSDIR'), pkg)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500125 moddir = os.path.join(pkgdir, localdir)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600126 workdir = None
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500127 if os.access(os.path.join(moddir, 'CVS'), os.R_OK):
128 logger.info("Update " + ud.url)
129 bb.fetch2.check_network_access(d, cvsupdatecmd, ud.url)
130 # update sources there
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600131 workdir = moddir
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500132 cmd = cvsupdatecmd
133 else:
134 logger.info("Fetch " + ud.url)
135 # check out sources there
136 bb.utils.mkdirhier(pkgdir)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600137 workdir = pkgdir
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500138 logger.debug(1, "Running %s", cvscmd)
139 bb.fetch2.check_network_access(d, cvscmd, ud.url)
140 cmd = cvscmd
141
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600142 runfetchcmd(cmd, d, cleanup=[moddir], workdir=workdir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500143
144 if not os.access(moddir, os.R_OK):
145 raise FetchError("Directory %s was not readable despite sucessful fetch?!" % moddir, ud.url)
146
147 scmdata = ud.parm.get("scmdata", "")
148 if scmdata == "keep":
149 tar_flags = ""
150 else:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600151 tar_flags = "--exclude='CVS'"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500152
153 # tar them up to a defined filename
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600154 workdir = None
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500155 if 'fullpath' in ud.parm:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600156 workdir = pkgdir
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500157 cmd = "tar %s -czf %s %s" % (tar_flags, ud.localpath, localdir)
158 else:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600159 workdir = os.path.dirname(os.path.realpath(moddir))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500160 cmd = "tar %s -czf %s %s" % (tar_flags, ud.localpath, os.path.basename(moddir))
161
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600162 runfetchcmd(cmd, d, cleanup=[ud.localpath], workdir=workdir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500163
164 def clean(self, ud, d):
165 """ Clean CVS Files and tarballs """
166
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500167 pkg = d.getVar('PN')
168 pkgdir = os.path.join(d.getVar("CVSDIR"), pkg)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500169
170 bb.utils.remove(pkgdir, True)
171 bb.utils.remove(ud.localpath)
172