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

Torben Hohn torben.hohn at linutronix.de
Wed Jun 24 16:54:35 CEST 2020


On Tue, Jun 23, 2020 at 12:31:10PM -0400, Olivier Dion wrote:
> 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
> +""")


lets have a little bit more..

maybe use pkg-config to link against something.
using a shell script to generate some files, is a bit annoying.
why do you need to do this ?

why cant you have a set of mako template for example, that generate the
files ?  a bit like elbe init ?


> +
> +    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

yeah. we can just rely on binfmt-misc here.

other option would be userinterpr from elbepack/xmldefaults.py
porbably needs a bit of fixing.

but i would say, we should go with binfmt.

on debian i would just install
https://packages.debian.org/de/buster/qemu-user-binfmt


> +
> +            # 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
> 
> 
> _______________________________________________
> elbe-devel mailing list
> elbe-devel at linutronix.de
> https://lists.linutronix.de/mailman/listinfo/elbe-devel

-- 
Torben Hohn
Linutronix GmbH | Bahnhofstrasse 3 | D-88690 Uhldingen-Mühlhofen
Phone: +49 7556 25 999 18; Fax.: +49 7556 25 999 99

Hinweise zum Datenschutz finden Sie hier (Informations on data privacy 
can be found here): https://linutronix.de/kontakt/Datenschutz.php

Linutronix GmbH | Firmensitz (Registered Office): Uhldingen-Mühlhofen | 
Registergericht (Registration Court): Amtsgericht Freiburg i.Br., HRB700 
806 | Geschäftsführer (Managing Directors): Heinz Egger, Thomas Gleixner



More information about the elbe-devel mailing list