]>
git.ipfire.org Git - pakfire.git/blob - python/pakfire/packages/make.py
2 ###############################################################################
4 # Pakfire - The IPFire package management system #
5 # Copyright (C) 2011 Pakfire development team #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
20 ###############################################################################
29 from urlgrabber
.grabber
import URLGrabber
, URLGrabError
30 from urlgrabber
.progress
import TextMeter
35 import pakfire
.chroot
as chroot
36 import pakfire
.downloader
as downloader
37 import pakfire
.util
as util
39 from base
import Package
40 from file import SourcePackage
42 from pakfire
.constants
import *
43 from pakfire
.i18n
import _
45 class MakefileBase(Package
):
46 def __init__(self
, pakfire
, filename
):
47 Package
.__init
__(self
, pakfire
)
49 # Save the filename of the makefile.
50 self
.filename
= os
.path
.abspath(filename
)
53 environ
= self
.pakfire
.environ
55 "PARALLELISMFLAGS" : "-j%s" % util
.calc_parallelism(),
58 # Open and parse the makefile.
59 self
.lexer
= lexer
.RootLexer
.open(self
.filename
, environ
=environ
)
62 def package_filename(self
):
63 return PACKAGE_FILENAME_FMT
% {
65 "ext" : PACKAGE_EXTENSION
,
67 "release" : self
.release
,
68 "version" : self
.version
,
75 errors
.append(_("Package name is undefined."))
78 errors
.append(_("Package version is undefined."))
86 return self
.lexer
.get_var("name")
90 epoch
= self
.lexer
.get_var("epoch")
98 return self
.lexer
.get_var("version")
102 release
= self
.lexer
.get_var("release")
105 tag
= self
.lexer
.get_var("DISTRO_DISTTAG")
108 return ".".join((release
, tag
))
112 return self
.lexer
.get_var("summary")
115 def description(self
):
116 description
= self
.lexer
.get_var("description")
118 # Replace all backslashes at the end of a line.
119 return description
.replace("\\\n", "\n")
123 groups
= self
.lexer
.get_var("groups").split()
125 return sorted(groups
)
129 return self
.lexer
.get_var("url")
133 return self
.lexer
.get_var("license")
136 def maintainer(self
):
137 maintainer
= self
.lexer
.get_var("maintainer")
140 maintainer
= self
.lexer
.get_var("DISTRO_MAINTAINER")
146 return self
.lexer
.get_var("DISTRO_VENDOR")
150 return self
.lexer
.get_var("BUILDROOT")
153 def build_host(self
):
154 return socket
.gethostname()
156 # XXX build_id and build_time are used to create a source package
161 # Not existant for Makefiles
165 def build_time(self
):
167 # Not existant for Makefiles
171 class Makefile(MakefileBase
):
174 hash1
= util
.calc_hash1(self
.filename
)
176 # Return UUID version 5 (SHA1 hash)
177 return "%8s-%4s-5%3s-%4s-%11s" % \
178 (hash1
[0:8], hash1
[9:13], hash1
[14:17], hash1
[18:22], hash1
[23:34])
182 return os
.path
.dirname(self
.filename
)
187 This is only used to create the name of the source package.
195 for lexer
in self
.lexer
.packages
:
196 name
= lexer
.get_var("_name")
198 pkg
= MakefilePackage(self
.pakfire
, name
, lexer
)
207 if self
.pakfire
.distro
.source_dl
:
208 dls
.append(self
.pakfire
.distro
.source_dl
)
210 dl
= self
.lexer
.get_var("source_dl")
218 Download all external sources and return a list with the local
221 # Download source files.
222 grabber
= downloader
.SourceDownloader(self
.pakfire
,
223 mirrors
=self
.source_dl
)
225 return grabber
.download(self
.sources
)
227 def dist(self
, resultdirs
):
229 Create a source package.
231 # Download all files we need for this package.
234 p
= packager
.SourcePackager(self
.pakfire
, self
)
237 def dump(self
, *args
, **kwargs
):
238 dump
= MakefileBase
.dump(self
, *args
, **kwargs
)
239 dump
= dump
.splitlines()
241 #dump += ["", _("Containing the following binary packages:"),]
243 #for pkg in self.packages:
244 # _dump = pkg.dump(*args, **kwargs)
246 # for line in _dump.splitlines():
247 # dump.append(" %s" % line)
250 return "\n".join(dump
)
252 def get_buildscript(self
, stage
):
253 return self
.lexer
.build
.get_var("_%s" % stage
)
256 def prerequires(self
):
261 return self
.lexer
.build
.get_var("requires", "").split()
278 basedir
= os
.path
.dirname(self
.filename
)
280 for dirs
, subdirs
, _files
in os
.walk(basedir
):
282 files
.append(os
.path
.join(dirs
, f
))
288 return self
.lexer
.get_var("sources").split()
294 # Include quality agent exports.
295 exports
.update(self
.lexer
.quality_agent
.exports
)
297 for export
in self
.lexer
.build
.exports
:
298 exports
[export
] = self
.lexer
.build
.get_var(export
)
302 def extract(self
, message
=None, prefix
=None):
303 # XXX neeed to make this waaaaaaaaaay better.
310 message
= "%-10s : %s" % (message
, self
.friendly_name
)
311 pb
= util
.make_progress(message
, len(files
), eta
=False)
313 dir_len
= len(os
.path
.dirname(self
.filename
))
315 # Copy all files that belong to the package
323 logging
.debug("%s/%s" % (prefix
, _f
))
325 path
= "%s/%s" % (prefix
, _f
)
327 path_dir
= os
.path
.dirname(path
)
328 if not os
.path
.exists(path_dir
):
329 os
.makedirs(path_dir
)
331 shutil
.copy2(f
, path
)
336 # Download source files.
337 for _filename
in self
.download():
338 filename
= "%s/files/%s" % (prefix
, os
.path
.basename(_filename
))
339 dirname
= os
.path
.dirname(filename
)
341 if not os
.path
.exists(dirname
):
344 shutil
.copy2(_filename
, filename
)
347 class MakefilePackage(MakefileBase
):
348 def __init__(self
, pakfire
, name
, lexer
):
349 Package
.__init
__(self
, pakfire
)
354 # Store additional dependencies in here.
355 self
._dependencies
= {}
363 return self
.lexer
.get_var("arch", "%{DISTRO_ARCH}")
366 def configfiles(self
):
367 return self
.lexer
.get_var("configfiles").split()
371 return self
.lexer
.get_var("files").split()
377 def track_dependencies(self
, builder
, path
):
378 result
= builder
.do("/usr/lib/pakfire/dependency-tracker %s" \
379 % path
, returnOutput
=True)
381 for line
in result
.splitlines():
382 m
= re
.match(r
"^(\w+)=(.*)$", line
)
386 key
, val
= m
.groups()
388 if not key
in ("prerequires", "requires", "provides", "conflicts", "obsoletes",):
391 val
= val
.strip("\"")
394 self
._dependencies
[key
] = sorted(val
)
396 def get_deps(self
, key
):
397 # Collect all dependencies that were set in the makefile by the user.
398 deps
= self
.lexer
.get_var(key
).split()
400 # Collect all dependencies that were discovered by the tracker.
401 deps
+= self
._dependencies
.get(key
, [])
410 def prerequires(self
):
411 return self
.get_deps("prerequires")
415 return self
.get_deps("requires")
419 return self
.get_deps("provides")
423 return self
.get_deps("obsoletes")
427 return self
.get_deps("conflicts")
429 def get_scriptlet(self
, type):
430 scriptlet
= self
.lexer
.scriptlets
.get(type, None)
432 if scriptlet
is None and self
.lexer
.template
:
433 scriptlet
= self
.lexer
.template
.scriptlets
.get(type, None)
439 # The size of this is unknown.