sourceipk: fix race condition with compileconfigs/multi-kernel
[openembedded.git] / classes / metadata_scm.bbclass
blobf79ea1998faeaf14aa69fa79a20bfd9491f32a5f
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     try:
67         rev = oe_run(d, ["git", "symbolic-ref", "HEAD"], cwd=path).rstrip()
68     except oe.process.CmdError:
69         rev = "<unknown>"
70     else:
71         rev = rev.replace("refs/heads/", "")
72     return rev
74 def base_get_metadata_git_revision(path, d):
75     try:
76         rev = oe_run(d, ["git", "rev-parse", "--verify", "--short", "HEAD"],
77                      cwd=path).rstrip()
78     except oe.process.CmdError:
79         rev = "<unknown>"
80     return rev