[elbe-devel] [PATCH 07/13] elbeproject: implement build_sdk function

Manuel Traut manut at linutronix.de
Mon Jan 29 14:02:37 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.

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 | 54 +++++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 48 insertions(+), 6 deletions(-)

diff --git a/elbepack/elbeproject.py b/elbepack/elbeproject.py
index ba0cb40a..eec9376e 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):
@@ -81,6 +84,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 +146,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 +184,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 = []
@@ -209,10 +216,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))
@@ -228,8 +234,44 @@ 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"]
+
+        # 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
+        crosstoolchainpkg = "gcc-%s" % self.xml.defs["triplet"]
+        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()
-- 
2.15.1




More information about the elbe-devel mailing list