# Recipe creation tool - create command plugin
#
# Copyright (C) 2014-2016 Intel Corporation
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
import sys
import os
import argparse
import glob
import fnmatch
import re
import json
import logging
import scriptutils
from urllib.parse import urlparse, urldefrag, urlsplit
import hashlib
import bb.fetch2
logger = logging.getLogger('recipetool')
tinfoil = None
plugins = None
def log_error_cond(message, debugonly):
if debugonly:
logger.debug(message)
else:
logger.error(message)
def log_info_cond(message, debugonly):
if debugonly:
logger.debug(message)
else:
logger.info(message)
def plugin_init(pluginlist):
# Take a reference to the list so we can use it later
global plugins
plugins = pluginlist
def tinfoil_init(instance):
global tinfoil
tinfoil = instance
class RecipeHandler(object):
recipelibmap = {}
recipeheadermap = {}
recipecmakefilemap = {}
recipebinmap = {}
def __init__(self):
self._devtool = False
@staticmethod
def load_libmap(d):
'''Load library->recipe mapping'''
import oe.package
if RecipeHandler.recipelibmap:
return
# First build up library->package mapping
shlib_providers = oe.package.read_shlib_providers(d)
libdir = d.getVar('libdir')
base_libdir = d.getVar('base_libdir')
libpaths = list(set([base_libdir, libdir]))
libname_re = re.compile('^lib(.+)\.so.*$')
pkglibmap = {}
for lib, item in shlib_providers.items():
for path, pkg in item.items():
if path in libpaths:
res = libname_re.match(lib)
if res:
libname = res.group(1)
if not libname in pkglibmap:
pkglibmap[libname] = pkg[0]
else:
logger.debug('unable to extract library name from %s' % lib)
# Now turn it into a library->recipe mapping
pkgdata_dir = d.getVar('PKGDATA_DIR')
for libname, pkg in pkglibmap.items():
try:
with open(os.path.join(pkgdata_dir, 'runtime', pkg)) as f:
for line in f:
if line.startswith('PN:'):
RecipeHandler.recipelibmap[libname] = line.split(':', 1)[-1].strip()
break
except IOError as ioe:
if ioe.errno == 2:
logger.warn('unable to find a pkgdata file for package %s' % pkg)
else:
raise
# Some overrides - these should be mapped to the virtual
RecipeHandler.recipelibmap['GL'] = 'virtual/libgl'
RecipeHandler.recipelibmap['EGL'] = 'virtual/egl'
RecipeHandler.recipelibmap['GLESv2'] = 'virtual/libgles2'
@staticmethod
def load_devel_filemap(d):
'''Build up development file->recipe mapping'''
if RecipeHandler.recipeheadermap:
return
pkgdata_dir = d.getVar('PKGDATA_DIR')
includedir = d.getVar('includedir')
cmakedir = os.path.join(d.getVar('libdir'), 'cmake')
for pkg in glob.glob(os.path.join(pkgdata_dir, 'runtime', '*-dev')):
with open(os.path.join(pkgdata_dir, 'runtime', pkg)) as f:
pn = None
headers = []
cmakefiles = []
for line in f:
if line.startswith('PN:'):
pn = line.split(':', 1)[-1].strip()
elif line.startswith('FILES_INFO:'):
val = line.split(':', 1)[1].strip()
dictval = json.loads(val)
for fullpth in sorted(dictval):
if fullpth.startswith(includedir) and fullpth.endswith('.h'):
headers.append(os.path.relpath(fullpth, includedir))
elif fullpth.startswith(cmakedir) and fullpth.endswith('.cmake'):
cmakefiles.append(os.path.relpath(fullpth, cmakedir))
if pn and headers:
for header in headers:
RecipeHandler.recipeheadermap[header] = pn
if pn and cmakefiles:
for fn in cmakefiles:
RecipeHandler.recipecmakefilemap[fn] = pn
@staticmethod
def load_binmap(d):
'''Build up native binary->recipe mapping'''
if RecipeHandler.recipebinmap:
return
sstate_manifests = d.getVar('SSTATE_MANIFESTS')
staging_bindir_native = d.getVar('STAGING_BINDIR_NATIVE')
build_arch = d.getVar('BUILD_ARCH')
fileprefix = 'manifest-%s-' % build_arch
for fn in glob.glob(os.path.join(sstate_manifests, '%s*-native.populate_sysroot' % fileprefix)):
with open(fn, 'r') as f:
pn = os.path.basename(fn).rsplit('.', 1)[0][len(fileprefix):]
for line in f:
if line.startswith(<
|