summaryrefslogtreecommitdiffstats
path: root/scripts/lib/recipetool/create_kernel.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/lib/recipetool/create_kernel.py')
-rw-r--r--scripts/lib/recipetool/create_kernel.py99
1 files changed, 99 insertions, 0 deletions
diff --git a/scripts/lib/recipetool/create_kernel.py b/scripts/lib/recipetool/create_kernel.py
new file mode 100644
index 0000000000..c6e86bd2b9
--- /dev/null
+++ b/scripts/lib/recipetool/create_kernel.py
@@ -0,0 +1,99 @@
1# Recipe creation tool - kernel support plugin
2#
3# Copyright (C) 2016 Intel Corporation
4#
5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License version 2 as
7# published by the Free Software Foundation.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License along
15# with this program; if not, write to the Free Software Foundation, Inc.,
16# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18import re
19import logging
20from recipetool.create import RecipeHandler, read_pkgconfig_provides, validate_pv
21
22logger = logging.getLogger('recipetool')
23
24tinfoil = None
25
26def tinfoil_init(instance):
27 global tinfoil
28 tinfoil = instance
29
30
31class KernelRecipeHandler(RecipeHandler):
32 def process(self, srctree, classes, lines_before, lines_after, handled, extravalues):
33 import bb.process
34 if 'buildsystem' in handled:
35 return False
36
37 for tell in ['arch', 'firmware', 'Kbuild', 'Kconfig']:
38 if not os.path.exists(os.path.join(srctree, tell)):
39 return False
40
41 handled.append('buildsystem')
42 del lines_after[:]
43 del classes[:]
44 template = os.path.join(tinfoil.config_data.getVar('COREBASE', True), 'meta-skeleton', 'recipes-kernel', 'linux', 'linux-yocto-custom.bb')
45 def handle_var(varname, origvalue, op, newlines):
46 if varname in ['SRCREV', 'SRCREV_machine']:
47 while newlines[-1].startswith('#'):
48 del newlines[-1]
49 try:
50 stdout, _ = bb.process.run('git rev-parse HEAD', cwd=srctree, shell=True)
51 except bb.process.ExecutionError as e:
52 stdout = None
53 if stdout:
54 return stdout.strip(), op, 0, True
55 elif varname == 'LINUX_VERSION':
56 makefile = os.path.join(srctree, 'Makefile')
57 if os.path.exists(makefile):
58 kversion = -1
59 kpatchlevel = -1
60 ksublevel = -1
61 kextraversion = ''
62 with open(makefile, 'r') as f:
63 for i, line in enumerate(f):
64 if i > 10:
65 break
66 if line.startswith('VERSION ='):
67 kversion = int(line.split('=')[1].strip())
68 elif line.startswith('PATCHLEVEL ='):
69 kpatchlevel = int(line.split('=')[1].strip())
70 elif line.startswith('SUBLEVEL ='):
71 ksublevel = int(line.split('=')[1].strip())
72 elif line.startswith('EXTRAVERSION ='):
73 kextraversion = line.split('=')[1].strip()
74 version = ''
75 if kversion > -1 and kpatchlevel > -1:
76 version = '%d.%d' % (kversion, kpatchlevel)
77 if ksublevel > -1:
78 version += '.%d' % ksublevel
79 version += kextraversion
80 if version:
81 return version, op, 0, True
82 elif varname == 'SRC_URI':
83 while newlines[-1].startswith('#'):
84 del newlines[-1]
85 elif varname == 'COMPATIBLE_MACHINE':
86 while newlines[-1].startswith('#'):
87 del newlines[-1]
88 machine = tinfoil.config_data.getVar('MACHINE', True)
89 return machine, op, 0, True
90 return origvalue, op, 0, True
91 with open(template, 'r') as f:
92 varlist = ['SRCREV', 'SRCREV_machine', 'SRC_URI', 'LINUX_VERSION', 'COMPATIBLE_MACHINE']
93 (_, newlines) = bb.utils.edit_metadata(f, varlist, handle_var)
94 lines_before[:] = [line.rstrip('\n') for line in newlines]
95
96 return True
97
98def register_recipe_handlers(handlers):
99 handlers.append((KernelRecipeHandler(), 100))