diff options
| author | Tudor Florea <tudor.florea@enea.com> | 2014-10-16 03:05:19 +0200 |
|---|---|---|
| committer | Tudor Florea <tudor.florea@enea.com> | 2014-10-16 03:05:19 +0200 |
| commit | c527fd1f14c27855a37f2e8ac5346ce8d940ced2 (patch) | |
| tree | bb002c1fdf011c41dbd2f0927bed23ecb5f83c97 /meta/classes/metadata_scm.bbclass | |
| download | poky-daisy-140929.tar.gz | |
initial commit for Enea Linux 4.0-140929daisy-140929
Migrated from the internal git server on the daisy-enea-point-release branch
Signed-off-by: Tudor Florea <tudor.florea@enea.com>
Diffstat (limited to 'meta/classes/metadata_scm.bbclass')
| -rw-r--r-- | meta/classes/metadata_scm.bbclass | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/meta/classes/metadata_scm.bbclass b/meta/classes/metadata_scm.bbclass new file mode 100644 index 0000000000..ba0edf9486 --- /dev/null +++ b/meta/classes/metadata_scm.bbclass | |||
| @@ -0,0 +1,82 @@ | |||
| 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): | ||
| 68 | branch = os.popen('cd %s; git branch 2>&1 | grep "^* " | tr -d "* "' % path).read() | ||
| 69 | |||
| 70 | if len(branch) != 0: | ||
| 71 | return branch | ||
| 72 | return "<unknown>" | ||
| 73 | |||
| 74 | def base_get_metadata_git_revision(path, d): | ||
| 75 | f = os.popen("cd %s; git log -n 1 --pretty=oneline -- 2>&1" % path) | ||
| 76 | data = f.read() | ||
| 77 | if f.close() is None: | ||
| 78 | rev = data.split(" ")[0] | ||
| 79 | if len(rev) != 0: | ||
| 80 | return rev | ||
| 81 | return "<unknown>" | ||
| 82 | |||
