srctree & gitver
I'm going to summarize the features of the two classes I've created over the past couple days. I believe that they will make the lives of app & kernel developers much easier when dealing with bitbake/OE/MVL6.
srctree facilitates bitbake builds in existing source trees, bypassing the fetch/unpack/patch idiom. It's easy to allow the user to put the recipe in their source tree, if they want to store it in their scm repository with their app/kernel code, or you can point the recipe at external trees. This works for app and kernel development.
gitver facilitates extraction of version information from git. By default, it runs 'git describe' to get the version. If that fails, it will set the version to 0.0-<sha1 hash>. This version is stored in the ${GITVER} variable, and can be used in the recipe's PV variable. When using this, it will automatically detect changes to .git/HEAD (i.e. commit your local changes, check out a different branch, ..) and invalidate the bitbake cache, pick up the new PV, and know that it needs to re-run the build steps.
Examples:
Common steps:
$ cd myproject ~/oe/projects/myproject $ . ./setup.sh
Example of a user who wants bitbake to build their existing source tree outside the project:
Userland:
$ cd myproject ~/oe/projects/myproject $ . ./setup.sh $ cat <<END >collections/custom/hello.bb inherit srctree
# Pointing to the external source tree
S = "${HOME}/code/hello"
DESCRIPTION = "Hello, World"
do_install () {
install -D -m 0755 hello ${D}${bindir}/hello
}
END
$ bitbake hello
Kernel:
$ cat <<END >collections/custom/linux.bb inherit kernel srctree gitver
# Strip off the leading 'v' from the Linux kernel git tags PV = "${@'${GITVER}'[1:]}"
# Point to my existing kernel development tree
S = "${HOME}/code/linux-2.6"
END
$ bitbake linux
Example of a user who wants their source tree to live in their project:
Userland:
$ mkdir collections/hello
$ cd collections/hello
~/oe/projects/myproject/collections/hello
$ cat <<END >hello.c
heredoc> #include <stdio.h>
heredoc>
heredoc> int main(int argc, char **argv)
heredoc> {
heredoc> printf("Hello, World!\n");
heredoc> }
heredoc> END
$ cat <<END >Makefile
heredoc> all: hello
heredoc> hello: hello.c
heredoc> \$(CC) \$(CFLAGS) \$(LDFLAGS) hello.c -o hello
heredoc> clean:
heredoc> rm -f hello
heredoc> END
$ cat <<END >hello.bb
heredoc> inherit srctree
heredoc>
heredoc> DESCRIPTION = "Hello, World."
heredoc>
heredoc> do_install () {
heredoc> install -D -m 0755 hello \${D}\${bindir}/hello
heredoc> }
heredoc> END
$ bitbake hello
NOTE: Handling BitBake files: \ (0010/0010) [100%%]
NOTE: Parsing finished. 0 cached, 10 parsed, 0 skipped, 0 masked.
NOTE: Resolving any missing task queue dependencies
NOTE: Preparing runqueue
NOTE: Executing runqueue
NOTE: Running task 1 of 2 (ID: 1,
/home/clarson/oe/projects/myproject/collections/hello/hello.bb,
do_populate_staging)
NOTE: Running task 2 of 2 (ID: 0,
/home/clarson/oe/projects/myproject/collections/hello/hello.bb,
do_build)
NOTE: Tasks Summary: Attempted 2 tasks of which 0 didn't need to be
rerun and 0 failed.
$ ls
hello hello.bb hello.c Makefile
$ ./hello
Hello, World!
$ bitbake -c clean hello
NOTE: Handling BitBake files: \ (0010/0010) [100%%]
NOTE: Parsing finished. 10 cached, 0 parsed, 0 skipped, 0 masked.
NOTE: Cache is clean, not saving.
NOTE: Resolving any missing task queue dependencies
NOTE: Preparing runqueue
NOTE: Executing runqueue
NOTE: Running task 1 of 1 (ID: 0,
/home/clarson/oe/projects/myproject/collections/hello/hello.bb,
do_clean)
NOTE: Removing stamps
NOTE: Removing /home/clarson/oe/projects/myproject/tmp/work/i486-linux/hello-1.0-r0
NOTE: Running make clean
NOTE: Tasks Summary: Attempted 1 tasks of which 0 didn't need to be
rerun and 0 failed.
$ ls
hello.bb hello.c Makefile
$ sed -i -e 's,World,Country,' hello.c
$ bitbake hello
NOTE: Handling BitBake files: \ (0010/0010) [100%%]
NOTE: Parsing finished. 10 cached, 0 parsed, 0 skipped, 0 masked.
NOTE: Cache is clean, not saving.
NOTE: Resolving any missing task queue dependencies
NOTE: Preparing runqueue
NOTE: Executing runqueue
NOTE: Running task 1 of 2 (ID: 1,
/home/clarson/oe/projects/myproject/collections/hello/hello.bb,
do_populate_staging)
NOTE: Running task 2 of 2 (ID: 0,
/home/clarson/oe/projects/myproject/collections/hello/hello.bb,
do_build)
NOTE: Tasks Summary: Attempted 2 tasks of which 0 didn't need to be
rerun and 0 failed.
$ ./hello
Hello, Country!
$Kernel:
$ git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git collections/linux-2.6 [... git output ...] $ cat <<END >collections/linux-2.6/linux.bb inherit kernel srctree gitver
# Strip off the leading 'v' from the Linux kernel git tags PV = "${@'${GITVER}'[1:]}"
END
$ bitbake linux
Signature · 7 lines
Chris Larson clarson at kergoth dot com clarson at mvista dot com Founder - BitBake, OpenEmbedded, OpenZaurus Maintainer - Tslib Software Engineer MontaVista Software, Inc.
Hello Chris,
Quoted 4 lines · Chris Larson
I'm going to summarize the features of the two classes I've created over the past couple days. I believe that they will make the lives of app & kernel developers much easier when dealing with bitbake/OE/MVL6.
Thanks for the extensive description and examples.
Indeeds this looks like a time saver for many.
Regards,
Signature · 1 line
Leon
Hello Chris,
On Wed, Aug 26, 2009 at 11:05 PM, Chris Larson<[email protected]> wrote:
[...]
Quoted 8 lines
gitver facilitates extraction of version information from git. By default, it runs 'git describe' to get the version. If that fails, it will set the version to 0.0-<sha1 hash>. This version is stored in the ${GITVER} variable, and can be used in the recipe's PV variable. When using this, it will automatically detect changes to .git/HEAD (i.e. commit your local changes, check out a different branch, ..) and invalidate the bitbake cache, pick up the new PV, and know that it needs to re-run the build steps.
[...]
In the line of your gitver class we've been using a bitbake change for it already for some time.
What we did is to add a AUTOPV (as we have AUTOREV) to bitbake and use it in OE.
I'm attaching the diff for it here.
Signature · 3 lines
Otavio Salvador O.S. Systems E-mail: [email protected] http://www.ossystems.com.br Mobile: +55 53 9981-7854 http://projetos.ossystems.com.br
lib/bb/fetch/__init__.py +34 -13
@@ -197,6 +197,20 @@ def localpaths(d): srcrev_internal_call = False +def get_scms(d, urldata, rev_support_only = True): + scms = [] + for u in urldata: + ud = urldata[u] + if not rev_support_only or (rev_support_only and ud.method.suppports_srcrev()): + if not ud.setup: + ud.setup_localpath(d) + scms.append(u) + + if len(scms) == 0: + bb.msg.error(bb.msg.domain.Fetcher, "SRCREV was used yet no valid SCM was found in SRC_URI") + + return scms + def get_srcrev(d): """ Return the version string for the current package
@@ -218,20 +232,8 @@ def get_srcrev(d): if bb.fetch.srcrev_internal_call: return "SRCREVINACTION" - scms = [] - - # Only call setup_localpath on URIs which suppports_srcrev() urldata = init(bb.data.getVar('SRC_URI', d, 1).split(), d, False) - for u in urldata: - ud = urldata[u] - if ud.method.suppports_srcrev(): - if not ud.setup: - ud.setup_localpath(d) - scms.append(u) - - if len(scms) == 0: - bb.msg.error(bb.msg.domain.Fetcher, "SRCREV was used yet no valid SCM was found in SRC_URI") - raise ParameterError + scms = get_scms(d, urldata) bb.data.setVar('__BB_DONT_CACHE','1', d)
@@ -254,6 +256,25 @@ def get_srcrev(d): return format +def describe_revision(d): + """ + Return the output of 'git describe' or 'NO_REV_DESCR' in case no + tag is found. + """ + urldata = init(bb.data.getVar('SRC_URI', d, 1).split(), d, False) + bb.data.setVar('__BB_DONT_CACHE','1', d) + scms = get_scms(d, urldata) + scm = '' + if len(scms) == 1: + scm = scms[0] + else: + bb.msg.error(bb.msg.domain.Fetcher, "describe_revision does not support multiple SCMs.") + + try: + return urldata[scm].method.describe_revision(scm, urldata[scm], d) + except NoMethodError: + return "NO_REV_DESCR" + def localpath(url, d, cache = True): """ Called from the parser with cache=False since the cache isn't ready
lib/bb/fetch/git.py +32 -8
@@ -149,6 +149,16 @@ class Git(Fetch): def _want_sortable_revision(self, url, ud, d): return bb.data.getVar("BB_GIT_CLONE_FOR_SRCREV", d, True) or False + def _chrepo(self, repodir, ud, d): + # Check if we have the rev already + if not os.path.exists(repodir): + print "no repo" + self.go(None, ud, d) + + os.chdir(repodir) + if not self._contains_ref(ud.tag, d): + self.go(None, ud, d) + def _sortable_revision(self, url, ud, d): """ This is only called when _want_sortable_revision called true
@@ -170,14 +180,7 @@ class Git(Fetch): cwd = os.getcwd() - # Check if we have the rev already - if not os.path.exists(repodir): - print "no repo" - self.go(None, ud, d) - - os.chdir(repodir) - if not self._contains_ref(ud.tag, d): - self.go(None, ud, d) + self._chrepo(repodir, ud, d) output = runfetchcmd("git rev-list %s -- 2> /dev/null | wc -l" % ud.tag, d, quiet=True) os.chdir(cwd)
@@ -187,3 +190,24 @@ class Git(Fetch): return sortable_revision + def describe_revision(self, url, ud, d): + gitsrcname = '%s%s' % (ud.host, ud.path.replace('/', '.')) + repodir = os.path.join(data.expand('${GITDIR}', d), gitsrcname) + + # Runtime warning on wrongly configured sources + if ud.tag == "1": + bb.msg.error(1, bb.msg.domain.Fetcher, "SRCREV is '1'. This indicates a configuration error of %s" % url) + return "0+1" + + cwd = os.getcwd() + + self._chrepo(repodir, ud, d) + + rev_descr = '' + try: + rev_descr = runfetchcmd("git describe %s 2>/dev/null" % ud.tag, d, quiet=True).strip() + except FetchError: + rev_descr = "0.0.0-%s-g%s" % (runfetchcmd("git rev-list %s -- 2> /dev/null | wc -l" % ud.tag, d, quiet=True).strip(), + runfetchcmd("git describe %s --always 2> /dev/null" % ud.tag, d, quiet=True).strip()) + os.chdir(cwd) + return rev_descr.replace('-', '.')
Seems interesting, but how are you making use of it? It wouldn't be particularly useful for recipes that have to fetch, since you can't change PV before and after fetch without things exploding.
Quoted 32 lines · Otavio Salvador
Hello Chris,
On Wed, Aug 26, 2009 at 11:05 PM, Chris Larson<[email protected]> wrote:
[...]Quoted 8 lines
gitver facilitates extraction of version information from git. By default, it runs 'git describe' to get the version. If that fails, it will set the version to 0.0-<sha1 hash>. This version is stored in the ${GITVER} variable, and can be used in the recipe's PV variable. When using this, it will automatically detect changes to .git/HEAD (i.e. commit your local changes, check out a different branch, ..) and invalidate the bitbake cache, pick up the new PV, and know that it needs to re-run the build steps.
[...]
In the line of your gitver class we've been using a bitbake change for it already for some time.
What we did is to add a AUTOPV (as we have AUTOREV) to bitbake and use it in OE.
I'm attaching the diff for it here.
--
Otavio Salvador O.S. Systems
E-mail: [email protected] http://www.ossystems.com.br
Mobile: +55 53 9981-7854 http://projetos.ossystems.com.br_______________________________________________
Openembedded-devel mailing list
[email protected]
http://lists.linuxtogo.org/cgi-bin/mailman/listinfo/openembedded-devel
Signature · 7 lines
Chris Larson clarson at kergoth dot com clarson at mvista dot com Founder - BitBake, OpenEmbedded, OpenZaurus Maintainer - Tslib Software Engineer MontaVista Software, Inc.
In bitbake.conf
@@ -532,6 +534,7 @@ UPDATECOMMAND_svn = "/usr/bin/env svn update ${SVNCOOPTS}"
SRCDATE = "${DATE}"
SRCREV = "1"
AUTOREV = "${@bb.fetch.get_srcrev(d)}"
+AUTOPV = "${@bb.fetch.describe_revision(d)}"
SRC_URI = "file://${FILE}"
Quoted 54 lines · Chris Larson
Seems interesting, but how are you making use of it? It wouldn't be particularly useful for recipes that have to fetch, since you can't change PV before and after fetch without things exploding.
Quoted 26 lines · Otavio Salvador
Hello Chris,
On Wed, Aug 26, 2009 at 11:05 PM, Chris Larson<[email protected]> wrote:
[...]Quoted 8 lines
gitver facilitates extraction of version information from git. By default, it runs 'git describe' to get the version. If that fails, it will set the version to 0.0-<sha1 hash>. This version is stored in the ${GITVER} variable, and can be used in the recipe's PV variable. When using this, it will automatically detect changes to .git/HEAD (i.e. commit your local changes, check out a different branch, ..) and invalidate the bitbake cache, pick up the new PV, and know that it needs to re-run the build steps.
[...]
In the line of your gitver class we've been using a bitbake change for it already for some time.
What we did is to add a AUTOPV (as we have AUTOREV) to bitbake and use it in OE.
I'm attaching the diff for it here.
--
Otavio Salvador O.S. Systems
E-mail: [email protected] http://www.ossystems.com.br
Mobile: +55 53 9981-7854 http://projetos.ossystems.com.brQuoted 6 lines
_______________________________________________
Openembedded-devel mailing list
[email protected]
http://lists.linuxtogo.org/cgi-bin/mailman/listinfo/openembedded-devel--
Chris Larson
clarson at kergoth dot com
clarson at mvista dot com
Founder - BitBake, OpenEmbedded, OpenZaurus
Maintainer - Tslib
Software Engineer
MontaVista Software, Inc._______________________________________________
Openembedded-devel mailing list
[email protected]
http://lists.linuxtogo.org/cgi-bin/mailman/listinfo/openembedded-devel
Signature · 3 lines
Otavio Salvador O.S. Systems E-mail: [email protected] http://www.ossystems.com.br Mobile: +55 53 9981-7854 http://projetos.ossystems.com.br
This doesn't answer my question, however. You wouldn't be able to safely use AUTOPV in PV unless you're pointing S to an existing non-fetched git repository, since PV would change before and after the fetch, so I was attempting to clarify this. Since you can't use it safely for fetched sources, it doesn't really belong in bb.fetch.
Quoted 78 lines · Otavio Salvador
In bitbake.conf
(quoted diff) +0
-0@@ -532,6 +534,7 @@ UPDATECOMMAND_svn = "/usr/bin/env svn update ${SVNCOOPTS}"SRCDATE = "${DATE}"
SRCREV = "1"
AUTOREV = "${@bb.fetch.get_srcrev(d)}"
+AUTOPV = "${@bb.fetch.describe_revision(d)}"SRC_URI = "file://${FILE}"
Quoted 49 lines · Chris Larson
Seems interesting, but how are you making use of it? It wouldn't be particularly useful for recipes that have to fetch, since you can't change PV before and after fetch without things exploding.
Quoted 26 lines · Otavio Salvador
Hello Chris,
On Wed, Aug 26, 2009 at 11:05 PM, Chris Larson<[email protected]> wrote:
[...]Quoted 8 lines
gitver facilitates extraction of version information from git. By default, it runs 'git describe' to get the version. If that fails, it will set the version to 0.0-<sha1 hash>. This version is stored in the ${GITVER} variable, and can be used in the recipe's PV variable. When using this, it will automatically detect changes to .git/HEAD (i.e. commit your local changes, check out a different branch, ..) and invalidate the bitbake cache, pick up the new PV, and know that it needs to re-run the build steps.
[...]
In the line of your gitver class we've been using a bitbake change for it already for some time.
What we did is to add a AUTOPV (as we have AUTOREV) to bitbake and use it in OE.
I'm attaching the diff for it here.
--
Otavio Salvador O.S. Systems
E-mail: [email protected] http://www.ossystems.com.br
Mobile: +55 53 9981-7854 http://projetos.ossystems.com.brQuoted 6 lines
_______________________________________________
Openembedded-devel mailing list
[email protected]
http://lists.linuxtogo.org/cgi-bin/mailman/listinfo/openembedded-devel--
Chris Larson
clarson at kergoth dot com
clarson at mvista dot com
Founder - BitBake, OpenEmbedded, OpenZaurus
Maintainer - Tslib
Software Engineer
MontaVista Software, Inc.Quoted 5 lines
_______________________________________________
Openembedded-devel mailing list
[email protected]
http://lists.linuxtogo.org/cgi-bin/mailman/listinfo/openembedded-devel--
Otavio Salvador O.S. Systems
E-mail: [email protected] http://www.ossystems.com.br
Mobile: +55 53 9981-7854 http://projetos.ossystems.com.br_______________________________________________
Openembedded-devel mailing list
[email protected]
http://lists.linuxtogo.org/cgi-bin/mailman/listinfo/openembedded-devel
Signature · 7 lines
Chris Larson clarson at kergoth dot com clarson at mvista dot com Founder - BitBake, OpenEmbedded, OpenZaurus Maintainer - Tslib Software Engineer MontaVista Software, Inc.
Hello,
Quoted 5 lines · Chris Larson
This doesn't answer my question, however. You wouldn't be able to safely use AUTOPV in PV unless you're pointing S to an existing non-fetched git repository, since PV would change before and after the fetch, so I was attempting to clarify this. Since you can't use it safely for fetched sources, it doesn't really belong in bb.fetch.
Sorry but you're wrong. When evaluating the cache it checks if remote has been change. So it works quite well and we're using it since April ;-)
Signature · 3 lines
Otavio Salvador O.S. Systems E-mail: [email protected] http://www.ossystems.com.br Mobile: +55 53 9981-7854 http://projetos.ossystems.com.br