Alexander Amelkin | 407064a | 2020-07-16 02:00:11 +0300 | [diff] [blame] | 1 | # 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 | |
| 16 | python do_compile_prepend() { |
| 17 | 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 | |
| 51 | version = versionList[0] if len(versionList) > 0 else '' |
| 52 | if versionList[1][:2] == 'rc' or versionList[1] == 'dev': # Remove the '-rcX' and '-dev' parts |
| 53 | rcdev = versionList[1] |
| 54 | versionList.pop(1) |
| 55 | patch_level = versionList[1] if len(versionList) > 1 else 0 |
| 56 | git_hash = versionList[2] if len(versionList) > 2 else 'nongit' |
| 57 | dirty = ('dirty' == versionList[3]) if len(versionList) > 3 else 0 |
| 58 | |
| 59 | # For release branches: |
| 60 | if 'release' == branch_type: |
| 61 | flag = '' |
| 62 | if not product_tagged: |
| 63 | # If there is no tag, take branch name for the major version |
| 64 | # and assume the minor version to be 0, patch level will |
| 65 | # represent the number of commits since branch creation |
| 66 | # (assuming that it branched off the master branch) |
| 67 | patch_level = run_git(d, 'rev-list --count origin/master..%s' |
| 68 | % '/'.join(branch_info)) |
| 69 | # Prevent zero patch level. Zero patch level is an official release. |
| 70 | patch_level = str(int(patch_level) + 1) |
| 71 | version = branch_name.split('-')[0] |
| 72 | version += '.0' |
| 73 | # Any build from a release/<product>/* branch without a <product>-* tag |
| 74 | # is not an official release |
| 75 | release = 'Unofficial ' + branch_name |
| 76 | flag = '-unofficial' |
| 77 | else: |
| 78 | # If there is a product tag, then it is used as the normal tag to |
| 79 | # designate the major and minor version, patch level is as usual |
| 80 | # the number of commits since the tag. |
| 81 | release = version |
| 82 | if (rcdev): |
| 83 | flag = '-' + rcdev |
| 84 | release += flag |
| 85 | # Official releases happen only exactly on tags, without extra |
| 86 | # commits. Release candidates and development releases are also |
| 87 | # not considered 'official' |
| 88 | if int(patch_level) or rcdev: |
| 89 | release = 'Unofficial ' + release |
| 90 | flag += '-unofficial' |
| 91 | |
| 92 | version_id = version |
| 93 | version_id += 'r' + git_hash[1:7] |
| 94 | version_id += ('p' + patch_level) if int(patch_level) else '' |
| 95 | version_id += flag |
| 96 | version_id += '-dirty' if dirty else '' |
| 97 | name = 'YADRO %s BMC Firmware' |
| 98 | else: |
| 99 | version_id += ("-" + branch_name) if (branch_name) else '' |
| 100 | release = version_id |
| 101 | name = 'YADRO %s BMC Development Firmware' |
| 102 | |
| 103 | u_product = branch_product.upper() |
| 104 | |
| 105 | d.setVar('VERSION_ID', version_id) |
| 106 | d.setVar('VERSION', version) |
| 107 | d.setVar('RELEASE', release) |
| 108 | d.setVar('PATCH_LEVEL', patch_level) |
| 109 | d.setVar('NAME', '%s' % (name % u_product)) |
| 110 | d.setVar('PRETTY_NAME', '%s %s' % (name % u_product, release)) |
| 111 | |
| 112 | print ('%s VERSION_ID = %s' % (u_product, version_id)) |
| 113 | print ('%s RELEASE = %s' % (u_product, release)) |
| 114 | print ('%s PATCH_LEVEL = %s' % (u_product, patch_level)) |
| 115 | } |
| 116 | |
| 117 | python do_compile_append () { |
| 118 | with open(d.expand('${B}/issue'), 'w') as f: |
| 119 | f.write('%s %s @ \\l\n' % (name % u_product, release)) |
| 120 | } |
| 121 | |
| 122 | do_install_append () { |
| 123 | install -m 0644 issue ${D}${sysconfdir}/issue |
| 124 | install -m 0644 issue ${D}${sysconfdir}/issue.net |
| 125 | } |
| 126 | |
| 127 | CONFFILES_${PN} += " ${sysconfdir}/issue ${sysconfdir}/issue.net" |
| 128 | OS_RELEASE_FIELDS_append = " RELEASE PATCH_LEVEL" |
| 129 | BB_DONT_CACHE = "1" |