blob: 7cd842a187b3ef7adb75949dffe8537254c50a5b [file] [log] [blame]
Alexander Amelkin407064a2020-07-16 02:00:11 +03001# This recipe append assumes that all YADRO branches follow the
2# <type>/<product>/<description> convention, or are either
3# "merge/upstream" or "master" e.g.:
4#
5# release/nicole/v1
6# feature/vesnin/some-feature
7# merge/upstream
8# master
9#
10# Release branches (release/<machine>/vX) are expected to be forked off
11# the master branch and may contain tags in the form
12# <machine>-vX.Y[-rcZ|-dev*]. All release branches without machine tags,
13# as well as any non-release branches produce 'Unofficial' builds.
14# So do the release branches with -rc or -dev suffix in the latest tag.
15
Andrei Kartashev0f66db42021-08-17 21:47:15 +030016python do_compile:prepend() {
Alexander Amelkin407064a2020-07-16 02:00:11 +030017 print ("Preparing YADRO-specific version information")
18 version_id = d.getVar('VERSION_ID')
19
20 print ('Original VERSION_ID = %s' % version_id)
21
22 versionList = version_id.split('-')
23
24 branch_info = run_git(d, 'rev-parse --abbrev-ref HEAD').split('/')
25 branch_type = branch_info[0]
26
27 if len(branch_info) > 1:
28 branch_product = branch_info[1]
29 else:
30 branch_product = d.getVar('MACHINE', True).split('-')[0]
31
32 if len(branch_info) > 2:
33 # This is for <type>/<product>/<description> branches
34 # and <type>/<product>/<any>/<level>/<of>/<hierarchy> branches alike
35 branch_name = '-'.join(branch_info[2::])
36 else:
37 # This is for "merge/upstream", "master" and any arbitrary branches
38 branch_name = '-'.join(branch_info)
39
40 print ('Branch type = %s' % branch_type)
41 print ('Branch product = %s' % branch_product)
42 print ('Branch name = %s' % branch_name)
43
44 # For <product>-vX.Y tags, simply strip off the '<product>-' part,
45 # then pretend it is a normal version tag
46 product_tagged = False
47 if branch_product == versionList[0]:
48 product_tagged = True
49 versionList.pop(0)
50
Alexander Amelkin377d8f42021-01-26 23:53:05 +030051 rcdev = ""
Alexander Amelkin407064a2020-07-16 02:00:11 +030052 version = versionList[0] if len(versionList) > 0 else ''
53 if versionList[1][:2] == 'rc' or versionList[1] == 'dev': # Remove the '-rcX' and '-dev' parts
54 rcdev = versionList[1]
55 versionList.pop(1)
56 patch_level = versionList[1] if len(versionList) > 1 else 0
57 git_hash = versionList[2] if len(versionList) > 2 else 'nongit'
58 dirty = ('dirty' == versionList[3]) if len(versionList) > 3 else 0
59
60 # For release branches:
61 if 'release' == branch_type:
62 flag = ''
63 if not product_tagged:
64 # If there is no tag, take branch name for the major version
65 # and assume the minor version to be 0, patch level will
66 # represent the number of commits since branch creation
67 # (assuming that it branched off the master branch)
68 patch_level = run_git(d, 'rev-list --count origin/master..%s'
69 % '/'.join(branch_info))
70 # Prevent zero patch level. Zero patch level is an official release.
71 patch_level = str(int(patch_level) + 1)
72 version = branch_name.split('-')[0]
73 version += '.0'
74 # Any build from a release/<product>/* branch without a <product>-* tag
75 # is not an official release
76 release = 'Unofficial ' + branch_name
77 flag = '-unofficial'
78 else:
79 # If there is a product tag, then it is used as the normal tag to
80 # designate the major and minor version, patch level is as usual
81 # the number of commits since the tag.
82 release = version
83 if (rcdev):
84 flag = '-' + rcdev
85 release += flag
86 # Official releases happen only exactly on tags, without extra
87 # commits. Release candidates and development releases are also
88 # not considered 'official'
89 if int(patch_level) or rcdev:
90 release = 'Unofficial ' + release
91 flag += '-unofficial'
92
93 version_id = version
94 version_id += 'r' + git_hash[1:7]
95 version_id += ('p' + patch_level) if int(patch_level) else ''
96 version_id += flag
97 version_id += '-dirty' if dirty else ''
98 name = 'YADRO %s BMC Firmware'
99 else:
100 version_id += ("-" + branch_name) if (branch_name) else ''
101 release = version_id
102 name = 'YADRO %s BMC Development Firmware'
103
104 u_product = branch_product.upper()
105
106 d.setVar('VERSION_ID', version_id)
107 d.setVar('VERSION', version)
108 d.setVar('RELEASE', release)
109 d.setVar('PATCH_LEVEL', patch_level)
110 d.setVar('NAME', '%s' % (name % u_product))
111 d.setVar('PRETTY_NAME', '%s %s' % (name % u_product, release))
112
113 print ('%s VERSION_ID = %s' % (u_product, version_id))
114 print ('%s RELEASE = %s' % (u_product, release))
115 print ('%s PATCH_LEVEL = %s' % (u_product, patch_level))
116}
117
Andrei Kartashev0f66db42021-08-17 21:47:15 +0300118python do_compile:append () {
Alexander Amelkin407064a2020-07-16 02:00:11 +0300119 with open(d.expand('${B}/issue'), 'w') as f:
120 f.write('%s %s @ \\l\n' % (name % u_product, release))
121}
122
Andrei Kartashev0f66db42021-08-17 21:47:15 +0300123do_install:append () {
Alexander Amelkin407064a2020-07-16 02:00:11 +0300124 install -m 0644 issue ${D}${sysconfdir}/issue
125 install -m 0644 issue ${D}${sysconfdir}/issue.net
126}
127
Andrei Kartashev0f66db42021-08-17 21:47:15 +0300128CONFFILES:${PN} += " ${sysconfdir}/issue ${sysconfdir}/issue.net"
129OS_RELEASE_FIELDS:append = " RELEASE PATCH_LEVEL"
Alexander Amelkin407064a2020-07-16 02:00:11 +0300130BB_DONT_CACHE = "1"