blob: f7ed66d8c697405c3248d128b3a36420e5d2d2a5 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001# Copyright (C) 2012 Linux Foundation
2# Author: Richard Purdie
3# Some code and influence taken from srctree.bbclass:
4# Copyright (C) 2009 Chris Larson <clarson@kergoth.com>
5# Released under the MIT license (see COPYING.MIT for the terms)
6#
7# externalsrc.bbclass enables use of an existing source tree, usually external to
8# the build system to build a piece of software rather than the usual fetch/unpack/patch
9# process.
10#
11# To use, add externalsrc to the global inherit and set EXTERNALSRC to point at the
12# directory you want to use containing the sources e.g. from local.conf for a recipe
13# called "myrecipe" you would do:
14#
15# INHERIT += "externalsrc"
16# EXTERNALSRC_pn-myrecipe = "/path/to/my/source/tree"
17#
18# In order to make this class work for both target and native versions (or with
19# multilibs/cross or other BBCLASSEXTEND variants), B is set to point to a separate
20# directory under the work directory (split source and build directories). This is
21# the default, but the build directory can be set to the source directory if
22# circumstances dictate by setting EXTERNALSRC_BUILD to the same value, e.g.:
23#
24# EXTERNALSRC_BUILD_pn-myrecipe = "/path/to/my/source/tree"
25#
26
27SRCTREECOVEREDTASKS ?= "do_patch do_unpack do_fetch"
28
29python () {
30 externalsrc = d.getVar('EXTERNALSRC', True)
31 if externalsrc:
32 d.setVar('S', externalsrc)
33 externalsrcbuild = d.getVar('EXTERNALSRC_BUILD', True)
34 if externalsrcbuild:
35 d.setVar('B', externalsrcbuild)
36 else:
37 d.setVar('B', '${WORKDIR}/${BPN}-${PV}/')
38
39 local_srcuri = []
40 fetch = bb.fetch2.Fetch((d.getVar('SRC_URI', True) or '').split(), d)
41 for url in fetch.urls:
42 url_data = fetch.ud[url]
43 parm = url_data.parm
44 if (url_data.type == 'file' or
45 'type' in parm and parm['type'] == 'kmeta'):
46 local_srcuri.append(url)
47
48 d.setVar('SRC_URI', ' '.join(local_srcuri))
49
50 if '{SRCPV}' in d.getVar('PV', False):
51 # Dummy value because the default function can't be called with blank SRC_URI
52 d.setVar('SRCPV', '999')
53
54 tasks = filter(lambda k: d.getVarFlag(k, "task"), d.keys())
55
56 for task in tasks:
57 if task.endswith("_setscene"):
58 # sstate is never going to work for external source trees, disable it
59 bb.build.deltask(task, d)
60 else:
61 # Since configure will likely touch ${S}, ensure only we lock so one task has access at a time
62 d.appendVarFlag(task, "lockfiles", " ${S}/singletask.lock")
63
64 # We do not want our source to be wiped out, ever (kernel.bbclass does this for do_clean)
65 cleandirs = (d.getVarFlag(task, 'cleandirs', False) or '').split()
66 setvalue = False
67 for cleandir in cleandirs[:]:
68 if d.expand(cleandir) == externalsrc:
69 cleandirs.remove(cleandir)
70 setvalue = True
71 if setvalue:
72 d.setVarFlag(task, 'cleandirs', ' '.join(cleandirs))
73
74 fetch_tasks = ['do_fetch', 'do_unpack']
75 # If we deltask do_patch, there's no dependency to ensure do_unpack gets run, so add one
Patrick Williamsf1e5d692016-03-30 15:21:19 -050076 # Note that we cannot use d.appendVarFlag() here because deps is expected to be a list object, not a string
77 d.setVarFlag('do_configure', 'deps', (d.getVarFlag('do_configure', 'deps', False) or []) + ['do_unpack'])
Patrick Williamsc124f4f2015-09-15 14:41:29 -050078
79 for task in d.getVar("SRCTREECOVEREDTASKS", True).split():
80 if local_srcuri and task in fetch_tasks:
81 continue
82 bb.build.deltask(task, d)
83
84 d.prependVarFlag('do_compile', 'prefuncs', "externalsrc_compile_prefunc ")
85
86 # Ensure compilation happens every time
87 d.setVarFlag('do_compile', 'nostamp', '1')
88}
89
90python externalsrc_compile_prefunc() {
91 # Make it obvious that this is happening, since forgetting about it could lead to much confusion
Patrick Williamsf1e5d692016-03-30 15:21:19 -050092 bb.plain('NOTE: %s: compiling from external source tree %s' % (d.getVar('PN', True), d.getVar('EXTERNALSRC', True)))
Patrick Williamsc124f4f2015-09-15 14:41:29 -050093}