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) |
| 6 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 7 | scms = [base_get_metadata_git_revision] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 8 | |
| 9 | for scm in scms: |
| 10 | rev = scm(path, d) |
| 11 | if rev != "<unknown>": |
| 12 | return rev |
| 13 | |
| 14 | return "<unknown>" |
| 15 | |
| 16 | def base_detect_branch(d): |
| 17 | path = base_get_scmbasepath(d) |
| 18 | |
| 19 | scms = [base_get_metadata_git_branch] |
| 20 | |
| 21 | for scm in scms: |
| 22 | rev = scm(path, d) |
| 23 | if rev != "<unknown>": |
| 24 | return rev.strip() |
| 25 | |
| 26 | return "<unknown>" |
| 27 | |
| 28 | def base_get_scmbasepath(d): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 29 | return os.path.join(d.getVar('COREBASE'), 'meta') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 30 | |
| 31 | def base_get_metadata_monotone_branch(path, d): |
| 32 | monotone_branch = "<unknown>" |
| 33 | try: |
| 34 | with open("%s/_MTN/options" % path) as f: |
| 35 | monotone_branch = f.read().strip() |
| 36 | if monotone_branch.startswith( "database" ): |
| 37 | monotone_branch_words = monotone_branch.split() |
| 38 | monotone_branch = monotone_branch_words[ monotone_branch_words.index( "branch" )+1][1:-1] |
| 39 | except: |
| 40 | pass |
| 41 | return monotone_branch |
| 42 | |
| 43 | def base_get_metadata_monotone_revision(path, d): |
| 44 | monotone_revision = "<unknown>" |
| 45 | try: |
| 46 | with open("%s/_MTN/revision" % path) as f: |
| 47 | monotone_revision = f.read().strip() |
| 48 | if monotone_revision.startswith( "format_version" ): |
| 49 | monotone_revision_words = monotone_revision.split() |
| 50 | monotone_revision = monotone_revision_words[ monotone_revision_words.index( "old_revision" )+1][1:-1] |
| 51 | except IOError: |
| 52 | pass |
| 53 | return monotone_revision |
| 54 | |
| 55 | def base_get_metadata_svn_revision(path, d): |
| 56 | # This only works with older subversion. For newer versions |
| 57 | # this function will need to be fixed by someone interested |
| 58 | revision = "<unknown>" |
| 59 | try: |
| 60 | with open("%s/.svn/entries" % path) as f: |
| 61 | revision = f.readlines()[3].strip() |
| 62 | except (IOError, IndexError): |
| 63 | pass |
| 64 | return revision |
| 65 | |
| 66 | def base_get_metadata_git_branch(path, d): |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 67 | import bb.process |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 68 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 69 | try: |
| 70 | rev, _ = bb.process.run('git rev-parse --abbrev-ref HEAD', cwd=path) |
| 71 | except bb.process.ExecutionError: |
| 72 | rev = '<unknown>' |
| 73 | return rev.strip() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 74 | |
| 75 | def base_get_metadata_git_revision(path, d): |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 76 | import bb.process |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 77 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 78 | try: |
| 79 | rev, _ = bb.process.run('git rev-parse HEAD', cwd=path) |
| 80 | except bb.process.ExecutionError: |
| 81 | rev = '<unknown>' |
| 82 | return rev.strip() |