Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 3 | # Copyright (C) 2013 Wind River Systems, Inc. |
| 4 | # Copyright (C) 2014 Intel Corporation |
| 5 | # |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 6 | # SPDX-License-Identifier: GPL-2.0-or-later |
| 7 | # |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 8 | # - list available recipes which have PACKAGECONFIG flags |
| 9 | # - list available PACKAGECONFIG flags and all affected recipes |
| 10 | # - list all recipes and PACKAGECONFIG information |
| 11 | |
| 12 | import sys |
| 13 | import optparse |
| 14 | import os |
| 15 | |
| 16 | |
| 17 | scripts_path = os.path.abspath(os.path.dirname(os.path.abspath(sys.argv[0]))) |
| 18 | lib_path = os.path.abspath(scripts_path + '/../lib') |
| 19 | sys.path = sys.path + [lib_path] |
| 20 | |
| 21 | import scriptpath |
| 22 | |
| 23 | # For importing the following modules |
| 24 | bitbakepath = scriptpath.add_bitbake_lib_path() |
| 25 | if not bitbakepath: |
| 26 | sys.stderr.write("Unable to find bitbake by searching parent directory of this script or PATH\n") |
| 27 | sys.exit(1) |
| 28 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 29 | import bb.cooker |
| 30 | import bb.providers |
| 31 | import bb.tinfoil |
| 32 | |
| 33 | def get_fnlist(bbhandler, pkg_pn, preferred): |
| 34 | ''' Get all recipe file names ''' |
| 35 | if preferred: |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 36 | (latest_versions, preferred_versions, required_versions) = bb.providers.findProviders(bbhandler.config_data, bbhandler.cooker.recipecaches[''], pkg_pn) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 37 | |
| 38 | fn_list = [] |
| 39 | for pn in sorted(pkg_pn): |
| 40 | if preferred: |
| 41 | fn_list.append(preferred_versions[pn][1]) |
| 42 | else: |
| 43 | fn_list.extend(pkg_pn[pn]) |
| 44 | |
| 45 | return fn_list |
| 46 | |
| 47 | def get_recipesdata(bbhandler, preferred): |
| 48 | ''' Get data of all available recipes which have PACKAGECONFIG flags ''' |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 49 | pkg_pn = bbhandler.cooker.recipecaches[''].pkg_pn |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 50 | |
| 51 | data_dict = {} |
| 52 | for fn in get_fnlist(bbhandler, pkg_pn, preferred): |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 53 | data = bbhandler.parse_recipe_file(fn) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 54 | flags = data.getVarFlags("PACKAGECONFIG") |
| 55 | flags.pop('doc', None) |
| 56 | if flags: |
| 57 | data_dict[fn] = data |
| 58 | |
| 59 | return data_dict |
| 60 | |
| 61 | def collect_pkgs(data_dict): |
| 62 | ''' Collect available pkgs in which have PACKAGECONFIG flags ''' |
| 63 | # pkg_dict = {'pkg1': ['flag1', 'flag2',...]} |
| 64 | pkg_dict = {} |
| 65 | for fn in data_dict: |
| 66 | pkgconfigflags = data_dict[fn].getVarFlags("PACKAGECONFIG") |
| 67 | pkgconfigflags.pop('doc', None) |
Brad Bishop | 96ff198 | 2019-08-19 13:50:42 -0400 | [diff] [blame] | 68 | pkgname = data_dict[fn].getVar("PN") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 69 | pkg_dict[pkgname] = sorted(pkgconfigflags.keys()) |
| 70 | |
| 71 | return pkg_dict |
| 72 | |
| 73 | def collect_flags(pkg_dict): |
| 74 | ''' Collect available PACKAGECONFIG flags and all affected pkgs ''' |
| 75 | # flag_dict = {'flag': ['pkg1', 'pkg2',...]} |
| 76 | flag_dict = {} |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 77 | for pkgname, flaglist in pkg_dict.items(): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 78 | for flag in flaglist: |
| 79 | if flag in flag_dict: |
| 80 | flag_dict[flag].append(pkgname) |
| 81 | else: |
| 82 | flag_dict[flag] = [pkgname] |
| 83 | |
| 84 | return flag_dict |
| 85 | |
| 86 | def display_pkgs(pkg_dict): |
| 87 | ''' Display available pkgs which have PACKAGECONFIG flags ''' |
| 88 | pkgname_len = len("RECIPE NAME") + 1 |
| 89 | for pkgname in pkg_dict: |
| 90 | if pkgname_len < len(pkgname): |
| 91 | pkgname_len = len(pkgname) |
| 92 | pkgname_len += 1 |
| 93 | |
| 94 | header = '%-*s%s' % (pkgname_len, str("RECIPE NAME"), str("PACKAGECONFIG FLAGS")) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 95 | print(header) |
| 96 | print(str("").ljust(len(header), '=')) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 97 | for pkgname in sorted(pkg_dict): |
| 98 | print('%-*s%s' % (pkgname_len, pkgname, ' '.join(pkg_dict[pkgname]))) |
| 99 | |
| 100 | |
| 101 | def display_flags(flag_dict): |
| 102 | ''' Display available PACKAGECONFIG flags and all affected pkgs ''' |
| 103 | flag_len = len("PACKAGECONFIG FLAG") + 5 |
| 104 | |
| 105 | header = '%-*s%s' % (flag_len, str("PACKAGECONFIG FLAG"), str("RECIPE NAMES")) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 106 | print(header) |
| 107 | print(str("").ljust(len(header), '=')) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 108 | |
| 109 | for flag in sorted(flag_dict): |
| 110 | print('%-*s%s' % (flag_len, flag, ' '.join(sorted(flag_dict[flag])))) |
| 111 | |
| 112 | def display_all(data_dict): |
| 113 | ''' Display all pkgs and PACKAGECONFIG information ''' |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 114 | print(str("").ljust(50, '=')) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 115 | for fn in data_dict: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 116 | print('%s' % data_dict[fn].getVar("P")) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 117 | print(fn) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 118 | packageconfig = data_dict[fn].getVar("PACKAGECONFIG") or '' |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 119 | if packageconfig.strip() == '': |
| 120 | packageconfig = 'None' |
| 121 | print('PACKAGECONFIG %s' % packageconfig) |
| 122 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 123 | for flag,flag_val in data_dict[fn].getVarFlags("PACKAGECONFIG").items(): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 124 | if flag == "doc": |
| 125 | continue |
| 126 | print('PACKAGECONFIG[%s] %s' % (flag, flag_val)) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 127 | print('') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 128 | |
| 129 | def main(): |
| 130 | pkg_dict = {} |
| 131 | flag_dict = {} |
| 132 | |
| 133 | # Collect and validate input |
| 134 | parser = optparse.OptionParser( |
| 135 | description = "Lists recipes and PACKAGECONFIG flags. Without -a or -f, recipes and their available PACKAGECONFIG flags are listed.", |
| 136 | usage = """ |
| 137 | %prog [options]""") |
| 138 | |
| 139 | parser.add_option("-f", "--flags", |
| 140 | help = "list available PACKAGECONFIG flags and affected recipes", |
| 141 | action="store_const", dest="listtype", const="flags", default="recipes") |
| 142 | parser.add_option("-a", "--all", |
| 143 | help = "list all recipes and PACKAGECONFIG information", |
| 144 | action="store_const", dest="listtype", const="all") |
| 145 | parser.add_option("-p", "--preferred-only", |
| 146 | help = "where multiple recipe versions are available, list only the preferred version", |
| 147 | action="store_true", dest="preferred", default=False) |
| 148 | |
| 149 | options, args = parser.parse_args(sys.argv) |
| 150 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 151 | with bb.tinfoil.Tinfoil() as bbhandler: |
| 152 | bbhandler.prepare() |
| 153 | print("Gathering recipe data...") |
| 154 | data_dict = get_recipesdata(bbhandler, options.preferred) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 155 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 156 | if options.listtype == 'flags': |
| 157 | pkg_dict = collect_pkgs(data_dict) |
| 158 | flag_dict = collect_flags(pkg_dict) |
| 159 | display_flags(flag_dict) |
| 160 | elif options.listtype == 'recipes': |
| 161 | pkg_dict = collect_pkgs(data_dict) |
| 162 | display_pkgs(pkg_dict) |
| 163 | elif options.listtype == 'all': |
| 164 | display_all(data_dict) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 165 | |
| 166 | if __name__ == "__main__": |
| 167 | main() |