summaryrefslogtreecommitdiffstats
path: root/meta/classes/devtool-source.bbclass
diff options
context:
space:
mode:
Diffstat (limited to 'meta/classes/devtool-source.bbclass')
-rw-r--r--meta/classes/devtool-source.bbclass192
1 files changed, 0 insertions, 192 deletions
diff --git a/meta/classes/devtool-source.bbclass b/meta/classes/devtool-source.bbclass
deleted file mode 100644
index 2e0070486b..0000000000
--- a/meta/classes/devtool-source.bbclass
+++ /dev/null
@@ -1,192 +0,0 @@
1#
2# Copyright OpenEmbedded Contributors
3#
4# SPDX-License-Identifier: MIT
5#
6
7# Development tool - source extraction helper class
8#
9# NOTE: this class is intended for use by devtool and should not be
10# inherited manually.
11#
12# Copyright (C) 2014-2017 Intel Corporation
13#
14# This program is free software; you can redistribute it and/or modify
15# it under the terms of the GNU General Public License version 2 as
16# published by the Free Software Foundation.
17#
18# This program is distributed in the hope that it will be useful,
19# but WITHOUT ANY WARRANTY; without even the implied warranty of
20# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21# GNU General Public License for more details.
22#
23# You should have received a copy of the GNU General Public License along
24# with this program; if not, write to the Free Software Foundation, Inc.,
25# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26
27
28DEVTOOL_TEMPDIR ?= ""
29
30python() {
31 tempdir = d.getVar('DEVTOOL_TEMPDIR')
32
33 if not tempdir:
34 bb.fatal('devtool-source class is for internal use by devtool only')
35
36 # Make a subdir so we guard against WORKDIR==S
37 workdir = os.path.join(tempdir, 'workdir')
38 d.setVar('WORKDIR', workdir)
39 if not d.getVar('S').startswith(workdir):
40 # Usually a shared workdir recipe (kernel, gcc)
41 # Try to set a reasonable default
42 if bb.data.inherits_class('kernel', d):
43 d.setVar('S', '${WORKDIR}/source')
44 else:
45 d.setVar('S', '${WORKDIR}/%s' % os.path.basename(d.getVar('S')))
46 if bb.data.inherits_class('kernel', d):
47 # We don't want to move the source to STAGING_KERNEL_DIR here
48 d.setVar('STAGING_KERNEL_DIR', '${S}')
49
50 d.setVar('STAMPS_DIR', os.path.join(tempdir, 'stamps'))
51 d.setVar('T', os.path.join(tempdir, 'temp'))
52
53 # Hook in pre/postfuncs
54 is_kernel_yocto = bb.data.inherits_class('kernel-yocto', d)
55 if is_kernel_yocto:
56 unpacktask = 'do_kernel_checkout'
57 d.appendVarFlag('do_configure', 'postfuncs', ' devtool_post_configure')
58 else:
59 unpacktask = 'do_unpack'
60 d.appendVarFlag(unpacktask, 'postfuncs', ' devtool_post_unpack')
61 d.appendVarFlag('do_patch', 'postfuncs', ' devtool_post_patch')
62
63 # NOTE: in order for the patch stuff to be fully functional,
64 # PATCHTOOL and PATCH_COMMIT_FUNCTIONS need to be set; we can't
65 # do that here because we can't guarantee the order of the anonymous
66 # functions, so it gets done in the bbappend we create.
67}
68
69
70python devtool_post_unpack() {
71 import oe.recipeutils
72 import shutil
73 sys.path.insert(0, os.path.join(d.getVar('COREBASE'), 'scripts', 'lib'))
74 import scriptutils
75 from devtool import setup_git_repo
76
77 tempdir = d.getVar('DEVTOOL_TEMPDIR')
78 workdir = d.getVar('WORKDIR')
79 unpackdir = d.getVar('UNPACKDIR')
80 srcsubdir = d.getVar('S')
81
82 # Add locally copied files to gitignore as we add back to the metadata directly
83 local_files = oe.recipeutils.get_recipe_local_files(d)
84 srcabspath = os.path.abspath(srcsubdir)
85 local_files = [fname for fname in local_files if
86 os.path.exists(os.path.join(unpackdir, fname)) and
87 srcabspath == unpackdir]
88 if local_files:
89 with open(os.path.join(tempdir, '.gitignore'), 'a+') as f:
90 f.write('# Ignore local files, by default. Remove following lines'
91 'if you want to commit the directory to Git\n')
92 for fname in local_files:
93 f.write('%s\n' % fname)
94
95 if srcsubdir.startswith(unpackdir) and os.path.dirname(srcsubdir) != unpackdir:
96 # Handle if S is set to a subdirectory of the source
97 srcsubdir = os.path.normpath(os.path.join(unpackdir, os.path.relpath(srcsubdir, unpackdir).split(os.sep)[0]))
98
99 scriptutils.git_convert_standalone_clone(srcsubdir)
100
101 # Make sure that srcsubdir exists
102 bb.utils.mkdirhier(srcsubdir)
103 if not os.listdir(srcsubdir):
104 bb.warn("No source unpacked to S - either the %s recipe "
105 "doesn't use any source or the correct source "
106 "directory could not be determined" % d.getVar('PN'))
107
108 devbranch = d.getVar('DEVTOOL_DEVBRANCH')
109 setup_git_repo(srcsubdir, d.getVar('PV'), devbranch, d=d)
110
111 (stdout, _) = bb.process.run('git rev-parse HEAD', cwd=srcsubdir)
112 initial_rev = stdout.rstrip()
113 with open(os.path.join(tempdir, 'initial_rev'), 'w') as f:
114 f.write(initial_rev)
115
116 with open(os.path.join(tempdir, 'srcsubdir'), 'w') as f:
117 f.write(srcsubdir)
118}
119
120python devtool_post_patch() {
121 import shutil
122 tempdir = d.getVar('DEVTOOL_TEMPDIR')
123 with open(os.path.join(tempdir, 'srcsubdir'), 'r') as f:
124 srcsubdir = f.read()
125 with open(os.path.join(tempdir, 'initial_rev'), 'r') as f:
126 initial_rev = f.read()
127
128 def rm_patches():
129 patches_dir = os.path.join(srcsubdir, 'patches')
130 if os.path.exists(patches_dir):
131 shutil.rmtree(patches_dir)
132 # Restore any "patches" directory that was actually part of the source tree
133 try:
134 bb.process.run('git checkout -- patches', cwd=srcsubdir)
135 except bb.process.ExecutionError:
136 pass
137
138 extra_overrides = d.getVar('DEVTOOL_EXTRA_OVERRIDES')
139 if extra_overrides:
140 extra_overrides = set(extra_overrides.split(':'))
141 devbranch = d.getVar('DEVTOOL_DEVBRANCH')
142 default_overrides = d.getVar('OVERRIDES').split(':')
143 no_overrides = []
144 # First, we may have some overrides that are referred to in the recipe set in
145 # our configuration, so we need to make a branch that excludes those
146 for override in default_overrides:
147 if override not in extra_overrides:
148 no_overrides.append(override)
149 if default_overrides != no_overrides:
150 # Some overrides are active in the current configuration, so
151 # we need to create a branch where none of the overrides are active
152 bb.process.run('git checkout %s -b devtool-no-overrides' % initial_rev, cwd=srcsubdir)
153 # Run do_patch function with the override applied
154 localdata = bb.data.createCopy(d)
155 localdata.setVar('OVERRIDES', ':'.join(no_overrides))
156 localdata.setVar('FILESOVERRIDES', ':'.join(no_overrides))
157 bb.build.exec_func('do_patch', localdata)
158 rm_patches()
159 # Now we need to reconcile the dev branch with the no-overrides one
160 # (otherwise we'd likely be left with identical commits that have different hashes)
161 bb.process.run('git checkout %s' % devbranch, cwd=srcsubdir)
162 bb.process.run('git rebase devtool-no-overrides', cwd=srcsubdir)
163 else:
164 bb.process.run('git checkout %s -b devtool-no-overrides' % devbranch, cwd=srcsubdir)
165
166 for override in extra_overrides:
167 localdata = bb.data.createCopy(d)
168 if override in default_overrides:
169 bb.process.run('git branch devtool-override-%s %s' % (override, devbranch), cwd=srcsubdir)
170 else:
171 # Reset back to the initial commit on a new branch
172 bb.process.run('git checkout %s -b devtool-override-%s' % (initial_rev, override), cwd=srcsubdir)
173 # Run do_patch function with the override applied
174 localdata.setVar('OVERRIDES', ':'.join(no_overrides + [override]))
175 localdata.setVar('FILESOVERRIDES', ':'.join(no_overrides + [override]))
176 bb.build.exec_func('do_patch', localdata)
177 rm_patches()
178 # Now we need to reconcile the new branch with the no-overrides one
179 # (otherwise we'd likely be left with identical commits that have different hashes)
180 bb.process.run('git rebase devtool-no-overrides', cwd=srcsubdir)
181 bb.process.run('git checkout %s' % devbranch, cwd=srcsubdir)
182 bb.process.run('git tag -f --no-sign devtool-patched', cwd=srcsubdir)
183 if os.path.exists(os.path.join(srcsubdir, '.gitmodules')):
184 bb.process.run('git submodule foreach --recursive "git tag -f --no-sign devtool-patched"', cwd=srcsubdir)
185
186}
187
188python devtool_post_configure() {
189 import shutil
190 tempdir = d.getVar('DEVTOOL_TEMPDIR')
191 shutil.copy2(os.path.join(d.getVar('B'), '.config'), tempdir)
192}