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