6 from urllib2 import urlopen, HTTPError, URLError
8 ARTIFACTS_URL = "http://autobuild.buildroot.net/artefacts/"
11 def open_log_file(builddir, stage, logtofile=True):
13 Open a file for logging and return its handler.
14 If logtofile is True, returns sys.stdout. Otherwise opens a file
15 with a suitable name in the build directory.
18 fhandle = open("{}-{}.log".format(builddir, stage), 'a+')
24 def filepath(relpath):
25 return os.path.join(os.getcwd(), "support/testing", relpath)
28 def download(dldir, filename):
29 finalpath = os.path.join(dldir, filename)
30 if os.path.exists(finalpath):
33 if not os.path.exists(dldir):
36 tmpfile = tempfile.mktemp(dir=dldir)
37 print "Downloading to {}".format(tmpfile)
40 url_fh = urlopen(os.path.join(ARTIFACTS_URL, filename))
41 with open(tmpfile, "w+") as tmpfile_fh:
42 tmpfile_fh.write(url_fh.read())
43 except (HTTPError, URLError), err:
47 print "Renaming from %s to %s" % (tmpfile, finalpath)
48 os.rename(tmpfile, finalpath)
52 def get_elf_arch_tag(builddir, prefix, fpath, tag):
54 Runs the cross readelf on 'fpath', then extracts the value of tag 'tag'.
56 >>> get_elf_arch_tag('output', 'arm-none-linux-gnueabi-',
57 'bin/busybox', 'Tag_CPU_arch')
61 cmd = ["host/bin/{}-readelf".format(prefix),
62 "-A", os.path.join("target", fpath)]
63 out = subprocess.check_output(cmd, cwd=builddir, env={"LANG": "C"})
64 regexp = re.compile("^ {}: (.*)$".format(tag))
65 for line in out.splitlines():
66 m = regexp.match(line)
73 def get_file_arch(builddir, prefix, fpath):
74 return get_elf_arch_tag(builddir, prefix, fpath, "Tag_CPU_arch")
77 def get_elf_prog_interpreter(builddir, prefix, fpath):
79 Runs the cross readelf on 'fpath' to extract the program interpreter
82 >>> get_elf_prog_interpreter('br-tests/TestExternalToolchainLinaroArm',
83 'arm-linux-gnueabihf',
85 /lib/ld-linux-armhf.so.3
88 cmd = ["host/bin/{}-readelf".format(prefix),
89 "-l", os.path.join("target", fpath)]
90 out = subprocess.check_output(cmd, cwd=builddir, env={"LANG": "C"})
91 regexp = re.compile("^ *\[Requesting program interpreter: (.*)\]$")
92 for line in out.splitlines():
93 m = regexp.match(line)