summaryrefslogtreecommitdiffstats
path: root/scripts/find_dependencies.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/find_dependencies.py')
-rwxr-xr-xscripts/find_dependencies.py214
1 files changed, 214 insertions, 0 deletions
diff --git a/scripts/find_dependencies.py b/scripts/find_dependencies.py
new file mode 100755
index 0000000..cffe32b
--- /dev/null
+++ b/scripts/find_dependencies.py
@@ -0,0 +1,214 @@
1#!/usr/bin/env python3
2
3from argparse import ArgumentParser
4import os.path
5import sys
6
7scripts_path = os.path.dirname(os.path.realpath(__file__))
8bb_lib_path = os.path.abspath(scripts_path + '/../../poky/bitbake/lib')
9sys.path = sys.path + [bb_lib_path]
10
11import bb.fetch2
12import bb.tinfoil
13
14
15PRINT_PROGRESS = True
16SKIP_BUILD_TOOLS = True
17KNOWN_BUILD_TOOLS = ['virtual/x86_64-poky-linux-gcc', # gcc-cross-x86_64
18 'virtual/x86_64-poky-linux-compilerlibs', # gcc-runtime
19 'virtual/i586-poky-linux-gcc', # gcc-cross-i586
20 'virtual/i586-poky-linux-compilerlibs', # gcc-runtime
21 'virtual/libc', # glibc
22 'virtual/libintl', # glibc
23 'virtual/libiconv', # glibc
24 'virtual/crypt', # glibc
25 'autoconf-native',
26 'automake-native',
27 'libtool-native',
28 'gnu-config-native',
29 'm4-native',
30 'texinfo-dummy-native',
31 'gettext-minimal-native',
32 'libtool-cross',
33 'gettext-native',
34 'util-linux-native',
35 'pkgconfig-native',
36 'makedepend-native']
37
38
39def get_recipe_info(tinfoil, rn):
40 try:
41 info = tinfoil.get_recipe_info(rn)
42 except Exception:
43 print('Failed to get recipe info for: %s' % rn)
44 return []
45 if not info:
46 print('No recipe info found for: %s' % rn)
47 return []
48 append_files = tinfoil.get_file_appends(info.fn)
49 appends = True
50 data = tinfoil.parse_recipe_file(info.fn, appends, append_files)
51 data.pn = info.pn
52 data.pv = info.pv
53 return data
54
55
56def print_package(manifest_file, data, is_project):
57 src_uri = data.getVar('SRC_URI').split()
58 lic = data.getVar('LICENSE')
59 summary = data.getVar('SUMMARY')
60 homepage = data.getVar('HOMEPAGE')
61 srcrev = data.getVar('SRCREV')
62 branch = data.getVar('BRANCH')
63
64 if is_project:
65 manifest_file.write(' id:\n')
66 else:
67 manifest_file.write('- id:\n')
68 manifest_file.write(' package_manager: "Yocto"\n')
69 manifest_file.write(' namespace: ""\n')
70 manifest_file.write(' name: "%s"\n' % data.pn)
71 manifest_file.write(' version: "%s"\n' % data.pv)
72 manifest_file.write(' declared_lics:\n')
73 manifest_file.write(' - "%s"\n' % lic)
74 if is_project:
75 manifest_file.write(' aliases: []\n')
76 if summary:
77 manifest_file.write(' description: "%s"\n' % summary)
78 else:
79 description = data.getVar('DESCRIPTION')
80 manifest_file.write(' description: "%s"\n' % description)
81 manifest_file.write(' homepage_url: "%s"\n' % homepage)
82 # Binary artifacts almost never exist in Yocto.
83 manifest_file.write(' binary_artifact:\n')
84 manifest_file.write(' url: ""\n')
85 manifest_file.write(' hash: ""\n')
86 manifest_file.write(' hash_algorithm: ""\n')
87 manifest_file.write(' source_artifact:\n')
88 repos = []
89 for src in src_uri:
90 # Strip options.
91 # TODO: ignore files with apply=false?
92 src = src.split(';', maxsplit=1)[0]
93 src_type = src.split('://', maxsplit=1)[0]
94 if src_type == 'file':
95 # TODO: Get full path of patches and other files within the source
96 # repo, not just the filesystem?
97 fetch = bb.fetch2.Fetch([], data)
98 local = fetch.localpath(src)
99 manifest_file.write(' - "%s"\n' % local)
100 else:
101 manifest_file.write(' - "%s"\n' % src)
102 if src_type != 'http' and src_type != 'https' and src_type != 'ftp' and src_type != 'ssh':
103 repos.append(src)
104 if len(repos) > 1:
105 print('Multiple repos for one package are not supported. Package: %s' % info.pn)
106 for repo in repos:
107 vcs_type, url = repo.split('://', maxsplit=1)
108 manifest_file.write(' vcs:\n')
109 if vcs_type == 'gitsm':
110 vcs_type = 'git'
111 manifest_file.write(' type: "%s"\n' % vcs_type)
112 manifest_file.write(' url: "%s"\n' % url)
113 # TODO: Actually support multiple repos here:
114 # TODO: catch and replace AUTOINC?
115 manifest_file.write(' revision: "%s"\n' % srcrev)
116 manifest_file.write(' branch: "%s"\n' % branch)
117
118
119def find_dependencies(manifest_file, tinfoil, assume_provided, recipe_info, packages, rn, order):
120 data = recipe_info[rn]
121 # Filter out packages from the assume_provided list.
122 depends = []
123 for dep in data.depends:
124 if dep not in assume_provided:
125 depends.append(dep)
126
127 if PRINT_PROGRESS:
128 # Print high-order dependencies as a form of logging/progress notifcation.
129 if order == 2:
130 print(rn)
131 if order == 3:
132 print(' ' + rn)
133
134 # order == 1 is for the initial recipe. We've already printed its
135 # information, so skip it.
136 if order > 1:
137 spaces = ' ' * order
138 manifest_file.write('%s- namespace: ""\n' % spaces)
139 manifest_file.write('%s name: "%s"\n' % (spaces, data.pn))
140 manifest_file.write('%s version: "%s"\n' % (spaces, data.pv))
141 if not depends:
142 manifest_file.write('%s dependencies: []\n' % spaces)
143 else:
144 manifest_file.write('%s dependencies:\n' % spaces)
145
146 # First find all dependencies not seen yet to our master list.
147 for dep in depends:
148 if dep not in packages:
149 packages.append(dep)
150 dep_data = get_recipe_info(tinfoil, dep)
151 # Do this once now to reduce the number of bitbake calls.
152 dep_data.depends = dep_data.getVar('DEPENDS').split()
153 recipe_info[dep] = dep_data
154
155 # Then recursively analyze all of the dependencies for the current recipe.
156 for dep in depends:
157 find_dependencies(manifest_file, tinfoil, assume_provided, recipe_info, packages, dep, order + 1)
158
159 if order > 1:
160 manifest_file.write('%s errors: []\n' % spaces)
161
162
163def main():
164 parser = ArgumentParser(description='Find all dependencies of a recipe.')
165 parser.add_argument('recipe', metavar='recipe', help='a recipe to investigate')
166 args = parser.parse_args()
167 rn = args.recipe
168 with bb.tinfoil.Tinfoil() as tinfoil:
169 tinfoil.prepare()
170 # These are the packages that bitbake assumes are provided by the host
171 # system. They do not have recipes, so searching tinfoil for them will
172 # not work. Anyway, by nature they are only build tools and will not be
173 # distributed in an image.
174 assume_provided = tinfoil.config_data.getVar('ASSUME_PROVIDED').split()
175 if SKIP_BUILD_TOOLS:
176 assume_provided.extend(KNOWN_BUILD_TOOLS)
177
178 data = get_recipe_info(tinfoil, rn)
179 if not data:
180 print('Nothing to do!')
181 return
182
183 with open(rn + '-dependencies.yml', "w") as manifest_file:
184 manifest_file.write('project:\n')
185 data.depends = []
186 depends = data.getVar('DEPENDS').split()
187 for dep in depends:
188 if dep not in assume_provided:
189 data.depends.append(dep)
190 print_package(manifest_file, data, is_project=True)
191 manifest_file.write(' scopes:\n')
192 manifest_file.write(' - name: "all"\n')
193 manifest_file.write(' delivered: true\n')
194 if not data.depends:
195 manifest_file.write(' dependencies: []\n')
196 else:
197 manifest_file.write(' dependencies:\n')
198
199 recipe_info = dict([(rn, data)])
200 packages = []
201 find_dependencies(manifest_file, tinfoil, assume_provided, recipe_info, packages, rn, order=1)
202
203 manifest_file.write('packages:\n')
204
205 # Iterate through the list of packages found to print out their full
206 # information. Skip the initial recipe since we already printed it out.
207 for p in packages:
208 if p is not rn:
209 data = recipe_info[p]
210 print_package(manifest_file, data, is_project=False)
211
212
213if __name__ == "__main__":
214 main()