Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | METADATA_BRANCH ?= "${@base_detect_branch(d)}" |
| 2 | METADATA_REVISION ?= "${@base_detect_revision(d)}" |
| 3 | |
| 4 | def base_detect_revision(d): |
| 5 | path = base_get_scmbasepath(d) |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 6 | return base_get_metadata_git_revision(path, d) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7 | |
| 8 | def base_detect_branch(d): |
| 9 | path = base_get_scmbasepath(d) |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 10 | return base_get_metadata_git_branch(path, d) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 11 | |
| 12 | def base_get_scmbasepath(d): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 13 | return os.path.join(d.getVar('COREBASE'), 'meta') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 14 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 15 | def base_get_metadata_svn_revision(path, d): |
| 16 | # This only works with older subversion. For newer versions |
| 17 | # this function will need to be fixed by someone interested |
| 18 | revision = "<unknown>" |
| 19 | try: |
| 20 | with open("%s/.svn/entries" % path) as f: |
| 21 | revision = f.readlines()[3].strip() |
| 22 | except (IOError, IndexError): |
| 23 | pass |
| 24 | return revision |
| 25 | |
| 26 | def base_get_metadata_git_branch(path, d): |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 27 | import bb.process |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 28 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 29 | try: |
| 30 | rev, _ = bb.process.run('git rev-parse --abbrev-ref HEAD', cwd=path) |
| 31 | except bb.process.ExecutionError: |
| 32 | rev = '<unknown>' |
| 33 | return rev.strip() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 34 | |
| 35 | def base_get_metadata_git_revision(path, d): |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 36 | import bb.process |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 37 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 38 | try: |
| 39 | rev, _ = bb.process.run('git rev-parse HEAD', cwd=path) |
| 40 | except bb.process.ExecutionError: |
| 41 | rev = '<unknown>' |
| 42 | return rev.strip() |