summaryrefslogtreecommitdiffstats
path: root/waflib/extras/package.py
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-09-15 14:51:02 +0200
committerDavid Robillard <d@drobilla.net>2018-09-15 14:51:02 +0200
commit4a3f0b45918fb172d33b6b5f6a736087db0754cc (patch)
tree818f80aee210eac7ff53cf45de53df3991430d3e /waflib/extras/package.py
parent1bd8d938429c42b54286068fe3a5b22743fbc794 (diff)
parenteede9648d50c3750f6f8d1319a79dd76d7f10b55 (diff)
downloadingen-4a3f0b45918fb172d33b6b5f6a736087db0754cc.tar.gz
ingen-4a3f0b45918fb172d33b6b5f6a736087db0754cc.tar.bz2
ingen-4a3f0b45918fb172d33b6b5f6a736087db0754cc.zip
Merge commit 'eede9648d50c3750f6f8d1319a79dd76d7f10b55' as 'waflib'
Diffstat (limited to 'waflib/extras/package.py')
-rw-r--r--waflib/extras/package.py76
1 files changed, 76 insertions, 0 deletions
diff --git a/waflib/extras/package.py b/waflib/extras/package.py
new file mode 100644
index 00000000..c06498eb
--- /dev/null
+++ b/waflib/extras/package.py
@@ -0,0 +1,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, ..
+