Bug 6302 - Versions of packages retrieved from github.com are wrong
Summary: Versions of packages retrieved from github.com are wrong
Status: RESOLVED FIXED
Alias: None
Product: buildroot
Classification: Unclassified
Component: Outdated package (show other bugs)
Version: unspecified
Hardware: All All
: P5 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-06-06 01:38 UTC by Andrew Scheller
Modified: 2013-06-10 03:44 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Scheller 2013-06-06 01:38:42 UTC
I'm no buildroot or github expert (so apologies if I get some of the terminology wrong), but I think I've found a bit of a nasty problem with the way buildroot downloads specific versions of packages from github.com. At first I thought it was because the .mk files for the specific rpi-* packages I was looking at were set up wrong, but I've been investigating the problem for much of this afternoon and I think it actually affects the .mk files for many packages :-(

According to http://www.buildroot.org/downloads/manual/manual.html#github-download-url packages in github with a specific tag can be downloaded with:
FOO_VERSION = v1.0
FOO_SITE = http://github.com/<user>/<package>/tarball/$(FOO_VERSION)
(where here 'v1.0' is the tag in github)

And for those packages where you don't have a specific tag but instead want to download a specific revision, you can use:
FOO_VERSION = 1234567
FOO_SITE = http://github.com/<user>/<package>/tarball/<branch>
(where here '1234567' is the first 7 characters of the github commit hash)

In my tests, the former (downloading a specific tag) works okay, but the latter (downloading a specific revision) actually doesn't work as expected. I can't tell if this used to work and has become broken recently by a change to github.com, or if it's always been broken (but nobody ever noticed), or if I'm simply misunderstanding things (to save me looking stupid, hopefully it's not this last one!).

I'll stick with the two FOO examples above, but substituting 'fooauthor' for '<user>', 'foopackage' for '<package>' and 'master' for <branch>...

When downloading a specific tag, the first example above would download http://github.com/fooauthor/foopackage/tarball/v1.0/foo-v1.0.tar.gz to dl/foo-v1.0.tar.gz and this is the part that works correctly.
When downloading a specific revision, the second example above would download http://github.com/fooauthor/foopackage/tarball/master/foo-1234567.tar.gz to dl/foo-1234567.tar.gz and this appears to work fine, but it actually downloads the latest revision of the master branch, and not the 1234567 revision as you might expect! So if 1234567 _is_ indeed the latest revision, then things all look okay, which may be why nobody noticed this bug before, but things go quickly wrong if there's commits after 1234567.

In my testing, it seems that _whatever_ filename you have after the .../master/ in the URL will get ignored, and you'll always get the latest commit from the master branch. However it seems that you can actually specify a revision instead of <branch> and it will then work as expected, i.e. AFAICT the 'download by revision' example above should be modified to:
FOO_VERSION = 1234567
FOO_SITE = http://github.com/<user>/<package>/tarball/$(FOO_VERSION)

and then buildroot will download http://github.com/fooauthor/foopackage/tarball/1234567/foo-1234567.tar.gz to dl/foo-1234567.tar.gz and this *will* then work as expected. Obviously you could set FOO_VERSION to 'master' and it would go back to the previous behaviour of downloading the latest commit on the master branch, but at least this behaviour would then be explicit rather than implicit.

Where the <branch> has been used (which I've replaced with $(FOO_VERSION)) I've found that you can either use a tag-name, a branch-name, or a (full or partial) commit-id, and then following another slash you can include any filename you want, which makes no difference to the file github.com serves to you.

To give a more concrete example, I found a random repository with lots of commits, tags and branches: https://github.com/libgit2/libgit2
As of 2012-06-06 these URLs all result in the identical file being downloaded:
[by branch-name]
http://github.com/libgit2/libgit2/tarball/master  (wget saves to 'master')
http://github.com/libgit2/libgit2/tarball/master/  (wget saves to 'index.html')
http://github.com/libgit2/libgit2/tarball/master/libgit2-master.tar.gz  (wget saves to 'libgit2-master.tar.gz')
http://github.com/libgit2/libgit2/tarball/master/libgit2-dummy-filename.tgz
[by tag-name]
http://github.com/libgit2/libgit2/tarball/v0.18.0
http://github.com/libgit2/libgit2/tarball/v0.18.0/libgit2-v0.18.0.tar.gz
[by commit-id]
http://github.com/libgit2/libgit2/tarball/a50086d
http://github.com/libgit2/libgit2/tarball/a50086d/libgit2-a50086d.tar.gz
http://github.com/libgit2/libgit2/tarball/a50086d174/libgit2-a50086d174.tar.gz
http://github.com/libgit2/libgit2/tarball/a50086d174658914d4d6462afbc83b02825b1f5b
http://github.com/libgit2/libgit2/tarball/a50086d174658914d4d6462afbc83b02825b1f5b/libgit2-a50086d174658914d4d6462afbc83b02825b1f5b.tar.gz
(I used 'sha1sum *' to verify all the downloaded files are identical. In each case the files inside the tarfile are inside a 'libgit2-libgit2-a50086d' subdirectory)

And these URLs result in identical files being downloaded:
[by commit-id]
http://github.com/libgit2/libgit2/tarball/36c2dfe
http://github.com/libgit2/libgit2/tarball/36c2dfe/libgit2-36c2dfe.tar.gz
http://github.com/libgit2/libgit2/tarball/36c2dfed69/libgit2-36c2dfed69.tar.gz
http://github.com/libgit2/libgit2/tarball/36c2dfed696f80a20ca1352f32ec8b136b800c30/libgit2-36c2dfed696f80a20ca1352f32ec8b136b800c30.tar.gz

And these URLs result in identical files being downloaded:
[by branch-name]
http://github.com/libgit2/libgit2/tarball/development
http://github.com/libgit2/libgit2/tarball/development/libgit2-development.tar.gz
[by commit-id]
http://github.com/libgit2/libgit2/tarball/2e1fa15
http://github.com/libgit2/libgit2/tarball/2e1fa15/libgit2-2e1fa15.tar.gz

etc. etc. you get the idea. The only (unlikely occurrence) I didn't test was a branch-name having the same name as a tag-name. Obviously the match-ups between branch-names and commit-ids shown above will go 'out of sync' once more commits have been made to those branches.


In summary, I believe http://www.buildroot.org/downloads/manual/manual.html#github-download-url should be updated to say that FOO_SITE should always look like:
FOO_SITE = http://github.com/<user>/<package>/tarball/$(FOO_VERSION)
and then mention that FOO_VERSION can either specify a tag-name or a commit-id or a branch-name.

In the current git version of buildroot, by constructing a funky find command:
find package -exec grep -P '^[A-Z0-9_]+_SITE\s*=\s*https?://github\.com/.*/tarball/(?!.*\$\(.+\))' {} \; -print | grep \.mk | sort

...I believe these are the packages that need to have their _SITE setting updated in their .mk file:
jsmin, libcofi, linenoise, lua-msgpack-native, mtdev2tuio, ne10, omap-u-boot-utils, rpi-firmware, rpi-userland, socketcand, sunxi-boards, sunxi-tools, ti-utils, tslib
Comment 1 Peter Korsgaard 2013-06-06 21:12:38 UTC
Fixed in git by Spenser. Thanks both!
Comment 2 Andrew Scheller 2013-06-06 23:42:30 UTC
Great!
But http://git.buildroot.net/buildroot/tree/docs/manual/adding-packages-tips.txt still needs to be updated (and http://www.buildroot.org/downloads/manual/manual.html regenerated as necessary) to prevent other people making the same mistake in future...
Comment 3 Peter Korsgaard 2013-06-07 08:52:44 UTC
(In reply to comment #2)
> Great!
> But
> http://git.buildroot.net/buildroot/tree/docs/manual/adding-packages-tips.txt
> still needs to be updated (and
> http://www.buildroot.org/downloads/manual/manual.html regenerated as necessary)
> to prevent other people making the same mistake in future...

Manual updated in git and website updated, thanks.
Comment 4 Andrew Scheller 2013-06-07 10:56:41 UTC
Fantastic, thanks to all involved (and so quick too!).

Just for my future reference, this is the related mailing-list thread http://thread.gmane.org/gmane.comp.lib.uclibc.buildroot/60950 and these are the git commit ids that were involved in fixing this bug:
f0f124f36a8616a1e0895b2eb9411a8459daa3c9  (jsmin)
9bb2757c461271f4458294d417f440f839513e33  (libcofi)
b89e8141e3247e28387e14a2959d3ec8ea11f12c  (linenoise)
55c90b10b3c73ff0708ceb73645c51658f4821aa  (lua-msgpack-native)
e9c9bd2d62a1d09f2f54b55f05301be0e06981df  (mtdev2tuio)
c2b205c038bc0dba3960917f2eb1bd30fbc24b03  (ne10)
ae5be552b6435437db42b168b61aa15b8bed2fbc  (omap-u-boot-utils)
6b16001d4f026fd08f14a4b2043710531b50a0ad  (rpi-firmware)
8645437c0cc0fffa6962030ddd90698ab917891e  (rpi-userland)
fe64434df6c8a5f3516f92caf9c04d6dedda444b  (socketcand)
8ad0ab6e16e67a1d1269aec7ddc1b70d10d86e82  (sunxi-boards)
63c39b52ce3cfacf12071e8d76a5a30c57fe54d6  (sunxi-tools)
7869f83bda815279f8245913d33062e525d4efe1  (ti-utils)
013365238f0b00f01dcc173edf2f3b6e37f7beb1  (tslib)
484b6dd8a3abccf0be34d1bed3761a8809ba23be  (manual)
86bfe7cca9bca292f00f7a41221ae5879f4a5769  (manual)
Comment 5 Andrew Scheller 2013-06-10 03:44:56 UTC
Fixing this bug also involved commit ids:
41190ef0f1ffb68675bfe77205e9207363546377  (linenoise)
0b8ed5b53d066f86f09e01d02a5e0bd715c17b70  (lua-msgpack-native)
because they were using invalid git hashes (which this bug had been masking).