diff options
author | cajun-rat <philip.wise@here.com> | 2018-07-24 11:59:07 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-24 11:59:07 +0200 |
commit | b9f5eedb21dd57c8e9f713022242e5a521863886 (patch) | |
tree | 00013fc0c10ee84250a8250aeb77c58f5cc3887c /scripts | |
parent | 90d7ec219b8143a2f36a7c24631385ddbdffc9a9 (diff) | |
parent | a9e7ea37fd7a86f6cd687908f8d95747a07c6765 (diff) | |
download | meta-updater-b9f5eedb21dd57c8e9f713022242e5a521863886.tar.gz |
Merge pull request #351 from advancedtelematic/feat/better-dependencies
Feat/better dependencies
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/find_aktualizr_dependencies.sh | 23 | ||||
-rwxr-xr-x | scripts/find_dependencies.py | 214 | ||||
-rwxr-xr-x | scripts/find_packages.py | 125 |
3 files changed, 237 insertions, 125 deletions
diff --git a/scripts/find_aktualizr_dependencies.sh b/scripts/find_aktualizr_dependencies.sh new file mode 100755 index 0000000..786d8a9 --- /dev/null +++ b/scripts/find_aktualizr_dependencies.sh | |||
@@ -0,0 +1,23 @@ | |||
1 | #!/bin/bash | ||
2 | set -euo pipefail | ||
3 | |||
4 | parentdir="$(dirname "$0")" | ||
5 | |||
6 | # Does NOT include garage-sign, anything used only for testing (i.e. strace and | ||
7 | # gtest), any of the git submodules, all of which are also only used for | ||
8 | # testing (tuf-test-vectors, isotp-c, ostreesysroot, and HdrHistogram_c), or | ||
9 | # any other third party modules included directly into the source tree | ||
10 | # (jsoncpp, open62541, picojson). Also check libp11, dpkg, and systemd since | ||
11 | # those are common dependencies not enabled by default. | ||
12 | ${parentdir}/find_dependencies.py aktualizr | ||
13 | ${parentdir}/find_dependencies.py aktualizr-auto-prov | ||
14 | ${parentdir}/find_dependencies.py aktualizr-implicit-prov | ||
15 | ${parentdir}/find_dependencies.py aktualizr-ca-implicit-prov | ||
16 | ${parentdir}/find_dependencies.py aktualizr-hsm-prov | ||
17 | ${parentdir}/find_dependencies.py aktualizr-disable-send-ip | ||
18 | ${parentdir}/find_dependencies.py aktualizr-example-interface | ||
19 | ${parentdir}/find_dependencies.py aktualizr-log-debug | ||
20 | ${parentdir}/find_dependencies.py libp11 | ||
21 | ${parentdir}/find_dependencies.py dpkg | ||
22 | ${parentdir}/find_dependencies.py systemd | ||
23 | |||
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 | |||
3 | from argparse import ArgumentParser | ||
4 | import os.path | ||
5 | import sys | ||
6 | |||
7 | scripts_path = os.path.dirname(os.path.realpath(__file__)) | ||
8 | bb_lib_path = os.path.abspath(scripts_path + '/../../poky/bitbake/lib') | ||
9 | sys.path = sys.path + [bb_lib_path] | ||
10 | |||
11 | import bb.fetch2 | ||
12 | import bb.tinfoil | ||
13 | |||
14 | |||
15 | PRINT_PROGRESS = True | ||
16 | SKIP_BUILD_TOOLS = True | ||
17 | KNOWN_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 | |||
39 | def 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 | |||
56 | def 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 | |||
119 | def 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 | |||
163 | def 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 | |||
213 | if __name__ == "__main__": | ||
214 | main() | ||
diff --git a/scripts/find_packages.py b/scripts/find_packages.py deleted file mode 100755 index 7a60a17..0000000 --- a/scripts/find_packages.py +++ /dev/null | |||
@@ -1,125 +0,0 @@ | |||
1 | #!/usr/bin/env python3 | ||
2 | |||
3 | import os.path | ||
4 | import sys | ||
5 | |||
6 | scripts_path = os.path.dirname(os.path.realpath(__file__)) | ||
7 | bb_lib_path = os.path.abspath(scripts_path + '/../../poky/bitbake/lib') | ||
8 | sys.path = sys.path + [bb_lib_path] | ||
9 | |||
10 | import bb.fetch2 | ||
11 | import bb.tinfoil | ||
12 | |||
13 | |||
14 | def print_deps(tinfoil, abcd_file, rn): | ||
15 | try: | ||
16 | info = tinfoil.get_recipe_info(rn) | ||
17 | except Exception: | ||
18 | print('Failed to get recipe info for: %s' % rn) | ||
19 | return [] | ||
20 | if not info: | ||
21 | print('No recipe info found for: %s' % rn) | ||
22 | return [] | ||
23 | append_files = tinfoil.get_file_appends(info.fn) | ||
24 | appends = True | ||
25 | data = tinfoil.parse_recipe_file(info.fn, appends, append_files) | ||
26 | src_uri = data.getVar('SRC_URI').split() | ||
27 | lic = data.getVar('LICENSE') | ||
28 | summary = data.getVar('SUMMARY') | ||
29 | description = data.getVar('DESCRIPTION') | ||
30 | homepage = data.getVar('HOMEPAGE') | ||
31 | srcrev = data.getVar('SRCREV') | ||
32 | branch = data.getVar('BRANCH') | ||
33 | depends = data.getVar('DEPENDS').split() | ||
34 | |||
35 | abcd_file.write('- id:\n') | ||
36 | abcd_file.write(' package_manager: "Yocto"\n') | ||
37 | abcd_file.write(' name: "%s"\n' % info.pn) | ||
38 | abcd_file.write(' version: "%s"\n' % info.pv) | ||
39 | abcd_file.write(' declared_lics:\n') | ||
40 | abcd_file.write(' - "%s"\n' % lic) | ||
41 | if summary: | ||
42 | abcd_file.write(' description: "%s"\n' % summary) | ||
43 | else: | ||
44 | abcd_file.write(' description: "%s"\n' % description) | ||
45 | abcd_file.write(' homepage_url: "%s"\n' % homepage) | ||
46 | abcd_file.write(' source_artifact:\n') | ||
47 | repos = [] | ||
48 | for src in src_uri: | ||
49 | # Strip options. | ||
50 | # TODO: ignore files with apply=false? | ||
51 | src = src.split(';', maxsplit=1)[0] | ||
52 | src_type = src.split('://', maxsplit=1)[0] | ||
53 | if src_type == 'file': | ||
54 | # TODO: Get full path of patches and other files within the source | ||
55 | # repo, not just the filesystem? | ||
56 | fetch = bb.fetch2.Fetch([], data) | ||
57 | local = fetch.localpath(src) | ||
58 | abcd_file.write(' - "%s"\n' % local) | ||
59 | else: | ||
60 | abcd_file.write(' - "%s"\n' % src) | ||
61 | if src_type != 'http' and src_type != 'https' and src_type != 'ftp' and src_type != 'ssh': | ||
62 | repos.append(src) | ||
63 | if len(repos) > 1: | ||
64 | print('Multiple repos not fully supported yet. Pacakge: %s' % info.pn) | ||
65 | for repo in repos: | ||
66 | vcs_type, url = repo.split('://', maxsplit=1) | ||
67 | abcd_file.write(' vcs:\n') | ||
68 | if vcs_type == 'gitsm': | ||
69 | vcs_type = 'git' | ||
70 | abcd_file.write(' type: "%s"\n' % vcs_type) | ||
71 | abcd_file.write(' url: "%s"\n' % url) | ||
72 | # TODO: Actually support multiple repos here: | ||
73 | abcd_file.write(' revision: "%s"\n' % srcrev) | ||
74 | abcd_file.write(' branch: "%s"\n' % branch) | ||
75 | |||
76 | abcd_file.write(' dependencies:\n') | ||
77 | for dep in depends: | ||
78 | abcd_file.write(' - "%s"\n' % dep) | ||
79 | # TODO: search for transitive dependencies here? Each dependency will | ||
80 | # get checked for its own dependencies sooner or later. | ||
81 | |||
82 | return depends | ||
83 | |||
84 | |||
85 | def main(): | ||
86 | abcd_manifest = 'manifest.abcd' | ||
87 | with open(abcd_manifest, "w") as abcd_file, bb.tinfoil.Tinfoil() as tinfoil: | ||
88 | tinfoil.prepare() | ||
89 | # These are the packages that bitbake assumes are provided by the host | ||
90 | # system. They do not have recipes, so searching tinfoil for them will | ||
91 | # not work. Anyway, by nature they are not included in code we release, | ||
92 | # only used by it. | ||
93 | assume_provided = tinfoil.config_data.getVar('ASSUME_PROVIDED').split() | ||
94 | abcd_file.write('packages:\n') | ||
95 | |||
96 | # Does NOT include garage-sign, anything used only for testing (i.e. | ||
97 | # strace and gtest), any of the git submodules, all of which are also | ||
98 | # only used for testing (tuf-test-vectors, isotp-c, ostreesysroot, | ||
99 | # and HdrHistogram_c), or any other third party modules included | ||
100 | # directly into the source tree (jsoncpp, open62541, picojson) | ||
101 | recipes_to_check = ['aktualizr', | ||
102 | 'aktualizr-native', | ||
103 | 'aktualizr-auto-prov', | ||
104 | 'aktualizr-implicit-prov', | ||
105 | 'aktualizr-ca-implicit-prov', | ||
106 | 'aktualizr-hsm-prov', | ||
107 | 'aktualizr-disable-send-ip', | ||
108 | 'aktualizr-example-interface', | ||
109 | 'aktualizr-log-debug', | ||
110 | 'libp11', # BUILD_P11 (HSM) only | ||
111 | 'dpkg', # BUILD_DEB only | ||
112 | 'systemd'] # BUILD_SYSTEMD only | ||
113 | |||
114 | # Iterate through the list of recipes to check. Append any dependencies | ||
115 | # found that aren't already in the list. As long as we only add to the | ||
116 | # list, it should be safe. | ||
117 | for recipe in recipes_to_check: | ||
118 | depends = print_deps(tinfoil, abcd_file, recipe) | ||
119 | for dep in depends: | ||
120 | if dep not in recipes_to_check and dep not in assume_provided: | ||
121 | recipes_to_check.append(dep) | ||
122 | |||
123 | |||
124 | if __name__ == "__main__": | ||
125 | main() | ||