Skip to content

Instantly share code, notes, and snippets.

@kergoth
Created March 14, 2011 18:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kergoth/869616 to your computer and use it in GitHub Desktop.
Save kergoth/869616 to your computer and use it in GitHub Desktop.
Automatic ASSUME_PROVIDED based upon what's available in the build machine (not for the faint of heart, you've been warned)
def auto_assume_provided():
import kergoth.assume as assume
import kergoth.assumptions
return ' '.join(assume.test_assumptions())
ASSUME_PROVIDED += "${@auto_assume_provided()}"
import os
assumptions = {}
def have(cmd):
for subdir in os.environ.get('PATH', '').split(':'):
if os.path.exists(os.path.join(subdir, cmd)):
return True
return False
def simple_assumptions(check, *cmds, **kwcmds):
def check_assumption(cmd, provide):
if check(cmd):
return provide
def new_check_assumption(provide):
return lambda cmd: check_assumption(cmd, provide)
native_check = lambda cmd: check_assumption(cmd, '%s-native' % cmd)
for cmd in cmds:
assumptions[cmd] = native_check
for cmd, provide in kwcmds.iteritems():
assumptions[cmd] = new_check_assumption(provide)
call = lambda x: x()
def assumed(func):
assumptions[func] = call
return func
def test_assumptions():
for arg, testfunc in assumptions.iteritems():
result = testfunc(arg)
if result:
yield result
from assume import have, assumed, simple_assumptions
import oe.process
import os.path
simple_assumptions(have,
'fakeroot',
'pseudo',
'sed',
'grep',
'unzip',
'patch',
'diffstat',
'cvs',
'bzip2',
'bc',
'chrpath',
'quilt',
'git',
'bison',
'flex',
'gperf',
'gzip',
'gperf',
# 'gettext', - not safe atm, some recipes grab config.rpath directly from
# the oe sysroot
**{
'svn': 'subversion-native',
'makeinfo': 'texinfo-native',
'eu-strip': 'elfutils-native',
}
)
simple_assumptions(check=os.path.exists, **{
'/usr/lib/libz.a': 'zlib-native',
'/usr/lib/libcurl.a': 'curl-native',
'/usr/lib/libreadline.a': 'readline-native',
# '/usr/lib/libsqlite3.a': 'sqlite3-native',
'/usr/lib/libuuid.a': 'util-linux-native',
})
def gnu_version(name, minversion):
try:
veroutput = oe.process.run([name, '--version'])
except oe.process.CmdError:
return None
firstline = veroutput.splitlines()[0]
strversion = firstline.split()[-1]
version = [int(c) for c in strversion.split('.')]
if version >= minversion:
return '%s-native' % name
@assumed
def m4():
return gnu_version('m4', [1, 4, 6])
@assumed
def tar():
return gnu_version('tar', [1, 20])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment