Introducing LunaBuild to the build flow (#36)
[lunaix-os.git] / lunaix-os / scripts / build-tools / lbuild / common.py
1 from lib.utils import join_path
2 import os
3
4 class BuildEnvironment:
5     def __init__(self, workspace_dir) -> None:
6         self.__config_provider = None
7         self.__sources = []
8         self.__headers = []
9         self.__inc_dir = []
10         self.__ws_dir = workspace_dir
11
12     def set_config_provider(self, provider):
13         self.__config_provider = provider
14     
15     def config_provider(self):
16         return self.__config_provider
17     
18     def add_sources(self, sources):
19         self.__sources += sources
20
21     def add_headers(self, sources):
22         for h in sources:
23             if not os.path.isdir(h):
24                 self.__headers.append(h)
25             else:
26                 self.__inc_dir.append(h)
27
28     def to_wspath(self, file):
29         path = join_path(self.__ws_dir, file)
30         return os.path.relpath(path, self.__ws_dir)
31     
32     def export(self, out_dir):
33         path = os.path.join(out_dir, "sources.list")
34         with open(path, "w") as f:
35             f.write("\n".join(self.__sources))
36
37         path = os.path.join(out_dir, "headers.list")
38         with open(path, "w") as f:
39             f.write("\n".join(self.__headers))
40
41         path = os.path.join(out_dir, "includes.list")
42         with open(path, "w") as f:
43             f.write("\n".join(self.__inc_dir))