Add %env section support 98/191698/1
authorSlava Barinov <v.barinov@samsung.com>
Wed, 17 Oct 2018 06:28:03 +0000 (09:28 +0300)
committerDongkyun Son <dongkyun.s@samsung.com>
Mon, 22 Oct 2018 10:30:33 +0000 (19:30 +0900)
Kickstart file now may have section for environment variables setup.
Section should look like

 %env
 VARIABLE1=0x1000
 VARIABLE2="value"
 %end

This environment is set up for mic process and propagated into child processes
during firmware build.

Change-Id: I22cd45a4b3c2ff7c4c7d27abe1ef1936d4d350f9
Signed-off-by: Slava Barinov <v.barinov@samsung.com>
mic/imager/baseimager.py
mic/kickstart/__init__.py

index f33138e..7df75cf 100644 (file)
@@ -148,6 +148,10 @@ class BaseImageCreator(object):
 
         # No ks provided when called by convertor, so skip the dependency check
         if self.ks:
+            if hasattr(self.ks.handler, "env"):
+                for n, v in kickstart.get_env(self.ks):
+                    msger.debug("Setting up envvar %s = %s" % (n, v))
+                    os.environ[n] = v
             # If we have btrfs partition we need to check necessary tools
             for part in self.ks.handler.partition.partitions:
                 if part.fstype and part.fstype == "btrfs":
index 2eaa425..4cf9bd7 100755 (executable)
@@ -70,6 +70,22 @@ class AttachmentSection(kssections.Section):
     def handleHeader(self, lineno, args):
         kssections.Section.handleHeader(self, lineno, args)
 
+class EnvSection(kssections.Section):
+    sectionOpen = "%env"
+
+    def handleLine(self, line):
+        if not self.handler:
+            return
+
+        (h, s, t) = line.partition('#')
+        line = h.rstrip()
+        (n, s, v) = line.partition('=')
+        self.handler.env.append((n, v))
+
+    def handleHeader(self, lineno, args):
+        self.handler.env = []
+        kssections.Section.handleHeader(self, lineno, args)
+
 def apply_wrapper(func):
     def wrapper(*kargs, **kwargs):
         try:
@@ -119,6 +135,7 @@ def read_kickstart(path):
     ks = ksparser.KickstartParser(KSHandlers(), errorsAreFatal=False)
     ks.registerSection(PrepackageSection(ks.handler))
     ks.registerSection(AttachmentSection(ks.handler))
+    ks.registerSection(EnvSection(ks.handler))
 
     try:
         ks.readKickstart(path)
@@ -809,6 +826,9 @@ def convert_method_to_repo(ks):
 def get_attachment(ks, required=()):
     return ks.handler.attachment.packageList + list(required)
 
+def get_env(ks, required=()):
+    return ks.handler.env
+
 def get_pre_packages(ks, required=()):
     return ks.handler.prepackages.packageList + list(required)