blob: c06498eba8f567830e4af512da1664fd93922b82 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
#! /usr/bin/env python
# encoding: utf-8
# Thomas Nagy, 2011
"""
Obtain packages, unpack them in a location, and add associated uselib variables
(CFLAGS_pkgname, LIBPATH_pkgname, etc).
The default is use a Dependencies.txt file in the source directory.
This is a work in progress.
Usage:
def options(opt):
opt.load('package')
def configure(conf):
conf.load_packages()
"""
from waflib import Logs
from waflib.Configure import conf
try:
from urllib import request
except ImportError:
from urllib import urlopen
else:
urlopen = request.urlopen
CACHEVAR = 'WAFCACHE_PACKAGE'
@conf
def get_package_cache_dir(self):
cache = None
if CACHEVAR in conf.environ:
cache = conf.environ[CACHEVAR]
cache = self.root.make_node(cache)
elif self.env[CACHEVAR]:
cache = self.env[CACHEVAR]
cache = self.root.make_node(cache)
else:
cache = self.srcnode.make_node('.wafcache_package')
cache.mkdir()
return cache
@conf
def download_archive(self, src, dst):
for x in self.env.PACKAGE_REPO:
url = '/'.join((x, src))
try:
web = urlopen(url)
try:
if web.getcode() != 200:
continue
except AttributeError:
pass
except Exception:
# on python3 urlopen throws an exception
# python 2.3 does not have getcode and throws an exception to fail
continue
else:
tmp = self.root.make_node(dst)
tmp.write(web.read())
Logs.warn('Downloaded %s from %s', tmp.abspath(), url)
break
else:
self.fatal('Could not get the package %s' % src)
@conf
def load_packages(self):
self.get_package_cache_dir()
# read the dependencies, get the archives, ..
|