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