diff options
Diffstat (limited to 'scripts/install-buildtools')
-rwxr-xr-x | scripts/install-buildtools | 103 |
1 files changed, 79 insertions, 24 deletions
diff --git a/scripts/install-buildtools b/scripts/install-buildtools index 92fb1eb7d2..9da364981e 100755 --- a/scripts/install-buildtools +++ b/scripts/install-buildtools | |||
@@ -4,7 +4,7 @@ | |||
4 | # | 4 | # |
5 | # Copyright (C) 2017-2020 Intel Corporation | 5 | # Copyright (C) 2017-2020 Intel Corporation |
6 | # | 6 | # |
7 | # SPDX-License-Identifier: MIT | 7 | # SPDX-License-Identifier: GPL-2.0-only |
8 | # | 8 | # |
9 | # NOTE: --with-extended-buildtools is on by default | 9 | # NOTE: --with-extended-buildtools is on by default |
10 | # | 10 | # |
@@ -37,6 +37,7 @@ import logging | |||
37 | import os | 37 | import os |
38 | import re | 38 | import re |
39 | import shutil | 39 | import shutil |
40 | import shlex | ||
40 | import stat | 41 | import stat |
41 | import subprocess | 42 | import subprocess |
42 | import sys | 43 | import sys |
@@ -49,21 +50,56 @@ sys.path = sys.path + [lib_path] | |||
49 | import scriptutils | 50 | import scriptutils |
50 | import scriptpath | 51 | import scriptpath |
51 | 52 | ||
52 | # Figure out where is the bitbake/lib/bb since we need bb.utils.md5_file | ||
53 | bitbakepath = scriptpath.add_bitbake_lib_path() | ||
54 | if not bitbakepath: | ||
55 | sys.stderr.write("Unable to find bitbake by searching parent directory " | ||
56 | "of this script or PATH\n") | ||
57 | sys.exit(1) | ||
58 | 53 | ||
59 | PROGNAME = 'install-buildtools' | 54 | PROGNAME = 'install-buildtools' |
60 | logger = scriptutils.logger_create(PROGNAME, stream=sys.stdout) | 55 | logger = scriptutils.logger_create(PROGNAME, stream=sys.stdout) |
61 | 56 | ||
62 | DEFAULT_INSTALL_DIR: str = os.path.join(os.path.split(scripts_path)[0],'buildtools') | 57 | DEFAULT_INSTALL_DIR = os.path.join(os.path.split(scripts_path)[0],'buildtools') |
63 | DEFAULT_BASE_URL: str = 'http://downloads.yoctoproject.org/releases/yocto' | 58 | DEFAULT_BASE_URL = 'http://downloads.yoctoproject.org/releases/yocto' |
64 | DEFAULT_RELEASE: str = 'yocto-3.1_M3' | 59 | DEFAULT_RELEASE = 'yocto-3.1_M3' |
65 | DEFAULT_INSTALLER_VERSION: str = '3.0+snapshot' | 60 | DEFAULT_INSTALLER_VERSION = '3.0+snapshot' |
66 | DEFAULT_BUILDDATE: str = "20200315" | 61 | DEFAULT_BUILDDATE = "20200315" |
62 | |||
63 | # Python version sanity check | ||
64 | if not (sys.version_info.major == 3 and sys.version_info.minor >= 4): | ||
65 | logger.error("This script requires Python 3.4 or greater") | ||
66 | logger.error("You have Python %s.%s" % | ||
67 | (sys.version_info.major, sys.version_info.minor)) | ||
68 | sys.exit(1) | ||
69 | |||
70 | # The following three functions are copied directly from | ||
71 | # bitbake/lib/bb/utils.py, in order to allow this script | ||
72 | # to run on versions of python earlier than what bitbake | ||
73 | # supports (e.g. less than Python 3.5 for YP 3.1 release) | ||
74 | |||
75 | def _hasher(method, filename): | ||
76 | import mmap | ||
77 | |||
78 | with open(filename, "rb") as f: | ||
79 | try: | ||
80 | with mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ) as mm: | ||
81 | for chunk in iter(lambda: mm.read(8192), b''): | ||
82 | method.update(chunk) | ||
83 | except ValueError: | ||
84 | # You can't mmap() an empty file so silence this exception | ||
85 | pass | ||
86 | return method.hexdigest() | ||
87 | |||
88 | |||
89 | def md5_file(filename): | ||
90 | """ | ||
91 | Return the hex string representation of the MD5 checksum of filename. | ||
92 | """ | ||
93 | import hashlib | ||
94 | return _hasher(hashlib.md5(), filename) | ||
95 | |||
96 | def sha256_file(filename): | ||
97 | """ | ||
98 | Return the hex string representation of the 256-bit SHA checksum of | ||
99 | filename. | ||
100 | """ | ||
101 | import hashlib | ||
102 | return _hasher(hashlib.sha256(), filename) | ||
67 | 103 | ||
68 | 104 | ||
69 | def main(): | 105 | def main(): |
@@ -72,10 +108,10 @@ def main(): | |||
72 | global DEFAULT_RELEASE | 108 | global DEFAULT_RELEASE |
73 | global DEFAULT_INSTALLER_VERSION | 109 | global DEFAULT_INSTALLER_VERSION |
74 | global DEFAULT_BUILDDATE | 110 | global DEFAULT_BUILDDATE |
75 | filename: str = "" | 111 | filename = "" |
76 | release: str = "" | 112 | release = "" |
77 | buildtools_url: str = "" | 113 | buildtools_url = "" |
78 | install_dir: str = "" | 114 | install_dir = "" |
79 | 115 | ||
80 | parser = argparse.ArgumentParser( | 116 | parser = argparse.ArgumentParser( |
81 | description="Buildtools installation helper", | 117 | description="Buildtools installation helper", |
@@ -187,10 +223,9 @@ def main(): | |||
187 | 223 | ||
188 | # Verify checksum | 224 | # Verify checksum |
189 | if args.check: | 225 | if args.check: |
190 | import bb | ||
191 | logger.info("Fetching buildtools installer checksum") | 226 | logger.info("Fetching buildtools installer checksum") |
192 | checksum_type = "" | 227 | checksum_type = "" |
193 | for checksum_type in ["md5sum", "sha256"]: | 228 | for checksum_type in ["md5sum", "sha256"]: |
194 | check_url = "{}.{}".format(buildtools_url, checksum_type) | 229 | check_url = "{}.{}".format(buildtools_url, checksum_type) |
195 | checksum_filename = "{}.{}".format(filename, checksum_type) | 230 | checksum_filename = "{}.{}".format(filename, checksum_type) |
196 | tmpbuildtools_checksum = os.path.join(tmpsdk_dir, checksum_filename) | 231 | tmpbuildtools_checksum = os.path.join(tmpsdk_dir, checksum_filename) |
@@ -215,9 +250,9 @@ def main(): | |||
215 | return 1 | 250 | return 1 |
216 | checksum = m.group('checksum') | 251 | checksum = m.group('checksum') |
217 | if checksum_type == "md5sum": | 252 | if checksum_type == "md5sum": |
218 | checksum_value = bb.utils.md5_file(tmpbuildtools) | 253 | checksum_value = md5_file(tmpbuildtools) |
219 | else: | 254 | else: |
220 | checksum_value = bb.utils.sha256_file(tmpbuildtools) | 255 | checksum_value = sha256_file(tmpbuildtools) |
221 | if checksum == checksum_value: | 256 | if checksum == checksum_value: |
222 | logger.info("Checksum success") | 257 | logger.info("Checksum success") |
223 | else: | 258 | else: |
@@ -239,6 +274,21 @@ def main(): | |||
239 | if ret != 0: | 274 | if ret != 0: |
240 | logger.error("Could not run buildtools installer") | 275 | logger.error("Could not run buildtools installer") |
241 | 276 | ||
277 | # Setup the environment | ||
278 | logger.info("Setting up the environment") | ||
279 | regex = re.compile(r'^(?P<export>export )?(?P<env_var>[A-Z_]+)=(?P<env_val>.+)$') | ||
280 | with open("%s/environment-setup-x86_64-pokysdk-linux" % | ||
281 | install_dir, 'rb') as f: | ||
282 | for line in f: | ||
283 | match = regex.search(line.decode('utf-8')) | ||
284 | logger.debug("export regex: %s" % match) | ||
285 | if match: | ||
286 | env_var = match.group('env_var') | ||
287 | logger.debug("env_var: %s" % env_var) | ||
288 | env_val = match.group('env_val') | ||
289 | logger.debug("env_val: %s" % env_val) | ||
290 | os.environ[env_var] = env_val | ||
291 | |||
242 | # Test installation | 292 | # Test installation |
243 | logger.info("Testing installation") | 293 | logger.info("Testing installation") |
244 | tool = "" | 294 | tool = "" |
@@ -252,10 +302,15 @@ def main(): | |||
252 | else: | 302 | else: |
253 | tool = 'tar' | 303 | tool = 'tar' |
254 | logger.debug("install_dir: %s" % install_dir) | 304 | logger.debug("install_dir: %s" % install_dir) |
255 | proc = subprocess.run(". %s/environment-setup-x86_64-pokysdk-linux && which %s" % | 305 | cmd = shlex.split("/usr/bin/which %s" % tool) |
256 | (install_dir, tool), | 306 | logger.debug("cmd: %s" % cmd) |
257 | shell=True, stdout=subprocess.PIPE) | 307 | logger.debug("tool: %s" % tool) |
258 | which_tool = proc.stdout.decode("utf-8") | 308 | proc = subprocess.Popen(cmd, stdout=subprocess.PIPE) |
309 | output, errors = proc.communicate() | ||
310 | logger.debug("proc.args: %s" % proc.args) | ||
311 | logger.debug("proc.communicate(): output %s" % output) | ||
312 | logger.debug("proc.communicate(): errors %s" % errors) | ||
313 | which_tool = output.decode('utf-8') | ||
259 | logger.debug("which %s: %s" % (tool, which_tool)) | 314 | logger.debug("which %s: %s" % (tool, which_tool)) |
260 | ret = proc.returncode | 315 | ret = proc.returncode |
261 | if not which_tool.startswith(install_dir): | 316 | if not which_tool.startswith(install_dir): |