ti-dsplink: Add support for DM6446 build (~ from Niclas)
[openembedded.git] / classes / metadata_scm.bbclass
blobffc6a8adfe5a064afa5393ac78aebd990ff1f581
1 METADATA_SCM = "${@base_get_scm(d)}"
2 METADATA_REVISION = "${@base_get_scm_revision(d)}"
3 METADATA_BRANCH = "${@base_get_scm_branch(d)}"
5 def base_get_scm(d):
6         from bb import which
7         baserepo = os.path.dirname(os.path.dirname(which(d.getVar("BBPATH", 1), "classes/base.bbclass")))
8         for (scm, scmpath) in {"svn": ".svn",
9                                "git": ".git",
10                                "monotone": "_MTN"}.iteritems():
11                 if os.path.exists(os.path.join(baserepo, scmpath)):
12                         return "%s %s" % (scm, baserepo)
13         return "<unknown> %s" % baserepo
15 def base_get_scm_revision(d):
16         (scm, path) = d.getVar("METADATA_SCM", 1).split()
17         try:
18                 if scm != "<unknown>":
19                         return globals()["base_get_metadata_%s_revision" % scm](path, d)
20                 else:
21                         return scm
22         except KeyError:
23                 return "<unknown>"
25 def base_get_scm_branch(d):
26         (scm, path) = d.getVar("METADATA_SCM", 1).split()
27         try:
28                 if scm != "<unknown>":
29                         return globals()["base_get_metadata_%s_branch" % scm](path, d)
30                 else:
31                         return scm
32         except KeyError:
33                 return "<unknown>"
35 def base_get_metadata_monotone_branch(path, d):
36         monotone_branch = "<unknown>"
37         try:
38                 monotone_branch = file( "%s/_MTN/options" % path ).read().strip()
39                 if monotone_branch.startswith( "database" ):
40                         monotone_branch_words = monotone_branch.split()
41                         monotone_branch = monotone_branch_words[ monotone_branch_words.index( "branch" )+1][1:-1]
42         except:
43                 pass
44         return monotone_branch
46 def base_get_metadata_monotone_revision(path, d):
47         monotone_revision = "<unknown>"
48         try:
49                 monotone_revision = file( "%s/_MTN/revision" % path ).read().strip()
50                 if monotone_revision.startswith( "format_version" ):
51                         monotone_revision_words = monotone_revision.split()
52                         monotone_revision = monotone_revision_words[ monotone_revision_words.index( "old_revision" )+1][1:-1]
53         except IOError:
54                 pass
55         return monotone_revision
57 def base_get_metadata_svn_revision(path, d):
58         revision = "<unknown>"
59         try:
60                 revision = file( "%s/.svn/entries" % path ).readlines()[3].strip()
61         except IOError:
62                 pass
63         return revision
65 def base_get_metadata_git_branch(path, d):
66         branch = os.popen('cd %s; PATH=%s git symbolic-ref HEAD 2>/dev/null' % (path, d.getVar("PATH", 1))).read().rstrip()
68         if len(branch) != 0:
69                 return branch.replace("refs/heads/", "")
70         return "<unknown>"
72 def base_get_metadata_git_revision(path, d):
73         rev = os.popen("cd %s; PATH=%s git show-ref HEAD 2>/dev/null" % (path, d.getVar("PATH", 1))).read().split(" ")[0].rstrip()
74         if len(rev) != 0:
75                 return rev
76         return "<unknown>"