blob: b1d6c852d86556373c909b825056cd88a6da9556 [file] [log] [blame]
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001#!/usr/bin/env python3
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003# Copyright (C) 2013 Wind River Systems, Inc.
4# Copyright (C) 2014 Intel Corporation
5#
Brad Bishopc342db32019-05-15 21:57:59 -04006# SPDX-License-Identifier: GPL-2.0-or-later
7#
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008# - list available recipes which have PACKAGECONFIG flags
9# - list available PACKAGECONFIG flags and all affected recipes
10# - list all recipes and PACKAGECONFIG information
11
12import sys
13import optparse
14import os
15
16
17scripts_path = os.path.abspath(os.path.dirname(os.path.abspath(sys.argv[0])))
18lib_path = os.path.abspath(scripts_path + '/../lib')
19sys.path = sys.path + [lib_path]
20
21import scriptpath
22
23# For importing the following modules
24bitbakepath = scriptpath.add_bitbake_lib_path()
25if 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 Williamsc124f4f2015-09-15 14:41:29 -050029import bb.cooker
30import bb.providers
31import bb.tinfoil
32
33def get_fnlist(bbhandler, pkg_pn, preferred):
34 ''' Get all recipe file names '''
35 if preferred:
Patrick Williamsc0f7c042017-02-23 20:41:17 -060036 (latest_versions, preferred_versions) = bb.providers.findProviders(bbhandler.config_data, bbhandler.cooker.recipecaches[''], pkg_pn)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050037
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
47def get_recipesdata(bbhandler, preferred):
48 ''' Get data of all available recipes which have PACKAGECONFIG flags '''
Patrick Williamsc0f7c042017-02-23 20:41:17 -060049 pkg_pn = bbhandler.cooker.recipecaches[''].pkg_pn
Patrick Williamsc124f4f2015-09-15 14:41:29 -050050
51 data_dict = {}
52 for fn in get_fnlist(bbhandler, pkg_pn, preferred):
Patrick Williamsc0f7c042017-02-23 20:41:17 -060053 data = bbhandler.parse_recipe_file(fn)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050054 flags = data.getVarFlags("PACKAGECONFIG")
55 flags.pop('doc', None)
56 if flags:
57 data_dict[fn] = data
58
59 return data_dict
60
61def 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 Bishop6e60e8b2018-02-01 10:27:11 -050068 pkgname = data_dict[fn].getVar("P")
Patrick Williamsc124f4f2015-09-15 14:41:29 -050069 pkg_dict[pkgname] = sorted(pkgconfigflags.keys())
70
71 return pkg_dict
72
73def collect_flags(pkg_dict):
74 ''' Collect available PACKAGECONFIG flags and all affected pkgs '''
75 # flag_dict = {'flag': ['pkg1', 'pkg2',...]}
76 flag_dict = {}
Patrick Williamsc0f7c042017-02-23 20:41:17 -060077 for pkgname, flaglist in pkg_dict.items():
Patrick Williamsc124f4f2015-09-15 14:41:29 -050078 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
86def 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 Williamsc0f7c042017-02-23 20:41:17 -060095 print(header)
96 print(str("").ljust(len(header), '='))
Patrick Williamsc124f4f2015-09-15 14:41:29 -050097 for pkgname in sorted(pkg_dict):
98 print('%-*s%s' % (pkgname_len, pkgname, ' '.join(pkg_dict[pkgname])))
99
100
101def 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 Williamsc0f7c042017-02-23 20:41:17 -0600106 print(header)
107 print(str("").ljust(len(header), '='))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500108
109 for flag in sorted(flag_dict):
110 print('%-*s%s' % (flag_len, flag, ' '.join(sorted(flag_dict[flag]))))
111
112def display_all(data_dict):
113 ''' Display all pkgs and PACKAGECONFIG information '''
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600114 print(str("").ljust(50, '='))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500115 for fn in data_dict:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500116 print('%s' % data_dict[fn].getVar("P"))
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600117 print(fn)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500118 packageconfig = data_dict[fn].getVar("PACKAGECONFIG") or ''
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500119 if packageconfig.strip() == '':
120 packageconfig = 'None'
121 print('PACKAGECONFIG %s' % packageconfig)
122
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600123 for flag,flag_val in data_dict[fn].getVarFlags("PACKAGECONFIG").items():
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500124 if flag == "doc":
125 continue
126 print('PACKAGECONFIG[%s] %s' % (flag, flag_val))
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600127 print('')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500128
129def 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 Williamsc0f7c042017-02-23 20:41:17 -0600151 with bb.tinfoil.Tinfoil() as bbhandler:
152 bbhandler.prepare()
153 print("Gathering recipe data...")
154 data_dict = get_recipesdata(bbhandler, options.preferred)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500155
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600156 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 Williamsc124f4f2015-09-15 14:41:29 -0500165
166if __name__ == "__main__":
167 main()