diff options
author | Chris Larson <chris_larson@mentor.com> | 2010-03-09 16:55:37 -0700 |
---|---|---|
committer | Chris Larson <chris_larson@mentor.com> | 2010-03-19 10:42:04 -0700 |
commit | 89b7e433719f43f1c36c76cb8856d559014e99bc (patch) | |
tree | b32fb12b2530280ea8c896ffc30a84aac3cca039 /classes/metadata_scm.bbclass | |
parent | a215c2f283476776567506c2e3f969c48f7e5e3d (diff) |
Initial split of base.bbclass
Acked-by: Richard Purdie <rpurdie@linux.intel.com>
Acked-by: Marcin Juszkiewicz <marcin@juszkiewicz.com.pl>
Signed-off-by: Chris Larson <chris_larson@mentor.com>
Diffstat (limited to 'classes/metadata_scm.bbclass')
-rw-r--r-- | classes/metadata_scm.bbclass | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/classes/metadata_scm.bbclass b/classes/metadata_scm.bbclass new file mode 100644 index 0000000000..ffc6a8adfe --- /dev/null +++ b/classes/metadata_scm.bbclass @@ -0,0 +1,76 @@ +METADATA_SCM = "${@base_get_scm(d)}" +METADATA_REVISION = "${@base_get_scm_revision(d)}" +METADATA_BRANCH = "${@base_get_scm_branch(d)}" + +def base_get_scm(d): + from bb import which + baserepo = os.path.dirname(os.path.dirname(which(d.getVar("BBPATH", 1), "classes/base.bbclass"))) + for (scm, scmpath) in {"svn": ".svn", + "git": ".git", + "monotone": "_MTN"}.iteritems(): + if os.path.exists(os.path.join(baserepo, scmpath)): + return "%s %s" % (scm, baserepo) + return "<unknown> %s" % baserepo + +def base_get_scm_revision(d): + (scm, path) = d.getVar("METADATA_SCM", 1).split() + try: + if scm != "<unknown>": + return globals()["base_get_metadata_%s_revision" % scm](path, d) + else: + return scm + except KeyError: + return "<unknown>" + +def base_get_scm_branch(d): + (scm, path) = d.getVar("METADATA_SCM", 1).split() + try: + if scm != "<unknown>": + return globals()["base_get_metadata_%s_branch" % scm](path, d) + else: + return scm + except KeyError: + return "<unknown>" + +def base_get_metadata_monotone_branch(path, d): + monotone_branch = "<unknown>" + try: + monotone_branch = file( "%s/_MTN/options" % path ).read().strip() + if monotone_branch.startswith( "database" ): + monotone_branch_words = monotone_branch.split() + monotone_branch = monotone_branch_words[ monotone_branch_words.index( "branch" )+1][1:-1] + except: + pass + return monotone_branch + +def base_get_metadata_monotone_revision(path, d): + monotone_revision = "<unknown>" + try: + monotone_revision = file( "%s/_MTN/revision" % path ).read().strip() + if monotone_revision.startswith( "format_version" ): + monotone_revision_words = monotone_revision.split() + monotone_revision = monotone_revision_words[ monotone_revision_words.index( "old_revision" )+1][1:-1] + except IOError: + pass + return monotone_revision + +def base_get_metadata_svn_revision(path, d): + revision = "<unknown>" + try: + revision = file( "%s/.svn/entries" % path ).readlines()[3].strip() + except IOError: + pass + return revision + +def base_get_metadata_git_branch(path, d): + branch = os.popen('cd %s; PATH=%s git symbolic-ref HEAD 2>/dev/null' % (path, d.getVar("PATH", 1))).read().rstrip() + + if len(branch) != 0: + return branch.replace("refs/heads/", "") + return "<unknown>" + +def base_get_metadata_git_revision(path, d): + rev = os.popen("cd %s; PATH=%s git show-ref HEAD 2>/dev/null" % (path, d.getVar("PATH", 1))).read().split(" ")[0].rstrip() + if len(rev) != 0: + return rev + return "<unknown>" |