summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorTim Orling <timothy.t.orling@linux.intel.com>2020-04-03 16:11:38 -0700
committerRichard Purdie <richard.purdie@linuxfoundation.org>2020-04-05 11:46:38 +0100
commit58796dc18f6614c1111f4308e3165a64ab1435de (patch)
tree9131e7c8eab90f8426946da07e69b35c4e8d9005 /scripts
parent45157a4e8217f997996cd6b0ab47f0a3c4cc1f48 (diff)
downloadpoky-58796dc18f6614c1111f4308e3165a64ab1435de.tar.gz
scripts/install-buildtools: refactor for Python 3.4
Our least common denominator supported distro is debian-8 which has python 3.4. The whole point of the install-buildtools script is to make it easier on the user to install buildtools tarball. So it needs to run on Python 3.4. The way we checked if the install was successful in the prior version of the script was not workable in python 3.4. Since the environment-setup-... script is currently just exporting environment variables, use os.environ to do the equivalent from values gleaned via regex from the environment-setup-... file. Corrected a couple minor whitespace errors NOTE: License changed to GPL-2.0-only due to inclusion of code copied directly from bitbake/lib/bb/utils.py. This avoids the need to depend on bitbake, which is now Python 3.5+ only. (From OE-Core rev: 869020dac889e9ed79a294f308a87cfd946a68bd) Signed-off-by: Tim Orling <timothy.t.orling@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/install-buildtools103
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
37import os 37import os
38import re 38import re
39import shutil 39import shutil
40import shlex
40import stat 41import stat
41import subprocess 42import subprocess
42import sys 43import sys
@@ -49,21 +50,56 @@ sys.path = sys.path + [lib_path]
49import scriptutils 50import scriptutils
50import scriptpath 51import scriptpath
51 52
52# Figure out where is the bitbake/lib/bb since we need bb.utils.md5_file
53bitbakepath = scriptpath.add_bitbake_lib_path()
54if 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
59PROGNAME = 'install-buildtools' 54PROGNAME = 'install-buildtools'
60logger = scriptutils.logger_create(PROGNAME, stream=sys.stdout) 55logger = scriptutils.logger_create(PROGNAME, stream=sys.stdout)
61 56
62DEFAULT_INSTALL_DIR: str = os.path.join(os.path.split(scripts_path)[0],'buildtools') 57DEFAULT_INSTALL_DIR = os.path.join(os.path.split(scripts_path)[0],'buildtools')
63DEFAULT_BASE_URL: str = 'http://downloads.yoctoproject.org/releases/yocto' 58DEFAULT_BASE_URL = 'http://downloads.yoctoproject.org/releases/yocto'
64DEFAULT_RELEASE: str = 'yocto-3.1_M3' 59DEFAULT_RELEASE = 'yocto-3.1_M3'
65DEFAULT_INSTALLER_VERSION: str = '3.0+snapshot' 60DEFAULT_INSTALLER_VERSION = '3.0+snapshot'
66DEFAULT_BUILDDATE: str = "20200315" 61DEFAULT_BUILDDATE = "20200315"
62
63# Python version sanity check
64if 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
75def _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
89def 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
96def 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
69def main(): 105def 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):