summaryrefslogtreecommitdiffstats
path: root/scripts/find_dependencies.py
diff options
context:
space:
mode:
authorPatrick Vacek <patrickvacek@gmail.com>2018-06-28 14:03:59 +0200
committerPatrick Vacek <patrickvacek@gmail.com>2018-06-28 14:03:59 +0200
commit8109f0a7555566d37a8f10f3ee97887a47a438e6 (patch)
tree8ecf790bb1d3ab69cda33b34ece0b1ec2d957d89 /scripts/find_dependencies.py
parent4302f526c8f2ced7dadbb5f2e5c5de770b4cd12d (diff)
downloadmeta-updater-8109f0a7555566d37a8f10f3ee97887a47a438e6.tar.gz
find_dependencies.py: rename from find_packages.py.
More generic, hopefully a bit clearer. The input must be a recipe, but recipes depend on packages.
Diffstat (limited to 'scripts/find_dependencies.py')
-rwxr-xr-xscripts/find_dependencies.py207
1 files changed, 207 insertions, 0 deletions
diff --git a/scripts/find_dependencies.py b/scripts/find_dependencies.py
new file mode 100755
index 0000000..0192912
--- /dev/null
+++ b/scripts/find_dependencies.py
@@ -0,0 +1,207 @@
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 depends = data.depends
122
123 # order == 1 is for the initial recipe. We've already printed its
124 # information, so skip it.
125 if order > 1:
126 spaces = ' ' * order
127 manifest_file.write('%s- namespace: ""\n' % spaces)
128 manifest_file.write('%s name: "%s"\n' % (spaces, data.pn))
129 manifest_file.write('%s version: "%s"\n' % (spaces, data.pv))
130 if not depends:
131 manifest_file.write('%s dependencies: []\n' % spaces)
132 else:
133 manifest_file.write('%s dependencies:\n' % spaces)
134
135 if PRINT_PROGRESS:
136 # Print high-order dependencies as a form of logging/progress notifcation.
137 if order == 2:
138 print(rn)
139 if order == 3:
140 print(' ' + rn)
141
142 # First find all dependencies not seen yet to our master list.
143 for dep in depends:
144 if dep not in packages and dep not in assume_provided:
145 packages.append(dep)
146 dep_data = get_recipe_info(tinfoil, dep)
147 # Do this once now to reduce the number of bitbake calls.
148 dep_data.depends = dep_data.getVar('DEPENDS').split()
149 recipe_info[dep] = dep_data
150 # Then recursively analyze all of the dependencies for the current recipe.
151 for dep in depends:
152 if dep not in assume_provided:
153 find_dependencies(manifest_file, tinfoil, assume_provided, recipe_info, packages, dep, order + 1)
154
155 if order > 1:
156 manifest_file.write('%s errors: []\n' % spaces)
157
158
159def main():
160 parser = ArgumentParser(description='Find all dependencies of a recipe.')
161 parser.add_argument('recipe', metavar='recipe', help='a recipe to investigate')
162 args = parser.parse_args()
163 rn = args.recipe
164 with bb.tinfoil.Tinfoil() as tinfoil:
165 tinfoil.prepare()
166 # These are the packages that bitbake assumes are provided by the host
167 # system. They do not have recipes, so searching tinfoil for them will
168 # not work. Anyway, by nature they are only build tools and will not be
169 # distributed in an image.
170 assume_provided = tinfoil.config_data.getVar('ASSUME_PROVIDED').split()
171 if SKIP_BUILD_TOOLS:
172 assume_provided.extend(KNOWN_BUILD_TOOLS)
173
174 data = get_recipe_info(tinfoil, rn)
175 if not data:
176 print('Nothing to do!')
177 return
178
179 with open(rn + '-dependencies.yml', "w") as manifest_file:
180 manifest_file.write('project:\n')
181 data.depends = []
182 depends = data.getVar('DEPENDS').split()
183 for dep in depends:
184 if dep not in assume_provided:
185 data.depends.append(dep)
186 print_package(manifest_file, data, is_project=True)
187 manifest_file.write(' scopes:\n')
188 manifest_file.write(' - name: "all"\n')
189 manifest_file.write(' delivered: true\n')
190 manifest_file.write(' dependencies:\n')
191
192 recipe_info = dict([(rn, data)])
193 packages = []
194 find_dependencies(manifest_file, tinfoil, assume_provided, recipe_info, packages, rn, order=1)
195
196 manifest_file.write('packages:\n')
197
198 # Iterate through the list of packages found to print out their full
199 # information. Skip the initial recipe since we already printed it out.
200 for p in packages:
201 if p is not rn:
202 data = recipe_info[p]
203 print_package(manifest_file, data, is_project=False)
204
205
206if __name__ == "__main__":
207 main()