[elbe-devel] [PATCH v2 5/6] commands check-build: Add SDK checker

Olivier Dion dion at linutronix.de
Mon Aug 3 18:40:34 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>
Acked-by: Torben Hohn <torben.hohn at linutronix.de>
---
 elbepack/commands/check-build.py | 81 ++++++++++++++++++++++++++++++++
 1 file changed, 81 insertions(+)

diff --git a/elbepack/commands/check-build.py b/elbepack/commands/check-build.py
index c2e4ab37..98b8793f 100644
--- a/elbepack/commands/check-build.py
+++ b/elbepack/commands/check-build.py
@@ -7,6 +7,7 @@ import glob
 import logging
 import optparse
 import os
+import shutil
 import tempfile
 import traceback
 
@@ -539,3 +540,83 @@ class CheckImage(CheckBase):
                      img_name, ''.join(transcript))
 
         return ret or child.exitstatus
+
+ at CheckBase.register("sdk")
+class CheckSDK(CheckBase):
+    """Check if SDK is working"""
+
+    script = """
+set -x
+
+. $ELBE_SDK_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=$(./hello)
+
+if [ $? -eq 0 ] && [ "$out" = "Hello World!" ] ;
+then
+    exit 0
+fi
+exit 1
+"""
+
+    def do_sdk(self, sdk):
+
+        with TmpdirFilesystem() 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])
+
+            # NOTE!  This script requires binfmt to be installed.
+            do("/bin/sh", stdin=self.script, env_add={"ELBE_SDK_ENV": env})
+
+    def run(self):
+        xml  = etree("source.xml")
+        for sdk in glob.glob("setup-elbe-sdk*"):
+            self.do_sdk(sdk)
-- 
2.28.0



More information about the elbe-devel mailing list