integrate C/LDFLAGS into LunaBuild flow
[lunaix-os.git] / lunaix-os / scripts / build-tools / lbuild / common.py
index c559b0aab6bfd10dfc7d468153af216378efcd3a..a973760136bacc09dca68c6e56e4f47f0348c2af 100644 (file)
@@ -2,12 +2,15 @@ from lib.utils import join_path
 import os
 
 class BuildEnvironment:
 import os
 
 class BuildEnvironment:
-    def __init__(self, workspace_dir) -> None:
+    def __init__(self, workspace_dir, generator) -> None:
         self.__config_provider = None
         self.__sources = []
         self.__headers = []
         self.__inc_dir = []
         self.__ws_dir = workspace_dir
         self.__config_provider = None
         self.__sources = []
         self.__headers = []
         self.__inc_dir = []
         self.__ws_dir = workspace_dir
+        self.__ext_object = {}
+        self.__ext_function = {}
+        self.__generator = generator
 
     def set_config_provider(self, provider):
         self.__config_provider = provider
 
     def set_config_provider(self, provider):
         self.__config_provider = provider
@@ -29,15 +32,28 @@ class BuildEnvironment:
         path = join_path(self.__ws_dir, file)
         return os.path.relpath(path, self.__ws_dir)
     
         path = join_path(self.__ws_dir, file)
         return os.path.relpath(path, self.__ws_dir)
     
-    def export(self, out_dir):
-        path = os.path.join(out_dir, "sources.list")
-        with open(path, "w") as f:
-            f.write("\n".join(self.__sources))
-
-        path = os.path.join(out_dir, "headers.list")
-        with open(path, "w") as f:
-            f.write("\n".join(self.__headers))
-
-        path = os.path.join(out_dir, "includes.list")
-        with open(path, "w") as f:
-            f.write("\n".join(self.__inc_dir))
\ No newline at end of file
+    def export(self):
+        self.__generator.generate(self)
+
+    def get_object(self, key, _default=None):
+        return _default if key not in self.__ext_object else self.__ext_object[key]
+
+    def set_object(self, key, object):
+        self.__ext_object[key] = object
+
+    def srcs(self):
+        return list(self.__sources)
+    
+    def headers(self):
+        return list(self.__headers)
+    
+    def includes(self):
+        return list(self.__inc_dir)
+    
+    def add_external_func(self, function):
+        name = function.__name__
+        invk = lambda *args, **kwargs: function(self, *args, **kwargs)
+        self.__ext_function[name] = invk
+
+    def external_func_table(self):
+        return self.__ext_function
\ No newline at end of file