From d82ec729142e623be3e2ec8a18a0bd01ad8cf6e5 Mon Sep 17 00:00:00 2001 From: Slava Barinov Date: Wed, 17 Oct 2018 09:28:03 +0300 Subject: [PATCH] Add %env section support 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: Ida45e768781faf277438e3fb591d9bd931a09a1f Signed-off-by: Slava Barinov --- mic/imager/baseimager.py | 4 ++++ mic/kickstart/__init__.py | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/mic/imager/baseimager.py b/mic/imager/baseimager.py index f33138e..7df75cf 100644 --- a/mic/imager/baseimager.py +++ b/mic/imager/baseimager.py @@ -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": diff --git a/mic/kickstart/__init__.py b/mic/kickstart/__init__.py index 2eaa425..4cf9bd7 100755 --- a/mic/kickstart/__init__.py +++ b/mic/kickstart/__init__.py @@ -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) -- 2.7.4