[elbe-devel] [PATCH v2 17/24] elbeproject: implement build_sdk function

Manuel Traut manut at linutronix.de
Thu Feb 8 14:17:03 CET 2018


This generates a SDK including a host-sysroot with cross-toolchain and
the target-sysroot.

The SDK is generated in a 'yocto' like format: a self-extracting shell
script.

This is a basic implementation with some hard-coded values.
Currently only x86_64 host and arm-linux-gnueabihf target is supported.

Also the 'setup-environment-*' file is currently empty. So $PATH etc.
needs to be set by hand.

Signed-off-by: Manuel Traut <manut at linutronix.de>
---
 elbepack/elbeproject.py | 63 ++++++++++++++++++++++++++++++++++++++++++++-----
 elbepack/xmldefaults.py |  3 ++-
 2 files changed, 59 insertions(+), 7 deletions(-)

diff --git a/elbepack/elbeproject.py b/elbepack/elbeproject.py
index 3d0596c9..5dccd24f 100644
--- a/elbepack/elbeproject.py
+++ b/elbepack/elbeproject.py
@@ -42,7 +42,10 @@ from elbepack.pbuilder import (pbuilder_write_config, pbuilder_write_repo_hook,
 
 from elbepack.repomanager import ProjectRepo
 from elbepack.config import cfg
-from elbepack.pkgutils import get_uri
+from elbepack.pkgutils import extract_pkg
+from elbepack.directories import (mako_template_dir, pack_dir)
+from elbepack.templates import template
+
 
 class IncompatibleArchitectureException(Exception):
     def __init__(self, oldarch, newarch):
@@ -62,6 +65,11 @@ class AptCacheCommitError(Exception):
         Exception.__init__(self, "Error Committing rpcaptcache %s" % msg)
 
 
+class UnsupportedSDKException(Exception):
+    def __init__(self, triplet):
+        Exception.__init__(self, "SDK for %s currently unsupported" % triplet)
+
+
 class ElbeProject (object):
     def __init__(
             self,
@@ -81,6 +89,7 @@ class ElbeProject (object):
         self.builddir = os.path.abspath(str(builddir))
         self.chrootpath = os.path.join(self.builddir, "chroot")
         self.targetpath = os.path.join(self.builddir, "target")
+        self.sdkpath = os.path.join(self.builddir, "sdk")
 
         self.name = name
         self.override_buildtype = override_buildtype
@@ -142,7 +151,7 @@ class ElbeProject (object):
             self.buildenv = None
 
         # Create TargetFs instance, if the target directory exists
-        if os.path.exists(self.targetpath):
+        if os.path.exists(self.targetpath) and self.buildenv:
             self.targetfs = TargetFs(self.targetpath, self.log,
                                      self.buildenv.xml, clean=False)
         else:
@@ -180,6 +189,9 @@ class ElbeProject (object):
 
     def build_sysroot(self):
 
+        if not self.buildenv:
+            self.build()
+
         # ignore packages from debootstrap
         ignore_pkgs = [p.et.text for p in self.xml.node("debootstrappkgs")]
         ignore_dev_pkgs = []
@@ -210,10 +222,9 @@ class ElbeProject (object):
             self.log.do("chroot %s /usr/bin/symlinks -cr /usr/lib" %
                         self.chrootpath)
 
-        paths = self.__get_sysrootpaths()
+        paths = self.__get_sysroot_paths()
 
         self.log.do("rm %s" % sysrootfilelist, allow_fail=True)
-
         os.chdir(self.chrootpath)
         for p in paths:
             self.log.do('find -path "%s" >> %s' % (p, sysrootfilelist))
@@ -229,8 +240,48 @@ class ElbeProject (object):
         self.buildenv.rfs.remove("/etc/elbe_version", noerr=True)
 
     def build_sdk(self):
-        toolchain = "gcc-%s" % self.xml.defs["triplet"]
-        print(get_uri(self.xml.prj, self.xml.defs, 'amd64', toolchain))
+        triplet = self.xml.defs["triplet"]
+
+        try:
+            crosstoolchainpkg = "gcc-%s" % self.xml.defs["sdkarch"]
+        except KeyError:
+            raise UnsupportedSDKException(triplet)
+
+        # build target sysroot including libs and headers for the target
+        self.build_sysroot()
+        sdktargetpath = os.path.join(self.sdkpath, "sysroots", "target")
+        self.log.do("mkdir -p %s" % sdktargetpath)
+        self.log.do("tar xJf %s/sysroot.tar.xz -C %s" % (self.builddir,
+                                                          sdktargetpath))
+        # build host sysroot including cross compiler
+        hostsysrootpath = os.path.join(self.sdkpath, 'sysroots', 'host')
+        self.log.do('mkdir -p "%s"' % hostsysrootpath)
+        extract_pkg(self.xml.prj,
+                    hostsysrootpath,
+                    self.xml.defs,
+                    crosstoolchainpkg,
+                    'amd64',
+                    True)
+
+        # generate the setup script
+        sdkvalues = { 'sdk_arch': 'x86_64',
+                      'sdk_gcc_ver': '',
+                      'sdk_path': '/opt/elbe-sdk',
+                      'sdk_ext_path': '~/elbe-sdk',
+                      'real_multimach_target_sys': triplet,
+                      'sdk_title': 'ELBE %s' % self.xml.text("project/name"),
+                      'sdk_version': self.xml.text("project/version"),
+                    }
+        t = os.path.join(mako_template_dir, 'toolchain-shar-extract.sh.mako')
+        with open(os.path.join(self.builddir, 'setup-sdk.sh'), 'w') as f:
+            f.write(template(t, sdkvalues))
+
+        # create sdk tar and append it to setup script
+        self.log.do("cd %s; touch environment-setup-elbe" % self.sdkpath)
+        self.log.do("cd %s; tar cJf ../sdk.txz ." % self.sdkpath)
+        self.log.do("cd %s; cat sdk.txz >> setup-sdk.sh" % self.builddir)
+        self.log.do("cd %s; chmod +x setup-sdk.sh" % self.builddir)
+
 
     def pbuild(self, p):
         self.pdebuild_init()
diff --git a/elbepack/xmldefaults.py b/elbepack/xmldefaults.py
index 1237bcb7..4ac7de92 100644
--- a/elbepack/xmldefaults.py
+++ b/elbepack/xmldefaults.py
@@ -54,7 +54,8 @@ armhf_defaults = {
     "console": "ttyAMA0,115200n1",
     "machine": "versatilepb -cpu cortex-a9",
     "nicmodel": "smc91c111",
-    "triplet": "arm-linux-gnueabihf"
+    "triplet": "arm-linux-gnueabihf",
+    "sdkarch": "arm-linux-gnueabihf"
 }
 
 armhf_linaro48_defaults = {
-- 
2.15.1




More information about the elbe-devel mailing list