[elbe-devel] [PATCH 6/6] commands check-build: Add SDK checker
Olivier Dion
dion at linutronix.de
Tue Jun 23 18:31:10 CEST 2020
This checker finds all SDK scripts in a build and validates that they
work. This is done by extracting the scripts and building a small
auto-tools hello world project.
Signed-off-by: Olivier Dion <dion at linutronix.de>
---
elbepack/commands/check-build.py | 107 +++++++++++++++++++++++++++++++
1 file changed, 107 insertions(+)
diff --git a/elbepack/commands/check-build.py b/elbepack/commands/check-build.py
index 3dd4bf66..5bcf0df6 100644
--- a/elbepack/commands/check-build.py
+++ b/elbepack/commands/check-build.py
@@ -8,6 +8,7 @@ import logging
import multiprocessing.pool
import optparse
import os
+import string
import tempfile
import traceback
@@ -561,3 +562,109 @@ class CheckImage(CheckBase):
img_name, ''.join(transcript))
return ret or child.exitstatus
+
+ at CheckBase.register("skip-sdk")
+class CheckSDK(CheckBase):
+ """Check if SDK is working"""
+
+ # Following the steps here:
+ # <https://www.yoctoproject.org/docs/3.1/sdk-manual/sdk-manual.html#autotools-based-projects>
+ test_template = string.Template("""#!/bin/sh
+# Very useful for debugging
+set -x
+
+. $env
+
+mkdir project
+cd project || exit 1
+
+touch README
+
+cat -> hello.c <<EOF
+#include <stdio.h>
+int main(void)
+{
+ printf("Hello World!");
+ return 0;
+}
+EOF
+
+cat -> configure.ac <<EOF
+AC_INIT(hello,0.1)
+AM_INIT_AUTOMAKE([foreign])
+AC_PROG_CC
+AC_CONFIG_FILES(Makefile)
+AC_OUTPUT
+EOF
+
+cat -> Makefile.am <<EOF
+bin_PROGRAMS = hello
+hello_SOURCES = hello.c
+hello_LDFLAGS = -static
+EOF
+
+autoreconf -i
+
+./configure $${CONFIGURE_FLAGS}
+
+make
+make install DESTDIR=./tmp
+
+out=$$($interpreter ./hello)
+
+if [ $$? -eq 0 ] && [ "$$out" = "Hello World!" ] ;
+then
+ exit 0
+fi
+exit 1
+""")
+
+ def do_sdk(self, sdk, arch):
+
+ with TempDirectory() as _dir:
+
+ # Make a copy of the installer
+ shutil.copyfile(sdk, os.path.join(_dir, sdk))
+
+ # Let's work in our temp dir from now on
+ os.chdir(_dir)
+
+ # The script is self extracting; it needs to be executable
+ os.chmod(sdk, 0o744)
+
+ # Extract here with 'yes' to all answers
+ do("%s -y -d ." % os.path.join(_dir, sdk))
+
+ # Get environment file
+ env = os.path.join(_dir, glob.glob("environment-setup*")[0])
+
+ # This really should be 'if arch == host_arch:' in case the host is
+ # not on amd64 ? Or maybe binfmt would be good here?
+ if arch == "amd64":
+ interpreter = ""
+ elif arch == "ppc64el":
+ interpreter = "qemu-ppc64le"
+ elif arch in ("powerpc", "powerpcspe"):
+ interpreter = "qemu-ppc"
+ elif arch == "arm64":
+ interpreter = "qemu-aarch64"
+ elif arch in ("armhf", "armel"):
+ interpreter = "qemu-arm"
+ else:
+ interpreter = "qemu-%s" % arch
+
+ # Create script for testing the SDK
+ fname = os.path.join(_dir, "test-sdk.sh")
+ with open(fname, "w") as script:
+ script.write(self.test_template.substitute(env=env,
+ interpreter=interpreter))
+
+ # Execute it
+ os.chmod(fname, 0o744)
+ do(fname)
+
+ def run(self):
+ xml = etree("source.xml")
+ arch = xml.et.find("./project/buildtype").text
+ for sdk in glob.glob("setup-elbe-sdk*"):
+ self.do_sdk(sdk, arch)
--
2.27.0
More information about the elbe-devel
mailing list